blob: 3f35d8412f33c655ad2fa292d7f092c12033bfd0 [file] [log] [blame]
Andrew Geisslerf0343792020-11-18 10:42:21 -06001.. SPDX-License-Identifier: CC-BY-SA-2.0-UK
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002
3************
4Common Tasks
5************
6
7This chapter presents several common tasks you perform when you work
8with the Yocto Project Linux kernel. These tasks include preparing your
9host development system for kernel development, preparing a layer,
10modifying an existing recipe, patching the kernel, configuring the
11kernel, iterative development, working with your own sources, and
12incorporating 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
19Preparing the Build Host to Work on the Kernel
20==============================================
21
22Before you can do any kernel development, you need to be sure your build
23host is set up to use the Yocto Project. For information on how to get
Andrew Geissler09209ee2020-12-13 08:44:15 -060024set up, see the ":doc:`/dev-manual/start`" section in
Andrew Geisslerc9f78652020-09-18 14:11:35 -050025the Yocto Project Development Tasks Manual. Part of preparing the system
26is creating a local Git repository of the
27:term:`Source Directory` (``poky``) on your system. Follow the steps in the
Andrew Geissler09209ee2020-12-13 08:44:15 -060028":ref:`dev-manual/start:cloning the \`\`poky\`\` repository`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050029section in the Yocto Project Development Tasks Manual to set up your
30Source 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 Geissler4c19ea12020-10-27 13:52:24 -050036 desired version of Yocto Project. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -060037 ":ref:`dev-manual/start:checking out by branch in poky`" and
38 ":ref:`dev-manual/start:checking out by tag in poky`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -050039 sections in the Yocto Project Development Tasks Manual for more information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050040
41Kernel development is best accomplished using
Andrew Geissler09209ee2020-12-13 08:44:15 -060042:ref:`devtool <sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050043and not through traditional kernel workflow methods. The remainder of
44this section provides information for both scenarios.
45
46Getting Ready to Develop Using ``devtool``
47------------------------------------------
48
49Follow these steps to prepare to update the kernel image using
50``devtool``. Completing this procedure leaves you with a clean kernel
Andrew Geissler4c19ea12020-10-27 13:52:24 -050051image and ready to make modifications as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -060052":ref:`kernel-dev/common:using \`\`devtool\`\` to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050053section:
54
551. *Initialize the BitBake Environment:* Before building an extensible
56 SDK, you need to initialize the BitBake build environment by sourcing
Andrew Geisslerc926e172021-05-07 16:11:35 -050057 the build environment script (i.e. :ref:`structure-core-script`)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050058
Andrew Geissler95ac1b82021-03-31 14:34:31 -050059 $ cd poky
Andrew Geisslerc9f78652020-09-18 14:11:35 -050060 $ source oe-init-build-env
61
62 .. note::
63
64 The previous commands assume the
Andrew Geissler09209ee2020-12-13 08:44:15 -060065 :ref:`overview-manual/development-environment:yocto project source repositories`
Andrew Geissler4c19ea12020-10-27 13:52:24 -050066 (i.e. ``poky``) have been cloned using Git and the local repository is named
Andrew Geisslerc9f78652020-09-18 14:11:35 -050067 "poky".
68
692. *Prepare Your local.conf File:* By default, the
70 :term:`MACHINE` variable is set to
71 "qemux86-64", which is fine if you are building for the QEMU emulator
72 in 64-bit mode. However, if you are not, you need to set the
73 ``MACHINE`` variable appropriately in your ``conf/local.conf`` file
74 found in the
75 :term:`Build Directory` (i.e.
Andrew Geissler95ac1b82021-03-31 14:34:31 -050076 ``poky/build`` in this example).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050077
78 Also, since you are preparing to work on the kernel image, you need
79 to set the
80 :term:`MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS`
81 variable to include kernel modules.
82
83 In this example we wish to build for qemux86 so we must set the
84 ``MACHINE`` variable to "qemux86" and also add the "kernel-modules".
Andrew Geisslerc926e172021-05-07 16:11:35 -050085 As described we do this by appending to ``conf/local.conf``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050086
87 MACHINE = "qemux86"
88 MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules"
89
903. *Create a Layer for Patches:* You need to create a layer to hold
91 patches created for the kernel image. You can use the
Andrew Geisslerc926e172021-05-07 16:11:35 -050092 ``bitbake-layers create-layer`` command as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050093
Andrew Geissler95ac1b82021-03-31 14:34:31 -050094 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -050095 $ bitbake-layers create-layer ../../meta-mylayer
96 NOTE: Starting bitbake server...
97 Add your new layer with 'bitbake-layers add-layer ../../meta-mylayer'
98 $
99
100 .. note::
101
102 For background information on working with common and BSP layers,
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500103 see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600104 ":ref:`dev-manual/common-tasks:understanding and creating layers`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500105 section in the Yocto Project Development Tasks Manual and the
106 ":ref:`bsp-guide/bsp:bsp layers`" section in the Yocto Project Board
107 Support (BSP) Developer's Guide, respectively. For information on how to
108 use the ``bitbake-layers create-layer`` command to quickly set up a layer,
109 see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600110 ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500111 section in the Yocto Project Development Tasks Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500112
1134. *Inform the BitBake Build Environment About Your Layer:* As directed
114 when you created your layer, you need to add the layer to the
115 :term:`BBLAYERS` variable in the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500116 ``bblayers.conf`` file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500117
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500118 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500119 $ bitbake-layers add-layer ../../meta-mylayer
120 NOTE: Starting bitbake server...
121 $
122
1235. *Build the Extensible SDK:* Use BitBake to build the extensible SDK
Andrew Geisslerc926e172021-05-07 16:11:35 -0500124 specifically for use with images to be run using QEMU::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500125
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500126 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500127 $ bitbake core-image-minimal -c populate_sdk_ext
128
129 Once
130 the build finishes, you can find the SDK installer file (i.e.
Andrew Geisslerc926e172021-05-07 16:11:35 -0500131 ``*.sh`` file) in the following directory::
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500132
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500133 poky/build/tmp/deploy/sdk
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500134
135 For this example, the installer file is named
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600136 ``poky-glibc-x86_64-core-image-minimal-i586-toolchain-ext-&DISTRO;.sh``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500137
1386. *Install the Extensible SDK:* Use the following command to install
139 the SDK. For this example, install the SDK in the default
Andrew Geisslerc926e172021-05-07 16:11:35 -0500140 ``poky_sdk`` directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500141
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500142 $ cd poky/build/tmp/deploy/sdk
Andrew Geissler09209ee2020-12-13 08:44:15 -0600143 $ ./poky-glibc-x86_64-core-image-minimal-i586-toolchain-ext-&DISTRO;.sh
144 Poky (Yocto Project Reference Distro) Extensible SDK installer version &DISTRO;
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500145 ============================================================================
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500146 Enter target directory for SDK (default: poky_sdk):
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500147 You are about to install the SDK to "/home/scottrif/poky_sdk". Proceed [Y/n]? Y
148 Extracting SDK......................................done
149 Setting it up...
150 Extracting buildtools...
151 Preparing build system...
152 Parsing recipes: 100% |#################################################################| Time: 0:00:52
153 Initializing tasks: 100% |############## ###############################################| Time: 0:00:04
154 Checking sstate mirror object availability: 100% |######################################| Time: 0:00:00
155 Parsing recipes: 100% |#################################################################| Time: 0:00:33
156 Initializing tasks: 100% |##############################################################| Time: 0:00:00
157 done
158 SDK has been successfully set up and is ready to be used.
159 Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
160 $ . /home/scottrif/poky_sdk/environment-setup-i586-poky-linux
161
162
1637. *Set Up a New Terminal to Work With the Extensible SDK:* You must set
164 up a new terminal to work with the SDK. You cannot use the same
165 BitBake shell used to build the installer.
166
167 After opening a new shell, run the SDK environment setup script as
Andrew Geisslerc926e172021-05-07 16:11:35 -0500168 directed by the output from installing the SDK::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500169
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500170 $ source poky_sdk/environment-setup-i586-poky-linux
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500171 "SDK environment now set up; additionally you may now run devtool to perform development tasks.
172 Run devtool --help for further details.
173
174 .. note::
175
176 If you get a warning about attempting to use the extensible SDK in
177 an environment set up to run BitBake, you did not use a new shell.
178
1798. *Build the Clean Image:* The final step in preparing to work on the
180 kernel is to build an initial image using ``devtool`` in the new
Andrew Geisslerc926e172021-05-07 16:11:35 -0500181 terminal you just set up and initialized for SDK work::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500182
183 $ devtool build-image
184 Parsing recipes: 100% |##########################################| Time: 0:00:05
185 Parsing of 830 .bb files complete (0 cached, 830 parsed). 1299 targets, 47 skipped, 0 masked, 0 errors.
186 WARNING: No packages to add, building image core-image-minimal unmodified
187 Loading cache: 100% |############################################| Time: 0:00:00
188 Loaded 1299 entries from dependency cache.
189 NOTE: Resolving any missing task queue dependencies
190 Initializing tasks: 100% |#######################################| Time: 0:00:07
191 Checking sstate mirror object availability: 100% |###############| Time: 0:00:00
192 NOTE: Executing SetScene Tasks
193 NOTE: Executing RunQueue Tasks
194 NOTE: Tasks Summary: Attempted 2866 tasks of which 2604 didn't need to be rerun and all succeeded.
195 NOTE: Successfully built core-image-minimal. You can find output files in /home/scottrif/poky_sdk/tmp/deploy/images/qemux86
196
197 If you were
198 building for actual hardware and not for emulation, you could flash
199 the image to a USB stick on ``/dev/sdd`` and boot your device. For an
200 example that uses a Minnowboard, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600201 :yocto_wiki:`TipsAndTricks/KernelDevelopmentWithEsdk </TipsAndTricks/KernelDevelopmentWithEsdk>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500202 Wiki page.
203
204At this point you have set up to start making modifications to the
205kernel by using the extensible SDK. For a continued example, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600206":ref:`kernel-dev/common:using \`\`devtool\`\` to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500207section.
208
209Getting Ready for Traditional Kernel Development
210------------------------------------------------
211
212Getting ready for traditional kernel development using the Yocto Project
213involves many of the same steps as described in the previous section.
214However, you need to establish a local copy of the kernel source since
215you will be editing these files.
216
217Follow these steps to prepare to update the kernel image using
218traditional kernel development flow with the Yocto Project. Completing
219this procedure leaves you ready to make modifications to the kernel
Andrew Geissler09209ee2020-12-13 08:44:15 -0600220source as described in the ":ref:`kernel-dev/common:using traditional kernel development to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500221section:
222
2231. *Initialize the BitBake Environment:* Before you can do anything
224 using BitBake, you need to initialize the BitBake build environment
225 by sourcing the build environment script (i.e.
226 :ref:`structure-core-script`).
227 Also, for this example, be sure that the local branch you have
228 checked out for ``poky`` is the Yocto Project &DISTRO_NAME; branch. If
229 you need to checkout out the &DISTRO_NAME; branch, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600230 ":ref:`dev-manual/start:checking out by branch in poky`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500231 section in the Yocto Project Development Tasks Manual.
232 ::
233
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500234 $ cd poky
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500235 $ git branch
236 master
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500237 * &DISTRO_NAME_NO_CAP;
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500238 $ source oe-init-build-env
239
240 .. note::
241
242 The previous commands assume the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600243 :ref:`overview-manual/development-environment:yocto project source repositories`
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500244 (i.e. ``poky``) have been cloned using Git and the local repository is named
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500245 "poky".
246
2472. *Prepare Your local.conf File:* By default, the
248 :term:`MACHINE` variable is set to
249 "qemux86-64", which is fine if you are building for the QEMU emulator
250 in 64-bit mode. However, if you are not, you need to set the
251 ``MACHINE`` variable appropriately in your ``conf/local.conf`` file
252 found in the
253 :term:`Build Directory` (i.e.
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500254 ``poky/build`` in this example).
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500255
256 Also, since you are preparing to work on the kernel image, you need
257 to set the
258 :term:`MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS`
259 variable to include kernel modules.
260
261 In this example we wish to build for qemux86 so we must set the
262 ``MACHINE`` variable to "qemux86" and also add the "kernel-modules".
Andrew Geisslerc926e172021-05-07 16:11:35 -0500263 As described we do this by appending to ``conf/local.conf``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500264
265 MACHINE = "qemux86"
266 MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules"
267
2683. *Create a Layer for Patches:* You need to create a layer to hold
269 patches created for the kernel image. You can use the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500270 ``bitbake-layers create-layer`` command as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500271
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500272 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500273 $ bitbake-layers create-layer ../../meta-mylayer
274 NOTE: Starting bitbake server...
275 Add your new layer with 'bitbake-layers add-layer ../../meta-mylayer'
276
277 .. note::
278
279 For background information on working with common and BSP layers,
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500280 see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600281 ":ref:`dev-manual/common-tasks:understanding and creating layers`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500282 section in the Yocto Project Development Tasks Manual and the
283 ":ref:`bsp-guide/bsp:bsp layers`" section in the Yocto Project Board
284 Support (BSP) Developer's Guide, respectively. For information on how to
285 use the ``bitbake-layers create-layer`` command to quickly set up a layer,
286 see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600287 ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500288 section in the Yocto Project Development Tasks Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500289
2904. *Inform the BitBake Build Environment About Your Layer:* As directed
291 when you created your layer, you need to add the layer to the
292 :term:`BBLAYERS` variable in the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500293 ``bblayers.conf`` file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500294
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500295 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500296 $ bitbake-layers add-layer ../../meta-mylayer
297 NOTE: Starting bitbake server ...
298 $
299
3005. *Create a Local Copy of the Kernel Git Repository:* You can find Git
301 repositories of supported Yocto Project kernels organized under
302 "Yocto Linux Kernel" in the Yocto Project Source Repositories at
303 :yocto_git:`/`.
304
305 For simplicity, it is recommended that you create your copy of the
306 kernel Git repository outside of the
307 :term:`Source Directory`, which is
308 usually named ``poky``. Also, be sure you are in the
309 ``standard/base`` branch.
310
311 The following commands show how to create a local copy of the
312 ``linux-yocto-4.12`` kernel and be in the ``standard/base`` branch.
313
314 .. note::
315
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500316 The ``linux-yocto-4.12`` kernel can be used with the Yocto Project 2.4
317 release and forward.
318 You cannot use the ``linux-yocto-4.12`` kernel with releases prior to
319 Yocto Project 2.4.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500320
321 ::
322
323 $ cd ~
324 $ git clone git://git.yoctoproject.org/linux-yocto-4.12 --branch standard/base
325 Cloning into 'linux-yocto-4.12'...
326 remote: Counting objects: 6097195, done.
327 remote: Compressing objects: 100% (901026/901026), done.
328 remote: Total 6097195 (delta 5152604), reused 6096847 (delta 5152256)
329 Receiving objects: 100% (6097195/6097195), 1.24 GiB | 7.81 MiB/s, done.
330 Resolving deltas: 100% (5152604/5152604), done. Checking connectivity... done.
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500331 Checking out files: 100% (59846/59846), done.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500332
3336. *Create a Local Copy of the Kernel Cache Git Repository:* For
334 simplicity, it is recommended that you create your copy of the kernel
335 cache Git repository outside of the
336 :term:`Source Directory`, which is
337 usually named ``poky``. Also, for this example, be sure you are in
338 the ``yocto-4.12`` branch.
339
340 The following commands show how to create a local copy of the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500341 ``yocto-kernel-cache`` and be in the ``yocto-4.12`` branch::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500342
343 $ cd ~
344 $ git clone git://git.yoctoproject.org/yocto-kernel-cache --branch yocto-4.12
345 Cloning into 'yocto-kernel-cache'...
346 remote: Counting objects: 22639, done.
347 remote: Compressing objects: 100% (9761/9761), done.
348 remote: Total 22639 (delta 12400), reused 22586 (delta 12347)
349 Receiving objects: 100% (22639/22639), 22.34 MiB | 6.27 MiB/s, done.
350 Resolving deltas: 100% (12400/12400), done.
351 Checking connectivity... done.
352
353At this point, you are ready to start making modifications to the kernel
354using traditional kernel development steps. For a continued example, see
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500355the ":ref:`kernel-dev/common:using traditional kernel development to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500356section.
357
358Creating and Preparing a Layer
359==============================
360
361If you are going to be modifying kernel recipes, it is recommended that
362you create and prepare your own layer in which to do your work. Your
363layer contains its own :term:`BitBake`
364append files (``.bbappend``) and provides a convenient mechanism to
365create your own recipe files (``.bb``) as well as store and use kernel
366patch files. For background information on working with layers, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600367":ref:`dev-manual/common-tasks:understanding and creating layers`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500368section in the Yocto Project Development Tasks Manual.
369
370.. note::
371
372 The Yocto Project comes with many tools that simplify tasks you need
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500373 to perform. One such tool is the ``bitbake-layers create-layer``
374 command, which simplifies creating a new layer. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600375 ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500376 section in the Yocto Project Development Tasks Manual for
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500377 information on how to use this script to quick set up a new layer.
378
379To better understand the layer you create for kernel development, the
380following section describes how to create a layer without the aid of
381tools. These steps assume creation of a layer named ``mylayer`` in your
382home directory:
383
Andrew Geisslerc926e172021-05-07 16:11:35 -05003841. *Create Structure*: Create the layer's structure::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500385
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500386 $ mkdir meta-mylayer
387 $ mkdir meta-mylayer/conf
388 $ mkdir meta-mylayer/recipes-kernel
389 $ mkdir meta-mylayer/recipes-kernel/linux
390 $ mkdir meta-mylayer/recipes-kernel/linux/linux-yocto
391
392 The ``conf`` directory holds your configuration files, while the
393 ``recipes-kernel`` directory holds your append file and eventual
394 patch files.
395
3962. *Create the Layer Configuration File*: Move to the
397 ``meta-mylayer/conf`` directory and create the ``layer.conf`` file as
Andrew Geisslerc926e172021-05-07 16:11:35 -0500398 follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500399
400 # We have a conf and classes directory, add to BBPATH
401 BBPATH .= ":${LAYERDIR}"
402
403 # We have recipes-* directories, add to BBFILES
404 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
405 ${LAYERDIR}/recipes-*/*/*.bbappend"
406
407 BBFILE_COLLECTIONS += "mylayer"
408 BBFILE_PATTERN_mylayer = "^${LAYERDIR}/"
409 BBFILE_PRIORITY_mylayer = "5"
410
411 Notice ``mylayer`` as part of the last three statements.
412
4133. *Create the Kernel Recipe Append File*: Move to the
414 ``meta-mylayer/recipes-kernel/linux`` directory and create the
415 kernel's append file. This example uses the ``linux-yocto-4.12``
416 kernel. Thus, the name of the append file is
Andrew Geisslerc926e172021-05-07 16:11:35 -0500417 ``linux-yocto_4.12.bbappend``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500418
419 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
420
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500421 SRC_URI_append = " file://patch-file-one.patch"
422 SRC_URI_append = " file://patch-file-two.patch"
423 SRC_URI_append = " file://patch-file-three.patch"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500424
425 The :term:`FILESEXTRAPATHS` and :term:`SRC_URI` statements
426 enable the OpenEmbedded build system to find patch files. For more
427 information on using append files, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600428 ":ref:`dev-manual/common-tasks:using .bbappend files in your layer`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500429 section in the Yocto Project Development Tasks Manual.
430
431Modifying an Existing Recipe
432============================
433
434In many cases, you can customize an existing linux-yocto recipe to meet
435the needs of your project. Each release of the Yocto Project provides a
436few Linux kernel recipes from which you can choose. These are located in
437the :term:`Source Directory` in
438``meta/recipes-kernel/linux``.
439
440Modifying an existing recipe can consist of the following:
441
Andrew Geissler09209ee2020-12-13 08:44:15 -0600442- :ref:`kernel-dev/common:creating the append file`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500443
Andrew Geissler09209ee2020-12-13 08:44:15 -0600444- :ref:`kernel-dev/common:applying patches`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500445
Andrew Geissler09209ee2020-12-13 08:44:15 -0600446- :ref:`kernel-dev/common:changing the configuration`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500447
448Before modifying an existing recipe, be sure that you have created a
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500449minimal, custom layer from which you can work. See the
450":ref:`kernel-dev/common:creating and preparing a layer`" section for
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500451information.
452
453Creating the Append File
454------------------------
455
456You create this file in your custom layer. You also name it accordingly
457based on the linux-yocto recipe you are using. For example, if you are
458modifying the ``meta/recipes-kernel/linux/linux-yocto_4.12.bb`` recipe,
459the append file will typically be located as follows within your custom
460layer:
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500461
462.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500463
464 your-layer/recipes-kernel/linux/linux-yocto_4.12.bbappend
465
466The append file should initially extend the
467:term:`FILESPATH` search path by
468prepending the directory that contains your files to the
469:term:`FILESEXTRAPATHS`
Andrew Geisslerc926e172021-05-07 16:11:35 -0500470variable as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500471
472 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
473
474The path ``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``
475expands to "linux-yocto" in the current directory for this example. If
476you add any new files that modify the kernel recipe and you have
477extended ``FILESPATH`` as described above, you must place the files in
Andrew Geisslerc926e172021-05-07 16:11:35 -0500478your layer in the following area::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500479
480 your-layer/recipes-kernel/linux/linux-yocto/
481
482.. note::
483
484 If you are working on a new machine Board Support Package (BSP), be
Andrew Geissler09209ee2020-12-13 08:44:15 -0600485 sure to refer to the :doc:`/bsp-guide/index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500486
487As an example, consider the following append file used by the BSPs in
488``meta-yocto-bsp``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500489
490.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500491
492 meta-yocto-bsp/recipes-kernel/linux/linux-yocto_4.12.bbappend
493
494The following listing shows the file. Be aware that the actual commit ID
495strings in this example listing might be different than the actual
496strings in the file from the ``meta-yocto-bsp`` layer upstream.
497::
498
499 KBRANCH_genericx86 = "standard/base"
500 KBRANCH_genericx86-64 = "standard/base"
501
502 KMACHINE_genericx86 ?= "common-pc"
503 KMACHINE_genericx86-64 ?= "common-pc-64"
504 KBRANCH_edgerouter = "standard/edgerouter"
505 KBRANCH_beaglebone = "standard/beaglebone"
506
507 SRCREV_machine_genericx86 ?= "d09f2ce584d60ecb7890550c22a80c48b83c2e19"
508 SRCREV_machine_genericx86-64 ?= "d09f2ce584d60ecb7890550c22a80c48b83c2e19"
509 SRCREV_machine_edgerouter ?= "b5c8cfda2dfe296410d51e131289fb09c69e1e7d"
510 SRCREV_machine_beaglebone ?= "b5c8cfda2dfe296410d51e131289fb09c69e1e7d"
511
512
513 COMPATIBLE_MACHINE_genericx86 = "genericx86"
514 COMPATIBLE_MACHINE_genericx86-64 = "genericx86-64"
515 COMPATIBLE_MACHINE_edgerouter = "edgerouter"
516 COMPATIBLE_MACHINE_beaglebone = "beaglebone"
517
518 LINUX_VERSION_genericx86 = "4.12.7"
519 LINUX_VERSION_genericx86-64 = "4.12.7"
520 LINUX_VERSION_edgerouter = "4.12.10"
521 LINUX_VERSION_beaglebone = "4.12.10"
522
523This append file
524contains statements used to support several BSPs that ship with the
525Yocto Project. The file defines machines using the
526:term:`COMPATIBLE_MACHINE`
527variable and uses the
528:term:`KMACHINE` variable to ensure
529the machine name used by the OpenEmbedded build system maps to the
530machine name used by the Linux Yocto kernel. The file also uses the
531optional :term:`KBRANCH` variable to
532ensure the build process uses the appropriate kernel branch.
533
534Although this particular example does not use it, the
535:term:`KERNEL_FEATURES`
536variable could be used to enable features specific to the kernel. The
537append file points to specific commits in the
538:term:`Source Directory` Git repository and
539the ``meta`` Git repository branches to identify the exact kernel needed
540to build the BSP.
541
542One thing missing in this particular BSP, which you will typically need
543when developing a BSP, is the kernel configuration file (``.config``)
544for your BSP. When developing a BSP, you probably have a kernel
545configuration file or a set of kernel configuration files that, when
546taken together, define the kernel configuration for your BSP. You can
547accomplish this definition by putting the configurations in a file or a
548set of files inside a directory located at the same level as your
549kernel's append file and having the same name as the kernel's main
550recipe file. With all these conditions met, simply reference those files
551in the :term:`SRC_URI` statement in
552the append file.
553
554For example, suppose you had some configuration options in a file called
555``network_configs.cfg``. You can place that file inside a directory
556named ``linux-yocto`` and then add a ``SRC_URI`` statement such as the
557following to the append file. When the OpenEmbedded build system builds
558the kernel, the configuration options are picked up and applied.
559::
560
561 SRC_URI += "file://network_configs.cfg"
562
563To group related configurations into multiple files, you perform a
564similar procedure. Here is an example that groups separate
565configurations specifically for Ethernet and graphics into their own
566files and adds the configurations by using a ``SRC_URI`` statement like
Andrew Geisslerc926e172021-05-07 16:11:35 -0500567the following in your append file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500568
569 SRC_URI += "file://myconfig.cfg \
570 file://eth.cfg \
571 file://gfx.cfg"
572
573Another variable you can use in your kernel recipe append file is the
574:term:`FILESEXTRAPATHS`
575variable. When you use this statement, you are extending the locations
576used by the OpenEmbedded system to look for files and patches as the
577recipe is processed.
578
579.. note::
580
581 Other methods exist to accomplish grouping and defining configuration
582 options. For example, if you are working with a local clone of the
583 kernel repository, you could checkout the kernel's ``meta`` branch,
584 make your changes, and then push the changes to the local bare clone
585 of the kernel. The result is that you directly add configuration
586 options to the ``meta`` branch for your BSP. The configuration
587 options will likely end up in that location anyway if the BSP gets
588 added to the Yocto Project.
589
590 In general, however, the Yocto Project maintainers take care of
591 moving the ``SRC_URI``-specified configuration options to the
592 kernel's ``meta`` branch. Not only is it easier for BSP developers to
593 not have to worry about putting those configurations in the branch,
594 but having the maintainers do it allows them to apply 'global'
595 knowledge about the kinds of common configuration options multiple
596 BSPs in the tree are typically using. This allows for promotion of
597 common configurations into common features.
598
599Applying Patches
600----------------
601
602If you have a single patch or a small series of patches that you want to
603apply to the Linux kernel source, you can do so just as you would with
604any other recipe. You first copy the patches to the path added to
605:term:`FILESEXTRAPATHS` in
606your ``.bbappend`` file as described in the previous section, and then
607reference them in :term:`SRC_URI`
608statements.
609
610For example, you can apply a three-patch series by adding the following
Andrew Geisslerc926e172021-05-07 16:11:35 -0500611lines to your linux-yocto ``.bbappend`` file in your layer::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500612
613 SRC_URI += "file://0001-first-change.patch"
614 SRC_URI += "file://0002-second-change.patch"
615 SRC_URI += "file://0003-third-change.patch"
616
617The next time you run BitBake to build
618the Linux kernel, BitBake detects the change in the recipe and fetches
619and applies the patches before building the kernel.
620
621For a detailed example showing how to patch the kernel using
622``devtool``, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600623":ref:`kernel-dev/common:using \`\`devtool\`\` to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500624and
Andrew Geissler09209ee2020-12-13 08:44:15 -0600625":ref:`kernel-dev/common:using traditional kernel development to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500626sections.
627
628Changing the Configuration
629--------------------------
630
631You can make wholesale or incremental changes to the final ``.config``
632file used for the eventual Linux kernel configuration by including a
633``defconfig`` file and by specifying configuration fragments in the
634:term:`SRC_URI` to be applied to that
635file.
636
637If you have a complete, working Linux kernel ``.config`` file you want
638to use for the configuration, as before, copy that file to the
639appropriate ``${PN}`` directory in your layer's ``recipes-kernel/linux``
640directory, and rename the copied file to "defconfig". Then, add the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500641following lines to the linux-yocto ``.bbappend`` file in your layer::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500642
643 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
644 SRC_URI += "file://defconfig"
645
646The ``SRC_URI`` tells the build system how to search
647for the file, while the
648:term:`FILESEXTRAPATHS`
649extends the :term:`FILESPATH`
650variable (search directories) to include the ``${PN}`` directory you
651created to hold the configuration changes.
652
653.. note::
654
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500655 The build system applies the configurations from the ``defconfig``
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500656 file before applying any subsequent configuration fragments. The
657 final kernel configuration is a combination of the configurations in
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500658 the ``defconfig`` file and any configuration fragments you provide. You need
659 to realize that if you have any configuration fragments, the build system
660 applies these on top of and after applying the existing ``defconfig`` file
661 configurations.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500662
663Generally speaking, the preferred approach is to determine the
664incremental change you want to make and add that as a configuration
665fragment. For example, if you want to add support for a basic serial
666console, create a file named ``8250.cfg`` in the ``${PN}`` directory
Andrew Geisslerc926e172021-05-07 16:11:35 -0500667with the following content (without indentation)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500668
669 CONFIG_SERIAL_8250=y
670 CONFIG_SERIAL_8250_CONSOLE=y
671 CONFIG_SERIAL_8250_PCI=y
672 CONFIG_SERIAL_8250_NR_UARTS=4
673 CONFIG_SERIAL_8250_RUNTIME_UARTS=4
674 CONFIG_SERIAL_CORE=y
675 CONFIG_SERIAL_CORE_CONSOLE=y
676
677Next, include this
678configuration fragment and extend the ``FILESPATH`` variable in your
Andrew Geisslerc926e172021-05-07 16:11:35 -0500679``.bbappend`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500680
681 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
682 SRC_URI += "file://8250.cfg"
683
684The next time you run BitBake to build the
685Linux kernel, BitBake detects the change in the recipe and fetches and
686applies the new configuration before building the kernel.
687
688For a detailed example showing how to configure the kernel, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500689":ref:`kernel-dev/common:configuring the kernel`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500690
691Using an "In-Tree"  ``defconfig`` File
692--------------------------------------
693
694It might be desirable to have kernel configuration fragment support
695through a ``defconfig`` file that is pulled from the kernel source tree
696for the configured machine. By default, the OpenEmbedded build system
697looks for ``defconfig`` files in the layer used for Metadata, which is
Andrew Geisslerc926e172021-05-07 16:11:35 -0500698"out-of-tree", and then configures them using the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500699
700 SRC_URI += "file://defconfig"
701
702If you do not want to maintain copies of
703``defconfig`` files in your layer but would rather allow users to use
704the default configuration from the kernel tree and still be able to add
705configuration fragments to the
706:term:`SRC_URI` through, for example,
707append files, you can direct the OpenEmbedded build system to use a
708``defconfig`` file that is "in-tree".
709
710To specify an "in-tree" ``defconfig`` file, use the following statement
Andrew Geisslerc926e172021-05-07 16:11:35 -0500711form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500712
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500713 KBUILD_DEFCONFIG_KMACHINE ?= "defconfig_file"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500714
715Here is an example
716that assigns the ``KBUILD_DEFCONFIG`` variable based on "raspberrypi2"
717and provides the path to the "in-tree" ``defconfig`` file to be used for
Andrew Geisslerc926e172021-05-07 16:11:35 -0500718a Raspberry Pi 2, which is based on the Broadcom 2708/2709 chipset::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500719
720 KBUILD_DEFCONFIG_raspberrypi2 ?= "bcm2709_defconfig"
721
722Aside from modifying your kernel recipe and providing your own
723``defconfig`` file, you need to be sure no files or statements set
724``SRC_URI`` to use a ``defconfig`` other than your "in-tree" file (e.g.
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500725a kernel's ``linux-``\ `machine`\ ``.inc`` file). In other words, if the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500726build system detects a statement that identifies an "out-of-tree"
727``defconfig`` file, that statement will override your
728``KBUILD_DEFCONFIG`` variable.
729
730See the
731:term:`KBUILD_DEFCONFIG`
732variable description for more information.
733
734Using ``devtool`` to Patch the Kernel
735=====================================
736
737The steps in this procedure show you how you can patch the kernel using
738the extensible SDK and ``devtool``.
739
740.. note::
741
742 Before attempting this procedure, be sure you have performed the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500743 steps to get ready for updating the kernel as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600744 ":ref:`kernel-dev/common:getting ready to develop using \`\`devtool\`\``"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500745 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500746
747Patching the kernel involves changing or adding configurations to an
748existing kernel, changing or adding recipes to the kernel that are
749needed to support specific hardware features, or even altering the
750source code itself.
751
752This example creates a simple patch by adding some QEMU emulator console
753output at boot time through ``printk`` statements in the kernel's
754``calibrate.c`` source code file. Applying the patch and booting the
755modified image causes the added messages to appear on the emulator's
756console. The example is a continuation of the setup procedure found in
Andrew Geissler09209ee2020-12-13 08:44:15 -0600757the ":ref:`kernel-dev/common:getting ready to develop using \`\`devtool\`\``" Section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500758
7591. *Check Out the Kernel Source Files:* First you must use ``devtool``
760 to checkout the kernel source code in its workspace. Be sure you are
761 in the terminal set up to do work with the extensible SDK.
762
763 .. note::
764
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500765 See this step in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600766 ":ref:`kernel-dev/common:getting ready to develop using \`\`devtool\`\``"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500767 section for more information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500768
Andrew Geisslerc926e172021-05-07 16:11:35 -0500769 Use the following ``devtool`` command to check out the code::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500770
771 $ devtool modify linux-yocto
772
773 .. note::
774
775 During the checkout operation, a bug exists that could cause
776 errors such as the following to appear:
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500777
778 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500779
780 ERROR: Taskhash mismatch 2c793438c2d9f8c3681fd5f7bc819efa versus
781 be3a89ce7c47178880ba7bf6293d7404 for
782 /path/to/esdk/layers/poky/meta/recipes-kernel/linux/linux-yocto_4.10.bb.do_unpack
783
784
785 You can safely ignore these messages. The source code is correctly
786 checked out.
787
7882. *Edit the Source Files* Follow these steps to make some simple
789 changes to the source files:
790
791 1. *Change the working directory*: In the previous step, the output
792 noted where you can find the source files (e.g.
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500793 ``poky_sdk/workspace/sources/linux-yocto``). Change to where the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500794 kernel source code is before making your edits to the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500795 ``calibrate.c`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500796
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500797 $ cd poky_sdk/workspace/sources/linux-yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500798
799 2. *Edit the source file*: Edit the ``init/calibrate.c`` file to have
Andrew Geisslerc926e172021-05-07 16:11:35 -0500800 the following changes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500801
802 void calibrate_delay(void)
803 {
804 unsigned long lpj;
805 static bool printed;
806 int this_cpu = smp_processor_id();
807
808 printk("*************************************\n");
809 printk("* *\n");
810 printk("* HELLO YOCTO KERNEL *\n");
811 printk("* *\n");
812 printk("*************************************\n");
813
814 if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
815 .
816 .
817 .
818
8193. *Build the Updated Kernel Source:* To build the updated kernel
Andrew Geisslerc926e172021-05-07 16:11:35 -0500820 source, use ``devtool``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500821
822 $ devtool build linux-yocto
823
8244. *Create the Image With the New Kernel:* Use the
825 ``devtool build-image`` command to create a new image that has the
826 new kernel.
827
828 .. note::
829
830 If the image you originally created resulted in a Wic file, you
831 can use an alternate method to create the new image with the
832 updated kernel. For an example, see the steps in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600833 :yocto_wiki:`TipsAndTricks/KernelDevelopmentWithEsdk </TipsAndTricks/KernelDevelopmentWithEsdk>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500834 Wiki Page.
835
836 ::
837
838 $ cd ~
839 $ devtool build-image core-image-minimal
840
8415. *Test the New Image:* For this example, you can run the new image
842 using QEMU to verify your changes:
843
844 1. *Boot the image*: Boot the modified image in the QEMU emulator
Andrew Geisslerc926e172021-05-07 16:11:35 -0500845 using this command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500846
847 $ runqemu qemux86
848
849 2. *Verify the changes*: Log into the machine using ``root`` with no
850 password and then use the following shell command to scroll
851 through the console's boot output.
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500852
853 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500854
855 # dmesg | less
856
857 You should see
858 the results of your ``printk`` statements as part of the output
859 when you scroll down the console window.
860
8616. *Stage and commit your changes*: Within your eSDK terminal, change
862 your working directory to where you modified the ``calibrate.c`` file
Andrew Geisslerc926e172021-05-07 16:11:35 -0500863 and use these Git commands to stage and commit your changes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500864
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500865 $ cd poky_sdk/workspace/sources/linux-yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500866 $ git status
867 $ git add init/calibrate.c
868 $ git commit -m "calibrate: Add printk example"
869
8707. *Export the Patches and Create an Append File:* To export your
871 commits as patches and create a ``.bbappend`` file, use the following
872 command in the terminal used to work with the extensible SDK. This
873 example uses the previously established layer named ``meta-mylayer``.
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500874 ::
875
876 $ devtool finish linux-yocto ~/meta-mylayer
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500877
878 .. note::
879
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500880 See Step 3 of the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600881 ":ref:`kernel-dev/common:getting ready to develop using \`\`devtool\`\``"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500882 section for information on setting up this layer.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500883
884 Once the command
885 finishes, the patches and the ``.bbappend`` file are located in the
886 ``~/meta-mylayer/recipes-kernel/linux`` directory.
887
8888. *Build the Image With Your Modified Kernel:* You can now build an
889 image that includes your kernel patches. Execute the following
890 command from your
891 :term:`Build Directory` in the terminal
Andrew Geisslerc926e172021-05-07 16:11:35 -0500892 set up to run BitBake::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500893
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500894 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500895 $ bitbake core-image-minimal
896
897Using Traditional Kernel Development to Patch the Kernel
898========================================================
899
900The steps in this procedure show you how you can patch the kernel using
901traditional kernel development (i.e. not using ``devtool`` and the
902extensible SDK as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600903":ref:`kernel-dev/common:using \`\`devtool\`\` to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500904section).
905
906.. note::
907
908 Before attempting this procedure, be sure you have performed the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500909 steps to get ready for updating the kernel as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600910 ":ref:`kernel-dev/common:getting ready for traditional kernel development`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500911 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500912
913Patching the kernel involves changing or adding configurations to an
914existing kernel, changing or adding recipes to the kernel that are
915needed to support specific hardware features, or even altering the
916source code itself.
917
918The example in this section creates a simple patch by adding some QEMU
919emulator console output at boot time through ``printk`` statements in
920the kernel's ``calibrate.c`` source code file. Applying the patch and
921booting the modified image causes the added messages to appear on the
922emulator's console. The example is a continuation of the setup procedure
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500923found in the
924":ref:`kernel-dev/common:getting ready for traditional kernel development`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500925Section.
926
9271. *Edit the Source Files* Prior to this step, you should have used Git
928 to create a local copy of the repository for your kernel. Assuming
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500929 you created the repository as directed in the
930 ":ref:`kernel-dev/common:getting ready for traditional kernel development`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500931 section, use the following commands to edit the ``calibrate.c`` file:
932
933 1. *Change the working directory*: You need to locate the source
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500934 files in the local copy of the kernel Git repository. Change to
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500935 where the kernel source code is before making your edits to the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500936 ``calibrate.c`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500937
938 $ cd ~/linux-yocto-4.12/init
939
940 2. *Edit the source file*: Edit the ``calibrate.c`` file to have the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500941 following changes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500942
943 void calibrate_delay(void)
944 {
945 unsigned long lpj;
946 static bool printed;
947 int this_cpu = smp_processor_id();
948
949 printk("*************************************\n");
950 printk("* *\n");
951 printk("* HELLO YOCTO KERNEL *\n");
952 printk("* *\n");
953 printk("*************************************\n");
954
955 if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
956 .
957 .
958 .
959
9602. *Stage and Commit Your Changes:* Use standard Git commands to stage
Andrew Geisslerc926e172021-05-07 16:11:35 -0500961 and commit the changes you just made::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500962
963 $ git add calibrate.c
964 $ git commit -m "calibrate.c - Added some printk statements"
965
966 If you do not
967 stage and commit your changes, the OpenEmbedded Build System will not
968 pick up the changes.
969
9703. *Update Your local.conf File to Point to Your Source Files:* In
971 addition to your ``local.conf`` file specifying to use
972 "kernel-modules" and the "qemux86" machine, it must also point to the
973 updated kernel source files. Add
974 :term:`SRC_URI` and
975 :term:`SRCREV` statements similar
Andrew Geisslerc926e172021-05-07 16:11:35 -0500976 to the following to your ``local.conf``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500977
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500978 $ cd poky/build/conf
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500979
Andrew Geisslerc926e172021-05-07 16:11:35 -0500980 Add the following to the ``local.conf``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500981
982 SRC_URI_pn-linux-yocto = "git:///path-to/linux-yocto-4.12;protocol=file;name=machine;branch=standard/base; \
983 git:///path-to/yocto-kernel-cache;protocol=file;type=kmeta;name=meta;branch=yocto-4.12;destsuffix=${KMETA}"
984 SRCREV_meta_qemux86 = "${AUTOREV}"
985 SRCREV_machine_qemux86 = "${AUTOREV}"
986
987 .. note::
988
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500989 Be sure to replace `path-to`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500990 with the pathname to your local Git repositories. Also, you must
991 be sure to specify the correct branch and machine types. For this
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500992 example, the branch is ``standard/base`` and the machine is ``qemux86``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500993
9944. *Build the Image:* With the source modified, your changes staged and
995 committed, and the ``local.conf`` file pointing to the kernel files,
Andrew Geisslerc926e172021-05-07 16:11:35 -0500996 you can now use BitBake to build the image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500997
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500998 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500999 $ bitbake core-image-minimal
1000
10015. *Boot the image*: Boot the modified image in the QEMU emulator using
1002 this command. When prompted to login to the QEMU console, use "root"
Andrew Geisslerc926e172021-05-07 16:11:35 -05001003 with no password::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001004
Andrew Geissler95ac1b82021-03-31 14:34:31 -05001005 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001006 $ runqemu qemux86
1007
10086. *Look for Your Changes:* As QEMU booted, you might have seen your
1009 changes rapidly scroll by. If not, use these commands to see your
1010 changes:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001011
1012 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001013
1014 # dmesg | less
1015
1016 You should see the results of your
1017 ``printk`` statements as part of the output when you scroll down the
1018 console window.
1019
10207. *Generate the Patch File:* Once you are sure that your patch works
1021 correctly, you can generate a ``*.patch`` file in the kernel source
Andrew Geisslerc926e172021-05-07 16:11:35 -05001022 repository::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001023
1024 $ cd ~/linux-yocto-4.12/init
1025 $ git format-patch -1
1026 0001-calibrate.c-Added-some-printk-statements.patch
1027
10288. *Move the Patch File to Your Layer:* In order for subsequent builds
1029 to pick up patches, you need to move the patch file you created in
1030 the previous step to your layer ``meta-mylayer``. For this example,
1031 the layer created earlier is located in your home directory as
1032 ``meta-mylayer``. When the layer was created using the
1033 ``yocto-create`` script, no additional hierarchy was created to
1034 support patches. Before moving the patch file, you need to add
Andrew Geisslerc926e172021-05-07 16:11:35 -05001035 additional structure to your layer using the following commands::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001036
1037 $ cd ~/meta-mylayer
1038 $ mkdir recipes-kernel
1039 $ mkdir recipes-kernel/linux
1040 $ mkdir recipes-kernel/linux/linux-yocto
1041
1042 Once you have created this
1043 hierarchy in your layer, you can move the patch file using the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001044 following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001045
1046 $ mv ~/linux-yocto-4.12/init/0001-calibrate.c-Added-some-printk-statements.patch ~/meta-mylayer/recipes-kernel/linux/linux-yocto
1047
10489. *Create the Append File:* Finally, you need to create the
1049 ``linux-yocto_4.12.bbappend`` file and insert statements that allow
1050 the OpenEmbedded build system to find the patch. The append file
1051 needs to be in your layer's ``recipes-kernel/linux`` directory and it
1052 must be named ``linux-yocto_4.12.bbappend`` and have the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05001053 contents::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001054
1055 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
1056 SRC_URI_append = "file://0001-calibrate.c-Added-some-printk-statements.patch"
1057
1058 The :term:`FILESEXTRAPATHS` and :term:`SRC_URI` statements
1059 enable the OpenEmbedded build system to find the patch file.
1060
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001061 For more information on append files and patches, see the
1062 ":ref:`kernel-dev/common:creating the append file`" and
1063 ":ref:`kernel-dev/common:applying patches`" sections. You can also see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001064 ":ref:`dev-manual/common-tasks:using .bbappend files in your layer`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001065 section in the Yocto Project Development Tasks Manual.
1066
1067 .. note::
1068
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001069 To build ``core-image-minimal`` again and see the effects of your patch,
1070 you can essentially eliminate the temporary source files saved in
1071 ``poky/build/tmp/work/...`` and residual effects of the build by entering
Andrew Geisslerc926e172021-05-07 16:11:35 -05001072 the following sequence of commands::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001073
Andrew Geissler95ac1b82021-03-31 14:34:31 -05001074 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001075 $ bitbake -c cleanall yocto-linux
1076 $ bitbake core-image-minimal -c cleanall
1077 $ bitbake core-image-minimal
1078 $ runqemu qemux86
1079
1080
1081Configuring the Kernel
1082======================
1083
1084Configuring the Yocto Project kernel consists of making sure the
1085``.config`` file has all the right information in it for the image you
1086are building. You can use the ``menuconfig`` tool and configuration
1087fragments to make sure your ``.config`` file is just how you need it.
1088You can also save known configurations in a ``defconfig`` file that the
1089build system can use for kernel configuration.
1090
1091This section describes how to use ``menuconfig``, create and use
1092configuration fragments, and how to interactively modify your
1093``.config`` file to create the leanest kernel configuration file
1094possible.
1095
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001096For more information on kernel configuration, see the
1097":ref:`kernel-dev/common:changing the configuration`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001098
1099Using  ``menuconfig``
1100---------------------
1101
1102The easiest way to define kernel configurations is to set them through
1103the ``menuconfig`` tool. This tool provides an interactive method with
1104which to set kernel configurations. For general information on
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001105``menuconfig``, see https://en.wikipedia.org/wiki/Menuconfig.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001106
1107To use the ``menuconfig`` tool in the Yocto Project development
1108environment, you must do the following:
1109
1110- Because you launch ``menuconfig`` using BitBake, you must be sure to
1111 set up your environment by running the
1112 :ref:`structure-core-script` script found in
1113 the :term:`Build Directory`.
1114
1115- You must be sure of the state of your build's configuration in the
1116 :term:`Source Directory`.
1117
Andrew Geisslerc926e172021-05-07 16:11:35 -05001118- Your build host must have the following two packages installed::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001119
1120 libncurses5-dev
1121 libtinfo-dev
1122
1123The following commands initialize the BitBake environment, run the
1124:ref:`ref-tasks-kernel_configme`
1125task, and launch ``menuconfig``. These commands assume the Source
Andrew Geisslerc926e172021-05-07 16:11:35 -05001126Directory's top-level folder is ``poky``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001127
1128 $ cd poky
1129 $ source oe-init-build-env
1130 $ bitbake linux-yocto -c kernel_configme -f
1131 $ bitbake linux-yocto -c menuconfig
1132
1133Once ``menuconfig`` comes up, its standard
1134interface allows you to interactively examine and configure all the
1135kernel configuration parameters. After making your changes, simply exit
1136the tool and save your changes to create an updated version of the
1137``.config`` configuration file.
1138
1139.. note::
1140
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001141 You can use the entire ``.config`` file as the ``defconfig`` file. For
1142 information on ``defconfig`` files, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001143 ":ref:`kernel-dev/common:changing the configuration`",
1144 ":ref:`kernel-dev/common:using an "in-tree" \`\`defconfig\`\` file`",
1145 and ":ref:`kernel-dev/common:creating a \`\`defconfig\`\` file`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001146 sections.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001147
1148Consider an example that configures the "CONFIG_SMP" setting for the
1149``linux-yocto-4.12`` kernel.
1150
1151.. note::
1152
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001153 The OpenEmbedded build system recognizes this kernel as ``linux-yocto``
1154 through Metadata (e.g. :term:`PREFERRED_VERSION`\ ``_linux-yocto ?= "12.4%"``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001155
1156Once ``menuconfig`` launches, use the interface to navigate through the
1157selections to find the configuration settings in which you are
1158interested. For this example, you deselect "CONFIG_SMP" by clearing the
1159"Symmetric Multi-Processing Support" option. Using the interface, you
1160can find the option under "Processor Type and Features". To deselect
1161"CONFIG_SMP", use the arrow keys to highlight "Symmetric
1162Multi-Processing Support" and enter "N" to clear the asterisk. When you
1163are finished, exit out and save the change.
1164
1165Saving the selections updates the ``.config`` configuration file. This
1166is the file that the OpenEmbedded build system uses to configure the
1167kernel during the build. You can find and examine this file in the Build
1168Directory in ``tmp/work/``. The actual ``.config`` is located in the
1169area where the specific kernel is built. For example, if you were
1170building a Linux Yocto kernel based on the ``linux-yocto-4.12`` kernel
1171and you were building a QEMU image targeted for ``x86`` architecture,
1172the ``.config`` file would be:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001173
1174.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001175
1176 poky/build/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+gitAUTOINC+eda4d18...
1177 ...967-r0/linux-qemux86-standard-build/.config
1178
1179.. note::
1180
1181 The previous example directory is artificially split and many of the
1182 characters in the actual filename are omitted in order to make it
1183 more readable. Also, depending on the kernel you are using, the exact
1184 pathname might differ.
1185
1186Within the ``.config`` file, you can see the kernel settings. For
1187example, the following entry shows that symmetric multi-processor
Andrew Geisslerc926e172021-05-07 16:11:35 -05001188support is not set::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001189
1190 # CONFIG_SMP is not set
1191
1192A good method to isolate changed configurations is to use a combination
1193of the ``menuconfig`` tool and simple shell commands. Before changing
1194configurations with ``menuconfig``, copy the existing ``.config`` and
1195rename it to something else, use ``menuconfig`` to make as many changes
1196as you want and save them, then compare the renamed configuration file
1197against the newly created file. You can use the resulting differences as
1198your base to create configuration fragments to permanently save in your
1199kernel layer.
1200
1201.. note::
1202
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001203 Be sure to make a copy of the ``.config`` file and do not just rename it.
1204 The build system needs an existing ``.config`` file from which to work.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001205
1206Creating a  ``defconfig`` File
1207------------------------------
1208
1209A ``defconfig`` file in the context of the Yocto Project is often a
1210``.config`` file that is copied from a build or a ``defconfig`` taken
1211from the kernel tree and moved into recipe space. You can use a
1212``defconfig`` file to retain a known set of kernel configurations from
1213which the OpenEmbedded build system can draw to create the final
1214``.config`` file.
1215
1216.. note::
1217
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001218 Out-of-the-box, the Yocto Project never ships a ``defconfig`` or ``.config``
1219 file. The OpenEmbedded build system creates the final ``.config`` file used
1220 to configure the kernel.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001221
1222To create a ``defconfig``, start with a complete, working Linux kernel
1223``.config`` file. Copy that file to the appropriate
1224``${``\ :term:`PN`\ ``}`` directory in
1225your layer's ``recipes-kernel/linux`` directory, and rename the copied
1226file to "defconfig" (e.g.
1227``~/meta-mylayer/recipes-kernel/linux/linux-yocto/defconfig``). Then,
1228add the following lines to the linux-yocto ``.bbappend`` file in your
Andrew Geisslerc926e172021-05-07 16:11:35 -05001229layer::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001230
1231 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
1232 SRC_URI += "file://defconfig"
1233
1234The :term:`SRC_URI` tells the build system how to search for the file, while the
1235:term:`FILESEXTRAPATHS` extends the :term:`FILESPATH`
1236variable (search directories) to include the ``${PN}`` directory you
1237created to hold the configuration changes.
1238
1239.. note::
1240
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001241 The build system applies the configurations from the ``defconfig``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001242 file before applying any subsequent configuration fragments. The
1243 final kernel configuration is a combination of the configurations in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001244 the ``defconfig`` file and any configuration fragments you provide. You need
1245 to realize that if you have any configuration fragments, the build system
1246 applies these on top of and after applying the existing ``defconfig`` file
1247 configurations.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001248
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001249For more information on configuring the kernel, see the
1250":ref:`kernel-dev/common:changing the configuration`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001251
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001252Creating Configuration Fragments
1253--------------------------------
1254
1255Configuration fragments are simply kernel options that appear in a file
1256placed where the OpenEmbedded build system can find and apply them. The
1257build system applies configuration fragments after applying
1258configurations from a ``defconfig`` file. Thus, the final kernel
1259configuration is a combination of the configurations in the
1260``defconfig`` file and then any configuration fragments you provide. The
1261build system applies fragments on top of and after applying the existing
1262defconfig file configurations.
1263
1264Syntactically, the configuration statement is identical to what would
1265appear in the ``.config`` file, which is in the :term:`Build Directory`.
1266
1267.. note::
1268
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001269 For more information about where the ``.config`` file is located, see the
1270 example in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001271 ":ref:`kernel-dev/common:using \`\`menuconfig\`\``"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001272 section.
1273
1274It is simple to create a configuration fragment. One method is to use
1275shell commands. For example, issuing the following from the shell
1276creates a configuration fragment file named ``my_smp.cfg`` that enables
Andrew Geisslerc926e172021-05-07 16:11:35 -05001277multi-processor support within the kernel::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001278
1279 $ echo "CONFIG_SMP=y" >> my_smp.cfg
1280
1281.. note::
1282
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001283 All configuration fragment files must use the ``.cfg`` extension in order
1284 for the OpenEmbedded build system to recognize them as a configuration
1285 fragment.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001286
1287Another method is to create a configuration fragment using the
1288differences between two configuration files: one previously created and
1289saved, and one freshly created using the ``menuconfig`` tool.
1290
1291To create a configuration fragment using this method, follow these
1292steps:
1293
12941. *Complete a Build Through Kernel Configuration:* Complete a build at
Andrew Geisslerc926e172021-05-07 16:11:35 -05001295 least through the kernel configuration task as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001296
1297 $ bitbake linux-yocto -c kernel_configme -f
1298
1299 This step ensures that you create a
1300 ``.config`` file from a known state. Because situations exist where
1301 your build state might become unknown, it is best to run this task
1302 prior to starting ``menuconfig``.
1303
Andrew Geisslerc926e172021-05-07 16:11:35 -050013042. *Launch menuconfig:* Run the ``menuconfig`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001305
1306 $ bitbake linux-yocto -c menuconfig
1307
13083. *Create the Configuration Fragment:* Run the ``diffconfig`` command
1309 to prepare a configuration fragment. The resulting file
1310 ``fragment.cfg`` is placed in the
1311 ``${``\ :term:`WORKDIR`\ ``}``
Andrew Geisslerc926e172021-05-07 16:11:35 -05001312 directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001313
1314 $ bitbake linux-yocto -c diffconfig
1315
1316The ``diffconfig`` command creates a file that is a list of Linux kernel
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001317``CONFIG_`` assignments. See the
1318":ref:`kernel-dev/common:changing the configuration`" section for additional
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001319information on how to use the output as a configuration fragment.
1320
1321.. note::
1322
1323 You can also use this method to create configuration fragments for a
Andrew Geissler09209ee2020-12-13 08:44:15 -06001324 BSP. See the ":ref:`kernel-dev/advanced:bsp descriptions`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001325 section for more information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001326
1327Where do you put your configuration fragment files? You can place these
1328files in an area pointed to by
1329:term:`SRC_URI` as directed by your
1330``bblayers.conf`` file, which is located in your layer. The OpenEmbedded
1331build system picks up the configuration and adds it to the kernel's
1332configuration. For example, suppose you had a set of configuration
1333options in a file called ``myconfig.cfg``. If you put that file inside a
1334directory named ``linux-yocto`` that resides in the same directory as
1335the kernel's append file within your layer and then add the following
1336statements to the kernel's append file, those configuration options will
Andrew Geisslerc926e172021-05-07 16:11:35 -05001337be picked up and applied when the kernel is built::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001338
1339 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
1340 SRC_URI += "file://myconfig.cfg"
1341
1342As mentioned earlier, you can group related configurations into multiple
1343files and name them all in the ``SRC_URI`` statement as well. For
1344example, you could group separate configurations specifically for
1345Ethernet and graphics into their own files and add those by using a
Andrew Geisslerc926e172021-05-07 16:11:35 -05001346``SRC_URI`` statement like the following in your append file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001347
1348 SRC_URI += "file://myconfig.cfg \
1349 file://eth.cfg \
1350 file://gfx.cfg"
1351
1352Validating Configuration
1353------------------------
1354
1355You can use the
1356:ref:`ref-tasks-kernel_configcheck`
Andrew Geisslerc926e172021-05-07 16:11:35 -05001357task to provide configuration validation::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001358
1359 $ bitbake linux-yocto -c kernel_configcheck -f
1360
1361Running this task produces warnings for when a
1362requested configuration does not appear in the final ``.config`` file or
1363when you override a policy configuration in a hardware configuration
1364fragment.
1365
1366In order to run this task, you must have an existing ``.config`` file.
Andrew Geissler09209ee2020-12-13 08:44:15 -06001367See the ":ref:`kernel-dev/common:using \`\`menuconfig\`\``" section for
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001368information on how to create a configuration file.
1369
1370Following is sample output from the ``do_kernel_configcheck`` task:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001371
1372.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001373
1374 Loading cache: 100% |########################################################| Time: 0:00:00
1375 Loaded 1275 entries from dependency cache.
1376 NOTE: Resolving any missing task queue dependencies
1377
1378 Build Configuration:
1379 .
1380 .
1381 .
1382
1383 NOTE: Executing SetScene Tasks
1384 NOTE: Executing RunQueue Tasks
1385 WARNING: linux-yocto-4.12.12+gitAUTOINC+eda4d18ce4_16de014967-r0 do_kernel_configcheck:
1386 [kernel config]: specified values did not make it into the kernel's final configuration:
1387
1388 ---------- CONFIG_X86_TSC -----------------
1389 Config: CONFIG_X86_TSC
1390 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/bsp/common-pc/common-pc-cpu.cfg
1391 Requested value: CONFIG_X86_TSC=y
1392 Actual value:
1393
1394
1395 ---------- CONFIG_X86_BIGSMP -----------------
1396 Config: CONFIG_X86_BIGSMP
1397 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
1398 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
1399 Requested value: # CONFIG_X86_BIGSMP is not set
1400 Actual value:
1401
1402
1403 ---------- CONFIG_NR_CPUS -----------------
1404 Config: CONFIG_NR_CPUS
1405 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
1406 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/bsp/common-pc/common-pc.cfg
1407 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
1408 Requested value: CONFIG_NR_CPUS=8
1409 Actual value: CONFIG_NR_CPUS=1
1410
1411
1412 ---------- CONFIG_SCHED_SMT -----------------
1413 Config: CONFIG_SCHED_SMT
1414 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
1415 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
1416 Requested value: CONFIG_SCHED_SMT=y
1417 Actual value:
1418
1419
1420
1421 NOTE: Tasks Summary: Attempted 288 tasks of which 285 didn't need to be rerun and all succeeded.
1422
1423 Summary: There were 3 WARNING messages shown.
1424
1425.. note::
1426
1427 The previous output example has artificial line breaks to make it
1428 more readable.
1429
1430The output describes the various problems that you can encounter along
1431with where to find the offending configuration items. You can use the
1432information in the logs to adjust your configuration files and then
1433repeat the
1434:ref:`ref-tasks-kernel_configme`
1435and
1436:ref:`ref-tasks-kernel_configcheck`
1437tasks until they produce no warnings.
1438
1439For more information on how to use the ``menuconfig`` tool, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001440:ref:`kernel-dev/common:using \`\`menuconfig\`\`` section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001441
1442Fine-Tuning the Kernel Configuration File
1443-----------------------------------------
1444
1445You can make sure the ``.config`` file is as lean or efficient as
1446possible by reading the output of the kernel configuration fragment
1447audit, noting any issues, making changes to correct the issues, and then
1448repeating.
1449
1450As part of the kernel build process, the ``do_kernel_configcheck`` task
1451runs. This task validates the kernel configuration by checking the final
1452``.config`` file against the input files. During the check, the task
1453produces warning messages for the following issues:
1454
1455- Requested options that did not make the final ``.config`` file.
1456
1457- Configuration items that appear twice in the same configuration
1458 fragment.
1459
1460- Configuration items tagged as "required" that were overridden.
1461
1462- A board overrides a non-board specific option.
1463
1464- Listed options not valid for the kernel being processed. In other
1465 words, the option does not appear anywhere.
1466
1467.. note::
1468
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001469 The :ref:`ref-tasks-kernel_configcheck` task can also optionally report if
1470 an option is overridden during processing.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001471
1472For each output warning, a message points to the file that contains a
1473list of the options and a pointer to the configuration fragment that
1474defines them. Collectively, the files are the key to streamlining the
1475configuration.
1476
1477To streamline the configuration, do the following:
1478
14791. *Use a Working Configuration:* Start with a full configuration that
1480 you know works. Be sure the configuration builds and boots
1481 successfully. Use this configuration file as your baseline.
1482
14832. *Run Configure and Check Tasks:* Separately run the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001484 ``do_kernel_configme`` and ``do_kernel_configcheck`` tasks::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001485
1486 $ bitbake linux-yocto -c kernel_configme -f
1487 $ bitbake linux-yocto -c kernel_configcheck -f
1488
14893. *Process the Results:* Take the resulting list of files from the
1490 ``do_kernel_configcheck`` task warnings and do the following:
1491
1492 - Drop values that are redefined in the fragment but do not change
1493 the final ``.config`` file.
1494
1495 - Analyze and potentially drop values from the ``.config`` file that
1496 override required configurations.
1497
1498 - Analyze and potentially remove non-board specific options.
1499
1500 - Remove repeated and invalid options.
1501
15024. *Re-Run Configure and Check Tasks:* After you have worked through the
1503 output of the kernel configuration audit, you can re-run the
1504 ``do_kernel_configme`` and ``do_kernel_configcheck`` tasks to see the
1505 results of your changes. If you have more issues, you can deal with
1506 them as described in the previous step.
1507
1508Iteratively working through steps two through four eventually yields a
1509minimal, streamlined configuration file. Once you have the best
1510``.config``, you can build the Linux Yocto kernel.
1511
1512Expanding Variables
1513===================
1514
1515Sometimes it is helpful to determine what a variable expands to during a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001516build. You can examine the values of variables by examining the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001517output of the ``bitbake -e`` command. The output is long and is more
Andrew Geisslerc926e172021-05-07 16:11:35 -05001518easily managed in a text file, which allows for easy searches::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001519
1520 $ bitbake -e virtual/kernel > some_text_file
1521
1522Within the text file, you can see
1523exactly how each variable is expanded and used by the OpenEmbedded build
1524system.
1525
1526Working with a "Dirty" Kernel Version String
1527============================================
1528
1529If you build a kernel image and the version string has a "+" or a
1530"-dirty" at the end, uncommitted modifications exist in the kernel's
1531source directory. Follow these steps to clean up the version string:
1532
15331. *Discover the Uncommitted Changes:* Go to the kernel's locally cloned
1534 Git repository (source directory) and use the following Git command
Andrew Geisslerc926e172021-05-07 16:11:35 -05001535 to list the files that have been changed, added, or removed::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001536
1537 $ git status
1538
15392. *Commit the Changes:* You should commit those changes to the kernel
1540 source tree regardless of whether or not you will save, export, or
Andrew Geisslerc926e172021-05-07 16:11:35 -05001541 use the changes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001542
1543 $ git add
1544 $ git commit -s -a -m "getting rid of -dirty"
1545
15463. *Rebuild the Kernel Image:* Once you commit the changes, rebuild the
1547 kernel.
1548
1549 Depending on your particular kernel development workflow, the
1550 commands you use to rebuild the kernel might differ. For information
1551 on building the kernel image when using ``devtool``, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001552 ":ref:`kernel-dev/common:using \`\`devtool\`\` to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001553 section. For
1554 information on building the kernel image when using Bitbake, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001555 ":ref:`kernel-dev/common:using traditional kernel development to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001556 section.
1557
1558Working With Your Own Sources
1559=============================
1560
1561If you cannot work with one of the Linux kernel versions supported by
1562existing linux-yocto recipes, you can still make use of the Yocto
1563Project Linux kernel tooling by working with your own sources. When you
1564use your own sources, you will not be able to leverage the existing
1565kernel :term:`Metadata` and stabilization
1566work of the linux-yocto sources. However, you will be able to manage
1567your own Metadata in the same format as the linux-yocto sources.
1568Maintaining format compatibility facilitates converging with linux-yocto
1569on a future, mutually-supported kernel version.
1570
1571To help you use your own sources, the Yocto Project provides a
1572linux-yocto custom recipe (``linux-yocto-custom.bb``) that uses
1573``kernel.org`` sources and the Yocto Project Linux kernel tools for
1574managing kernel Metadata. You can find this recipe in the ``poky`` Git
1575repository of the Yocto Project :yocto_git:`Source Repository <>`
Andrew Geisslerc926e172021-05-07 16:11:35 -05001576at::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001577
1578 poky/meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb
1579
1580Here are some basic steps you can use to work with your own sources:
1581
15821. *Create a Copy of the Kernel Recipe:* Copy the
1583 ``linux-yocto-custom.bb`` recipe to your layer and give it a
1584 meaningful name. The name should include the version of the Yocto
1585 Linux kernel you are using (e.g. ``linux-yocto-myproject_4.12.bb``,
1586 where "4.12" is the base version of the Linux kernel with which you
1587 would be working).
1588
15892. *Create a Directory for Your Patches:* In the same directory inside
1590 your layer, create a matching directory to store your patches and
1591 configuration files (e.g. ``linux-yocto-myproject``).
1592
15933. *Ensure You Have Configurations:* Make sure you have either a
1594 ``defconfig`` file or configuration fragment files in your layer.
1595 When you use the ``linux-yocto-custom.bb`` recipe, you must specify a
1596 configuration. If you do not have a ``defconfig`` file, you can run
Andrew Geisslerc926e172021-05-07 16:11:35 -05001597 the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001598
1599 $ make defconfig
1600
1601 After running the command, copy the
1602 resulting ``.config`` file to the ``files`` directory in your layer
1603 as "defconfig" and then add it to the
1604 :term:`SRC_URI` variable in the
1605 recipe.
1606
1607 Running the ``make defconfig`` command results in the default
1608 configuration for your architecture as defined by your kernel.
1609 However, no guarantee exists that this configuration is valid for
1610 your use case, or that your board will even boot. This is
1611 particularly true for non-x86 architectures.
1612
1613 To use non-x86 ``defconfig`` files, you need to be more specific and
1614 find one that matches your board (i.e. for arm, you look in
1615 ``arch/arm/configs`` and use the one that is the best starting point
1616 for your board).
1617
16184. *Edit the Recipe:* Edit the following variables in your recipe as
1619 appropriate for your project:
1620
1621 - :term:`SRC_URI`: The
1622 ``SRC_URI`` should specify a Git repository that uses one of the
1623 supported Git fetcher protocols (i.e. ``file``, ``git``, ``http``,
1624 and so forth). The ``SRC_URI`` variable should also specify either
1625 a ``defconfig`` file or some configuration fragment files. The
1626 skeleton recipe provides an example ``SRC_URI`` as a syntax
1627 reference.
1628
1629 - :term:`LINUX_VERSION`:
1630 The Linux kernel version you are using (e.g. "4.12").
1631
1632 - :term:`LINUX_VERSION_EXTENSION`:
1633 The Linux kernel ``CONFIG_LOCALVERSION`` that is compiled into the
1634 resulting kernel and visible through the ``uname`` command.
1635
1636 - :term:`SRCREV`: The commit ID
1637 from which you want to build.
1638
1639 - :term:`PR`: Treat this variable the
1640 same as you would in any other recipe. Increment the variable to
1641 indicate to the OpenEmbedded build system that the recipe has
1642 changed.
1643
1644 - :term:`PV`: The default ``PV``
1645 assignment is typically adequate. It combines the
1646 ``LINUX_VERSION`` with the Source Control Manager (SCM) revision
1647 as derived from the :term:`SRCPV`
1648 variable. The combined results are a string with the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05001649 form::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001650
1651 3.19.11+git1+68a635bf8dfb64b02263c1ac80c948647cc76d5f_1+218bd8d2022b9852c60d32f0d770931e3cf343e2
1652
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001653 While lengthy, the extra verbosity in ``PV`` helps ensure you are
1654 using the exact sources from which you intend to build.
1655
1656 - :term:`COMPATIBLE_MACHINE`:
1657 A list of the machines supported by your new recipe. This variable
1658 in the example recipe is set by default to a regular expression
1659 that matches only the empty string, "(^$)". This default setting
1660 triggers an explicit build failure. You must change it to match a
1661 list of the machines that your new recipe supports. For example,
1662 to support the ``qemux86`` and ``qemux86-64`` machines, use the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001663 following form::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001664
1665 COMPATIBLE_MACHINE = "qemux86|qemux86-64"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001666
16675. *Customize Your Recipe as Needed:* Provide further customizations to
1668 your recipe as needed just as you would customize an existing
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001669 linux-yocto recipe. See the
1670 ":ref:`ref-manual/devtool-reference:modifying an existing recipe`" section
1671 for information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001672
1673Working with Out-of-Tree Modules
1674================================
1675
1676This section describes steps to build out-of-tree modules on your target
1677and describes how to incorporate out-of-tree modules in the build.
1678
1679Building Out-of-Tree Modules on the Target
1680------------------------------------------
1681
1682While the traditional Yocto Project development model would be to
1683include kernel modules as part of the normal build process, you might
1684find it useful to build modules on the target. This could be the case if
1685your target system is capable and powerful enough to handle the
1686necessary compilation. Before deciding to build on your target, however,
1687you should consider the benefits of using a proper cross-development
1688environment from your build host.
1689
1690If you want to be able to build out-of-tree modules on the target, there
1691are some steps you need to take on the target that is running your SDK
1692image. Briefly, the ``kernel-dev`` package is installed by default on
1693all ``*.sdk`` images and the ``kernel-devsrc`` package is installed on
1694many of the ``*.sdk`` images. However, you need to create some scripts
1695prior to attempting to build the out-of-tree modules on the target that
1696is running that image.
1697
1698Prior to attempting to build the out-of-tree modules, you need to be on
1699the target as root and you need to change to the ``/usr/src/kernel``
1700directory. Next, ``make`` the scripts:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001701
1702.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001703
1704 # cd /usr/src/kernel
1705 # make scripts
1706
1707Because all SDK image recipes include ``dev-pkgs``, the
1708``kernel-dev`` packages will be installed as part of the SDK image and
1709the ``kernel-devsrc`` packages will be installed as part of applicable
1710SDK images. The SDK uses the scripts when building out-of-tree modules.
1711Once you have switched to that directory and created the scripts, you
1712should be able to build your out-of-tree modules on the target.
1713
1714Incorporating Out-of-Tree Modules
1715---------------------------------
1716
1717While it is always preferable to work with sources integrated into the
1718Linux kernel sources, if you need an external kernel module, the
1719``hello-mod.bb`` recipe is available as a template from which you can
1720create your own out-of-tree Linux kernel module recipe.
1721
1722This template recipe is located in the ``poky`` Git repository of the
1723Yocto Project :yocto_git:`Source Repository <>` at:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001724
1725.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001726
1727 poky/meta-skeleton/recipes-kernel/hello-mod/hello-mod_0.1.bb
1728
1729To get started, copy this recipe to your layer and give it a meaningful
1730name (e.g. ``mymodule_1.0.bb``). In the same directory, create a new
1731directory named ``files`` where you can store any source files, patches,
1732or other files necessary for building the module that do not come with
1733the sources. Finally, update the recipe as needed for the module.
1734Typically, you will need to set the following variables:
1735
1736- :term:`DESCRIPTION`
1737
1738- :term:`LICENSE* <LICENSE>`
1739
1740- :term:`SRC_URI`
1741
1742- :term:`PV`
1743
1744Depending on the build system used by the module sources, you might need
1745to make some adjustments. For example, a typical module ``Makefile``
Andrew Geisslerc926e172021-05-07 16:11:35 -05001746looks much like the one provided with the ``hello-mod`` template::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001747
1748 obj-m := hello.o
1749
1750 SRC := $(shell pwd)
1751
1752 all:
1753 $(MAKE) -C $(KERNEL_SRC) M=$(SRC)
1754
1755 modules_install:
1756 $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
1757 ...
1758
1759The important point to note here is the :term:`KERNEL_SRC` variable. The
1760:ref:`module <ref-classes-module>` class sets this variable and the
1761:term:`KERNEL_PATH` variable to
1762``${STAGING_KERNEL_DIR}`` with the necessary Linux kernel build
1763information to build modules. If your module ``Makefile`` uses a
1764different variable, you might want to override the
1765:ref:`ref-tasks-compile` step, or
1766create a patch to the ``Makefile`` to work with the more typical
1767``KERNEL_SRC`` or ``KERNEL_PATH`` variables.
1768
1769After you have prepared your recipe, you will likely want to include the
1770module in your images. To do this, see the documentation for the
1771following variables in the Yocto Project Reference Manual and set one of
1772them appropriately for your machine configuration file:
1773
1774- :term:`MACHINE_ESSENTIAL_EXTRA_RDEPENDS`
1775
1776- :term:`MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS`
1777
1778- :term:`MACHINE_EXTRA_RDEPENDS`
1779
1780- :term:`MACHINE_EXTRA_RRECOMMENDS`
1781
1782Modules are often not required for boot and can be excluded from certain
Andrew Geisslerc926e172021-05-07 16:11:35 -05001783build configurations. The following allows for the most flexibility::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001784
1785 MACHINE_EXTRA_RRECOMMENDS += "kernel-module-mymodule"
1786
1787The value is
1788derived by appending the module filename without the ``.ko`` extension
1789to the string "kernel-module-".
1790
1791Because the variable is
1792:term:`RRECOMMENDS` and not a
1793:term:`RDEPENDS` variable, the build
1794will not fail if this module is not available to include in the image.
1795
1796Inspecting Changes and Commits
1797==============================
1798
1799A common question when working with a kernel is: "What changes have been
1800applied to this tree?" Rather than using "grep" across directories to
1801see what has changed, you can use Git to inspect or search the kernel
1802tree. Using Git is an efficient way to see what has changed in the tree.
1803
1804What Changed in a Kernel?
1805-------------------------
1806
1807Following are a few examples that show how to use Git commands to
1808examine changes. These examples are by no means the only way to see
1809changes.
1810
1811.. note::
1812
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001813 In the following examples, unless you provide a commit range, ``kernel.org``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001814 history is blended with Yocto Project kernel changes. You can form
1815 ranges by using branch names from the kernel tree as the upper and
1816 lower commit markers with the Git commands. You can see the branch
1817 names through the web interface to the Yocto Project source
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001818 repositories at :yocto_git:`/`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001819
1820To see a full range of the changes, use the ``git whatchanged`` command
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001821and specify a commit range for the branch (`commit`\ ``..``\ `commit`).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001822
1823Here is an example that looks at what has changed in the ``emenlow``
1824branch of the ``linux-yocto-3.19`` kernel. The lower commit range is the
1825commit associated with the ``standard/base`` branch, while the upper
1826commit range is the commit associated with the ``standard/emenlow``
1827branch.
1828::
1829
1830 $ git whatchanged origin/standard/base..origin/standard/emenlow
1831
Andrew Geisslerc926e172021-05-07 16:11:35 -05001832To see short, one line summaries of changes use the ``git log`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001833
1834 $ git log --oneline origin/standard/base..origin/standard/emenlow
1835
Andrew Geisslerc926e172021-05-07 16:11:35 -05001836Use this command to see code differences for the changes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001837
1838 $ git diff origin/standard/base..origin/standard/emenlow
1839
1840Use this command to see the commit log messages and the text
Andrew Geisslerc926e172021-05-07 16:11:35 -05001841differences::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001842
1843 $ git show origin/standard/base..origin/standard/emenlow
1844
1845Use this command to create individual patches for each change. Here is
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001846an example that creates patch files for each commit and places them
Andrew Geisslerc926e172021-05-07 16:11:35 -05001847in your ``Documents`` directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001848
1849 $ git format-patch -o $HOME/Documents origin/standard/base..origin/standard/emenlow
1850
1851Showing a Particular Feature or Branch Change
1852---------------------------------------------
1853
1854Tags in the Yocto Project kernel tree divide changes for significant
1855features or branches. The ``git show`` tag command shows changes based
Andrew Geisslerc926e172021-05-07 16:11:35 -05001856on a tag. Here is an example that shows ``systemtap`` changes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001857
1858 $ git show systemtap
1859
1860You can use the ``git branch --contains`` tag command to
1861show the branches that contain a particular feature. This command shows
Andrew Geisslerc926e172021-05-07 16:11:35 -05001862the branches that contain the ``systemtap`` feature::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001863
1864 $ git branch --contains systemtap
1865
1866Adding Recipe-Space Kernel Features
1867===================================
1868
1869You can add kernel features in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001870:ref:`recipe-space <kernel-dev/advanced:recipe-space metadata>`
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001871by using the :term:`KERNEL_FEATURES`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001872variable and by specifying the feature's ``.scc`` file path in the
1873:term:`SRC_URI` statement. When you
1874add features using this method, the OpenEmbedded build system checks to
1875be sure the features are present. If the features are not present, the
1876build stops. Kernel features are the last elements processed for
1877configuring and patching the kernel. Therefore, adding features in this
1878manner is a way to enforce specific features are present and enabled
1879without needing to do a full audit of any other layer's additions to the
1880``SRC_URI`` statement.
1881
1882You add a kernel feature by providing the feature as part of the
1883``KERNEL_FEATURES`` variable and by providing the path to the feature's
1884``.scc`` file, which is relative to the root of the kernel Metadata. The
1885OpenEmbedded build system searches all forms of kernel Metadata on the
1886``SRC_URI`` statement regardless of whether the Metadata is in the
1887"kernel-cache", system kernel Metadata, or a recipe-space Metadata (i.e.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001888part of the kernel recipe). See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001889":ref:`kernel-dev/advanced:kernel metadata location`" section for
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001890additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001891
1892When you specify the feature's ``.scc`` file on the ``SRC_URI``
1893statement, the OpenEmbedded build system adds the directory of that
1894``.scc`` file along with all its subdirectories to the kernel feature
1895search path. Because subdirectories are searched, you can reference a
1896single ``.scc`` file in the ``SRC_URI`` statement to reference multiple
1897kernel features.
1898
1899Consider the following example that adds the "test.scc" feature to the
1900build.
1901
19021. *Create the Feature File:* Create a ``.scc`` file and locate it just
1903 as you would any other patch file, ``.cfg`` file, or fetcher item you
1904 specify in the ``SRC_URI`` statement.
1905
1906 .. note::
1907
1908 - You must add the directory of the ``.scc`` file to the
1909 fetcher's search path in the same manner as you would add a
1910 ``.patch`` file.
1911
1912 - You can create additional ``.scc`` files beneath the directory
1913 that contains the file you are adding. All subdirectories are
1914 searched during the build as potential feature directories.
1915
1916 Continuing with the example, suppose the "test.scc" feature you are
Andrew Geisslerc926e172021-05-07 16:11:35 -05001917 adding has a ``test.scc`` file in the following directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001918
1919 my_recipe
1920 |
1921 +-linux-yocto
1922 |
1923 +-test.cfg
1924 +-test.scc
1925
1926 In this example, the
1927 ``linux-yocto`` directory has both the feature ``test.scc`` file and
1928 a similarly named configuration fragment file ``test.cfg``.
1929
19302. *Add the Feature File to SRC_URI:* Add the ``.scc`` file to the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001931 recipe's ``SRC_URI`` statement::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001932
1933 SRC_URI_append = " file://test.scc"
1934
1935 The leading space before the path is important as the path is
1936 appended to the existing path.
1937
19383. *Specify the Feature as a Kernel Feature:* Use the
1939 ``KERNEL_FEATURES`` statement to specify the feature as a kernel
Andrew Geisslerc926e172021-05-07 16:11:35 -05001940 feature::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001941
1942 KERNEL_FEATURES_append = " test.scc"
1943
1944 The OpenEmbedded build
1945 system processes the kernel feature when it builds the kernel.
1946
1947 .. note::
1948
1949 If other features are contained below "test.scc", then their
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001950 directories are relative to the directory containing the ``test.scc``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001951 file.