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