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