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'> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | <title>Common Tasks</title> |
| 7 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 8 | <para> |
| 9 | This chapter presents several common tasks you perform when you |
| 10 | work with the Yocto Project Linux kernel. |
| 11 | These tasks include preparing your host development system for |
| 12 | kernel development, preparing a layer, modifying an existing recipe, |
| 13 | patching the kernel, configuring the kernel, iterative development, |
| 14 | working with your own sources, and incorporating out-of-tree modules. |
| 15 | <note> |
| 16 | The examples presented in this chapter work with the Yocto Project |
| 17 | 2.4 Release and forward. |
| 18 | </note> |
| 19 | </para> |
| 20 | |
| 21 | <section id='preparing-the-build-host-to-work-on-the-kernel'> |
| 22 | <title>Preparing the Build Host to Work on the Kernel</title> |
| 23 | |
| 24 | <para> |
| 25 | Before you can do any kernel development, you need to be |
| 26 | sure your build host is set up to use the Yocto Project. |
| 27 | For information on how to get set up, see the |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 28 | "<ulink url='&YOCTO_DOCS_DEV_URL;#setting-up-the-development-host-to-use-the-yocto-project'>Preparing the Build Host</ulink>" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 29 | section in the Yocto Project Development Tasks Manual. |
| 30 | Part of preparing the system is creating a local Git |
| 31 | repository of the |
| 32 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> |
| 33 | (<filename>poky</filename>) on your system. |
| 34 | Follow the steps in the |
| 35 | "<ulink url='&YOCTO_DOCS_DEV_URL;#cloning-the-poky-repository'>Cloning the <filename>poky</filename> Repository</ulink>" |
| 36 | section in the Yocto Project Development Tasks Manual to set up your |
| 37 | Source Directory. |
| 38 | <note> |
| 39 | Be sure you check out the appropriate development branch or |
| 40 | you create your local branch by checking out a specific tag |
| 41 | to get the desired version of Yocto Project. |
| 42 | See the |
| 43 | "<ulink url='&YOCTO_DOCS_DEV_URL;#checking-out-by-branch-in-poky'>Checking Out by Branch in Poky</ulink>" |
| 44 | and |
| 45 | "<ulink url='&YOCTO_DOCS_DEV_URL;#checkout-out-by-tag-in-poky'>Checking Out by Tag in Poky</ulink>" |
| 46 | sections in the Yocto Project Development Tasks Manual for more |
| 47 | information. |
| 48 | </note> |
| 49 | </para> |
| 50 | |
| 51 | <para> |
| 52 | Kernel development is best accomplished using |
| 53 | <ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'><filename>devtool</filename></ulink> |
| 54 | and not through traditional kernel workflow methods. |
| 55 | The remainder of this section provides information for both |
| 56 | scenarios. |
| 57 | </para> |
| 58 | |
| 59 | <section id='getting-ready-to-develop-using-devtool'> |
| 60 | <title>Getting Ready to Develop Using <filename>devtool</filename></title> |
| 61 | |
| 62 | <para> |
| 63 | Follow these steps to prepare to update the kernel image using |
| 64 | <filename>devtool</filename>. |
| 65 | Completing this procedure leaves you with a clean kernel image |
| 66 | and ready to make modifications as described in the |
| 67 | "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>" |
| 68 | section: |
| 69 | <orderedlist> |
| 70 | <listitem><para> |
| 71 | <emphasis>Initialize the BitBake Environment:</emphasis> |
| 72 | Before building an extensible SDK, you need to |
| 73 | initialize the BitBake build environment by sourcing the |
| 74 | build environment script |
| 75 | (i.e. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>): |
| 76 | <literallayout class='monospaced'> |
| 77 | $ cd ~/poky |
| 78 | $ source oe-init-build-env |
| 79 | </literallayout> |
| 80 | <note> |
| 81 | The previous commands assume the |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 82 | <ulink url='&YOCTO_DOCS_OM_URL;#source-repositories'>Source Repositories</ulink> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 83 | (i.e. <filename>poky</filename>) have been cloned |
| 84 | using Git and the local repository is named |
| 85 | "poky". |
| 86 | </note> |
| 87 | </para></listitem> |
| 88 | <listitem><para> |
| 89 | <emphasis>Prepare Your <filename>local.conf</filename> File:</emphasis> |
| 90 | By default, the |
| 91 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 92 | variable is set to "qemux86", which is fine if you are |
| 93 | building for the QEMU emulator in 32-bit mode. |
| 94 | However, if you are not, you need to set the |
| 95 | <filename>MACHINE</filename> variable appropriately in |
| 96 | your <filename>conf/local.conf</filename> file found in |
| 97 | the |
| 98 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink> |
| 99 | (i.e. <filename>~/poky/build</filename> in this |
| 100 | example).</para> |
| 101 | |
| 102 | <para>Also, since you are preparing to work on the |
| 103 | kernel image, you need to set the |
| 104 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink> |
| 105 | variable to include kernel modules.</para> |
| 106 | |
| 107 | <para>This example uses the default "qemux86" for the |
| 108 | <filename>MACHINE</filename> variable but needs to |
| 109 | add the "kernel-modules": |
| 110 | <literallayout class='monospaced'> |
| 111 | MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules" |
| 112 | </literallayout> |
| 113 | </para></listitem> |
| 114 | <listitem><para> |
| 115 | <emphasis>Create a Layer for Patches:</emphasis> |
| 116 | You need to create a layer to hold patches created |
| 117 | for the kernel image. |
| 118 | You can use the |
| 119 | <filename>bitbake-layers create-layer</filename> |
| 120 | command as follows: |
| 121 | <literallayout class='monospaced'> |
| 122 | $ cd ~/poky/build |
| 123 | $ bitbake-layers create-layer ../../meta-mylayer |
| 124 | NOTE: Starting bitbake server... |
| 125 | Add your new layer with 'bitbake-layers add-layer ../../meta-mylayer' |
| 126 | $ |
| 127 | </literallayout> |
| 128 | <note> |
| 129 | For background information on working with |
| 130 | common and BSP layers, see the |
| 131 | "<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>" |
| 132 | section in the Yocto Project Development Tasks |
| 133 | Manual and the |
| 134 | "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>" |
| 135 | section in the Yocto Project Board Support (BSP) |
| 136 | Developer's Guide, respectively. |
| 137 | For information on how to use the |
| 138 | <filename>bitbake-layers create-layer</filename> |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 139 | command to quickly set up a layer, see the |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 140 | "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</ulink>" |
| 141 | section in the Yocto Project Development Tasks |
| 142 | Manual. |
| 143 | </note> |
| 144 | </para></listitem> |
| 145 | <listitem><para> |
| 146 | <emphasis>Inform the BitBake Build Environment About |
| 147 | Your Layer:</emphasis> |
| 148 | As directed when you created your layer, you need to |
| 149 | add the layer to the |
| 150 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink> |
| 151 | variable in the <filename>bblayers.conf</filename> file |
| 152 | as follows: |
| 153 | <literallayout class='monospaced'> |
| 154 | $ cd ~/poky/build |
| 155 | $ bitbake-layers add-layer ../../meta-mylayer |
| 156 | NOTE: Starting bitbake server... |
| 157 | $ |
| 158 | </literallayout> |
| 159 | </para></listitem> |
| 160 | <listitem><para> |
| 161 | <emphasis>Build the Extensible SDK:</emphasis> |
| 162 | Use BitBake to build the extensible SDK specifically |
| 163 | for use with images to be run using QEMU: |
| 164 | <literallayout class='monospaced'> |
| 165 | $ cd ~/poky/build |
| 166 | $ bitbake core-image-minimal -c populate_sdk_ext |
| 167 | </literallayout> |
| 168 | Once the build finishes, you can find the SDK installer |
| 169 | file (i.e. <filename>*.sh</filename> file) in the |
| 170 | following directory: |
| 171 | <literallayout class='monospaced'> |
| 172 | ~/poky/build/tmp/deploy/sdk |
| 173 | </literallayout> |
| 174 | For this example, the installer file is named |
| 175 | <filename>poky-glibc-x86_64-core-image-minimal-i586-toolchain-ext-&DISTRO;.sh</filename> |
| 176 | </para></listitem> |
| 177 | <listitem><para> |
| 178 | <emphasis>Install the Extensible SDK:</emphasis> |
| 179 | Use the following command to install the SDK. |
| 180 | For this example, install the SDK in the default |
| 181 | <filename>~/poky_sdk</filename> directory: |
| 182 | <literallayout class='monospaced'> |
| 183 | $ cd ~/poky/build/tmp/deploy/sdk |
| 184 | $ ./poky-glibc-x86_64-core-image-minimal-i586-toolchain-ext-&DISTRO;.sh |
| 185 | Poky (Yocto Project Reference Distro) Extensible SDK installer version &DISTRO; |
| 186 | ============================================================================ |
| 187 | Enter target directory for SDK (default: ~/poky_sdk): |
| 188 | You are about to install the SDK to "/home/scottrif/poky_sdk". Proceed[Y/n]? Y |
| 189 | Extracting SDK......................................done |
| 190 | Setting it up... |
| 191 | Extracting buildtools... |
| 192 | Preparing build system... |
| 193 | Parsing recipes: 100% |#################################################################| Time: 0:00:52 |
| 194 | Initializing tasks: 100% |############## ###############################################| Time: 0:00:04 |
| 195 | Checking sstate mirror object availability: 100% |######################################| Time: 0:00:00 |
| 196 | Parsing recipes: 100% |#################################################################| Time: 0:00:33 |
| 197 | Initializing tasks: 100% |##############################################################| Time: 0:00:00 |
| 198 | done |
| 199 | SDK has been successfully set up and is ready to be used. |
| 200 | Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g. |
| 201 | $ . /home/scottrif/poky_sdk/environment-setup-i586-poky-linux |
| 202 | </literallayout> |
| 203 | </para></listitem> |
| 204 | <listitem><para id='setting-up-the-esdk-terminal'> |
| 205 | <emphasis>Set Up a New Terminal to Work With the |
| 206 | Extensible SDK:</emphasis> |
| 207 | You must set up a new terminal to work with the SDK. |
| 208 | You cannot use the same BitBake shell used to build the |
| 209 | installer.</para> |
| 210 | |
| 211 | <para>After opening a new shell, run the SDK environment |
| 212 | setup script as directed by the output from installing |
| 213 | the SDK: |
| 214 | <literallayout class='monospaced'> |
| 215 | $ source ~/poky_sdk/environment-setup-i586-poky-linux |
| 216 | "SDK environment now set up; additionally you may now run devtool to perform development tasks. |
| 217 | Run devtool --help for further details. |
| 218 | </literallayout> |
| 219 | <note> |
| 220 | If you get a warning about attempting to use the |
| 221 | extensible SDK in an environment set up to run |
| 222 | BitBake, you did not use a new shell. |
| 223 | </note> |
| 224 | </para></listitem> |
| 225 | <listitem><para> |
| 226 | <emphasis>Build the Clean Image:</emphasis> |
| 227 | The final step in preparing to work on the kernel is to |
| 228 | build an initial image using |
| 229 | <filename>devtool</filename> in the new terminal you |
| 230 | just set up and initialized for SDK work: |
| 231 | <literallayout class='monospaced'> |
| 232 | $ devtool build-image |
| 233 | Parsing recipes: 100% |##########################################| Time: 0:00:05 |
| 234 | Parsing of 830 .bb files complete (0 cached, 830 parsed). 1299 targets, 47 skipped, 0 masked, 0 errors. |
| 235 | WARNING: No packages to add, building image core-image-minimal unmodified |
| 236 | Loading cache: 100% |############################################| Time: 0:00:00 |
| 237 | Loaded 1299 entries from dependency cache. |
| 238 | NOTE: Resolving any missing task queue dependencies |
| 239 | Initializing tasks: 100% |#######################################| Time: 0:00:07 |
| 240 | Checking sstate mirror object availability: 100% |###############| Time: 0:00:00 |
| 241 | NOTE: Executing SetScene Tasks |
| 242 | NOTE: Executing RunQueue Tasks |
| 243 | NOTE: Tasks Summary: Attempted 2866 tasks of which 2604 didn't need to be rerun and all succeeded. |
| 244 | NOTE: Successfully built core-image-minimal. You can find output files in /home/scottrif/poky_sdk/tmp/deploy/images/qemux86 |
| 245 | </literallayout> |
| 246 | If you were building for actual hardware and not for |
| 247 | emulation, you could flash the image to a USB stick |
| 248 | on <filename>/dev/sdd</filename> and boot your device. |
| 249 | For an example that uses a Minnowboard, see the |
| 250 | <ulink url='https://wiki.yoctoproject.org/wiki/TipsAndTricks/KernelDevelopmentWithEsdk'>TipsAndTricks/KernelDevelopmentWithEsdk</ulink> |
| 251 | Wiki page. |
| 252 | </para></listitem> |
| 253 | </orderedlist> |
| 254 | </para> |
| 255 | |
| 256 | <para> |
| 257 | At this point you have set up to start making modifications to |
| 258 | the kernel by using the extensible SDK. |
| 259 | For a continued example, see the |
| 260 | "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>" |
| 261 | section. |
| 262 | </para> |
| 263 | </section> |
| 264 | |
| 265 | <section id='getting-ready-for-traditional-kernel-development'> |
| 266 | <title>Getting Ready for Traditional Kernel Development</title> |
| 267 | |
| 268 | <para> |
| 269 | Getting ready for traditional kernel development using the Yocto |
| 270 | Project involves many of the same steps as described in the |
| 271 | previous section. |
| 272 | However, you need to establish a local copy of the kernel source |
| 273 | since you will be editing these files. |
| 274 | </para> |
| 275 | |
| 276 | <para> |
| 277 | Follow these steps to prepare to update the kernel image using |
| 278 | traditional kernel development flow with the Yocto Project. |
| 279 | Completing this procedure leaves you ready to make modifications |
| 280 | to the kernel source as described in the |
| 281 | "<link linkend='using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</link>" |
| 282 | section: |
| 283 | <orderedlist> |
| 284 | <listitem><para> |
| 285 | <emphasis>Initialize the BitBake Environment:</emphasis> |
| 286 | Before you can do anything using BitBake, you need to |
| 287 | initialize the BitBake build environment by sourcing the |
| 288 | build environment script |
| 289 | (i.e. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>). |
| 290 | Also, for this example, be sure that the local branch |
| 291 | you have checked out for <filename>poky</filename> is |
| 292 | the Yocto Project &DISTRO_NAME; branch. |
| 293 | If you need to checkout out the &DISTRO_NAME; branch, |
| 294 | see the |
| 295 | "<ulink url='&YOCTO_DOCS_DEV_URL;#checking-out-by-branch-in-poky'>Checking out by Branch in Poky</ulink>" |
| 296 | section in the Yocto Project Development Tasks Manual. |
| 297 | <literallayout class='monospaced'> |
| 298 | $ cd ~/poky |
| 299 | $ git branch |
| 300 | master |
| 301 | * &DISTRO_NAME; |
| 302 | $ source oe-init-build-env |
| 303 | </literallayout> |
| 304 | <note> |
| 305 | The previous commands assume the |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 306 | <ulink url='&YOCTO_DOCS_OM_URL;#source-repositories'>Source Repositories</ulink> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 307 | (i.e. <filename>poky</filename>) have been cloned |
| 308 | using Git and the local repository is named |
| 309 | "poky". |
| 310 | </note> |
| 311 | </para></listitem> |
| 312 | <listitem><para> |
| 313 | <emphasis>Prepare Your <filename>local.conf</filename> |
| 314 | File:</emphasis> |
| 315 | By default, the |
| 316 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 317 | variable is set to "qemux86", which is fine if you are |
| 318 | building for the QEMU emulator in 32-bit mode. |
| 319 | However, if you are not, you need to set the |
| 320 | <filename>MACHINE</filename> variable appropriately in |
| 321 | your <filename>conf/local.conf</filename> file found |
| 322 | in the |
| 323 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink> |
| 324 | (i.e. <filename>~/poky/build</filename> in this |
| 325 | example).</para> |
| 326 | |
| 327 | <para>Also, since you are preparing to work on the |
| 328 | kernel image, you need to set the |
| 329 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink> |
| 330 | variable to include kernel modules.</para> |
| 331 | |
| 332 | <para>This example uses the default "qemux86" for the |
| 333 | <filename>MACHINE</filename> variable but needs to |
| 334 | add the "kernel-modules": |
| 335 | <literallayout class='monospaced'> |
| 336 | MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules" |
| 337 | </literallayout> |
| 338 | </para></listitem> |
| 339 | <listitem><para> |
| 340 | <emphasis>Create a Layer for Patches:</emphasis> |
| 341 | You need to create a layer to hold patches created |
| 342 | for the kernel image. |
| 343 | You can use the |
| 344 | <filename>bitbake-layers create-layer</filename> |
| 345 | command as follows: |
| 346 | <literallayout class='monospaced'> |
| 347 | $ cd ~/poky/build |
| 348 | $ bitbake-layers create-layer ../../meta-mylayer |
| 349 | NOTE: Starting bitbake server... |
| 350 | Add your new layer with 'bitbake-layers add-layer ../../meta-mylayer' |
| 351 | </literallayout> |
| 352 | <note> |
| 353 | For background information on working with |
| 354 | common and BSP layers, see the |
| 355 | "<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>" |
| 356 | section in the Yocto Project Development Tasks |
| 357 | Manual and the |
| 358 | "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>" |
| 359 | section in the Yocto Project Board Support (BSP) |
| 360 | Developer's Guide, respectively. |
| 361 | For information on how to use the |
| 362 | <filename>bitbake-layers create-layer</filename> |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 363 | command to quickly set up a layer, see the |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 364 | "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</ulink>" |
| 365 | section in the Yocto Project Development Tasks |
| 366 | Manual. |
| 367 | </note> |
| 368 | </para></listitem> |
| 369 | <listitem><para> |
| 370 | <emphasis>Inform the BitBake Build Environment About |
| 371 | Your Layer:</emphasis> |
| 372 | As directed when you created your layer, you need to add |
| 373 | the layer to the |
| 374 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink> |
| 375 | variable in the <filename>bblayers.conf</filename> file |
| 376 | as follows: |
| 377 | <literallayout class='monospaced'> |
| 378 | $ cd ~/poky/build |
| 379 | $ bitbake-layers add-layer ../../meta-mylayer |
| 380 | NOTE: Starting bitbake server ... |
| 381 | $ |
| 382 | </literallayout> |
| 383 | </para></listitem> |
| 384 | <listitem><para> |
| 385 | <emphasis>Create a Local Copy of the Kernel Git |
| 386 | Repository:</emphasis> |
| 387 | You can find Git repositories of supported Yocto Project |
| 388 | kernels organized under "Yocto Linux Kernel" in the |
| 389 | Yocto Project Source Repositories at |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 390 | <ulink url='&YOCTO_GIT_URL;'></ulink>. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 391 | </para> |
| 392 | |
| 393 | <para> |
| 394 | For simplicity, it is recommended that you create your |
| 395 | copy of the kernel Git repository outside of the |
| 396 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>, |
| 397 | which is usually named <filename>poky</filename>. |
| 398 | Also, be sure you are in the |
| 399 | <filename>standard/base</filename> branch. |
| 400 | </para> |
| 401 | |
| 402 | <para> |
| 403 | The following commands show how to create a local copy |
| 404 | of the <filename>linux-yocto-4.12</filename> kernel and |
| 405 | be in the <filename>standard/base</filename> branch. |
| 406 | <note> |
| 407 | The <filename>linux-yocto-4.12</filename> kernel |
| 408 | can be used with the Yocto Project 2.4 release |
| 409 | and forward. |
| 410 | You cannot use the |
| 411 | <filename>linux-yocto-4.12</filename> kernel with |
| 412 | releases prior to Yocto Project 2.4: |
| 413 | </note> |
| 414 | <literallayout class='monospaced'> |
| 415 | $ cd ~ |
| 416 | $ git clone git://git.yoctoproject.org/linux-yocto-4.12 --branch standard/base |
| 417 | Cloning into 'linux-yocto-4.12'... |
| 418 | remote: Counting objects: 6097195, done. |
| 419 | remote: Compressing objects: 100% (901026/901026), done. |
| 420 | remote: Total 6097195 (delta 5152604), reused 6096847 (delta 5152256) |
| 421 | Receiving objects: 100% (6097195/6097195), 1.24 GiB | 7.81 MiB/s, done. |
| 422 | Resolving deltas: 100% (5152604/5152604), done. |
| 423 | Checking connectivity... done. |
| 424 | Checking out files: 100% (59846/59846), done. |
| 425 | </literallayout> |
| 426 | </para></listitem> |
| 427 | <listitem><para> |
| 428 | <emphasis>Create a Local Copy of the Kernel Cache Git |
| 429 | Repository:</emphasis> |
| 430 | For simplicity, it is recommended that you create your |
| 431 | copy of the kernel cache Git repository outside of the |
| 432 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>, |
| 433 | which is usually named <filename>poky</filename>. |
| 434 | Also, for this example, be sure you are in the |
| 435 | <filename>yocto-4.12</filename> branch. |
| 436 | </para> |
| 437 | |
| 438 | <para> |
| 439 | The following commands show how to create a local copy |
| 440 | of the <filename>yocto-kernel-cache</filename> and |
| 441 | be in the <filename>yocto-4.12</filename> branch: |
| 442 | <literallayout class='monospaced'> |
| 443 | $ cd ~ |
| 444 | $ git clone git://git.yoctoproject.org/yocto-kernel-cache --branch yocto-4.12 |
| 445 | Cloning into 'yocto-kernel-cache'... |
| 446 | remote: Counting objects: 22639, done. |
| 447 | remote: Compressing objects: 100% (9761/9761), done. |
| 448 | remote: Total 22639 (delta 12400), reused 22586 (delta 12347) |
| 449 | Receiving objects: 100% (22639/22639), 22.34 MiB | 6.27 MiB/s, done. |
| 450 | Resolving deltas: 100% (12400/12400), done. |
| 451 | Checking connectivity... done. |
| 452 | </literallayout> |
| 453 | </para></listitem> |
| 454 | </orderedlist> |
| 455 | </para> |
| 456 | |
| 457 | <para> |
| 458 | At this point, you are ready to start making modifications to |
| 459 | the kernel using traditional kernel development steps. |
| 460 | For a continued example, see the |
| 461 | "<link linkend='using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</link>" |
| 462 | section. |
| 463 | </para> |
| 464 | </section> |
| 465 | </section> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 466 | |
| 467 | <section id='creating-and-preparing-a-layer'> |
| 468 | <title>Creating and Preparing a Layer</title> |
| 469 | |
| 470 | <para> |
| 471 | If you are going to be modifying kernel recipes, it is recommended |
| 472 | that you create and prepare your own layer in which to do your |
| 473 | work. |
| 474 | Your layer contains its own |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 475 | <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink> |
| 476 | append files (<filename>.bbappend</filename>) and provides a |
| 477 | convenient mechanism to create your own recipe files |
| 478 | (<filename>.bb</filename>) as well as store and use kernel |
| 479 | patch files. |
| 480 | For background information on working with layers, see the |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 481 | "<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 482 | section in the Yocto Project Development Tasks Manual. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 483 | <note><title>Tip</title> |
| 484 | The Yocto Project comes with many tools that simplify |
| 485 | tasks you need to perform. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 486 | One such tool is the |
| 487 | <filename>bitbake-layers create-layer</filename> |
| 488 | command, which simplifies creating a new layer. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 489 | See the |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 490 | "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</ulink>" |
| 491 | section in the Yocto Project Development Tasks Manual for |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 492 | information on how to use this script to quick set up a |
| 493 | new layer. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 494 | </note> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 495 | </para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 496 | |
| 497 | <para> |
| 498 | To better understand the layer you create for kernel development, |
| 499 | the following section describes how to create a layer |
| 500 | without the aid of tools. |
| 501 | These steps assume creation of a layer named |
| 502 | <filename>mylayer</filename> in your home directory: |
| 503 | <orderedlist> |
| 504 | <listitem><para> |
| 505 | <emphasis>Create Structure</emphasis>: |
| 506 | Create the layer's structure: |
| 507 | <literallayout class='monospaced'> |
| 508 | $ cd $HOME |
| 509 | $ mkdir meta-mylayer |
| 510 | $ mkdir meta-mylayer/conf |
| 511 | $ mkdir meta-mylayer/recipes-kernel |
| 512 | $ mkdir meta-mylayer/recipes-kernel/linux |
| 513 | $ mkdir meta-mylayer/recipes-kernel/linux/linux-yocto |
| 514 | </literallayout> |
| 515 | The <filename>conf</filename> directory holds your |
| 516 | configuration files, while the |
| 517 | <filename>recipes-kernel</filename> directory holds your |
| 518 | append file and eventual patch files. |
| 519 | </para></listitem> |
| 520 | <listitem><para> |
| 521 | <emphasis>Create the Layer Configuration File</emphasis>: |
| 522 | Move to the <filename>meta-mylayer/conf</filename> |
| 523 | directory and create the <filename>layer.conf</filename> |
| 524 | file as follows: |
| 525 | <literallayout class='monospaced'> |
| 526 | # We have a conf and classes directory, add to BBPATH |
| 527 | BBPATH .= ":${LAYERDIR}" |
| 528 | |
| 529 | # We have recipes-* directories, add to BBFILES |
| 530 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ |
| 531 | ${LAYERDIR}/recipes-*/*/*.bbappend" |
| 532 | |
| 533 | BBFILE_COLLECTIONS += "mylayer" |
| 534 | BBFILE_PATTERN_mylayer = "^${LAYERDIR}/" |
| 535 | BBFILE_PRIORITY_mylayer = "5" |
| 536 | </literallayout> |
| 537 | Notice <filename>mylayer</filename> as part of the last |
| 538 | three statements. |
| 539 | </para></listitem> |
| 540 | <listitem><para> |
| 541 | <emphasis>Create the Kernel Recipe Append File</emphasis>: |
| 542 | Move to the |
| 543 | <filename>meta-mylayer/recipes-kernel/linux</filename> |
| 544 | directory and create the kernel's append file. |
| 545 | This example uses the |
| 546 | <filename>linux-yocto-4.12</filename> kernel. |
| 547 | Thus, the name of the append file is |
| 548 | <filename>linux-yocto_4.12.bbappend</filename>: |
| 549 | <literallayout class='monospaced'> |
| 550 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
| 551 | |
| 552 | SRC_URI_append += "file://<replaceable>patch-file-one</replaceable>" |
| 553 | SRC_URI_append += "file://<replaceable>patch-file-two</replaceable>" |
| 554 | SRC_URI_append += "file://<replaceable>patch-file-three</replaceable>" |
| 555 | </literallayout> |
| 556 | The |
| 557 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> |
| 558 | and |
| 559 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 560 | statements enable the OpenEmbedded build system to find |
| 561 | patch files. |
| 562 | For more information on using append files, see the |
| 563 | "<ulink url='&YOCTO_DOCS_DEV_URL;#using-bbappend-files'>Using .bbappend Files in Your Layer</ulink>" |
| 564 | section in the Yocto Project Development Tasks Manual. |
| 565 | </para></listitem> |
| 566 | </orderedlist> |
| 567 | </para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 568 | </section> |
| 569 | |
| 570 | <section id='modifying-an-existing-recipe'> |
| 571 | <title>Modifying an Existing Recipe</title> |
| 572 | |
| 573 | <para> |
| 574 | In many cases, you can customize an existing linux-yocto recipe to |
| 575 | meet the needs of your project. |
| 576 | Each release of the Yocto Project provides a few Linux |
| 577 | kernel recipes from which you can choose. |
| 578 | These are located in the |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 579 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 580 | in <filename>meta/recipes-kernel/linux</filename>. |
| 581 | </para> |
| 582 | |
| 583 | <para> |
| 584 | Modifying an existing recipe can consist of the following: |
| 585 | <itemizedlist> |
| 586 | <listitem><para>Creating the append file</para></listitem> |
| 587 | <listitem><para>Applying patches</para></listitem> |
| 588 | <listitem><para>Changing the configuration</para></listitem> |
| 589 | </itemizedlist> |
| 590 | </para> |
| 591 | |
| 592 | <para> |
| 593 | Before modifying an existing recipe, be sure that you have created |
| 594 | a minimal, custom layer from which you can work. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 595 | See the |
| 596 | "<link linkend='creating-and-preparing-a-layer'>Creating and Preparing a Layer</link>" |
| 597 | section for information. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 598 | </para> |
| 599 | |
| 600 | <section id='creating-the-append-file'> |
| 601 | <title>Creating the Append File</title> |
| 602 | |
| 603 | <para> |
| 604 | You create this file in your custom layer. |
| 605 | You also name it accordingly based on the linux-yocto recipe |
| 606 | you are using. |
| 607 | For example, if you are modifying the |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 608 | <filename>meta/recipes-kernel/linux/linux-yocto_4.12.bb</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 609 | recipe, the append file will typically be located as follows |
| 610 | within your custom layer: |
| 611 | <literallayout class='monospaced'> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 612 | <replaceable>your-layer</replaceable>/recipes-kernel/linux/linux-yocto_4.12.bbappend |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 613 | </literallayout> |
| 614 | The append file should initially extend the |
| 615 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> |
| 616 | search path by prepending the directory that contains your |
| 617 | files to the |
| 618 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> |
| 619 | variable as follows: |
| 620 | <literallayout class='monospaced'> |
| 621 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
| 622 | </literallayout> |
| 623 | 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> |
| 624 | expands to "linux-yocto" in the current directory for this |
| 625 | example. |
| 626 | If you add any new files that modify the kernel recipe and you |
| 627 | have extended <filename>FILESPATH</filename> as |
| 628 | described above, you must place the files in your layer in the |
| 629 | following area: |
| 630 | <literallayout class='monospaced'> |
| 631 | <replaceable>your-layer</replaceable>/recipes-kernel/linux/linux-yocto/ |
| 632 | </literallayout> |
| 633 | <note>If you are working on a new machine Board Support Package |
| 634 | (BSP), be sure to refer to the |
| 635 | <ulink url='&YOCTO_DOCS_BSP_URL;'>Yocto Project Board Support Package (BSP) Developer's Guide</ulink>. |
| 636 | </note> |
| 637 | </para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 638 | |
| 639 | <para> |
| 640 | As an example, consider the following append file |
| 641 | used by the BSPs in <filename>meta-yocto-bsp</filename>: |
| 642 | <literallayout class='monospaced'> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 643 | meta-yocto-bsp/recipes-kernel/linux/linux-yocto_4.12.bbappend |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 644 | </literallayout> |
| 645 | The following listing shows the file. |
| 646 | Be aware that the actual commit ID strings in this |
| 647 | example listing might be different than the actual strings |
| 648 | in the file from the <filename>meta-yocto-bsp</filename> |
| 649 | layer upstream. |
| 650 | <literallayout class='monospaced'> |
| 651 | KBRANCH_genericx86 = "standard/base" |
| 652 | KBRANCH_genericx86-64 = "standard/base" |
| 653 | |
| 654 | KMACHINE_genericx86 ?= "common-pc" |
| 655 | KMACHINE_genericx86-64 ?= "common-pc-64" |
| 656 | KBRANCH_edgerouter = "standard/edgerouter" |
| 657 | KBRANCH_beaglebone = "standard/beaglebone" |
| 658 | KBRANCH_mpc8315e-rdb = "standard/fsl-mpc8315e-rdb" |
| 659 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 660 | SRCREV_machine_genericx86 ?= "d09f2ce584d60ecb7890550c22a80c48b83c2e19" |
| 661 | SRCREV_machine_genericx86-64 ?= "d09f2ce584d60ecb7890550c22a80c48b83c2e19" |
| 662 | SRCREV_machine_edgerouter ?= "b5c8cfda2dfe296410d51e131289fb09c69e1e7d" |
| 663 | SRCREV_machine_beaglebone ?= "b5c8cfda2dfe296410d51e131289fb09c69e1e7d" |
| 664 | SRCREV_machine_mpc8315e-rdb ?= "2d1d010240846d7bff15d1fcc0cb6eb8a22fc78a" |
| 665 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 666 | |
| 667 | COMPATIBLE_MACHINE_genericx86 = "genericx86" |
| 668 | COMPATIBLE_MACHINE_genericx86-64 = "genericx86-64" |
| 669 | COMPATIBLE_MACHINE_edgerouter = "edgerouter" |
| 670 | COMPATIBLE_MACHINE_beaglebone = "beaglebone" |
| 671 | COMPATIBLE_MACHINE_mpc8315e-rdb = "mpc8315e-rdb" |
| 672 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 673 | LINUX_VERSION_genericx86 = "4.12.7" |
| 674 | LINUX_VERSION_genericx86-64 = "4.12.7" |
| 675 | LINUX_VERSION_edgerouter = "4.12.10" |
| 676 | LINUX_VERSION_beaglebone = "4.12.10" |
| 677 | LINUX_VERSION_mpc8315e-rdb = "4.12.10" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 678 | </literallayout> |
| 679 | This append file contains statements used to support |
| 680 | several BSPs that ship with the Yocto Project. |
| 681 | The file defines machines using the |
| 682 | <ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'><filename>COMPATIBLE_MACHINE</filename></ulink> |
| 683 | variable and uses the |
| 684 | <ulink url='&YOCTO_DOCS_REF_URL;#var-KMACHINE'><filename>KMACHINE</filename></ulink> |
| 685 | variable to ensure the machine name used by the OpenEmbedded |
| 686 | build system maps to the machine name used by the Linux Yocto |
| 687 | kernel. |
| 688 | The file also uses the optional |
| 689 | <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'><filename>KBRANCH</filename></ulink> |
| 690 | variable to ensure the build process uses the |
| 691 | appropriate kernel branch. |
| 692 | </para> |
| 693 | |
| 694 | <para> |
| 695 | Although this particular example does not use it, the |
| 696 | <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_FEATURES'><filename>KERNEL_FEATURES</filename></ulink> |
| 697 | variable could be used to enable features specific to |
| 698 | the kernel. |
| 699 | The append file points to specific commits in the |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 700 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 701 | Git repository and the <filename>meta</filename> Git repository |
| 702 | branches to identify the exact kernel needed to build the |
| 703 | BSP. |
| 704 | </para> |
| 705 | |
| 706 | <para> |
| 707 | One thing missing in this particular BSP, which you will |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 708 | typically need when developing a BSP, is the kernel |
| 709 | configuration file (<filename>.config</filename>) for your BSP. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 710 | When developing a BSP, you probably have a kernel configuration |
| 711 | file or a set of kernel configuration files that, when taken |
| 712 | together, define the kernel configuration for your BSP. |
| 713 | You can accomplish this definition by putting the configurations |
| 714 | in a file or a set of files inside a directory located at the |
| 715 | same level as your kernel's append file and having the same |
| 716 | name as the kernel's main recipe file. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 717 | With all these conditions met, simply reference those files in |
| 718 | the |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 719 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 720 | statement in the append file. |
| 721 | </para> |
| 722 | |
| 723 | <para> |
| 724 | For example, suppose you had some configuration options |
| 725 | in a file called <filename>network_configs.cfg</filename>. |
| 726 | You can place that file inside a directory named |
| 727 | <filename>linux-yocto</filename> and then add |
| 728 | a <filename>SRC_URI</filename> statement such as the |
| 729 | following to the append file. |
| 730 | When the OpenEmbedded build system builds the kernel, the |
| 731 | configuration options are picked up and applied. |
| 732 | <literallayout class='monospaced'> |
| 733 | SRC_URI += "file://network_configs.cfg" |
| 734 | </literallayout> |
| 735 | </para> |
| 736 | |
| 737 | <para> |
| 738 | To group related configurations into multiple files, you |
| 739 | perform a similar procedure. |
| 740 | Here is an example that groups separate configurations |
| 741 | specifically for Ethernet and graphics into their own |
| 742 | files and adds the configurations by using a |
| 743 | <filename>SRC_URI</filename> statement like the following |
| 744 | in your append file: |
| 745 | <literallayout class='monospaced'> |
| 746 | SRC_URI += "file://myconfig.cfg \ |
| 747 | file://eth.cfg \ |
| 748 | file://gfx.cfg" |
| 749 | </literallayout> |
| 750 | </para> |
| 751 | |
| 752 | <para> |
| 753 | Another variable you can use in your kernel recipe append |
| 754 | file is the |
| 755 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> |
| 756 | variable. |
| 757 | When you use this statement, you are extending the locations |
| 758 | used by the OpenEmbedded system to look for files and |
| 759 | patches as the recipe is processed. |
| 760 | </para> |
| 761 | |
| 762 | <note> |
| 763 | <para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 764 | Other methods exist to accomplish grouping and defining |
| 765 | configuration options. |
| 766 | For example, if you are working with a local clone of the |
| 767 | kernel repository, you could checkout the kernel's |
| 768 | <filename>meta</filename> branch, make your changes, and |
| 769 | then push the changes to the local bare clone of the |
| 770 | kernel. |
| 771 | The result is that you directly add configuration options |
| 772 | to the <filename>meta</filename> branch for your BSP. |
| 773 | The configuration options will likely end up in that |
| 774 | location anyway if the BSP gets added to the Yocto Project. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 775 | </para> |
| 776 | |
| 777 | <para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 778 | In general, however, the Yocto Project maintainers take |
| 779 | care of moving the <filename>SRC_URI</filename>-specified |
| 780 | configuration options to the kernel's |
| 781 | <filename>meta</filename> branch. |
| 782 | Not only is it easier for BSP developers to not have to |
| 783 | worry about putting those configurations in the branch, |
| 784 | but having the maintainers do it allows them to apply |
| 785 | 'global' knowledge about the kinds of common configuration |
| 786 | options multiple BSPs in the tree are typically using. |
| 787 | This allows for promotion of common configurations into |
| 788 | common features. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 789 | </para> |
| 790 | </note> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 791 | </section> |
| 792 | |
| 793 | <section id='applying-patches'> |
| 794 | <title>Applying Patches</title> |
| 795 | |
| 796 | <para> |
| 797 | If you have a single patch or a small series of patches |
| 798 | that you want to apply to the Linux kernel source, you |
| 799 | can do so just as you would with any other recipe. |
| 800 | You first copy the patches to the path added to |
| 801 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> |
| 802 | in your <filename>.bbappend</filename> file as described in |
| 803 | the previous section, and then reference them in |
| 804 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 805 | statements. |
| 806 | </para> |
| 807 | |
| 808 | <para> |
| 809 | For example, you can apply a three-patch series by adding the |
| 810 | following lines to your linux-yocto |
| 811 | <filename>.bbappend</filename> file in your layer: |
| 812 | <literallayout class='monospaced'> |
| 813 | SRC_URI += "file://0001-first-change.patch" |
| 814 | SRC_URI += "file://0002-second-change.patch" |
| 815 | SRC_URI += "file://0003-third-change.patch" |
| 816 | </literallayout> |
| 817 | The next time you run BitBake to build the Linux kernel, |
| 818 | BitBake detects the change in the recipe and fetches and |
| 819 | applies the patches before building the kernel. |
| 820 | </para> |
| 821 | |
| 822 | <para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 823 | For a detailed example showing how to patch the kernel using |
| 824 | <filename>devtool</filename>, see the |
| 825 | "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>" |
| 826 | and |
| 827 | "<link linkend='using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</link>" |
| 828 | sections. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 829 | </para> |
| 830 | </section> |
| 831 | |
| 832 | <section id='changing-the-configuration'> |
| 833 | <title>Changing the Configuration</title> |
| 834 | |
| 835 | <para> |
| 836 | You can make wholesale or incremental changes to the final |
| 837 | <filename>.config</filename> file used for the eventual |
| 838 | Linux kernel configuration by including a |
| 839 | <filename>defconfig</filename> file and by specifying |
| 840 | configuration fragments in the |
| 841 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 842 | to be applied to that file. |
| 843 | </para> |
| 844 | |
| 845 | <para> |
| 846 | If you have a complete, working Linux kernel |
| 847 | <filename>.config</filename> |
| 848 | file you want to use for the configuration, as before, copy |
| 849 | that file to the appropriate <filename>${PN}</filename> |
| 850 | directory in your layer's |
| 851 | <filename>recipes-kernel/linux</filename> directory, |
| 852 | and rename the copied file to "defconfig". |
| 853 | Then, add the following lines to the linux-yocto |
| 854 | <filename>.bbappend</filename> file in your layer: |
| 855 | <literallayout class='monospaced'> |
| 856 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
| 857 | SRC_URI += "file://defconfig" |
| 858 | </literallayout> |
| 859 | The <filename>SRC_URI</filename> tells the build system how to |
| 860 | search for the file, while the |
| 861 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> |
| 862 | extends the |
| 863 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> |
| 864 | variable (search directories) to include the |
| 865 | <filename>${PN}</filename> directory you created to hold the |
| 866 | configuration changes. |
| 867 | </para> |
| 868 | |
| 869 | <note> |
| 870 | The build system applies the configurations from the |
| 871 | <filename>defconfig</filename> file before applying any |
| 872 | subsequent configuration fragments. |
| 873 | The final kernel configuration is a combination of the |
| 874 | configurations in the <filename>defconfig</filename> file and |
| 875 | any configuration fragments you provide. |
| 876 | You need to realize that if you have any configuration |
| 877 | fragments, the build system applies these on top of and |
| 878 | after applying the existing <filename>defconfig</filename> |
| 879 | file configurations. |
| 880 | </note> |
| 881 | |
| 882 | <para> |
| 883 | Generally speaking, the preferred approach is to determine the |
| 884 | incremental change you want to make and add that as a |
| 885 | configuration fragment. |
| 886 | For example, if you want to add support for a basic serial |
| 887 | console, create a file named <filename>8250.cfg</filename> in |
| 888 | the <filename>${PN}</filename> directory with the following |
| 889 | content (without indentation): |
| 890 | <literallayout class='monospaced'> |
| 891 | CONFIG_SERIAL_8250=y |
| 892 | CONFIG_SERIAL_8250_CONSOLE=y |
| 893 | CONFIG_SERIAL_8250_PCI=y |
| 894 | CONFIG_SERIAL_8250_NR_UARTS=4 |
| 895 | CONFIG_SERIAL_8250_RUNTIME_UARTS=4 |
| 896 | CONFIG_SERIAL_CORE=y |
| 897 | CONFIG_SERIAL_CORE_CONSOLE=y |
| 898 | </literallayout> |
| 899 | Next, include this configuration fragment and extend the |
| 900 | <filename>FILESPATH</filename> variable in your |
| 901 | <filename>.bbappend</filename> file: |
| 902 | <literallayout class='monospaced'> |
| 903 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
| 904 | SRC_URI += "file://8250.cfg" |
| 905 | </literallayout> |
| 906 | The next time you run BitBake to build the Linux kernel, BitBake |
| 907 | detects the change in the recipe and fetches and applies the |
| 908 | new configuration before building the kernel. |
| 909 | </para> |
| 910 | |
| 911 | <para> |
| 912 | For a detailed example showing how to configure the kernel, |
| 913 | see the |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 914 | "<link linkend='configuring-the-kernel'>Configuring the Kernel</link>" |
| 915 | section. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 916 | </para> |
| 917 | </section> |
| 918 | |
| 919 | <section id='using-an-in-tree-defconfig-file'> |
| 920 | <title>Using an "In-Tree" <filename>defconfig</filename> File</title> |
| 921 | |
| 922 | <para> |
| 923 | It might be desirable to have kernel configuration fragment |
| 924 | support through a <filename>defconfig</filename> file that |
| 925 | is pulled from the kernel source tree for the configured |
| 926 | machine. |
| 927 | By default, the OpenEmbedded build system looks for |
| 928 | <filename>defconfig</filename> files in the layer used for |
| 929 | Metadata, which is "out-of-tree", and then configures them |
| 930 | using the following: |
| 931 | <literallayout class='monospaced'> |
| 932 | SRC_URI += "file://defconfig" |
| 933 | </literallayout> |
| 934 | If you do not want to maintain copies of |
| 935 | <filename>defconfig</filename> files in your layer but would |
| 936 | rather allow users to use the default configuration from the |
| 937 | kernel tree and still be able to add configuration fragments |
| 938 | to the |
| 939 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 940 | through, for example, append files, you can direct the |
| 941 | OpenEmbedded build system to use a |
| 942 | <filename>defconfig</filename> file that is "in-tree". |
| 943 | </para> |
| 944 | |
| 945 | <para> |
| 946 | To specify an "in-tree" <filename>defconfig</filename> file, |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 947 | use the following statement form: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 948 | <literallayout class='monospaced'> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 949 | KBUILD_DEFCONFIG_<replaceable>KMACHINE</replaceable> ?= <replaceable>defconfig_file</replaceable> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 950 | </literallayout> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 951 | Here is an example that appends the |
| 952 | <filename>KBUILD_DEFCONFIG</filename> variable with |
| 953 | "common-pc" and provides the path to the "in-tree" |
| 954 | <filename>defconfig</filename> file: |
| 955 | <literallayout class='monospaced'> |
| 956 | KBUILD_DEFCONFIG_common-pc ?= "/home/scottrif/configfiles/my_defconfig_file" |
| 957 | </literallayout> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 958 | </para> |
| 959 | |
| 960 | <para> |
| 961 | Aside from modifying your kernel recipe and providing your own |
| 962 | <filename>defconfig</filename> file, you need to be sure no |
| 963 | files or statements set <filename>SRC_URI</filename> to use a |
| 964 | <filename>defconfig</filename> other than your "in-tree" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 965 | file (e.g. a kernel's |
| 966 | <filename>linux-</filename><replaceable>machine</replaceable><filename>.inc</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 967 | file). |
| 968 | In other words, if the build system detects a statement |
| 969 | that identifies an "out-of-tree" |
| 970 | <filename>defconfig</filename> file, that statement |
| 971 | will override your |
| 972 | <filename>KBUILD_DEFCONFIG</filename> variable. |
| 973 | </para> |
| 974 | |
| 975 | <para> |
| 976 | See the |
| 977 | <ulink url='&YOCTO_DOCS_REF_URL;#var-KBUILD_DEFCONFIG'><filename>KBUILD_DEFCONFIG</filename></ulink> |
| 978 | variable description for more information. |
| 979 | </para> |
| 980 | </section> |
| 981 | </section> |
| 982 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 983 | <section id="using-devtool-to-patch-the-kernel"> |
| 984 | <title>Using <filename>devtool</filename> to Patch the Kernel</title> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 985 | |
| 986 | <para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 987 | The steps in this procedure show you how you can patch the |
| 988 | kernel using the extensible SDK and <filename>devtool</filename>. |
| 989 | <note> |
| 990 | Before attempting this procedure, be sure you have performed |
| 991 | the steps to get ready for updating the kernel as described |
| 992 | in the |
| 993 | "<link linkend='getting-ready-to-develop-using-devtool'>Getting Ready to Develop Using <filename>devtool</filename></link>" |
| 994 | section. |
| 995 | </note> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 996 | </para> |
| 997 | |
| 998 | <para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 999 | Patching the kernel involves changing or adding configurations |
| 1000 | to an existing kernel, changing or adding recipes to the kernel |
| 1001 | that are needed to support specific hardware features, or even |
| 1002 | altering the source code itself. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1003 | </para> |
| 1004 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1005 | <para> |
| 1006 | This example creates a simple patch by adding some QEMU emulator |
| 1007 | console output at boot time through <filename>printk</filename> |
| 1008 | statements in the kernel's <filename>calibrate.c</filename> source |
| 1009 | code file. |
| 1010 | Applying the patch and booting the modified image causes the added |
| 1011 | messages to appear on the emulator's console. |
| 1012 | The example is a continuation of the setup procedure found in |
| 1013 | the |
| 1014 | "<link linkend='getting-ready-to-develop-using-devtool'>Getting Ready to Develop Using <filename>devtool</filename></link>" |
| 1015 | Section. |
| 1016 | <orderedlist> |
| 1017 | <listitem><para> |
| 1018 | <emphasis>Check Out the Kernel Source Files:</emphasis> |
| 1019 | First you must use <filename>devtool</filename> to checkout |
| 1020 | the kernel source code in its workspace. |
| 1021 | Be sure you are in the terminal set up to do work |
| 1022 | with the extensible SDK. |
| 1023 | <note> |
| 1024 | See this |
| 1025 | <link linkend='setting-up-the-esdk-terminal'>step</link> |
| 1026 | in the |
| 1027 | "<link linkend='getting-ready-to-develop-using-devtool'>Getting Ready to Develop Using <filename>devtool</filename></link>" |
| 1028 | section for more information. |
| 1029 | </note> |
| 1030 | Use the following <filename>devtool</filename> command |
| 1031 | to check out the code: |
| 1032 | <literallayout class='monospaced'> |
| 1033 | $ devtool modify linux-yocto |
| 1034 | </literallayout> |
| 1035 | <note> |
| 1036 | During the checkout operation, a bug exists that could |
| 1037 | cause errors such as the following to appear: |
| 1038 | <literallayout class='monospaced'> |
| 1039 | ERROR: Taskhash mismatch 2c793438c2d9f8c3681fd5f7bc819efa versus |
| 1040 | be3a89ce7c47178880ba7bf6293d7404 for |
| 1041 | /path/to/esdk/layers/poky/meta/recipes-kernel/linux/linux-yocto_4.10.bb.do_unpack |
| 1042 | </literallayout> |
| 1043 | You can safely ignore these messages. |
| 1044 | The source code is correctly checked out. |
| 1045 | </note> |
| 1046 | </para></listitem> |
| 1047 | <listitem><para> |
| 1048 | <emphasis>Edit the Source Files</emphasis> |
| 1049 | Follow these steps to make some simple changes to the source |
| 1050 | files: |
| 1051 | <orderedlist> |
| 1052 | <listitem><para> |
| 1053 | <emphasis>Change the working directory</emphasis>: |
| 1054 | In the previous step, the output noted where you can find |
| 1055 | the source files (e.g. |
| 1056 | <filename>~/poky_sdk/workspace/sources/linux-yocto</filename>). |
| 1057 | Change to where the kernel source code is before making |
| 1058 | your edits to the <filename>calibrate.c</filename> file: |
| 1059 | <literallayout class='monospaced'> |
| 1060 | $ cd ~/poky_sdk/workspace/sources/linux-yocto |
| 1061 | </literallayout> |
| 1062 | </para></listitem> |
| 1063 | <listitem><para> |
| 1064 | <emphasis>Edit the source file</emphasis>: |
| 1065 | Edit the <filename>init/calibrate.c</filename> file to have |
| 1066 | the following changes: |
| 1067 | <literallayout class='monospaced'> |
| 1068 | void calibrate_delay(void) |
| 1069 | { |
| 1070 | unsigned long lpj; |
| 1071 | static bool printed; |
| 1072 | int this_cpu = smp_processor_id(); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1073 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1074 | printk("*************************************\n"); |
| 1075 | printk("* *\n"); |
| 1076 | printk("* HELLO YOCTO KERNEL *\n"); |
| 1077 | printk("* *\n"); |
| 1078 | printk("*************************************\n"); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1079 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1080 | if (per_cpu(cpu_loops_per_jiffy, this_cpu)) { |
| 1081 | . |
| 1082 | . |
| 1083 | . |
| 1084 | </literallayout> |
| 1085 | </para></listitem> |
| 1086 | </orderedlist> |
| 1087 | </para></listitem> |
| 1088 | <listitem><para> |
| 1089 | <emphasis>Build the Updated Kernel Source:</emphasis> |
| 1090 | To build the updated kernel source, use |
| 1091 | <filename>devtool</filename>: |
| 1092 | <literallayout class='monospaced'> |
| 1093 | $ devtool build linux-yocto |
| 1094 | </literallayout> |
| 1095 | </para></listitem> |
| 1096 | <listitem><para> |
| 1097 | <emphasis>Create the Image With the New Kernel:</emphasis> |
| 1098 | Use the <filename>devtool build-image</filename> command |
| 1099 | to create a new image that has the new kernel. |
| 1100 | <note> |
| 1101 | If the image you originally created resulted in a Wic |
| 1102 | file, you can use an alternate method to create the new |
| 1103 | image with the updated kernel. |
| 1104 | For an example, see the steps in the |
| 1105 | <ulink url='https://wiki.yoctoproject.org/wiki/TipsAndTricks/KernelDevelopmentWithEsdk'>TipsAndTricks/KernelDevelopmentWithEsdk</ulink> |
| 1106 | Wiki Page. |
| 1107 | </note> |
| 1108 | <literallayout class='monospaced'> |
| 1109 | $ cd ~ |
| 1110 | $ devtool build-image core-image-minimal |
| 1111 | </literallayout> |
| 1112 | </para></listitem> |
| 1113 | <listitem><para> |
| 1114 | <emphasis>Test the New Image:</emphasis> |
| 1115 | For this example, you can run the new image using QEMU |
| 1116 | to verify your changes: |
| 1117 | <orderedlist> |
| 1118 | <listitem><para> |
| 1119 | <emphasis>Boot the image</emphasis>: |
| 1120 | Boot the modified image in the QEMU emulator |
| 1121 | using this command: |
| 1122 | <literallayout class='monospaced'> |
| 1123 | $ runqemu qemux86 |
| 1124 | </literallayout> |
| 1125 | </para></listitem> |
| 1126 | <listitem><para> |
| 1127 | <emphasis>Verify the changes</emphasis>: |
| 1128 | Log into the machine using <filename>root</filename> |
| 1129 | with no password and then use the following shell |
| 1130 | command to scroll through the console's boot output. |
| 1131 | <literallayout class='monospaced'> |
| 1132 | # dmesg | less |
| 1133 | </literallayout> |
| 1134 | You should see the results of your |
| 1135 | <filename>printk</filename> statements |
| 1136 | as part of the output when you scroll down the |
| 1137 | console window. |
| 1138 | </para></listitem> |
| 1139 | </orderedlist> |
| 1140 | </para></listitem> |
| 1141 | <listitem><para> |
| 1142 | <emphasis>Stage and commit your changes</emphasis>: |
| 1143 | Within your eSDK terminal, change your working directory to |
| 1144 | where you modified the <filename>calibrate.c</filename> |
| 1145 | file and use these Git commands to stage and commit your |
| 1146 | changes: |
| 1147 | <literallayout class='monospaced'> |
| 1148 | $ cd ~/poky_sdk/workspace/sources/linux-yocto |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1149 | $ git status |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1150 | $ git add init/calibrate.c |
| 1151 | $ git commit -m "calibrate: Add printk example" |
| 1152 | </literallayout> |
| 1153 | </para></listitem> |
| 1154 | <listitem><para> |
| 1155 | <emphasis>Export the Patches and Create an Append File:</emphasis> |
| 1156 | To export your commits as patches and create a |
| 1157 | <filename>.bbappend</filename> file, use the following |
| 1158 | command in the terminal used to work with the extensible |
| 1159 | SDK. |
| 1160 | This example uses the previously established layer named |
| 1161 | <filename>meta-mylayer</filename>. |
| 1162 | <note> |
| 1163 | See Step 3 of the |
| 1164 | "<link linkend='getting-ready-to-develop-using-devtool'>Getting Ready to Develop Using devtool</link>" |
| 1165 | section for information on setting up this layer. |
| 1166 | </note> |
| 1167 | <literallayout class='monospaced'> |
| 1168 | $ devtool finish linux-yocto ~/meta-mylayer |
| 1169 | </literallayout> |
| 1170 | Once the command finishes, the patches and the |
| 1171 | <filename>.bbappend</filename> file are located in the |
| 1172 | <filename>~/meta-mylayer/recipes-kernel/linux</filename> |
| 1173 | directory. |
| 1174 | </para></listitem> |
| 1175 | <listitem><para> |
| 1176 | <emphasis>Build the Image With Your Modified Kernel:</emphasis> |
| 1177 | You can now build an image that includes your kernel |
| 1178 | patches. |
| 1179 | Execute the following command from your |
| 1180 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink> |
| 1181 | in the terminal set up to run BitBake: |
| 1182 | <literallayout class='monospaced'> |
| 1183 | $ cd ~/poky/build |
| 1184 | $ bitbake core-image-minimal |
| 1185 | </literallayout> |
| 1186 | </para></listitem> |
| 1187 | </orderedlist> |
| 1188 | </para> |
| 1189 | </section> |
| 1190 | |
| 1191 | <section id="using-traditional-kernel-development-to-patch-the-kernel"> |
| 1192 | <title>Using Traditional Kernel Development to Patch the Kernel</title> |
| 1193 | |
| 1194 | <para> |
| 1195 | The steps in this procedure show you how you can patch the |
| 1196 | kernel using traditional kernel development (i.e. not using |
| 1197 | <filename>devtool</filename> and the extensible SDK as |
| 1198 | described in the |
| 1199 | "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>" |
| 1200 | section). |
| 1201 | <note> |
| 1202 | Before attempting this procedure, be sure you have performed |
| 1203 | the steps to get ready for updating the kernel as described |
| 1204 | in the |
| 1205 | "<link linkend='getting-ready-for-traditional-kernel-development'>Getting Ready for Traditional Kernel Development</link>" |
| 1206 | section. |
| 1207 | </note> |
| 1208 | </para> |
| 1209 | |
| 1210 | <para> |
| 1211 | Patching the kernel involves changing or adding configurations |
| 1212 | to an existing kernel, changing or adding recipes to the kernel |
| 1213 | that are needed to support specific hardware features, or even |
| 1214 | altering the source code itself. |
| 1215 | </para> |
| 1216 | |
| 1217 | <para> |
| 1218 | The example in this section creates a simple patch by adding some |
| 1219 | QEMU emulator console output at boot time through |
| 1220 | <filename>printk</filename> statements in the kernel's |
| 1221 | <filename>calibrate.c</filename> source code file. |
| 1222 | Applying the patch and booting the modified image causes the added |
| 1223 | messages to appear on the emulator's console. |
| 1224 | The example is a continuation of the setup procedure found in |
| 1225 | the |
| 1226 | "<link linkend='getting-ready-for-traditional-kernel-development'>Getting Ready for Traditional Kernel Development</link>" |
| 1227 | Section. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1228 | <orderedlist> |
| 1229 | <listitem><para> |
| 1230 | <emphasis>Edit the Source Files</emphasis> |
| 1231 | Prior to this step, you should have used Git to create a |
| 1232 | local copy of the repository for your kernel. |
| 1233 | Assuming you created the repository as directed in the |
| 1234 | "<link linkend='getting-ready-for-traditional-kernel-development'>Getting Ready for Traditional Kernel Development</link>" |
| 1235 | section, use the following commands to edit the |
| 1236 | <filename>calibrate.c</filename> file: |
| 1237 | <orderedlist> |
| 1238 | <listitem><para> |
| 1239 | <emphasis>Change the working directory</emphasis>: |
| 1240 | You need to locate the source files in the |
| 1241 | local copy of the kernel Git repository: |
| 1242 | Change to where the kernel source code is before making |
| 1243 | your edits to the <filename>calibrate.c</filename> file: |
| 1244 | <literallayout class='monospaced'> |
| 1245 | $ cd ~/linux-yocto-4.12/init |
| 1246 | </literallayout> |
| 1247 | </para></listitem> |
| 1248 | <listitem><para> |
| 1249 | <emphasis>Edit the source file</emphasis>: |
| 1250 | Edit the <filename>calibrate.c</filename> file to have |
| 1251 | the following changes: |
| 1252 | <literallayout class='monospaced'> |
| 1253 | void calibrate_delay(void) |
| 1254 | { |
| 1255 | unsigned long lpj; |
| 1256 | static bool printed; |
| 1257 | int this_cpu = smp_processor_id(); |
| 1258 | |
| 1259 | printk("*************************************\n"); |
| 1260 | printk("* *\n"); |
| 1261 | printk("* HELLO YOCTO KERNEL *\n"); |
| 1262 | printk("* *\n"); |
| 1263 | printk("*************************************\n"); |
| 1264 | |
| 1265 | if (per_cpu(cpu_loops_per_jiffy, this_cpu)) { |
| 1266 | . |
| 1267 | . |
| 1268 | . |
| 1269 | </literallayout> |
| 1270 | </para></listitem> |
| 1271 | </orderedlist> |
| 1272 | </para></listitem> |
| 1273 | <listitem><para> |
| 1274 | <emphasis>Stage and Commit Your Changes:</emphasis> |
| 1275 | Use standard Git commands to stage and commit the changes |
| 1276 | you just made: |
| 1277 | <literallayout class='monospaced'> |
| 1278 | $ git add calibrate.c |
| 1279 | $ git commit -m "calibrate.c - Added some printk statements" |
| 1280 | </literallayout> |
| 1281 | If you do not stage and commit your changes, the OpenEmbedded |
| 1282 | Build System will not pick up the changes. |
| 1283 | </para></listitem> |
| 1284 | <listitem><para> |
| 1285 | <emphasis>Update Your <filename>local.conf</filename> File |
| 1286 | to Point to Your Source Files:</emphasis> |
| 1287 | In addition to your <filename>local.conf</filename> file |
| 1288 | specifying to use "kernel-modules" and the "qemux86" |
| 1289 | machine, it must also point to the updated kernel source |
| 1290 | files. |
| 1291 | Add |
| 1292 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 1293 | and |
| 1294 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink> |
| 1295 | statements similar to the following to your |
| 1296 | <filename>local.conf</filename>: |
| 1297 | <literallayout class='monospaced'> |
| 1298 | $ cd ~/poky/build/conf |
| 1299 | </literallayout> |
| 1300 | Add the following to the <filename>local.conf</filename>: |
| 1301 | <literallayout class='monospaced'> |
| 1302 | SRC_URI_pn-linux-yocto = "git:///<replaceable>path-to</replaceable>/linux-yocto-4.12;protocol=file;name=machine;branch=standard/base; \ |
| 1303 | git:///<replaceable>path-to</replaceable>/yocto-kernel-cache;protocol=file;type=kmeta;name=meta;branch=yocto-4.12;destsuffix=${KMETA}" |
| 1304 | SRCREV_meta_qemux86 = "${AUTOREV}" |
| 1305 | SRCREV_machine_qemux86 = "${AUTOREV}" |
| 1306 | </literallayout> |
| 1307 | <note> |
| 1308 | Be sure to replace |
| 1309 | <replaceable>path-to</replaceable> with the pathname |
| 1310 | to your local Git repositories. |
| 1311 | Also, you must be sure to specify the correct branch |
| 1312 | and machine types. |
| 1313 | For this example, the branch is |
| 1314 | <filename>standard/base</filename> and the machine is |
| 1315 | "qemux86". |
| 1316 | </note> |
| 1317 | </para></listitem> |
| 1318 | <listitem><para> |
| 1319 | <emphasis>Build the Image:</emphasis> |
| 1320 | With the source modified, your changes staged and |
| 1321 | committed, and the <filename>local.conf</filename> file |
| 1322 | pointing to the kernel files, you can now use BitBake to |
| 1323 | build the image: |
| 1324 | <literallayout class='monospaced'> |
| 1325 | $ cd ~/poky/build |
| 1326 | $ bitbake core-image-minimal |
| 1327 | </literallayout> |
| 1328 | </para></listitem> |
| 1329 | <listitem><para> |
| 1330 | <emphasis>Boot the image</emphasis>: |
| 1331 | Boot the modified image in the QEMU emulator |
| 1332 | using this command. |
| 1333 | When prompted to login to the QEMU console, use "root" |
| 1334 | with no password: |
| 1335 | <literallayout class='monospaced'> |
| 1336 | $ cd ~/poky/build |
| 1337 | $ runqemu qemux86 |
| 1338 | </literallayout> |
| 1339 | </para></listitem> |
| 1340 | <listitem><para> |
| 1341 | <emphasis>Look for Your Changes:</emphasis> |
| 1342 | As QEMU booted, you might have seen your changes rapidly |
| 1343 | scroll by. |
| 1344 | If not, use these commands to see your changes: |
| 1345 | <literallayout class='monospaced'> |
| 1346 | # dmesg | less |
| 1347 | </literallayout> |
| 1348 | You should see the results of your |
| 1349 | <filename>printk</filename> statements |
| 1350 | as part of the output when you scroll down the |
| 1351 | console window. |
| 1352 | </para></listitem> |
| 1353 | <listitem><para> |
| 1354 | <emphasis>Generate the Patch File:</emphasis> |
| 1355 | Once you are sure that your patch works correctly, you |
| 1356 | can generate a <filename>*.patch</filename> file in the |
| 1357 | kernel source repository: |
| 1358 | <literallayout class='monospaced'> |
| 1359 | $ cd ~/linux-yocto-4.12/init |
| 1360 | $ git format-patch -1 |
| 1361 | 0001-calibrate.c-Added-some-printk-statements.patch |
| 1362 | </literallayout> |
| 1363 | </para></listitem> |
| 1364 | <listitem><para> |
| 1365 | <emphasis>Move the Patch File to Your Layer:</emphasis> |
| 1366 | In order for subsequent builds to pick up patches, you |
| 1367 | need to move the patch file you created in the previous |
| 1368 | step to your layer <filename>meta-mylayer</filename>. |
| 1369 | For this example, the layer created earlier is located |
| 1370 | in your home directory as <filename>meta-mylayer</filename>. |
| 1371 | When the layer was created using the |
| 1372 | <filename>yocto-create</filename> script, no additional |
| 1373 | hierarchy was created to support patches. |
| 1374 | Before moving the patch file, you need to add additional |
| 1375 | structure to your layer using the following commands: |
| 1376 | <literallayout class='monospaced'> |
| 1377 | $ cd ~/meta-mylayer |
| 1378 | $ mkdir recipes-kernel |
| 1379 | $ mkdir recipes-kernel/linux |
| 1380 | $ mkdir recipes-kernel/linux/linux-yocto |
| 1381 | </literallayout> |
| 1382 | Once you have created this hierarchy in your layer, you can |
| 1383 | move the patch file using the following command: |
| 1384 | <literallayout class='monospaced'> |
| 1385 | $ mv ~/linux-yocto-4.12/init/0001-calibrate.c-Added-some-printk-statements.patch ~/meta-mylayer/recipes-kernel/linux/linux-yocto |
| 1386 | </literallayout> |
| 1387 | </para></listitem> |
| 1388 | <listitem><para> |
| 1389 | <emphasis>Create the Append File:</emphasis> |
| 1390 | Finally, you need to create the |
| 1391 | <filename>linux-yocto_4.12.bbappend</filename> file and |
| 1392 | insert statements that allow the OpenEmbedded build |
| 1393 | system to find the patch. |
| 1394 | The append file needs to be in your layer's |
| 1395 | <filename>recipes-kernel/linux</filename> |
| 1396 | directory and it must be named |
| 1397 | <filename>linux-yocto_4.12.bbappend</filename> and have |
| 1398 | the following contents: |
| 1399 | <literallayout class='monospaced'> |
| 1400 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
| 1401 | |
| 1402 | SRC_URI_append = " file://0001-calibrate.c-Added-some-printk-statements.patch" |
| 1403 | </literallayout> |
| 1404 | The |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1405 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1406 | and |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1407 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1408 | statements enable the OpenEmbedded build system to find |
| 1409 | the patch file.</para> |
| 1410 | |
| 1411 | <para>For more information on append files and patches, |
| 1412 | see the |
| 1413 | "<link linkend='creating-the-append-file'>Creating the Append File</link>" |
| 1414 | and |
| 1415 | "<link linkend='applying-patches'>Applying Patches</link>" |
| 1416 | sections. |
| 1417 | You can also see the |
| 1418 | "<ulink url='&YOCTO_DOCS_DEV_URL;#using-bbappend-files'>Using .bbappend Files in Your Layer"</ulink>" |
| 1419 | section in the Yocto Project Development Tasks Manual. |
| 1420 | <note> |
| 1421 | To build <filename>core-image-minimal</filename> |
| 1422 | again and see the effects of your patch, you can |
| 1423 | essentially eliminate the temporary source files |
| 1424 | saved in <filename>poky/build/tmp/work/...</filename> |
| 1425 | and residual effects of the build by entering the |
| 1426 | following sequence of commands: |
| 1427 | <literallayout class='monospaced'> |
| 1428 | $ cd ~/poky/build |
| 1429 | $ bitbake -c cleanall yocto-linux |
| 1430 | $ bitbake core-image-minimal -c cleanall |
| 1431 | $ bitbake core-image-minimal |
| 1432 | $ runqemu qemux86 |
| 1433 | </literallayout> |
| 1434 | </note> |
| 1435 | </para></listitem> |
| 1436 | </orderedlist> |
| 1437 | </para> |
| 1438 | </section> |
| 1439 | |
| 1440 | <section id='configuring-the-kernel'> |
| 1441 | <title>Configuring the Kernel</title> |
| 1442 | |
| 1443 | <para> |
| 1444 | Configuring the Yocto Project kernel consists of making sure the |
| 1445 | <filename>.config</filename> file has all the right information |
| 1446 | in it for the image you are building. |
| 1447 | You can use the <filename>menuconfig</filename> tool and |
| 1448 | configuration fragments to make sure your |
| 1449 | <filename>.config</filename> file is just how you need it. |
| 1450 | You can also save known configurations in a |
| 1451 | <filename>defconfig</filename> file that the build system can use |
| 1452 | for kernel configuration. |
| 1453 | </para> |
| 1454 | |
| 1455 | <para> |
| 1456 | This section describes how to use <filename>menuconfig</filename>, |
| 1457 | create and use configuration fragments, and how to interactively |
| 1458 | modify your <filename>.config</filename> file to create the |
| 1459 | leanest kernel configuration file possible. |
| 1460 | </para> |
| 1461 | |
| 1462 | <para> |
| 1463 | For more information on kernel configuration, see the |
| 1464 | "<link linkend='changing-the-configuration'>Changing the Configuration</link>" |
| 1465 | section. |
| 1466 | </para> |
| 1467 | |
| 1468 | <section id='using-menuconfig'> |
| 1469 | <title>Using <filename>menuconfig</filename></title> |
| 1470 | |
| 1471 | <para> |
| 1472 | The easiest way to define kernel configurations is to set |
| 1473 | them through the <filename>menuconfig</filename> tool. |
| 1474 | This tool provides an interactive method with which |
| 1475 | to set kernel configurations. |
| 1476 | For general information on <filename>menuconfig</filename>, see |
| 1477 | <ulink url='http://en.wikipedia.org/wiki/Menuconfig'></ulink>. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1478 | </para> |
| 1479 | |
| 1480 | <para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1481 | To use the <filename>menuconfig</filename> tool in the Yocto |
| 1482 | Project development environment, you must launch it using |
| 1483 | BitBake. |
| 1484 | Thus, the environment must be set up using the |
| 1485 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink> |
| 1486 | script found in the |
| 1487 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>. |
| 1488 | You must also be sure of the state of your build's |
| 1489 | configuration in the |
| 1490 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>. |
| 1491 | The following commands initialize the BitBake environment, |
| 1492 | run the |
| 1493 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configme'><filename>do_kernel_configme</filename></ulink> |
| 1494 | task, and launch <filename>menuconfig</filename>. |
| 1495 | These commands assume the Source Directory's top-level folder |
| 1496 | is <filename>~/poky</filename>: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1497 | <literallayout class='monospaced'> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1498 | $ cd poky |
| 1499 | $ source oe-init-build-env |
| 1500 | $ bitbake linux-yocto -c kernel_configme -f |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1501 | $ bitbake linux-yocto -c menuconfig |
| 1502 | </literallayout> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1503 | Once <filename>menuconfig</filename> comes up, its standard |
| 1504 | interface allows you to interactively examine and configure |
| 1505 | all the kernel configuration parameters. |
| 1506 | After making your changes, simply exit the tool and save your |
| 1507 | changes to create an updated version of the |
| 1508 | <filename>.config</filename> configuration file. |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1509 | <note> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1510 | You can use the entire <filename>.config</filename> file |
| 1511 | as the <filename>defconfig</filename> file. |
| 1512 | For information on <filename>defconfig</filename> files, |
| 1513 | see the |
| 1514 | "<link linkend='changing-the-configuration'>Changing the Configuration</link>", |
| 1515 | "<link linkend='using-an-in-tree-defconfig-file'>Using an In-Tree <filename>defconfig</filename> File</link>, |
| 1516 | and |
| 1517 | "<link linkend='creating-a-defconfig-file'>Creating a <filename>defconfig</filename> File</link>" |
| 1518 | sections. |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1519 | </note> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1520 | </para> |
| 1521 | |
| 1522 | <para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1523 | Consider an example that configures the "CONFIG_SMP" setting |
| 1524 | for the <filename>linux-yocto-4.12</filename> kernel. |
| 1525 | <note> |
| 1526 | The OpenEmbedded build system recognizes this kernel as |
| 1527 | <filename>linux-yocto</filename> through Metadata (e.g. |
| 1528 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_VERSION'><filename>PREFERRED_VERSION</filename></ulink><filename>_linux-yocto ?= "12.4%"</filename>). |
| 1529 | </note> |
| 1530 | Once <filename>menuconfig</filename> launches, use the |
| 1531 | interface to navigate through the selections to find the |
| 1532 | configuration settings in which you are interested. |
| 1533 | For this example, you deselect "CONFIG_SMP" by clearing the |
| 1534 | "Symmetric Multi-Processing Support" option. |
| 1535 | Using the interface, you can find the option under |
| 1536 | "Processor Type and Features". |
| 1537 | To deselect "CONFIG_SMP", use the arrow keys to |
| 1538 | highlight "Symmetric Multi-Processing Support" and enter "N" |
| 1539 | to clear the asterisk. |
| 1540 | When you are finished, exit out and save the change. |
| 1541 | </para> |
| 1542 | |
| 1543 | <para> |
| 1544 | Saving the selections updates the <filename>.config</filename> |
| 1545 | configuration file. |
| 1546 | This is the file that the OpenEmbedded build system uses to |
| 1547 | configure the kernel during the build. |
| 1548 | You can find and examine this file in the Build Directory in |
| 1549 | <filename>tmp/work/</filename>. |
| 1550 | The actual <filename>.config</filename> is located in the |
| 1551 | area where the specific kernel is built. |
| 1552 | For example, if you were building a Linux Yocto kernel based |
| 1553 | on the <filename>linux-yocto-4.12</filename> kernel and you |
| 1554 | were building a QEMU image targeted for |
| 1555 | <filename>x86</filename> architecture, the |
| 1556 | <filename>.config</filename> file would be: |
| 1557 | <literallayout class='monospaced'> |
| 1558 | poky/build/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+gitAUTOINC+eda4d18... |
| 1559 | ...967-r0/linux-qemux86-standard-build/.config |
| 1560 | </literallayout> |
| 1561 | <note> |
| 1562 | The previous example directory is artificially split and |
| 1563 | many of the characters in the actual filename are omitted |
| 1564 | in order to make it more readable. |
| 1565 | Also, depending on the kernel you are using, the exact |
| 1566 | pathname might differ. |
| 1567 | </note> |
| 1568 | </para> |
| 1569 | |
| 1570 | <para> |
| 1571 | Within the <filename>.config</filename> file, you can see the |
| 1572 | kernel settings. |
| 1573 | For example, the following entry shows that symmetric |
| 1574 | multi-processor support is not set: |
| 1575 | <literallayout class='monospaced'> |
| 1576 | # CONFIG_SMP is not set |
| 1577 | </literallayout> |
| 1578 | </para> |
| 1579 | |
| 1580 | <para> |
| 1581 | A good method to isolate changed configurations is to use a |
| 1582 | combination of the <filename>menuconfig</filename> tool and |
| 1583 | simple shell commands. |
| 1584 | Before changing configurations with |
| 1585 | <filename>menuconfig</filename>, copy the existing |
| 1586 | <filename>.config</filename> and rename it to something else, |
| 1587 | use <filename>menuconfig</filename> to make as many changes as |
| 1588 | you want and save them, then compare the renamed configuration |
| 1589 | file against the newly created file. |
| 1590 | You can use the resulting differences as your base to create |
| 1591 | configuration fragments to permanently save in your kernel |
| 1592 | layer. |
| 1593 | <note> |
| 1594 | Be sure to make a copy of the <filename>.config</filename> |
| 1595 | file and do not just rename it. |
| 1596 | The build system needs an existing |
| 1597 | <filename>.config</filename> file from which to work. |
| 1598 | </note> |
| 1599 | </para> |
| 1600 | </section> |
| 1601 | |
| 1602 | <section id='creating-a-defconfig-file'> |
| 1603 | <title>Creating a <filename>defconfig</filename> File</title> |
| 1604 | |
| 1605 | <para> |
| 1606 | A <filename>defconfig</filename> file is simply a |
| 1607 | <filename>.config</filename> renamed to "defconfig". |
| 1608 | You can use a <filename>defconfig</filename> file |
| 1609 | to retain a known set of kernel configurations from which the |
| 1610 | OpenEmbedded build system can draw to create the final |
| 1611 | <filename>.config</filename> file. |
| 1612 | <note> |
| 1613 | Out-of-the-box, the Yocto Project never ships a |
| 1614 | <filename>defconfig</filename> or |
| 1615 | <filename>.config</filename> file. |
| 1616 | The OpenEmbedded build system creates the final |
| 1617 | <filename>.config</filename> file used to configure the |
| 1618 | kernel. |
| 1619 | </note> |
| 1620 | </para> |
| 1621 | |
| 1622 | <para> |
| 1623 | To create a <filename>defconfig</filename>, start with a |
| 1624 | complete, working Linux kernel <filename>.config</filename> |
| 1625 | file. |
| 1626 | Copy that file to the appropriate |
| 1627 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename> |
| 1628 | directory in your layer's |
| 1629 | <filename>recipes-kernel/linux</filename> directory, and rename |
| 1630 | the copied file to "defconfig" (e.g. |
| 1631 | <filename>~/meta-mylayer/recipes-kernel/linux/linux-yocto/defconfig</filename>). |
| 1632 | Then, add the following lines to the linux-yocto |
| 1633 | <filename>.bbappend</filename> file in your layer: |
| 1634 | <literallayout class='monospaced'> |
| 1635 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
| 1636 | SRC_URI += "file://defconfig" |
| 1637 | </literallayout> |
| 1638 | The |
| 1639 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 1640 | tells the build system how to search for the file, while the |
| 1641 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> |
| 1642 | extends the |
| 1643 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> |
| 1644 | variable (search directories) to include the |
| 1645 | <filename>${PN}</filename> directory you created to hold the |
| 1646 | configuration changes. |
| 1647 | <note> |
| 1648 | The build system applies the configurations from the |
| 1649 | <filename>defconfig</filename> file before applying any |
| 1650 | subsequent configuration fragments. |
| 1651 | The final kernel configuration is a combination of the |
| 1652 | configurations in the <filename>defconfig</filename> |
| 1653 | file and any configuration fragments you provide. |
| 1654 | You need to realize that if you have any configuration |
| 1655 | fragments, the build system applies these on top of and |
| 1656 | after applying the existing defconfig file configurations. |
| 1657 | </note> |
| 1658 | For more information on configuring the kernel, see the |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1659 | "<link linkend='changing-the-configuration'>Changing the Configuration</link>" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1660 | section. |
| 1661 | </para> |
| 1662 | </section> |
| 1663 | |
| 1664 | <section id='creating-config-fragments'> |
| 1665 | <title>Creating Configuration Fragments</title> |
| 1666 | |
| 1667 | <para> |
| 1668 | Configuration fragments are simply kernel options that |
| 1669 | appear in a file placed where the OpenEmbedded build system |
| 1670 | can find and apply them. |
| 1671 | The build system applies configuration fragments after |
| 1672 | applying configurations from a <filename>defconfig</filename> |
| 1673 | file. |
| 1674 | Thus, the final kernel configuration is a combination of the |
| 1675 | configurations in the <filename>defconfig</filename> |
| 1676 | file and then any configuration fragments you provide. |
| 1677 | The build system applies fragments on top of and |
| 1678 | after applying the existing defconfig file configurations. |
| 1679 | </para> |
| 1680 | |
| 1681 | <para> |
| 1682 | Syntactically, the configuration statement is identical to |
| 1683 | what would appear in the <filename>.config</filename> file, |
| 1684 | which is in the |
| 1685 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>. |
| 1686 | <note> |
| 1687 | For more information about where the |
| 1688 | <filename>.config</filename> file is located, see the |
| 1689 | example in the |
| 1690 | "<link linkend='using-menuconfig'>Using <filename>menuconfig</filename></link>" |
| 1691 | section. |
| 1692 | </note> |
| 1693 | </para> |
| 1694 | |
| 1695 | <para> |
| 1696 | It is simple to create a configuration fragment. |
| 1697 | One method is to use shell commands. |
| 1698 | For example, issuing the following from the shell creates a |
| 1699 | configuration fragment file named |
| 1700 | <filename>my_smp.cfg</filename> that enables multi-processor |
| 1701 | support within the kernel: |
| 1702 | <literallayout class='monospaced'> |
| 1703 | $ echo "CONFIG_SMP=y" >> my_smp.cfg |
| 1704 | </literallayout> |
| 1705 | <note> |
| 1706 | All configuration fragment files must use the |
| 1707 | <filename>.cfg</filename> extension in order for the |
| 1708 | OpenEmbedded build system to recognize them as a |
| 1709 | configuration fragment. |
| 1710 | </note> |
| 1711 | </para> |
| 1712 | |
| 1713 | <para> |
| 1714 | Another method is to create a configuration fragment using the |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1715 | differences between two configuration files: one previously |
| 1716 | created and saved, and one freshly created using the |
| 1717 | <filename>menuconfig</filename> tool. |
| 1718 | </para> |
| 1719 | |
| 1720 | <para> |
| 1721 | To create a configuration fragment using this method, follow |
| 1722 | these steps: |
| 1723 | <orderedlist> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1724 | <listitem><para> |
| 1725 | <emphasis>Complete a Build Through Kernel Configuration:</emphasis> |
| 1726 | Complete a build at least through the kernel |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1727 | configuration task as follows: |
| 1728 | <literallayout class='monospaced'> |
| 1729 | $ bitbake linux-yocto -c kernel_configme -f |
| 1730 | </literallayout> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1731 | This step ensures that you create a |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1732 | <filename>.config</filename> file from a known state. |
| 1733 | Because situations exist where your build state might |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1734 | become unknown, it is best to run this task prior |
| 1735 | to starting <filename>menuconfig</filename>. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1736 | </para></listitem> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1737 | <listitem><para> |
| 1738 | <emphasis>Launch <filename>menuconfig</filename>:</emphasis> |
| 1739 | Run the <filename>menuconfig</filename> command: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1740 | <literallayout class='monospaced'> |
| 1741 | $ bitbake linux-yocto -c menuconfig |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1742 | </literallayout> |
| 1743 | </para></listitem> |
| 1744 | <listitem><para> |
| 1745 | <emphasis>Create the Configuration Fragment:</emphasis> |
| 1746 | Run the <filename>diffconfig</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1747 | command to prepare a configuration fragment. |
| 1748 | The resulting file <filename>fragment.cfg</filename> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1749 | is placed in the |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1750 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename> directory: |
| 1751 | <literallayout class='monospaced'> |
| 1752 | $ bitbake linux-yocto -c diffconfig |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1753 | </literallayout> |
| 1754 | </para></listitem> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1755 | </orderedlist> |
| 1756 | </para> |
| 1757 | |
| 1758 | <para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1759 | The <filename>diffconfig</filename> command creates a file |
| 1760 | that is a list of Linux kernel <filename>CONFIG_</filename> |
| 1761 | assignments. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1762 | See the "<link linkend='changing-the-configuration'>Changing the Configuration</link>" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1763 | section for additional information on how to use the output |
| 1764 | as a configuration fragment. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1765 | <note> |
| 1766 | You can also use this method to create configuration |
| 1767 | fragments for a BSP. |
| 1768 | See the "<link linkend='bsp-descriptions'>BSP Descriptions</link>" |
| 1769 | section for more information. |
| 1770 | </note> |
| 1771 | </para> |
| 1772 | |
| 1773 | <para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1774 | Where do you put your configuration fragment files? |
| 1775 | You can place these files in an area pointed to by |
| 1776 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 1777 | as directed by your <filename>bblayers.conf</filename> file, |
| 1778 | which is located in your layer. |
| 1779 | The OpenEmbedded build system picks up the configuration and |
| 1780 | adds it to the kernel's configuration. |
| 1781 | For example, suppose you had a set of configuration options |
| 1782 | in a file called <filename>myconfig.cfg</filename>. |
| 1783 | If you put that file inside a directory named |
| 1784 | <filename>linux-yocto</filename> that resides in the same |
| 1785 | directory as the kernel's append file within your layer |
| 1786 | and then add the following statements to the kernel's append |
| 1787 | file, those configuration options will be picked up and applied |
| 1788 | when the kernel is built: |
| 1789 | <literallayout class='monospaced'> |
| 1790 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
| 1791 | SRC_URI += "file://myconfig.cfg" |
| 1792 | </literallayout> |
| 1793 | </para> |
| 1794 | |
| 1795 | <para> |
| 1796 | As mentioned earlier, you can group related configurations |
| 1797 | into multiple files and name them all in the |
| 1798 | <filename>SRC_URI</filename> statement as well. |
| 1799 | For example, you could group separate configurations |
| 1800 | specifically for Ethernet and graphics into their own files |
| 1801 | and add those by using a <filename>SRC_URI</filename> statement |
| 1802 | like the following in your append file: |
| 1803 | <literallayout class='monospaced'> |
| 1804 | SRC_URI += "file://myconfig.cfg \ |
| 1805 | file://eth.cfg \ |
| 1806 | file://gfx.cfg" |
| 1807 | </literallayout> |
| 1808 | </para> |
| 1809 | </section> |
| 1810 | |
| 1811 | <section id='validating-configuration'> |
| 1812 | <title>Validating Configuration</title> |
| 1813 | |
| 1814 | <para> |
| 1815 | You can use the |
| 1816 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configcheck'><filename>do_kernel_configcheck</filename></ulink> |
| 1817 | task to provide configuration validation: |
| 1818 | <literallayout class='monospaced'> |
| 1819 | $ bitbake linux-yocto -c kernel_configcheck -f |
| 1820 | </literallayout> |
| 1821 | Running this task produces warnings for when a |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1822 | requested configuration does not appear in the final |
| 1823 | <filename>.config</filename> file or when you override a |
| 1824 | policy configuration in a hardware configuration fragment. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1825 | </para> |
| 1826 | |
| 1827 | <para> |
| 1828 | In order to run this task, you must have an existing |
| 1829 | <filename>.config</filename> file. |
| 1830 | See the |
| 1831 | "<link linkend='using-menuconfig'>Using <filename>menuconfig</filename></link>" |
| 1832 | section for information on how to create a configuration file. |
| 1833 | </para> |
| 1834 | |
| 1835 | <para> |
| 1836 | Following is sample output from the |
| 1837 | <filename>do_kernel_configcheck</filename> task: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1838 | <literallayout class='monospaced'> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1839 | Loading cache: 100% |########################################################| Time: 0:00:00 |
| 1840 | Loaded 1275 entries from dependency cache. |
| 1841 | NOTE: Resolving any missing task queue dependencies |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1842 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1843 | Build Configuration: |
| 1844 | . |
| 1845 | . |
| 1846 | . |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1847 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1848 | NOTE: Executing SetScene Tasks |
| 1849 | NOTE: Executing RunQueue Tasks |
| 1850 | WARNING: linux-yocto-4.12.12+gitAUTOINC+eda4d18ce4_16de014967-r0 do_kernel_configcheck: |
| 1851 | [kernel config]: specified values did not make it into the kernel's final configuration: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1852 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1853 | ---------- CONFIG_X86_TSC ----------------- |
| 1854 | Config: CONFIG_X86_TSC |
| 1855 | From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/bsp/common-pc/common-pc-cpu.cfg |
| 1856 | Requested value: CONFIG_X86_TSC=y |
| 1857 | Actual value: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1858 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1859 | |
| 1860 | ---------- CONFIG_X86_BIGSMP ----------------- |
| 1861 | Config: CONFIG_X86_BIGSMP |
| 1862 | From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg |
| 1863 | /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig |
| 1864 | Requested value: # CONFIG_X86_BIGSMP is not set |
| 1865 | Actual value: |
| 1866 | |
| 1867 | |
| 1868 | ---------- CONFIG_NR_CPUS ----------------- |
| 1869 | Config: CONFIG_NR_CPUS |
| 1870 | From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg |
| 1871 | /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/bsp/common-pc/common-pc.cfg |
| 1872 | /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig |
| 1873 | Requested value: CONFIG_NR_CPUS=8 |
| 1874 | Actual value: CONFIG_NR_CPUS=1 |
| 1875 | |
| 1876 | |
| 1877 | ---------- CONFIG_SCHED_SMT ----------------- |
| 1878 | Config: CONFIG_SCHED_SMT |
| 1879 | From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg |
| 1880 | /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig |
| 1881 | Requested value: CONFIG_SCHED_SMT=y |
| 1882 | Actual value: |
| 1883 | |
| 1884 | |
| 1885 | |
| 1886 | NOTE: Tasks Summary: Attempted 288 tasks of which 285 didn't need to be rerun and all succeeded. |
| 1887 | |
| 1888 | Summary: There were 3 WARNING messages shown. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1889 | </literallayout> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1890 | <note> |
| 1891 | The previous output example has artificial line breaks |
| 1892 | to make it more readable. |
| 1893 | </note> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1894 | </para> |
| 1895 | |
| 1896 | <para> |
| 1897 | The output describes the various problems that you can |
| 1898 | encounter along with where to find the offending configuration |
| 1899 | items. |
| 1900 | You can use the information in the logs to adjust your |
| 1901 | configuration files and then repeat the |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1902 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configme'><filename>do_kernel_configme</filename></ulink> |
| 1903 | and |
| 1904 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configcheck'><filename>do_kernel_configcheck</filename></ulink> |
| 1905 | tasks until they produce no warnings. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1906 | </para> |
| 1907 | |
| 1908 | <para> |
| 1909 | For more information on how to use the |
| 1910 | <filename>menuconfig</filename> tool, see the |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1911 | "<link linkend='using-menuconfig'>Using <filename>menuconfig</filename></link>" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1912 | section. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1913 | </para> |
| 1914 | </section> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1915 | |
| 1916 | <section id='fine-tuning-the-kernel-configuration-file'> |
| 1917 | <title>Fine-Tuning the Kernel Configuration File</title> |
| 1918 | |
| 1919 | <para> |
| 1920 | You can make sure the <filename>.config</filename> file is as |
| 1921 | lean or efficient as possible by reading the output of the |
| 1922 | kernel configuration fragment audit, noting any issues, making |
| 1923 | changes to correct the issues, and then repeating. |
| 1924 | </para> |
| 1925 | |
| 1926 | <para> |
| 1927 | As part of the kernel build process, the |
| 1928 | <filename>do_kernel_configcheck</filename> task runs. |
| 1929 | This task validates the kernel configuration by checking the |
| 1930 | final <filename>.config</filename> file against the input |
| 1931 | files. |
| 1932 | During the check, the task produces warning messages for the |
| 1933 | following issues: |
| 1934 | <itemizedlist> |
| 1935 | <listitem><para> |
| 1936 | Requested options that did not make the final |
| 1937 | <filename>.config</filename> file. |
| 1938 | </para></listitem> |
| 1939 | <listitem><para> |
| 1940 | Configuration items that appear twice in the same |
| 1941 | configuration fragment. |
| 1942 | </para></listitem> |
| 1943 | <listitem><para> |
| 1944 | Configuration items tagged as "required" that were |
| 1945 | overridden. |
| 1946 | </para></listitem> |
| 1947 | <listitem><para> |
| 1948 | A board overrides a non-board specific option. |
| 1949 | </para></listitem> |
| 1950 | <listitem><para> |
| 1951 | Listed options not valid for the kernel being |
| 1952 | processed. |
| 1953 | In other words, the option does not appear anywhere. |
| 1954 | </para></listitem> |
| 1955 | </itemizedlist> |
| 1956 | <note> |
| 1957 | The <filename>do_kernel_configcheck</filename> task can |
| 1958 | also optionally report if an option is overridden during |
| 1959 | processing. |
| 1960 | </note> |
| 1961 | </para> |
| 1962 | |
| 1963 | <para> |
| 1964 | For each output warning, a message points to the file |
| 1965 | that contains a list of the options and a pointer to the |
| 1966 | configuration fragment that defines them. |
| 1967 | Collectively, the files are the key to streamlining the |
| 1968 | configuration. |
| 1969 | </para> |
| 1970 | |
| 1971 | <para> |
| 1972 | To streamline the configuration, do the following: |
| 1973 | <orderedlist> |
| 1974 | <listitem><para> |
| 1975 | <emphasis>Use a Working Configuration:</emphasis> |
| 1976 | Start with a full configuration that you |
| 1977 | know works. |
| 1978 | Be sure the configuration builds and boots |
| 1979 | successfully. |
| 1980 | Use this configuration file as your baseline. |
| 1981 | </para></listitem> |
| 1982 | <listitem><para> |
| 1983 | <emphasis>Run Configure and Check Tasks:</emphasis> |
| 1984 | Separately run the |
| 1985 | <filename>do_kernel_configme</filename> and |
| 1986 | <filename>do_kernel_configcheck</filename> tasks: |
| 1987 | <literallayout class='monospaced'> |
| 1988 | $ bitbake linux-yocto -c kernel_configme -f |
| 1989 | $ bitbake linux-yocto -c kernel_configcheck -f |
| 1990 | </literallayout> |
| 1991 | </para></listitem> |
| 1992 | <listitem><para> |
| 1993 | <emphasis>Process the Results:</emphasis> |
| 1994 | Take the resulting list of files from the |
| 1995 | <filename>do_kernel_configcheck</filename> task |
| 1996 | warnings and do the following: |
| 1997 | <itemizedlist> |
| 1998 | <listitem><para> |
| 1999 | Drop values that are redefined in the fragment |
| 2000 | but do not change the final |
| 2001 | <filename>.config</filename> file. |
| 2002 | </para></listitem> |
| 2003 | <listitem><para> |
| 2004 | Analyze and potentially drop values from the |
| 2005 | <filename>.config</filename> file that override |
| 2006 | required configurations. |
| 2007 | </para></listitem> |
| 2008 | <listitem><para> |
| 2009 | Analyze and potentially remove non-board |
| 2010 | specific options. |
| 2011 | </para></listitem> |
| 2012 | <listitem><para> |
| 2013 | Remove repeated and invalid options. |
| 2014 | </para></listitem> |
| 2015 | </itemizedlist> |
| 2016 | </para></listitem> |
| 2017 | <listitem><para> |
| 2018 | <emphasis>Re-Run Configure and Check Tasks:</emphasis> |
| 2019 | After you have worked through the output of the kernel |
| 2020 | configuration audit, you can re-run the |
| 2021 | <filename>do_kernel_configme</filename> and |
| 2022 | <filename>do_kernel_configcheck</filename> tasks to |
| 2023 | see the results of your changes. |
| 2024 | If you have more issues, you can deal with them as |
| 2025 | described in the previous step. |
| 2026 | </para></listitem> |
| 2027 | </orderedlist> |
| 2028 | </para> |
| 2029 | |
| 2030 | <para> |
| 2031 | Iteratively working through steps two through four eventually |
| 2032 | yields a minimal, streamlined configuration file. |
| 2033 | Once you have the best <filename>.config</filename>, you can |
| 2034 | build the Linux Yocto kernel. |
| 2035 | </para> |
| 2036 | </section> |
| 2037 | </section> |
| 2038 | |
| 2039 | <section id='expanding-variables'> |
| 2040 | <title>Expanding Variables</title> |
| 2041 | |
| 2042 | <para> |
| 2043 | Sometimes it is helpful to determine what a variable expands |
| 2044 | to during a build. |
| 2045 | You can do examine the values of variables by examining the |
| 2046 | output of the <filename>bitbake -e</filename> command. |
| 2047 | The output is long and is more easily managed in a text file, |
| 2048 | which allows for easy searches: |
| 2049 | <literallayout class='monospaced'> |
| 2050 | $ bitbake -e virtual/kernel > <replaceable>some_text_file</replaceable> |
| 2051 | </literallayout> |
| 2052 | Within the text file, you can see exactly how each variable is |
| 2053 | expanded and used by the OpenEmbedded build system. |
| 2054 | </para> |
| 2055 | </section> |
| 2056 | |
| 2057 | <section id='working-with-a-dirty-kernel-version-string'> |
| 2058 | <title>Working with a "Dirty" Kernel Version String</title> |
| 2059 | |
| 2060 | <para> |
| 2061 | If you build a kernel image and the version string has a |
| 2062 | "+" or a "-dirty" at the end, uncommitted modifications exist |
| 2063 | in the kernel's source directory. |
| 2064 | Follow these steps to clean up the version string: |
| 2065 | <orderedlist> |
| 2066 | <listitem><para> |
| 2067 | <emphasis>Discover the Uncommitted Changes:</emphasis> |
| 2068 | Go to the kernel's locally cloned Git repository |
| 2069 | (source directory) and use the following Git command |
| 2070 | to list the files that have been changed, added, or |
| 2071 | removed: |
| 2072 | <literallayout class='monospaced'> |
| 2073 | $ git status |
| 2074 | </literallayout> |
| 2075 | </para></listitem> |
| 2076 | <listitem><para> |
| 2077 | <emphasis>Commit the Changes:</emphasis> |
| 2078 | You should commit those changes to the kernel source |
| 2079 | tree regardless of whether or not you will save, |
| 2080 | export, or use the changes: |
| 2081 | <literallayout class='monospaced'> |
| 2082 | $ git add |
| 2083 | $ git commit -s -a -m "getting rid of -dirty" |
| 2084 | </literallayout> |
| 2085 | </para></listitem> |
| 2086 | <listitem><para> |
| 2087 | <emphasis>Rebuild the Kernel Image:</emphasis> |
| 2088 | Once you commit the changes, rebuild the kernel.</para> |
| 2089 | |
| 2090 | <para>Depending on your particular kernel development |
| 2091 | workflow, the commands you use to rebuild the |
| 2092 | kernel might differ. |
| 2093 | For information on building the kernel image when |
| 2094 | using <filename>devtool</filename>, see the |
| 2095 | "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>" |
| 2096 | section. |
| 2097 | For information on building the kernel image when |
| 2098 | using Bitbake, see the |
| 2099 | "<link linkend='using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</link>" |
| 2100 | section. |
| 2101 | </para></listitem> |
| 2102 | </orderedlist> |
| 2103 | </para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2104 | </section> |
| 2105 | |
| 2106 | <section id='working-with-your-own-sources'> |
| 2107 | <title>Working With Your Own Sources</title> |
| 2108 | |
| 2109 | <para> |
| 2110 | If you cannot work with one of the Linux kernel |
| 2111 | versions supported by existing linux-yocto recipes, you can |
| 2112 | still make use of the Yocto Project Linux kernel tooling by |
| 2113 | working with your own sources. |
| 2114 | When you use your own sources, you will not be able to |
| 2115 | leverage the existing kernel |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2116 | <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink> and |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2117 | stabilization work of the linux-yocto sources. |
| 2118 | However, you will be able to manage your own Metadata in the same |
| 2119 | format as the linux-yocto sources. |
| 2120 | Maintaining format compatibility facilitates converging with |
| 2121 | linux-yocto on a future, mutually-supported kernel version. |
| 2122 | </para> |
| 2123 | |
| 2124 | <para> |
| 2125 | To help you use your own sources, the Yocto Project provides a |
| 2126 | linux-yocto custom recipe |
| 2127 | (<filename>linux-yocto-custom.bb</filename>) that uses |
| 2128 | <filename>kernel.org</filename> sources |
| 2129 | and the Yocto Project Linux kernel tools for managing |
| 2130 | kernel Metadata. |
| 2131 | You can find this recipe in the |
| 2132 | <filename>poky</filename> Git repository of the |
| 2133 | Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink> |
| 2134 | at: |
| 2135 | <literallayout class="monospaced"> |
| 2136 | poky/meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb |
| 2137 | </literallayout> |
| 2138 | </para> |
| 2139 | |
| 2140 | <para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2141 | Here are some basic steps you can use to work with your own |
| 2142 | sources: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2143 | <orderedlist> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2144 | <listitem><para> |
| 2145 | <emphasis>Create a Copy of the Kernel Recipe:</emphasis> |
| 2146 | Copy the <filename>linux-yocto-custom.bb</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2147 | recipe to your layer and give it a meaningful name. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2148 | The name should include the version of the Yocto Linux |
| 2149 | kernel you are using (e.g. |
| 2150 | <filename>linux-yocto-myproject_4.12.bb</filename>, |
| 2151 | where "4.12" is the base version of the Linux kernel |
| 2152 | with which you would be working). |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2153 | </para></listitem> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2154 | <listitem><para> |
| 2155 | <emphasis>Create a Directory for Your Patches:</emphasis> |
| 2156 | In the same directory inside your layer, create a matching |
| 2157 | directory to store your patches and configuration files |
| 2158 | (e.g. <filename>linux-yocto-myproject</filename>). |
| 2159 | </para></listitem> |
| 2160 | <listitem><para> |
| 2161 | <emphasis>Ensure You Have Configurations:</emphasis> |
| 2162 | Make sure you have either a <filename>defconfig</filename> |
| 2163 | file or configuration fragment files in your layer. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2164 | When you use the <filename>linux-yocto-custom.bb</filename> |
| 2165 | recipe, you must specify a configuration. |
| 2166 | If you do not have a <filename>defconfig</filename> file, |
| 2167 | you can run the following: |
| 2168 | <literallayout class='monospaced'> |
| 2169 | $ make defconfig |
| 2170 | </literallayout> |
| 2171 | After running the command, copy the resulting |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2172 | <filename>.config</filename> file to the |
| 2173 | <filename>files</filename> directory in your layer |
| 2174 | as "defconfig" and then add it to the |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2175 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 2176 | variable in the recipe.</para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2177 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2178 | <para>Running the <filename>make defconfig</filename> |
| 2179 | command results in the default configuration for your |
| 2180 | architecture as defined by your kernel. |
| 2181 | However, no guarantee exists that this configuration is |
| 2182 | valid for your use case, or that your board will even boot. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2183 | This is particularly true for non-x86 architectures.</para> |
| 2184 | |
| 2185 | <para>To use non-x86 <filename>defconfig</filename> files, |
| 2186 | you need to be more specific and find one that matches your |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2187 | board (i.e. for arm, you look in |
| 2188 | <filename>arch/arm/configs</filename> and use the one that |
| 2189 | is the best starting point for your board). |
| 2190 | </para></listitem> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2191 | <listitem><para> |
| 2192 | <emphasis>Edit the Recipe:</emphasis> |
| 2193 | Edit the following variables in your recipe as appropriate |
| 2194 | for your project: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2195 | <itemizedlist> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2196 | <listitem><para> |
| 2197 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2198 | The <filename>SRC_URI</filename> should specify |
| 2199 | a Git repository that uses one of the supported Git |
| 2200 | fetcher protocols (i.e. <filename>file</filename>, |
| 2201 | <filename>git</filename>, <filename>http</filename>, |
| 2202 | and so forth). |
| 2203 | The <filename>SRC_URI</filename> variable should |
| 2204 | also specify either a <filename>defconfig</filename> |
| 2205 | file or some configuration fragment files. |
| 2206 | The skeleton recipe provides an example |
| 2207 | <filename>SRC_URI</filename> as a syntax reference. |
| 2208 | </para></listitem> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2209 | <listitem><para> |
| 2210 | <ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION'><filename>LINUX_VERSION</filename></ulink>: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2211 | The Linux kernel version you are using (e.g. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2212 | "4.12"). |
| 2213 | </para></listitem> |
| 2214 | <listitem><para> |
| 2215 | <ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION_EXTENSION'><filename>LINUX_VERSION_EXTENSION</filename></ulink>: |
| 2216 | The Linux kernel |
| 2217 | <filename>CONFIG_LOCALVERSION</filename> that is |
| 2218 | compiled into the resulting kernel and visible |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2219 | through the <filename>uname</filename> command. |
| 2220 | </para></listitem> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2221 | <listitem><para> |
| 2222 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2223 | The commit ID from which you want to build. |
| 2224 | </para></listitem> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2225 | <listitem><para> |
| 2226 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>: |
| 2227 | Treat this variable the same as you would in any |
| 2228 | other recipe. |
| 2229 | Increment the variable to indicate to the |
| 2230 | OpenEmbedded build system that the recipe has |
| 2231 | changed. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2232 | </para></listitem> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2233 | <listitem><para> |
| 2234 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2235 | The default <filename>PV</filename> assignment is |
| 2236 | typically adequate. |
| 2237 | It combines the <filename>LINUX_VERSION</filename> |
| 2238 | with the Source Control Manager (SCM) revision |
| 2239 | as derived from the |
| 2240 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink> |
| 2241 | variable. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2242 | The combined results are a string with the |
| 2243 | following form: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2244 | <literallayout class='monospaced'> |
| 2245 | 3.19.11+git1+68a635bf8dfb64b02263c1ac80c948647cc76d5f_1+218bd8d2022b9852c60d32f0d770931e3cf343e2 |
| 2246 | </literallayout> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2247 | While lengthy, the extra verbosity in |
| 2248 | <filename>PV</filename> helps ensure you are using |
| 2249 | the exact sources from which you intend to build. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2250 | </para></listitem> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2251 | <listitem><para> |
| 2252 | <ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'><filename>COMPATIBLE_MACHINE</filename></ulink>: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2253 | A list of the machines supported by your new recipe. |
| 2254 | This variable in the example recipe is set |
| 2255 | by default to a regular expression that matches |
| 2256 | only the empty string, "(^$)". |
| 2257 | This default setting triggers an explicit build |
| 2258 | failure. |
| 2259 | You must change it to match a list of the machines |
| 2260 | that your new recipe supports. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2261 | For example, to support the |
| 2262 | <filename>qemux86</filename> and |
| 2263 | <filename>qemux86-64</filename> machines, use |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2264 | the following form: |
| 2265 | <literallayout class='monospaced'> |
| 2266 | COMPATIBLE_MACHINE = "qemux86|qemux86-64" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2267 | </literallayout> |
| 2268 | </para></listitem> |
| 2269 | </itemizedlist> |
| 2270 | </para></listitem> |
| 2271 | <listitem><para> |
| 2272 | <emphasis>Customize Your Recipe as Needed:</emphasis> |
| 2273 | Provide further customizations to your recipe |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2274 | as needed just as you would customize an existing |
| 2275 | linux-yocto recipe. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2276 | See the |
| 2277 | "<link linkend='modifying-an-existing-recipe'>Modifying an Existing Recipe</link>" |
| 2278 | section for information. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2279 | </para></listitem> |
| 2280 | </orderedlist> |
| 2281 | </para> |
| 2282 | </section> |
| 2283 | |
| 2284 | <section id='working-with-out-of-tree-modules'> |
| 2285 | <title>Working with Out-of-Tree Modules</title> |
| 2286 | |
| 2287 | <para> |
| 2288 | This section describes steps to build out-of-tree modules on |
| 2289 | your target and describes how to incorporate out-of-tree modules |
| 2290 | in the build. |
| 2291 | </para> |
| 2292 | |
| 2293 | <section id='building-out-of-tree-modules-on-the-target'> |
| 2294 | <title>Building Out-of-Tree Modules on the Target</title> |
| 2295 | |
| 2296 | <para> |
| 2297 | While the traditional Yocto Project development model would be |
| 2298 | to include kernel modules as part of the normal build |
| 2299 | process, you might find it useful to build modules on the |
| 2300 | target. |
| 2301 | This could be the case if your target system is capable |
| 2302 | and powerful enough to handle the necessary compilation. |
| 2303 | Before deciding to build on your target, however, you should |
| 2304 | consider the benefits of using a proper cross-development |
| 2305 | environment from your build host. |
| 2306 | </para> |
| 2307 | |
| 2308 | <para> |
| 2309 | If you want to be able to build out-of-tree modules on |
| 2310 | the target, there are some steps you need to take |
| 2311 | on the target that is running your SDK image. |
| 2312 | Briefly, the <filename>kernel-dev</filename> package |
| 2313 | is installed by default on all |
| 2314 | <filename>*.sdk</filename> images and the |
| 2315 | <filename>kernel-devsrc</filename> package is installed |
| 2316 | on many of the <filename>*.sdk</filename> images. |
| 2317 | However, you need to create some scripts prior to |
| 2318 | attempting to build the out-of-tree modules on the target |
| 2319 | that is running that image. |
| 2320 | </para> |
| 2321 | |
| 2322 | <para> |
| 2323 | Prior to attempting to build the out-of-tree modules, |
| 2324 | you need to be on the target as root and you need to |
| 2325 | change to the <filename>/usr/src/kernel</filename> directory. |
| 2326 | Next, <filename>make</filename> the scripts: |
| 2327 | <literallayout class='monospaced'> |
| 2328 | # cd /usr/src/kernel |
| 2329 | # make scripts |
| 2330 | </literallayout> |
| 2331 | Because all SDK image recipes include |
| 2332 | <filename>dev-pkgs</filename>, the |
| 2333 | <filename>kernel-dev</filename> packages will be installed |
| 2334 | as part of the SDK image and the |
| 2335 | <filename>kernel-devsrc</filename> packages will be installed |
| 2336 | as part of applicable SDK images. |
| 2337 | The SDK uses the scripts when building out-of-tree |
| 2338 | modules. |
| 2339 | Once you have switched to that directory and created the |
| 2340 | scripts, you should be able to build your out-of-tree modules |
| 2341 | on the target. |
| 2342 | </para> |
| 2343 | </section> |
| 2344 | |
| 2345 | <section id='incorporating-out-of-tree-modules'> |
| 2346 | <title>Incorporating Out-of-Tree Modules</title> |
| 2347 | |
| 2348 | <para> |
| 2349 | While it is always preferable to work with sources integrated |
| 2350 | into the Linux kernel sources, if you need an external kernel |
| 2351 | module, the <filename>hello-mod.bb</filename> recipe is |
| 2352 | available as a template from which you can create your |
| 2353 | own out-of-tree Linux kernel module recipe. |
| 2354 | </para> |
| 2355 | |
| 2356 | <para> |
| 2357 | This template recipe is located in the |
| 2358 | <filename>poky</filename> Git repository of the |
| 2359 | Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink> |
| 2360 | at: |
| 2361 | <literallayout class="monospaced"> |
| 2362 | poky/meta-skeleton/recipes-kernel/hello-mod/hello-mod_0.1.bb |
| 2363 | </literallayout> |
| 2364 | </para> |
| 2365 | |
| 2366 | <para> |
| 2367 | To get started, copy this recipe to your layer and give it a |
| 2368 | meaningful name (e.g. <filename>mymodule_1.0.bb</filename>). |
| 2369 | In the same directory, create a new directory named |
| 2370 | <filename>files</filename> where you can store any source files, |
| 2371 | patches, or other files necessary for building |
| 2372 | the module that do not come with the sources. |
| 2373 | Finally, update the recipe as needed for the module. |
| 2374 | Typically, you will need to set the following variables: |
| 2375 | <itemizedlist> |
| 2376 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink> |
| 2377 | </para></listitem> |
| 2378 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE*</filename></ulink> |
| 2379 | </para></listitem> |
| 2380 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 2381 | </para></listitem> |
| 2382 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> |
| 2383 | </para></listitem> |
| 2384 | </itemizedlist> |
| 2385 | </para> |
| 2386 | |
| 2387 | <para> |
| 2388 | Depending on the build system used by the module sources, |
| 2389 | you might need to make some adjustments. |
| 2390 | For example, a typical module <filename>Makefile</filename> |
| 2391 | looks much like the one provided with the |
| 2392 | <filename>hello-mod</filename> template: |
| 2393 | <literallayout class='monospaced'> |
| 2394 | obj-m := hello.o |
| 2395 | |
| 2396 | SRC := $(shell pwd) |
| 2397 | |
| 2398 | all: |
| 2399 | $(MAKE) -C $(KERNEL_SRC) M=$(SRC) |
| 2400 | |
| 2401 | modules_install: |
| 2402 | $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install |
| 2403 | ... |
| 2404 | </literallayout> |
| 2405 | </para> |
| 2406 | |
| 2407 | <para> |
| 2408 | The important point to note here is the |
| 2409 | <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_SRC'><filename>KERNEL_SRC</filename></ulink> |
| 2410 | variable. |
| 2411 | The |
| 2412 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-module'><filename>module</filename></ulink> |
| 2413 | class sets this variable and the |
| 2414 | <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_PATH'><filename>KERNEL_PATH</filename></ulink> |
| 2415 | variable to |
| 2416 | <filename>${<ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_KERNEL_DIR'><filename>STAGING_KERNEL_DIR</filename></ulink>}</filename> |
| 2417 | with the necessary Linux kernel build information to build |
| 2418 | modules. |
| 2419 | If your module <filename>Makefile</filename> uses a different |
| 2420 | variable, you might want to override the |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2421 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2422 | step, or create a patch to |
| 2423 | the <filename>Makefile</filename> to work with the more typical |
| 2424 | <filename>KERNEL_SRC</filename> or |
| 2425 | <filename>KERNEL_PATH</filename> variables. |
| 2426 | </para> |
| 2427 | |
| 2428 | <para> |
| 2429 | After you have prepared your recipe, you will likely want to |
| 2430 | include the module in your images. |
| 2431 | To do this, see the documentation for the following variables in |
| 2432 | the Yocto Project Reference Manual and set one of them |
| 2433 | appropriately for your machine configuration file: |
| 2434 | <itemizedlist> |
| 2435 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RDEPENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RDEPENDS</filename></ulink> |
| 2436 | </para></listitem> |
| 2437 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink> |
| 2438 | </para></listitem> |
| 2439 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RDEPENDS'><filename>MACHINE_EXTRA_RDEPENDS</filename></ulink> |
| 2440 | </para></listitem> |
| 2441 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RRECOMMENDS'><filename>MACHINE_EXTRA_RRECOMMENDS</filename></ulink> |
| 2442 | </para></listitem> |
| 2443 | </itemizedlist> |
| 2444 | </para> |
| 2445 | |
| 2446 | <para> |
| 2447 | Modules are often not required for boot and can be excluded from |
| 2448 | certain build configurations. |
| 2449 | The following allows for the most flexibility: |
| 2450 | <literallayout class='monospaced'> |
| 2451 | MACHINE_EXTRA_RRECOMMENDS += "kernel-module-mymodule" |
| 2452 | </literallayout> |
| 2453 | The value is derived by appending the module filename without |
| 2454 | the <filename>.ko</filename> extension to the string |
| 2455 | "kernel-module-". |
| 2456 | </para> |
| 2457 | |
| 2458 | <para> |
| 2459 | Because the variable is |
| 2460 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink> |
| 2461 | and not a |
| 2462 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink> |
| 2463 | variable, the build will not fail if this module is not |
| 2464 | available to include in the image. |
| 2465 | </para> |
| 2466 | </section> |
| 2467 | </section> |
| 2468 | |
| 2469 | |
| 2470 | <section id='inspecting-changes-and-commits'> |
| 2471 | <title>Inspecting Changes and Commits</title> |
| 2472 | |
| 2473 | <para> |
| 2474 | A common question when working with a kernel is: |
| 2475 | "What changes have been applied to this tree?" |
| 2476 | Rather than using "grep" across directories to see what has |
| 2477 | changed, you can use Git to inspect or search the kernel tree. |
| 2478 | Using Git is an efficient way to see what has changed in the tree. |
| 2479 | </para> |
| 2480 | |
| 2481 | <section id='what-changed-in-a-kernel'> |
| 2482 | <title>What Changed in a Kernel?</title> |
| 2483 | |
| 2484 | <para> |
| 2485 | Following are a few examples that show how to use Git |
| 2486 | commands to examine changes. |
| 2487 | These examples are by no means the only way to see changes. |
| 2488 | <note> |
| 2489 | In the following examples, unless you provide a commit |
| 2490 | range, <filename>kernel.org</filename> history is blended |
| 2491 | with Yocto Project kernel changes. |
| 2492 | You can form ranges by using branch names from the |
| 2493 | kernel tree as the upper and lower commit markers with |
| 2494 | the Git commands. |
| 2495 | You can see the branch names through the web interface |
| 2496 | to the Yocto Project source repositories at |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2497 | <ulink url='&YOCTO_GIT_URL;'></ulink>. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2498 | </note> |
| 2499 | To see a full range of the changes, use the |
| 2500 | <filename>git whatchanged</filename> command and specify a |
| 2501 | commit range for the branch |
| 2502 | (<replaceable>commit</replaceable><filename>..</filename><replaceable>commit</replaceable>). |
| 2503 | </para> |
| 2504 | |
| 2505 | <para> |
| 2506 | Here is an example that looks at what has changed in the |
| 2507 | <filename>emenlow</filename> branch of the |
| 2508 | <filename>linux-yocto-3.19</filename> kernel. |
| 2509 | The lower commit range is the commit associated with the |
| 2510 | <filename>standard/base</filename> branch, while |
| 2511 | the upper commit range is the commit associated with the |
| 2512 | <filename>standard/emenlow</filename> branch. |
| 2513 | <literallayout class='monospaced'> |
| 2514 | $ git whatchanged origin/standard/base..origin/standard/emenlow |
| 2515 | </literallayout> |
| 2516 | </para> |
| 2517 | |
| 2518 | <para> |
| 2519 | To see short, one line summaries of changes use the |
| 2520 | <filename>git log</filename> command: |
| 2521 | <literallayout class='monospaced'> |
| 2522 | $ git log --oneline origin/standard/base..origin/standard/emenlow |
| 2523 | </literallayout> |
| 2524 | </para> |
| 2525 | |
| 2526 | <para> |
| 2527 | Use this command to see code differences for the changes: |
| 2528 | <literallayout class='monospaced'> |
| 2529 | $ git diff origin/standard/base..origin/standard/emenlow |
| 2530 | </literallayout> |
| 2531 | </para> |
| 2532 | |
| 2533 | <para> |
| 2534 | Use this command to see the commit log messages and the |
| 2535 | text differences: |
| 2536 | <literallayout class='monospaced'> |
| 2537 | $ git show origin/standard/base..origin/standard/emenlow |
| 2538 | </literallayout> |
| 2539 | </para> |
| 2540 | |
| 2541 | <para> |
| 2542 | Use this command to create individual patches for |
| 2543 | each change. |
| 2544 | Here is an example that that creates patch files for each |
| 2545 | commit and places them in your <filename>Documents</filename> |
| 2546 | directory: |
| 2547 | <literallayout class='monospaced'> |
| 2548 | $ git format-patch -o $HOME/Documents origin/standard/base..origin/standard/emenlow |
| 2549 | </literallayout> |
| 2550 | </para> |
| 2551 | </section> |
| 2552 | |
| 2553 | <section id='showing-a-particular-feature-or-branch-change'> |
| 2554 | <title>Showing a Particular Feature or Branch Change</title> |
| 2555 | |
| 2556 | <para> |
| 2557 | Tags in the Yocto Project kernel tree divide changes for |
| 2558 | significant features or branches. |
| 2559 | The <filename>git show</filename> <replaceable>tag</replaceable> |
| 2560 | command shows changes based on a tag. |
| 2561 | Here is an example that shows <filename>systemtap</filename> |
| 2562 | changes: |
| 2563 | <literallayout class='monospaced'> |
| 2564 | $ git show systemtap |
| 2565 | </literallayout> |
| 2566 | You can use the |
| 2567 | <filename>git branch --contains</filename> <replaceable>tag</replaceable> |
| 2568 | command to show the branches that contain a particular feature. |
| 2569 | This command shows the branches that contain the |
| 2570 | <filename>systemtap</filename> feature: |
| 2571 | <literallayout class='monospaced'> |
| 2572 | $ git branch --contains systemtap |
| 2573 | </literallayout> |
| 2574 | </para> |
| 2575 | </section> |
| 2576 | </section> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2577 | |
| 2578 | <section id='adding-recipe-space-kernel-features'> |
| 2579 | <title>Adding Recipe-Space Kernel Features</title> |
| 2580 | |
| 2581 | <para> |
| 2582 | You can add kernel features in the |
| 2583 | <link linkend='recipe-space-metadata'>recipe-space</link> by |
| 2584 | using the |
| 2585 | <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_FEATURES'><filename>KERNEL_FEATURES</filename></ulink> |
| 2586 | variable and by specifying the feature's <filename>.scc</filename> |
| 2587 | file path in the |
| 2588 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 2589 | statement. |
| 2590 | When you add features using this method, the OpenEmbedded build |
| 2591 | system checks to be sure the features are present. |
| 2592 | If the features are not present, the build stops. |
| 2593 | Kernel features are the last elements processed for configuring |
| 2594 | and patching the kernel. |
| 2595 | Therefore, adding features in this manner is a way |
| 2596 | to enforce specific features are present and enabled |
| 2597 | without needing to do a full audit of any other layer's additions |
| 2598 | to the <filename>SRC_URI</filename> statement. |
| 2599 | </para> |
| 2600 | |
| 2601 | <para> |
| 2602 | You add a kernel feature by providing the feature as part of the |
| 2603 | <filename>KERNEL_FEATURES</filename> variable and by providing the |
| 2604 | path to the feature's <filename>.scc</filename> file, which is |
| 2605 | relative to the root of the kernel Metadata. |
| 2606 | The OpenEmbedded build system searches all forms of kernel |
| 2607 | Metadata on the <filename>SRC_URI</filename> statement regardless |
| 2608 | of whether the Metadata is in the "kernel-cache", system kernel |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2609 | Metadata, or a recipe-space Metadata (i.e. part of the kernel |
| 2610 | recipe). |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2611 | See the |
| 2612 | "<link linkend='kernel-metadata-location'>Kernel Metadata Location</link>" |
| 2613 | section for additional information. |
| 2614 | </para> |
| 2615 | |
| 2616 | <para> |
| 2617 | When you specify the feature's <filename>.scc</filename> file |
| 2618 | on the <filename>SRC_URI</filename> statement, the OpenEmbedded |
| 2619 | build system adds the directory of that |
| 2620 | <filename>.scc</filename> file along with all its subdirectories |
| 2621 | to the kernel feature search path. |
| 2622 | Because subdirectories are searched, you can reference a single |
| 2623 | <filename>.scc</filename> file in the |
| 2624 | <filename>SRC_URI</filename> statement to reference multiple kernel |
| 2625 | features. |
| 2626 | </para> |
| 2627 | |
| 2628 | <para> |
| 2629 | Consider the following example that adds the "test.scc" feature |
| 2630 | to the build. |
| 2631 | <orderedlist> |
| 2632 | <listitem><para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2633 | <emphasis>Create the Feature File:</emphasis> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2634 | Create a <filename>.scc</filename> file and locate it |
| 2635 | just as you would any other patch file, |
| 2636 | <filename>.cfg</filename> file, or fetcher item |
| 2637 | you specify in the <filename>SRC_URI</filename> |
| 2638 | statement. |
| 2639 | <note><title>Notes</title> |
| 2640 | <itemizedlist> |
| 2641 | <listitem><para> |
| 2642 | You must add the directory of the |
| 2643 | <filename>.scc</filename> file to the fetcher's |
| 2644 | search path in the same manner as you would |
| 2645 | add a <filename>.patch</filename> file. |
| 2646 | </para></listitem> |
| 2647 | <listitem><para> |
| 2648 | You can create additional |
| 2649 | <filename>.scc</filename> files beneath the |
| 2650 | directory that contains the file you are |
| 2651 | adding. |
| 2652 | All subdirectories are searched during the |
| 2653 | build as potential feature directories. |
| 2654 | </para></listitem> |
| 2655 | </itemizedlist> |
| 2656 | </note> |
| 2657 | Continuing with the example, suppose the "test.scc" |
| 2658 | feature you are adding has a |
| 2659 | <filename>test.scc</filename> file in the following |
| 2660 | directory: |
| 2661 | <literallayout class='monospaced'> |
| 2662 | <replaceable>my_recipe</replaceable> |
| 2663 | | |
| 2664 | +-linux-yocto |
| 2665 | | |
| 2666 | +-test.cfg |
| 2667 | +-test.scc |
| 2668 | </literallayout> |
| 2669 | In this example, the <filename>linux-yocto</filename> |
| 2670 | directory has both the feature |
| 2671 | <filename>test.scc</filename> file and a similarly |
| 2672 | named configuration fragment file |
| 2673 | <filename>test.cfg</filename>. |
| 2674 | </para></listitem> |
| 2675 | <listitem><para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2676 | <emphasis>Add the Feature File to <filename>SRC_URI</filename>:</emphasis> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2677 | Add the <filename>.scc</filename> file to the |
| 2678 | recipe's <filename>SRC_URI</filename> statement: |
| 2679 | <literallayout class='monospaced'> |
| 2680 | SRC_URI_append = " file://test.scc" |
| 2681 | </literallayout> |
| 2682 | The leading space before the path is important as the |
| 2683 | path is appended to the existing path. |
| 2684 | </para></listitem> |
| 2685 | <listitem><para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2686 | <emphasis>Specify the Feature as a Kernel Feature:</emphasis> |
| 2687 | Use the <filename>KERNEL_FEATURES</filename> statement |
| 2688 | to specify the feature as a kernel feature: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2689 | <literallayout class='monospaced'> |
| 2690 | KERNEL_FEATURES_append = " test.scc" |
| 2691 | </literallayout> |
| 2692 | The OpenEmbedded build system processes the kernel feature |
| 2693 | when it builds the kernel. |
| 2694 | <note> |
| 2695 | If other features are contained below "test.scc", |
| 2696 | then their directories are relative to the directory |
| 2697 | containing the <filename>test.scc</filename> file. |
| 2698 | </note> |
| 2699 | </para></listitem> |
| 2700 | </orderedlist> |
| 2701 | </para> |
| 2702 | </section> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2703 | </chapter> |
| 2704 | <!-- |
| 2705 | vim: expandtab tw=80 ts=4 |
| 2706 | --> |