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