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