blob: 690f61110ba617ea70e164f7dd24641d7bc4d2f7 [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
Patrick Williams92b42cb2022-09-03 06:53:57 -0500551. *Initialize the BitBake Environment:*
56 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
Patrick Williams2390b1b2022-11-03 13:47:49 -0500692. *Prepare Your local.conf File:* By default, the :term:`MACHINE` variable
70 is set to "qemux86-64", which is fine if you are building for the QEMU
71 emulator in 64-bit mode. However, if you are not, you need to set the
Andrew Geissler09036742021-06-25 14:25:14 -050072 :term:`MACHINE` variable appropriately in your ``conf/local.conf`` file
Patrick Williams2390b1b2022-11-03 13:47:49 -050073 found in the :term:`Build Directory` (i.e. ``poky/build`` in this example).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050074
75 Also, since you are preparing to work on the kernel image, you need
Patrick Williams2390b1b2022-11-03 13:47:49 -050076 to set the :term:`MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS` variable to include
77 kernel modules.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050078
79 In this example we wish to build for qemux86 so we must set the
Andrew Geissler5f350902021-07-23 13:09:54 -040080 :term:`MACHINE` variable to "qemux86" and also add the "kernel-modules".
Andrew Geisslerc926e172021-05-07 16:11:35 -050081 As described we do this by appending to ``conf/local.conf``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050082
83 MACHINE = "qemux86"
84 MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules"
85
863. *Create a Layer for Patches:* You need to create a layer to hold
87 patches created for the kernel image. You can use the
Andrew Geisslerc926e172021-05-07 16:11:35 -050088 ``bitbake-layers create-layer`` command as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050089
Andrew Geissler95ac1b82021-03-31 14:34:31 -050090 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -050091 $ bitbake-layers create-layer ../../meta-mylayer
92 NOTE: Starting bitbake server...
93 Add your new layer with 'bitbake-layers add-layer ../../meta-mylayer'
94 $
95
96 .. note::
97
98 For background information on working with common and BSP layers,
Andrew Geissler4c19ea12020-10-27 13:52:24 -050099 see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600100 ":ref:`dev-manual/common-tasks:understanding and creating layers`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500101 section in the Yocto Project Development Tasks Manual and the
102 ":ref:`bsp-guide/bsp:bsp layers`" section in the Yocto Project Board
103 Support (BSP) Developer's Guide, respectively. For information on how to
104 use the ``bitbake-layers create-layer`` command to quickly set up a layer,
105 see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600106 ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500107 section in the Yocto Project Development Tasks Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500108
1094. *Inform the BitBake Build Environment About Your Layer:* As directed
110 when you created your layer, you need to add the layer to the
111 :term:`BBLAYERS` variable in the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500112 ``bblayers.conf`` file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500113
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500114 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500115 $ bitbake-layers add-layer ../../meta-mylayer
116 NOTE: Starting bitbake server...
117 $
118
Patrick Williams92b42cb2022-09-03 06:53:57 -05001195. *Build the Clean Image:* The final step in preparing to work on the
120 kernel is to build an initial image using ``bitbake``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500121
Patrick Williams92b42cb2022-09-03 06:53:57 -0500122 $ bitbake core-image-minimal
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500123 Parsing recipes: 100% |##########################################| Time: 0:00:05
124 Parsing of 830 .bb files complete (0 cached, 830 parsed). 1299 targets, 47 skipped, 0 masked, 0 errors.
125 WARNING: No packages to add, building image core-image-minimal unmodified
126 Loading cache: 100% |############################################| Time: 0:00:00
127 Loaded 1299 entries from dependency cache.
128 NOTE: Resolving any missing task queue dependencies
129 Initializing tasks: 100% |#######################################| Time: 0:00:07
130 Checking sstate mirror object availability: 100% |###############| Time: 0:00:00
131 NOTE: Executing SetScene Tasks
132 NOTE: Executing RunQueue Tasks
133 NOTE: Tasks Summary: Attempted 2866 tasks of which 2604 didn't need to be rerun and all succeeded.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500134
135 If you were
136 building for actual hardware and not for emulation, you could flash
137 the image to a USB stick on ``/dev/sdd`` and boot your device. For an
138 example that uses a Minnowboard, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600139 :yocto_wiki:`TipsAndTricks/KernelDevelopmentWithEsdk </TipsAndTricks/KernelDevelopmentWithEsdk>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500140 Wiki page.
141
142At this point you have set up to start making modifications to the
Patrick Williams92b42cb2022-09-03 06:53:57 -0500143kernel. For a continued example, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600144":ref:`kernel-dev/common:using \`\`devtool\`\` to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500145section.
146
147Getting Ready for Traditional Kernel Development
148------------------------------------------------
149
150Getting ready for traditional kernel development using the Yocto Project
151involves many of the same steps as described in the previous section.
152However, you need to establish a local copy of the kernel source since
153you will be editing these files.
154
155Follow these steps to prepare to update the kernel image using
156traditional kernel development flow with the Yocto Project. Completing
157this procedure leaves you ready to make modifications to the kernel
Andrew Geissler09209ee2020-12-13 08:44:15 -0600158source as described in the ":ref:`kernel-dev/common:using traditional kernel development to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500159section:
160
1611. *Initialize the BitBake Environment:* Before you can do anything
162 using BitBake, you need to initialize the BitBake build environment
163 by sourcing the build environment script (i.e.
164 :ref:`structure-core-script`).
165 Also, for this example, be sure that the local branch you have
166 checked out for ``poky`` is the Yocto Project &DISTRO_NAME; branch. If
167 you need to checkout out the &DISTRO_NAME; branch, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600168 ":ref:`dev-manual/start:checking out by branch in poky`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500169 section in the Yocto Project Development Tasks Manual.
170 ::
171
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500172 $ cd poky
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500173 $ git branch
174 master
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500175 * &DISTRO_NAME_NO_CAP;
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500176 $ source oe-init-build-env
177
178 .. note::
179
180 The previous commands assume the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600181 :ref:`overview-manual/development-environment:yocto project source repositories`
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500182 (i.e. ``poky``) have been cloned using Git and the local repository is named
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500183 "poky".
184
Patrick Williams2390b1b2022-11-03 13:47:49 -05001852. *Prepare Your local.conf File:* By default, the :term:`MACHINE` variable is
186 set to "qemux86-64", which is fine if you are building for the QEMU emulator
187 in 64-bit mode. However, if you are not, you need to set the :term:`MACHINE`
188 variable appropriately in your ``conf/local.conf`` file found in the
189 :term:`Build Directory` (i.e. ``poky/build`` in this example).
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500190
191 Also, since you are preparing to work on the kernel image, you need
192 to set the
193 :term:`MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS`
194 variable to include kernel modules.
195
196 In this example we wish to build for qemux86 so we must set the
Andrew Geissler5f350902021-07-23 13:09:54 -0400197 :term:`MACHINE` variable to "qemux86" and also add the "kernel-modules".
Andrew Geisslerc926e172021-05-07 16:11:35 -0500198 As described we do this by appending to ``conf/local.conf``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500199
200 MACHINE = "qemux86"
201 MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules"
202
2033. *Create a Layer for Patches:* You need to create a layer to hold
204 patches created for the kernel image. You can use the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500205 ``bitbake-layers create-layer`` command as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500206
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500207 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500208 $ bitbake-layers create-layer ../../meta-mylayer
209 NOTE: Starting bitbake server...
210 Add your new layer with 'bitbake-layers add-layer ../../meta-mylayer'
211
212 .. note::
213
214 For background information on working with common and BSP layers,
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500215 see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600216 ":ref:`dev-manual/common-tasks:understanding and creating layers`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500217 section in the Yocto Project Development Tasks Manual and the
218 ":ref:`bsp-guide/bsp:bsp layers`" section in the Yocto Project Board
219 Support (BSP) Developer's Guide, respectively. For information on how to
220 use the ``bitbake-layers create-layer`` command to quickly set up a layer,
221 see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600222 ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500223 section in the Yocto Project Development Tasks Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500224
2254. *Inform the BitBake Build Environment About Your Layer:* As directed
226 when you created your layer, you need to add the layer to the
227 :term:`BBLAYERS` variable in the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500228 ``bblayers.conf`` file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500229
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500230 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500231 $ bitbake-layers add-layer ../../meta-mylayer
232 NOTE: Starting bitbake server ...
233 $
234
2355. *Create a Local Copy of the Kernel Git Repository:* You can find Git
236 repositories of supported Yocto Project kernels organized under
237 "Yocto Linux Kernel" in the Yocto Project Source Repositories at
238 :yocto_git:`/`.
239
240 For simplicity, it is recommended that you create your copy of the
241 kernel Git repository outside of the
242 :term:`Source Directory`, which is
243 usually named ``poky``. Also, be sure you are in the
244 ``standard/base`` branch.
245
246 The following commands show how to create a local copy of the
247 ``linux-yocto-4.12`` kernel and be in the ``standard/base`` branch.
248
249 .. note::
250
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500251 The ``linux-yocto-4.12`` kernel can be used with the Yocto Project 2.4
252 release and forward.
253 You cannot use the ``linux-yocto-4.12`` kernel with releases prior to
254 Yocto Project 2.4.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500255
256 ::
257
258 $ cd ~
259 $ git clone git://git.yoctoproject.org/linux-yocto-4.12 --branch standard/base
260 Cloning into 'linux-yocto-4.12'...
261 remote: Counting objects: 6097195, done.
262 remote: Compressing objects: 100% (901026/901026), done.
263 remote: Total 6097195 (delta 5152604), reused 6096847 (delta 5152256)
264 Receiving objects: 100% (6097195/6097195), 1.24 GiB | 7.81 MiB/s, done.
265 Resolving deltas: 100% (5152604/5152604), done. Checking connectivity... done.
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500266 Checking out files: 100% (59846/59846), done.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500267
2686. *Create a Local Copy of the Kernel Cache Git Repository:* For
269 simplicity, it is recommended that you create your copy of the kernel
270 cache Git repository outside of the
271 :term:`Source Directory`, which is
272 usually named ``poky``. Also, for this example, be sure you are in
273 the ``yocto-4.12`` branch.
274
275 The following commands show how to create a local copy of the
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700276 ``yocto-kernel-cache`` and switch to the ``yocto-4.12`` branch::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500277
278 $ cd ~
279 $ git clone git://git.yoctoproject.org/yocto-kernel-cache --branch yocto-4.12
280 Cloning into 'yocto-kernel-cache'...
281 remote: Counting objects: 22639, done.
282 remote: Compressing objects: 100% (9761/9761), done.
283 remote: Total 22639 (delta 12400), reused 22586 (delta 12347)
284 Receiving objects: 100% (22639/22639), 22.34 MiB | 6.27 MiB/s, done.
285 Resolving deltas: 100% (12400/12400), done.
286 Checking connectivity... done.
287
288At this point, you are ready to start making modifications to the kernel
289using traditional kernel development steps. For a continued example, see
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500290the ":ref:`kernel-dev/common:using traditional kernel development to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500291section.
292
293Creating and Preparing a Layer
294==============================
295
296If you are going to be modifying kernel recipes, it is recommended that
297you create and prepare your own layer in which to do your work. Your
298layer contains its own :term:`BitBake`
299append files (``.bbappend``) and provides a convenient mechanism to
300create your own recipe files (``.bb``) as well as store and use kernel
301patch files. For background information on working with layers, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600302":ref:`dev-manual/common-tasks:understanding and creating layers`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500303section in the Yocto Project Development Tasks Manual.
304
305.. note::
306
307 The Yocto Project comes with many tools that simplify tasks you need
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500308 to perform. One such tool is the ``bitbake-layers create-layer``
309 command, which simplifies creating a new layer. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600310 ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500311 section in the Yocto Project Development Tasks Manual for
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500312 information on how to use this script to quick set up a new layer.
313
314To better understand the layer you create for kernel development, the
315following section describes how to create a layer without the aid of
316tools. These steps assume creation of a layer named ``mylayer`` in your
317home directory:
318
Andrew Geisslerc926e172021-05-07 16:11:35 -05003191. *Create Structure*: Create the layer's structure::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500320
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500321 $ mkdir meta-mylayer
322 $ mkdir meta-mylayer/conf
323 $ mkdir meta-mylayer/recipes-kernel
324 $ mkdir meta-mylayer/recipes-kernel/linux
325 $ mkdir meta-mylayer/recipes-kernel/linux/linux-yocto
326
327 The ``conf`` directory holds your configuration files, while the
328 ``recipes-kernel`` directory holds your append file and eventual
329 patch files.
330
3312. *Create the Layer Configuration File*: Move to the
332 ``meta-mylayer/conf`` directory and create the ``layer.conf`` file as
Andrew Geisslerc926e172021-05-07 16:11:35 -0500333 follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500334
335 # We have a conf and classes directory, add to BBPATH
336 BBPATH .= ":${LAYERDIR}"
337
338 # We have recipes-* directories, add to BBFILES
339 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
340 ${LAYERDIR}/recipes-*/*/*.bbappend"
341
342 BBFILE_COLLECTIONS += "mylayer"
343 BBFILE_PATTERN_mylayer = "^${LAYERDIR}/"
344 BBFILE_PRIORITY_mylayer = "5"
345
346 Notice ``mylayer`` as part of the last three statements.
347
3483. *Create the Kernel Recipe Append File*: Move to the
349 ``meta-mylayer/recipes-kernel/linux`` directory and create the
350 kernel's append file. This example uses the ``linux-yocto-4.12``
351 kernel. Thus, the name of the append file is
Andrew Geisslerc926e172021-05-07 16:11:35 -0500352 ``linux-yocto_4.12.bbappend``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500353
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500354 FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500355
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500356 SRC_URI += "file://patch-file-one.patch"
357 SRC_URI += "file://patch-file-two.patch"
358 SRC_URI += "file://patch-file-three.patch"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500359
360 The :term:`FILESEXTRAPATHS` and :term:`SRC_URI` statements
361 enable the OpenEmbedded build system to find patch files. For more
362 information on using append files, see the
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500363 ":ref:`dev-manual/common-tasks:appending other layers metadata with your layer`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500364 section in the Yocto Project Development Tasks Manual.
365
366Modifying an Existing Recipe
367============================
368
369In many cases, you can customize an existing linux-yocto recipe to meet
370the needs of your project. Each release of the Yocto Project provides a
371few Linux kernel recipes from which you can choose. These are located in
372the :term:`Source Directory` in
373``meta/recipes-kernel/linux``.
374
375Modifying an existing recipe can consist of the following:
376
Andrew Geissler09209ee2020-12-13 08:44:15 -0600377- :ref:`kernel-dev/common:creating the append file`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500378
Andrew Geissler09209ee2020-12-13 08:44:15 -0600379- :ref:`kernel-dev/common:applying patches`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500380
Andrew Geissler09209ee2020-12-13 08:44:15 -0600381- :ref:`kernel-dev/common:changing the configuration`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500382
383Before modifying an existing recipe, be sure that you have created a
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500384minimal, custom layer from which you can work. See the
385":ref:`kernel-dev/common:creating and preparing a layer`" section for
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500386information.
387
388Creating the Append File
389------------------------
390
391You create this file in your custom layer. You also name it accordingly
392based on the linux-yocto recipe you are using. For example, if you are
393modifying the ``meta/recipes-kernel/linux/linux-yocto_4.12.bb`` recipe,
394the append file will typically be located as follows within your custom
395layer:
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500396
397.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500398
399 your-layer/recipes-kernel/linux/linux-yocto_4.12.bbappend
400
401The append file should initially extend the
402:term:`FILESPATH` search path by
403prepending the directory that contains your files to the
404:term:`FILESEXTRAPATHS`
Andrew Geisslerc926e172021-05-07 16:11:35 -0500405variable as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500406
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500407 FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500408
409The path ``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``
410expands to "linux-yocto" in the current directory for this example. If
411you add any new files that modify the kernel recipe and you have
Andrew Geissler09036742021-06-25 14:25:14 -0500412extended :term:`FILESPATH` as described above, you must place the files in
Andrew Geisslerc926e172021-05-07 16:11:35 -0500413your layer in the following area::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500414
415 your-layer/recipes-kernel/linux/linux-yocto/
416
417.. note::
418
419 If you are working on a new machine Board Support Package (BSP), be
Andrew Geissler09209ee2020-12-13 08:44:15 -0600420 sure to refer to the :doc:`/bsp-guide/index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500421
422As an example, consider the following append file used by the BSPs in
423``meta-yocto-bsp``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500424
425.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500426
427 meta-yocto-bsp/recipes-kernel/linux/linux-yocto_4.12.bbappend
428
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700429Here are the contents of this file. Be aware that the actual commit ID
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500430strings in this example listing might be different than the actual
431strings in the file from the ``meta-yocto-bsp`` layer upstream.
432::
433
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500434 KBRANCH:genericx86 = "standard/base"
435 KBRANCH:genericx86-64 = "standard/base"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500436
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500437 KMACHINE:genericx86 ?= "common-pc"
438 KMACHINE:genericx86-64 ?= "common-pc-64"
439 KBRANCH:edgerouter = "standard/edgerouter"
440 KBRANCH:beaglebone = "standard/beaglebone"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500441
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500442 SRCREV_machine:genericx86 ?= "d09f2ce584d60ecb7890550c22a80c48b83c2e19"
443 SRCREV_machine:genericx86-64 ?= "d09f2ce584d60ecb7890550c22a80c48b83c2e19"
444 SRCREV_machine:edgerouter ?= "b5c8cfda2dfe296410d51e131289fb09c69e1e7d"
445 SRCREV_machine:beaglebone ?= "b5c8cfda2dfe296410d51e131289fb09c69e1e7d"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500446
447
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500448 COMPATIBLE_MACHINE:genericx86 = "genericx86"
449 COMPATIBLE_MACHINE:genericx86-64 = "genericx86-64"
450 COMPATIBLE_MACHINE:edgerouter = "edgerouter"
451 COMPATIBLE_MACHINE:beaglebone = "beaglebone"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500452
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500453 LINUX_VERSION:genericx86 = "4.12.7"
454 LINUX_VERSION:genericx86-64 = "4.12.7"
455 LINUX_VERSION:edgerouter = "4.12.10"
456 LINUX_VERSION:beaglebone = "4.12.10"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500457
458This append file
459contains statements used to support several BSPs that ship with the
460Yocto Project. The file defines machines using the
461:term:`COMPATIBLE_MACHINE`
462variable and uses the
463:term:`KMACHINE` variable to ensure
464the machine name used by the OpenEmbedded build system maps to the
465machine name used by the Linux Yocto kernel. The file also uses the
466optional :term:`KBRANCH` variable to
467ensure the build process uses the appropriate kernel branch.
468
469Although this particular example does not use it, the
470:term:`KERNEL_FEATURES`
471variable could be used to enable features specific to the kernel. The
472append file points to specific commits in the
473:term:`Source Directory` Git repository and
474the ``meta`` Git repository branches to identify the exact kernel needed
475to build the BSP.
476
477One thing missing in this particular BSP, which you will typically need
478when developing a BSP, is the kernel configuration file (``.config``)
479for your BSP. When developing a BSP, you probably have a kernel
480configuration file or a set of kernel configuration files that, when
481taken together, define the kernel configuration for your BSP. You can
482accomplish this definition by putting the configurations in a file or a
483set of files inside a directory located at the same level as your
484kernel's append file and having the same name as the kernel's main
485recipe file. With all these conditions met, simply reference those files
486in the :term:`SRC_URI` statement in
487the append file.
488
489For example, suppose you had some configuration options in a file called
490``network_configs.cfg``. You can place that file inside a directory
Andrew Geissler09036742021-06-25 14:25:14 -0500491named ``linux-yocto`` and then add a :term:`SRC_URI` statement such as the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500492following to the append file. When the OpenEmbedded build system builds
493the kernel, the configuration options are picked up and applied.
494::
495
496 SRC_URI += "file://network_configs.cfg"
497
498To group related configurations into multiple files, you perform a
499similar procedure. Here is an example that groups separate
500configurations specifically for Ethernet and graphics into their own
Andrew Geissler09036742021-06-25 14:25:14 -0500501files and adds the configurations by using a :term:`SRC_URI` statement like
Andrew Geisslerc926e172021-05-07 16:11:35 -0500502the following in your append file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500503
504 SRC_URI += "file://myconfig.cfg \
505 file://eth.cfg \
506 file://gfx.cfg"
507
508Another variable you can use in your kernel recipe append file is the
509:term:`FILESEXTRAPATHS`
510variable. When you use this statement, you are extending the locations
511used by the OpenEmbedded system to look for files and patches as the
512recipe is processed.
513
514.. note::
515
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700516 There are other ways of grouping and defining configuration
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500517 options. For example, if you are working with a local clone of the
518 kernel repository, you could checkout the kernel's ``meta`` branch,
519 make your changes, and then push the changes to the local bare clone
520 of the kernel. The result is that you directly add configuration
521 options to the ``meta`` branch for your BSP. The configuration
522 options will likely end up in that location anyway if the BSP gets
523 added to the Yocto Project.
524
525 In general, however, the Yocto Project maintainers take care of
Andrew Geissler5f350902021-07-23 13:09:54 -0400526 moving the :term:`SRC_URI`-specified configuration options to the
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700527 kernel's ``meta`` branch. Not only is it easier for BSP developers
528 not to have to put those configurations in the branch,
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500529 but having the maintainers do it allows them to apply 'global'
530 knowledge about the kinds of common configuration options multiple
531 BSPs in the tree are typically using. This allows for promotion of
532 common configurations into common features.
533
534Applying Patches
535----------------
536
537If you have a single patch or a small series of patches that you want to
538apply to the Linux kernel source, you can do so just as you would with
539any other recipe. You first copy the patches to the path added to
540:term:`FILESEXTRAPATHS` in
541your ``.bbappend`` file as described in the previous section, and then
542reference them in :term:`SRC_URI`
543statements.
544
545For example, you can apply a three-patch series by adding the following
Andrew Geisslerc926e172021-05-07 16:11:35 -0500546lines to your linux-yocto ``.bbappend`` file in your layer::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500547
548 SRC_URI += "file://0001-first-change.patch"
549 SRC_URI += "file://0002-second-change.patch"
550 SRC_URI += "file://0003-third-change.patch"
551
552The next time you run BitBake to build
553the Linux kernel, BitBake detects the change in the recipe and fetches
554and applies the patches before building the kernel.
555
556For a detailed example showing how to patch the kernel using
557``devtool``, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600558":ref:`kernel-dev/common:using \`\`devtool\`\` to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500559and
Andrew Geissler09209ee2020-12-13 08:44:15 -0600560":ref:`kernel-dev/common:using traditional kernel development to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500561sections.
562
563Changing the Configuration
564--------------------------
565
566You can make wholesale or incremental changes to the final ``.config``
567file used for the eventual Linux kernel configuration by including a
568``defconfig`` file and by specifying configuration fragments in the
569:term:`SRC_URI` to be applied to that
570file.
571
572If you have a complete, working Linux kernel ``.config`` file you want
573to use for the configuration, as before, copy that file to the
574appropriate ``${PN}`` directory in your layer's ``recipes-kernel/linux``
575directory, and rename the copied file to "defconfig". Then, add the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500576following lines to the linux-yocto ``.bbappend`` file in your layer::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500577
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500578 FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500579 SRC_URI += "file://defconfig"
580
Andrew Geissler09036742021-06-25 14:25:14 -0500581The :term:`SRC_URI` tells the build system how to search
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500582for the file, while the
583:term:`FILESEXTRAPATHS`
584extends the :term:`FILESPATH`
585variable (search directories) to include the ``${PN}`` directory you
586created to hold the configuration changes.
587
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700588You can also use a regular ``defconfig`` file, as generated by the
589:ref:`ref-tasks-savedefconfig`
590task instead of a complete ``.config`` file. This only specifies the
591non-default configuration values. You need to additionally set
592:term:`KCONFIG_MODE`
593in the linux-yocto ``.bbappend`` file in your layer::
594
595 KCONFIG_MODE = "alldefconfig"
596
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500597.. note::
598
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500599 The build system applies the configurations from the ``defconfig``
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500600 file before applying any subsequent configuration fragments. The
601 final kernel configuration is a combination of the configurations in
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500602 the ``defconfig`` file and any configuration fragments you provide. You need
603 to realize that if you have any configuration fragments, the build system
604 applies these on top of and after applying the existing ``defconfig`` file
605 configurations.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500606
607Generally speaking, the preferred approach is to determine the
608incremental change you want to make and add that as a configuration
609fragment. For example, if you want to add support for a basic serial
610console, create a file named ``8250.cfg`` in the ``${PN}`` directory
Andrew Geisslerc926e172021-05-07 16:11:35 -0500611with the following content (without indentation)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500612
613 CONFIG_SERIAL_8250=y
614 CONFIG_SERIAL_8250_CONSOLE=y
615 CONFIG_SERIAL_8250_PCI=y
616 CONFIG_SERIAL_8250_NR_UARTS=4
617 CONFIG_SERIAL_8250_RUNTIME_UARTS=4
618 CONFIG_SERIAL_CORE=y
619 CONFIG_SERIAL_CORE_CONSOLE=y
620
621Next, include this
Andrew Geissler09036742021-06-25 14:25:14 -0500622configuration fragment and extend the :term:`FILESPATH` variable in your
Andrew Geisslerc926e172021-05-07 16:11:35 -0500623``.bbappend`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500624
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500625 FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500626 SRC_URI += "file://8250.cfg"
627
628The next time you run BitBake to build the
629Linux kernel, BitBake detects the change in the recipe and fetches and
630applies the new configuration before building the kernel.
631
632For a detailed example showing how to configure the kernel, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500633":ref:`kernel-dev/common:configuring the kernel`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500634
635Using an "In-Tree"  ``defconfig`` File
636--------------------------------------
637
638It might be desirable to have kernel configuration fragment support
639through a ``defconfig`` file that is pulled from the kernel source tree
640for the configured machine. By default, the OpenEmbedded build system
641looks for ``defconfig`` files in the layer used for Metadata, which is
Andrew Geisslerc926e172021-05-07 16:11:35 -0500642"out-of-tree", and then configures them using the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500643
644 SRC_URI += "file://defconfig"
645
646If you do not want to maintain copies of
647``defconfig`` files in your layer but would rather allow users to use
648the default configuration from the kernel tree and still be able to add
649configuration fragments to the
650:term:`SRC_URI` through, for example,
651append files, you can direct the OpenEmbedded build system to use a
652``defconfig`` file that is "in-tree".
653
654To specify an "in-tree" ``defconfig`` file, use the following statement
Andrew Geisslerc926e172021-05-07 16:11:35 -0500655form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500656
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500657 KBUILD_DEFCONFIG_KMACHINE ?= "defconfig_file"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500658
659Here is an example
Andrew Geissler09036742021-06-25 14:25:14 -0500660that assigns the :term:`KBUILD_DEFCONFIG` variable based on "raspberrypi2"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500661and provides the path to the "in-tree" ``defconfig`` file to be used for
Andrew Geisslerc926e172021-05-07 16:11:35 -0500662a Raspberry Pi 2, which is based on the Broadcom 2708/2709 chipset::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500663
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500664 KBUILD_DEFCONFIG:raspberrypi2 ?= "bcm2709_defconfig"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500665
666Aside from modifying your kernel recipe and providing your own
667``defconfig`` file, you need to be sure no files or statements set
Andrew Geissler5f350902021-07-23 13:09:54 -0400668:term:`SRC_URI` to use a ``defconfig`` other than your "in-tree" file (e.g.
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500669a kernel's ``linux-``\ `machine`\ ``.inc`` file). In other words, if the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500670build system detects a statement that identifies an "out-of-tree"
671``defconfig`` file, that statement will override your
Andrew Geissler09036742021-06-25 14:25:14 -0500672:term:`KBUILD_DEFCONFIG` variable.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500673
674See the
675:term:`KBUILD_DEFCONFIG`
676variable description for more information.
677
678Using ``devtool`` to Patch the Kernel
679=====================================
680
681The steps in this procedure show you how you can patch the kernel using
Patrick Williams92b42cb2022-09-03 06:53:57 -0500682``devtool``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500683
684.. note::
685
686 Before attempting this procedure, be sure you have performed the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500687 steps to get ready for updating the kernel as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600688 ":ref:`kernel-dev/common:getting ready to develop using \`\`devtool\`\``"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500689 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500690
691Patching the kernel involves changing or adding configurations to an
692existing kernel, changing or adding recipes to the kernel that are
693needed to support specific hardware features, or even altering the
694source code itself.
695
696This example creates a simple patch by adding some QEMU emulator console
697output at boot time through ``printk`` statements in the kernel's
698``calibrate.c`` source code file. Applying the patch and booting the
699modified image causes the added messages to appear on the emulator's
700console. The example is a continuation of the setup procedure found in
Andrew Geissler09209ee2020-12-13 08:44:15 -0600701the ":ref:`kernel-dev/common:getting ready to develop using \`\`devtool\`\``" Section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500702
7031. *Check Out the Kernel Source Files:* First you must use ``devtool``
Patrick Williams92b42cb2022-09-03 06:53:57 -0500704 to checkout the kernel source code in its workspace.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500705
706 .. note::
707
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500708 See this step in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600709 ":ref:`kernel-dev/common:getting ready to develop using \`\`devtool\`\``"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500710 section for more information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500711
Andrew Geisslerc926e172021-05-07 16:11:35 -0500712 Use the following ``devtool`` command to check out the code::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500713
714 $ devtool modify linux-yocto
715
716 .. note::
717
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700718 During the checkout operation, there is a bug that could cause
719 errors such as the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500720
721 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500722
723 ERROR: Taskhash mismatch 2c793438c2d9f8c3681fd5f7bc819efa versus
724 be3a89ce7c47178880ba7bf6293d7404 for
725 /path/to/esdk/layers/poky/meta/recipes-kernel/linux/linux-yocto_4.10.bb.do_unpack
726
727
728 You can safely ignore these messages. The source code is correctly
729 checked out.
730
7312. *Edit the Source Files* Follow these steps to make some simple
732 changes to the source files:
733
734 1. *Change the working directory*: In the previous step, the output
735 noted where you can find the source files (e.g.
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500736 ``poky_sdk/workspace/sources/linux-yocto``). Change to where the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500737 kernel source code is before making your edits to the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500738 ``calibrate.c`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500739
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500740 $ cd poky_sdk/workspace/sources/linux-yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500741
742 2. *Edit the source file*: Edit the ``init/calibrate.c`` file to have
Andrew Geisslerc926e172021-05-07 16:11:35 -0500743 the following changes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500744
745 void calibrate_delay(void)
746 {
747 unsigned long lpj;
748 static bool printed;
749 int this_cpu = smp_processor_id();
750
751 printk("*************************************\n");
752 printk("* *\n");
753 printk("* HELLO YOCTO KERNEL *\n");
754 printk("* *\n");
755 printk("*************************************\n");
756
757 if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
758 .
759 .
760 .
761
7623. *Build the Updated Kernel Source:* To build the updated kernel
Andrew Geisslerc926e172021-05-07 16:11:35 -0500763 source, use ``devtool``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500764
765 $ devtool build linux-yocto
766
7674. *Create the Image With the New Kernel:* Use the
768 ``devtool build-image`` command to create a new image that has the
769 new kernel.
770
771 .. note::
772
773 If the image you originally created resulted in a Wic file, you
774 can use an alternate method to create the new image with the
775 updated kernel. For an example, see the steps in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600776 :yocto_wiki:`TipsAndTricks/KernelDevelopmentWithEsdk </TipsAndTricks/KernelDevelopmentWithEsdk>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500777 Wiki Page.
778
779 ::
780
781 $ cd ~
782 $ devtool build-image core-image-minimal
783
7845. *Test the New Image:* For this example, you can run the new image
785 using QEMU to verify your changes:
786
787 1. *Boot the image*: Boot the modified image in the QEMU emulator
Andrew Geisslerc926e172021-05-07 16:11:35 -0500788 using this command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500789
790 $ runqemu qemux86
791
792 2. *Verify the changes*: Log into the machine using ``root`` with no
793 password and then use the following shell command to scroll
794 through the console's boot output.
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500795
796 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500797
798 # dmesg | less
799
800 You should see
801 the results of your ``printk`` statements as part of the output
802 when you scroll down the console window.
803
Patrick Williams92b42cb2022-09-03 06:53:57 -05008046. *Stage and commit your changes*: Change
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500805 your working directory to where you modified the ``calibrate.c`` file
Andrew Geisslerc926e172021-05-07 16:11:35 -0500806 and use these Git commands to stage and commit your changes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500807
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500808 $ cd poky_sdk/workspace/sources/linux-yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500809 $ git status
810 $ git add init/calibrate.c
811 $ git commit -m "calibrate: Add printk example"
812
8137. *Export the Patches and Create an Append File:* To export your
814 commits as patches and create a ``.bbappend`` file, use the following
Patrick Williams92b42cb2022-09-03 06:53:57 -0500815 command. This example uses the previously established layer named ``meta-mylayer``.
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500816 ::
817
818 $ devtool finish linux-yocto ~/meta-mylayer
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500819
820 .. note::
821
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500822 See Step 3 of the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600823 ":ref:`kernel-dev/common:getting ready to develop using \`\`devtool\`\``"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500824 section for information on setting up this layer.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500825
826 Once the command
827 finishes, the patches and the ``.bbappend`` file are located in the
828 ``~/meta-mylayer/recipes-kernel/linux`` directory.
829
8308. *Build the Image With Your Modified Kernel:* You can now build an
831 image that includes your kernel patches. Execute the following
Patrick Williams2390b1b2022-11-03 13:47:49 -0500832 command from your :term:`Build Directory` in the terminal
Andrew Geisslerc926e172021-05-07 16:11:35 -0500833 set up to run BitBake::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500834
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500835 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500836 $ bitbake core-image-minimal
837
838Using Traditional Kernel Development to Patch the Kernel
839========================================================
840
841The steps in this procedure show you how you can patch the kernel using
Patrick Williams92b42cb2022-09-03 06:53:57 -0500842traditional kernel development (i.e. not using ``devtool``
843as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600844":ref:`kernel-dev/common:using \`\`devtool\`\` to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500845section).
846
847.. note::
848
849 Before attempting this procedure, be sure you have performed the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500850 steps to get ready for updating the kernel as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600851 ":ref:`kernel-dev/common:getting ready for traditional kernel development`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500852 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500853
854Patching the kernel involves changing or adding configurations to an
855existing kernel, changing or adding recipes to the kernel that are
856needed to support specific hardware features, or even altering the
857source code itself.
858
859The example in this section creates a simple patch by adding some QEMU
860emulator console output at boot time through ``printk`` statements in
861the kernel's ``calibrate.c`` source code file. Applying the patch and
862booting the modified image causes the added messages to appear on the
863emulator's console. The example is a continuation of the setup procedure
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500864found in the
865":ref:`kernel-dev/common:getting ready for traditional kernel development`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500866Section.
867
8681. *Edit the Source Files* Prior to this step, you should have used Git
869 to create a local copy of the repository for your kernel. Assuming
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500870 you created the repository as directed in the
871 ":ref:`kernel-dev/common:getting ready for traditional kernel development`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500872 section, use the following commands to edit the ``calibrate.c`` file:
873
874 1. *Change the working directory*: You need to locate the source
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500875 files in the local copy of the kernel Git repository. Change to
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500876 where the kernel source code is before making your edits to the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500877 ``calibrate.c`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500878
879 $ cd ~/linux-yocto-4.12/init
880
881 2. *Edit the source file*: Edit the ``calibrate.c`` file to have the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500882 following changes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500883
884 void calibrate_delay(void)
885 {
886 unsigned long lpj;
887 static bool printed;
888 int this_cpu = smp_processor_id();
889
890 printk("*************************************\n");
891 printk("* *\n");
892 printk("* HELLO YOCTO KERNEL *\n");
893 printk("* *\n");
894 printk("*************************************\n");
895
896 if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
897 .
898 .
899 .
900
9012. *Stage and Commit Your Changes:* Use standard Git commands to stage
Andrew Geisslerc926e172021-05-07 16:11:35 -0500902 and commit the changes you just made::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500903
904 $ git add calibrate.c
905 $ git commit -m "calibrate.c - Added some printk statements"
906
907 If you do not
908 stage and commit your changes, the OpenEmbedded Build System will not
909 pick up the changes.
910
9113. *Update Your local.conf File to Point to Your Source Files:* In
912 addition to your ``local.conf`` file specifying to use
913 "kernel-modules" and the "qemux86" machine, it must also point to the
914 updated kernel source files. Add
915 :term:`SRC_URI` and
916 :term:`SRCREV` statements similar
Andrew Geisslerc926e172021-05-07 16:11:35 -0500917 to the following to your ``local.conf``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500918
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500919 $ cd poky/build/conf
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500920
Andrew Geisslerc926e172021-05-07 16:11:35 -0500921 Add the following to the ``local.conf``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500922
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500923 SRC_URI:pn-linux-yocto = "git:///path-to/linux-yocto-4.12;protocol=file;name=machine;branch=standard/base; \
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500924 git:///path-to/yocto-kernel-cache;protocol=file;type=kmeta;name=meta;branch=yocto-4.12;destsuffix=${KMETA}"
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500925 SRCREV_meta:qemux86 = "${AUTOREV}"
926 SRCREV_machine:qemux86 = "${AUTOREV}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500927
928 .. note::
929
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500930 Be sure to replace `path-to`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500931 with the pathname to your local Git repositories. Also, you must
932 be sure to specify the correct branch and machine types. For this
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500933 example, the branch is ``standard/base`` and the machine is ``qemux86``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500934
9354. *Build the Image:* With the source modified, your changes staged and
936 committed, and the ``local.conf`` file pointing to the kernel files,
Andrew Geisslerc926e172021-05-07 16:11:35 -0500937 you can now use BitBake to build the image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500938
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500939 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500940 $ bitbake core-image-minimal
941
9425. *Boot the image*: Boot the modified image in the QEMU emulator using
943 this command. When prompted to login to the QEMU console, use "root"
Andrew Geisslerc926e172021-05-07 16:11:35 -0500944 with no password::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500945
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500946 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500947 $ runqemu qemux86
948
9496. *Look for Your Changes:* As QEMU booted, you might have seen your
950 changes rapidly scroll by. If not, use these commands to see your
951 changes:
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500952
953 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500954
955 # dmesg | less
956
957 You should see the results of your
958 ``printk`` statements as part of the output when you scroll down the
959 console window.
960
9617. *Generate the Patch File:* Once you are sure that your patch works
962 correctly, you can generate a ``*.patch`` file in the kernel source
Andrew Geisslerc926e172021-05-07 16:11:35 -0500963 repository::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500964
965 $ cd ~/linux-yocto-4.12/init
966 $ git format-patch -1
967 0001-calibrate.c-Added-some-printk-statements.patch
968
9698. *Move the Patch File to Your Layer:* In order for subsequent builds
970 to pick up patches, you need to move the patch file you created in
971 the previous step to your layer ``meta-mylayer``. For this example,
972 the layer created earlier is located in your home directory as
973 ``meta-mylayer``. When the layer was created using the
974 ``yocto-create`` script, no additional hierarchy was created to
975 support patches. Before moving the patch file, you need to add
Andrew Geisslerc926e172021-05-07 16:11:35 -0500976 additional structure to your layer using the following commands::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500977
978 $ cd ~/meta-mylayer
979 $ mkdir recipes-kernel
980 $ mkdir recipes-kernel/linux
981 $ mkdir recipes-kernel/linux/linux-yocto
982
983 Once you have created this
984 hierarchy in your layer, you can move the patch file using the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500985 following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500986
987 $ mv ~/linux-yocto-4.12/init/0001-calibrate.c-Added-some-printk-statements.patch ~/meta-mylayer/recipes-kernel/linux/linux-yocto
988
9899. *Create the Append File:* Finally, you need to create the
990 ``linux-yocto_4.12.bbappend`` file and insert statements that allow
991 the OpenEmbedded build system to find the patch. The append file
992 needs to be in your layer's ``recipes-kernel/linux`` directory and it
993 must be named ``linux-yocto_4.12.bbappend`` and have the following
Andrew Geisslerc926e172021-05-07 16:11:35 -0500994 contents::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500995
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500996 FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500997 SRC_URI += "file://0001-calibrate.c-Added-some-printk-statements.patch"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500998
999 The :term:`FILESEXTRAPATHS` and :term:`SRC_URI` statements
1000 enable the OpenEmbedded build system to find the patch file.
1001
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001002 For more information on append files and patches, see the
1003 ":ref:`kernel-dev/common:creating the append file`" and
1004 ":ref:`kernel-dev/common:applying patches`" sections. You can also see the
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001005 ":ref:`dev-manual/common-tasks:appending other layers metadata with your layer`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001006 section in the Yocto Project Development Tasks Manual.
1007
1008 .. note::
1009
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001010 To build ``core-image-minimal`` again and see the effects of your patch,
1011 you can essentially eliminate the temporary source files saved in
1012 ``poky/build/tmp/work/...`` and residual effects of the build by entering
Andrew Geisslerc926e172021-05-07 16:11:35 -05001013 the following sequence of commands::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001014
Andrew Geissler95ac1b82021-03-31 14:34:31 -05001015 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001016 $ bitbake -c cleanall yocto-linux
1017 $ bitbake core-image-minimal -c cleanall
1018 $ bitbake core-image-minimal
1019 $ runqemu qemux86
1020
1021
1022Configuring the Kernel
1023======================
1024
1025Configuring the Yocto Project kernel consists of making sure the
1026``.config`` file has all the right information in it for the image you
1027are building. You can use the ``menuconfig`` tool and configuration
1028fragments to make sure your ``.config`` file is just how you need it.
1029You can also save known configurations in a ``defconfig`` file that the
1030build system can use for kernel configuration.
1031
1032This section describes how to use ``menuconfig``, create and use
1033configuration fragments, and how to interactively modify your
1034``.config`` file to create the leanest kernel configuration file
1035possible.
1036
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001037For more information on kernel configuration, see the
1038":ref:`kernel-dev/common:changing the configuration`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001039
1040Using  ``menuconfig``
1041---------------------
1042
1043The easiest way to define kernel configurations is to set them through
1044the ``menuconfig`` tool. This tool provides an interactive method with
1045which to set kernel configurations. For general information on
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001046``menuconfig``, see https://en.wikipedia.org/wiki/Menuconfig.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001047
1048To use the ``menuconfig`` tool in the Yocto Project development
1049environment, you must do the following:
1050
1051- Because you launch ``menuconfig`` using BitBake, you must be sure to
Patrick Williams2390b1b2022-11-03 13:47:49 -05001052 set up your environment by running the :ref:`structure-core-script` script
1053 found in the :term:`Build Directory`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001054
1055- You must be sure of the state of your build's configuration in the
1056 :term:`Source Directory`.
1057
Andrew Geisslerc926e172021-05-07 16:11:35 -05001058- Your build host must have the following two packages installed::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001059
1060 libncurses5-dev
1061 libtinfo-dev
1062
1063The following commands initialize the BitBake environment, run the
1064:ref:`ref-tasks-kernel_configme`
1065task, and launch ``menuconfig``. These commands assume the Source
Andrew Geisslerc926e172021-05-07 16:11:35 -05001066Directory's top-level folder is ``poky``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001067
1068 $ cd poky
1069 $ source oe-init-build-env
1070 $ bitbake linux-yocto -c kernel_configme -f
1071 $ bitbake linux-yocto -c menuconfig
1072
1073Once ``menuconfig`` comes up, its standard
1074interface allows you to interactively examine and configure all the
1075kernel configuration parameters. After making your changes, simply exit
1076the tool and save your changes to create an updated version of the
1077``.config`` configuration file.
1078
1079.. note::
1080
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001081 You can use the entire ``.config`` file as the ``defconfig`` file. For
1082 information on ``defconfig`` files, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001083 ":ref:`kernel-dev/common:changing the configuration`",
1084 ":ref:`kernel-dev/common:using an "in-tree" \`\`defconfig\`\` file`",
1085 and ":ref:`kernel-dev/common:creating a \`\`defconfig\`\` file`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001086 sections.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001087
1088Consider an example that configures the "CONFIG_SMP" setting for the
1089``linux-yocto-4.12`` kernel.
1090
1091.. note::
1092
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001093 The OpenEmbedded build system recognizes this kernel as ``linux-yocto``
1094 through Metadata (e.g. :term:`PREFERRED_VERSION`\ ``_linux-yocto ?= "12.4%"``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001095
1096Once ``menuconfig`` launches, use the interface to navigate through the
1097selections to find the configuration settings in which you are
1098interested. For this example, you deselect "CONFIG_SMP" by clearing the
1099"Symmetric Multi-Processing Support" option. Using the interface, you
1100can find the option under "Processor Type and Features". To deselect
1101"CONFIG_SMP", use the arrow keys to highlight "Symmetric
1102Multi-Processing Support" and enter "N" to clear the asterisk. When you
1103are finished, exit out and save the change.
1104
Patrick Williams2390b1b2022-11-03 13:47:49 -05001105Saving the selections updates the ``.config`` configuration file. This is the
1106file that the OpenEmbedded build system uses to configure the kernel during
1107the build. You can find and examine this file in the :term:`Build Directory`
1108in ``tmp/work/``. The actual ``.config`` is located in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001109area where the specific kernel is built. For example, if you were
1110building a Linux Yocto kernel based on the ``linux-yocto-4.12`` kernel
1111and you were building a QEMU image targeted for ``x86`` architecture,
1112the ``.config`` file would be:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001113
1114.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001115
1116 poky/build/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+gitAUTOINC+eda4d18...
1117 ...967-r0/linux-qemux86-standard-build/.config
1118
1119.. note::
1120
1121 The previous example directory is artificially split and many of the
1122 characters in the actual filename are omitted in order to make it
1123 more readable. Also, depending on the kernel you are using, the exact
1124 pathname might differ.
1125
1126Within the ``.config`` file, you can see the kernel settings. For
1127example, the following entry shows that symmetric multi-processor
Andrew Geisslerc926e172021-05-07 16:11:35 -05001128support is not set::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001129
1130 # CONFIG_SMP is not set
1131
1132A good method to isolate changed configurations is to use a combination
1133of the ``menuconfig`` tool and simple shell commands. Before changing
1134configurations with ``menuconfig``, copy the existing ``.config`` and
1135rename it to something else, use ``menuconfig`` to make as many changes
1136as you want and save them, then compare the renamed configuration file
1137against the newly created file. You can use the resulting differences as
1138your base to create configuration fragments to permanently save in your
1139kernel layer.
1140
1141.. note::
1142
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001143 Be sure to make a copy of the ``.config`` file and do not just rename it.
1144 The build system needs an existing ``.config`` file from which to work.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001145
1146Creating a  ``defconfig`` File
1147------------------------------
1148
1149A ``defconfig`` file in the context of the Yocto Project is often a
1150``.config`` file that is copied from a build or a ``defconfig`` taken
1151from the kernel tree and moved into recipe space. You can use a
1152``defconfig`` file to retain a known set of kernel configurations from
1153which the OpenEmbedded build system can draw to create the final
1154``.config`` file.
1155
1156.. note::
1157
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001158 Out-of-the-box, the Yocto Project never ships a ``defconfig`` or ``.config``
1159 file. The OpenEmbedded build system creates the final ``.config`` file used
1160 to configure the kernel.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001161
1162To create a ``defconfig``, start with a complete, working Linux kernel
1163``.config`` file. Copy that file to the appropriate
1164``${``\ :term:`PN`\ ``}`` directory in
1165your layer's ``recipes-kernel/linux`` directory, and rename the copied
1166file to "defconfig" (e.g.
1167``~/meta-mylayer/recipes-kernel/linux/linux-yocto/defconfig``). Then,
1168add the following lines to the linux-yocto ``.bbappend`` file in your
Andrew Geisslerc926e172021-05-07 16:11:35 -05001169layer::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001170
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001171 FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001172 SRC_URI += "file://defconfig"
1173
1174The :term:`SRC_URI` tells the build system how to search for the file, while the
1175:term:`FILESEXTRAPATHS` extends the :term:`FILESPATH`
1176variable (search directories) to include the ``${PN}`` directory you
1177created to hold the configuration changes.
1178
1179.. note::
1180
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001181 The build system applies the configurations from the ``defconfig``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001182 file before applying any subsequent configuration fragments. The
1183 final kernel configuration is a combination of the configurations in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001184 the ``defconfig`` file and any configuration fragments you provide. You need
1185 to realize that if you have any configuration fragments, the build system
1186 applies these on top of and after applying the existing ``defconfig`` file
1187 configurations.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001188
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001189For more information on configuring the kernel, see the
1190":ref:`kernel-dev/common:changing the configuration`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001191
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001192Creating Configuration Fragments
1193--------------------------------
1194
1195Configuration fragments are simply kernel options that appear in a file
1196placed where the OpenEmbedded build system can find and apply them. The
1197build system applies configuration fragments after applying
1198configurations from a ``defconfig`` file. Thus, the final kernel
1199configuration is a combination of the configurations in the
1200``defconfig`` file and then any configuration fragments you provide. The
1201build system applies fragments on top of and after applying the existing
1202defconfig file configurations.
1203
1204Syntactically, the configuration statement is identical to what would
1205appear in the ``.config`` file, which is in the :term:`Build Directory`.
1206
1207.. note::
1208
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001209 For more information about where the ``.config`` file is located, see the
1210 example in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001211 ":ref:`kernel-dev/common:using \`\`menuconfig\`\``"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001212 section.
1213
1214It is simple to create a configuration fragment. One method is to use
1215shell commands. For example, issuing the following from the shell
1216creates a configuration fragment file named ``my_smp.cfg`` that enables
Andrew Geisslerc926e172021-05-07 16:11:35 -05001217multi-processor support within the kernel::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001218
1219 $ echo "CONFIG_SMP=y" >> my_smp.cfg
1220
1221.. note::
1222
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001223 All configuration fragment files must use the ``.cfg`` extension in order
1224 for the OpenEmbedded build system to recognize them as a configuration
1225 fragment.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001226
1227Another method is to create a configuration fragment using the
1228differences between two configuration files: one previously created and
1229saved, and one freshly created using the ``menuconfig`` tool.
1230
1231To create a configuration fragment using this method, follow these
1232steps:
1233
12341. *Complete a Build Through Kernel Configuration:* Complete a build at
Andrew Geisslerc926e172021-05-07 16:11:35 -05001235 least through the kernel configuration task as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001236
1237 $ bitbake linux-yocto -c kernel_configme -f
1238
1239 This step ensures that you create a
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001240 ``.config`` file from a known state. Because there are situations where
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001241 your build state might become unknown, it is best to run this task
1242 prior to starting ``menuconfig``.
1243
Andrew Geisslerc926e172021-05-07 16:11:35 -050012442. *Launch menuconfig:* Run the ``menuconfig`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001245
1246 $ bitbake linux-yocto -c menuconfig
1247
12483. *Create the Configuration Fragment:* Run the ``diffconfig`` command
1249 to prepare a configuration fragment. The resulting file
1250 ``fragment.cfg`` is placed in the
1251 ``${``\ :term:`WORKDIR`\ ``}``
Andrew Geisslerc926e172021-05-07 16:11:35 -05001252 directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001253
1254 $ bitbake linux-yocto -c diffconfig
1255
1256The ``diffconfig`` command creates a file that is a list of Linux kernel
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001257``CONFIG_`` assignments. See the
1258":ref:`kernel-dev/common:changing the configuration`" section for additional
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001259information on how to use the output as a configuration fragment.
1260
1261.. note::
1262
1263 You can also use this method to create configuration fragments for a
Andrew Geissler09209ee2020-12-13 08:44:15 -06001264 BSP. See the ":ref:`kernel-dev/advanced:bsp descriptions`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001265 section for more information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001266
1267Where do you put your configuration fragment files? You can place these
1268files in an area pointed to by
1269:term:`SRC_URI` as directed by your
1270``bblayers.conf`` file, which is located in your layer. The OpenEmbedded
1271build system picks up the configuration and adds it to the kernel's
1272configuration. For example, suppose you had a set of configuration
1273options in a file called ``myconfig.cfg``. If you put that file inside a
1274directory named ``linux-yocto`` that resides in the same directory as
1275the kernel's append file within your layer and then add the following
1276statements to the kernel's append file, those configuration options will
Andrew Geisslerc926e172021-05-07 16:11:35 -05001277be picked up and applied when the kernel is built::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001278
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001279 FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001280 SRC_URI += "file://myconfig.cfg"
1281
1282As mentioned earlier, you can group related configurations into multiple
Andrew Geissler09036742021-06-25 14:25:14 -05001283files and name them all in the :term:`SRC_URI` statement as well. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001284example, you could group separate configurations specifically for
1285Ethernet and graphics into their own files and add those by using a
Andrew Geissler09036742021-06-25 14:25:14 -05001286:term:`SRC_URI` statement like the following in your append file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001287
1288 SRC_URI += "file://myconfig.cfg \
1289 file://eth.cfg \
1290 file://gfx.cfg"
1291
1292Validating Configuration
1293------------------------
1294
1295You can use the
1296:ref:`ref-tasks-kernel_configcheck`
Andrew Geisslerc926e172021-05-07 16:11:35 -05001297task to provide configuration validation::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001298
1299 $ bitbake linux-yocto -c kernel_configcheck -f
1300
1301Running this task produces warnings for when a
1302requested configuration does not appear in the final ``.config`` file or
1303when you override a policy configuration in a hardware configuration
1304fragment.
1305
1306In order to run this task, you must have an existing ``.config`` file.
Andrew Geissler09209ee2020-12-13 08:44:15 -06001307See the ":ref:`kernel-dev/common:using \`\`menuconfig\`\``" section for
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001308information on how to create a configuration file.
1309
Patrick Williams2194f502022-10-16 14:26:09 -05001310Following is sample output from the :ref:`ref-tasks-kernel_configcheck` task:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001311
1312.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001313
1314 Loading cache: 100% |########################################################| Time: 0:00:00
1315 Loaded 1275 entries from dependency cache.
1316 NOTE: Resolving any missing task queue dependencies
1317
1318 Build Configuration:
1319 .
1320 .
1321 .
1322
1323 NOTE: Executing SetScene Tasks
1324 NOTE: Executing RunQueue Tasks
1325 WARNING: linux-yocto-4.12.12+gitAUTOINC+eda4d18ce4_16de014967-r0 do_kernel_configcheck:
1326 [kernel config]: specified values did not make it into the kernel's final configuration:
1327
1328 ---------- CONFIG_X86_TSC -----------------
1329 Config: CONFIG_X86_TSC
1330 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/bsp/common-pc/common-pc-cpu.cfg
1331 Requested value: CONFIG_X86_TSC=y
1332 Actual value:
1333
1334
1335 ---------- CONFIG_X86_BIGSMP -----------------
1336 Config: CONFIG_X86_BIGSMP
1337 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
1338 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
1339 Requested value: # CONFIG_X86_BIGSMP is not set
1340 Actual value:
1341
1342
1343 ---------- CONFIG_NR_CPUS -----------------
1344 Config: CONFIG_NR_CPUS
1345 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
1346 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/bsp/common-pc/common-pc.cfg
1347 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
1348 Requested value: CONFIG_NR_CPUS=8
1349 Actual value: CONFIG_NR_CPUS=1
1350
1351
1352 ---------- CONFIG_SCHED_SMT -----------------
1353 Config: CONFIG_SCHED_SMT
1354 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
1355 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
1356 Requested value: CONFIG_SCHED_SMT=y
1357 Actual value:
1358
1359
1360
1361 NOTE: Tasks Summary: Attempted 288 tasks of which 285 didn't need to be rerun and all succeeded.
1362
1363 Summary: There were 3 WARNING messages shown.
1364
1365.. note::
1366
1367 The previous output example has artificial line breaks to make it
1368 more readable.
1369
1370The output describes the various problems that you can encounter along
1371with where to find the offending configuration items. You can use the
1372information in the logs to adjust your configuration files and then
1373repeat the
1374:ref:`ref-tasks-kernel_configme`
1375and
1376:ref:`ref-tasks-kernel_configcheck`
1377tasks until they produce no warnings.
1378
1379For more information on how to use the ``menuconfig`` tool, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001380:ref:`kernel-dev/common:using \`\`menuconfig\`\`` section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001381
1382Fine-Tuning the Kernel Configuration File
1383-----------------------------------------
1384
1385You can make sure the ``.config`` file is as lean or efficient as
1386possible by reading the output of the kernel configuration fragment
1387audit, noting any issues, making changes to correct the issues, and then
1388repeating.
1389
Patrick Williams2194f502022-10-16 14:26:09 -05001390As part of the kernel build process, the :ref:`ref-tasks-kernel_configcheck` task
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001391runs. This task validates the kernel configuration by checking the final
1392``.config`` file against the input files. During the check, the task
1393produces warning messages for the following issues:
1394
1395- Requested options that did not make the final ``.config`` file.
1396
1397- Configuration items that appear twice in the same configuration
1398 fragment.
1399
1400- Configuration items tagged as "required" that were overridden.
1401
1402- A board overrides a non-board specific option.
1403
1404- Listed options not valid for the kernel being processed. In other
1405 words, the option does not appear anywhere.
1406
1407.. note::
1408
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001409 The :ref:`ref-tasks-kernel_configcheck` task can also optionally report if
1410 an option is overridden during processing.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001411
1412For each output warning, a message points to the file that contains a
1413list of the options and a pointer to the configuration fragment that
1414defines them. Collectively, the files are the key to streamlining the
1415configuration.
1416
1417To streamline the configuration, do the following:
1418
14191. *Use a Working Configuration:* Start with a full configuration that
1420 you know works. Be sure the configuration builds and boots
1421 successfully. Use this configuration file as your baseline.
1422
14232. *Run Configure and Check Tasks:* Separately run the
Patrick Williams2194f502022-10-16 14:26:09 -05001424 :ref:`ref-tasks-kernel_configme` and :ref:`ref-tasks-kernel_configcheck` tasks::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001425
1426 $ bitbake linux-yocto -c kernel_configme -f
1427 $ bitbake linux-yocto -c kernel_configcheck -f
1428
14293. *Process the Results:* Take the resulting list of files from the
Patrick Williams2194f502022-10-16 14:26:09 -05001430 :ref:`ref-tasks-kernel_configcheck` task warnings and do the following:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001431
1432 - Drop values that are redefined in the fragment but do not change
1433 the final ``.config`` file.
1434
1435 - Analyze and potentially drop values from the ``.config`` file that
1436 override required configurations.
1437
1438 - Analyze and potentially remove non-board specific options.
1439
1440 - Remove repeated and invalid options.
1441
14424. *Re-Run Configure and Check Tasks:* After you have worked through the
1443 output of the kernel configuration audit, you can re-run the
Patrick Williams2194f502022-10-16 14:26:09 -05001444 :ref:`ref-tasks-kernel_configme` and :ref:`ref-tasks-kernel_configcheck` tasks to see the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001445 results of your changes. If you have more issues, you can deal with
1446 them as described in the previous step.
1447
1448Iteratively working through steps two through four eventually yields a
1449minimal, streamlined configuration file. Once you have the best
1450``.config``, you can build the Linux Yocto kernel.
1451
1452Expanding Variables
1453===================
1454
1455Sometimes it is helpful to determine what a variable expands to during a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001456build. You can examine the values of variables by examining the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001457output of the ``bitbake -e`` command. The output is long and is more
Andrew Geisslerc926e172021-05-07 16:11:35 -05001458easily managed in a text file, which allows for easy searches::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001459
1460 $ bitbake -e virtual/kernel > some_text_file
1461
1462Within the text file, you can see
1463exactly how each variable is expanded and used by the OpenEmbedded build
1464system.
1465
1466Working with a "Dirty" Kernel Version String
1467============================================
1468
1469If you build a kernel image and the version string has a "+" or a
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001470"-dirty" at the end, it means there are uncommitted modifications in the kernel's
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001471source directory. Follow these steps to clean up the version string:
1472
14731. *Discover the Uncommitted Changes:* Go to the kernel's locally cloned
1474 Git repository (source directory) and use the following Git command
Andrew Geisslerc926e172021-05-07 16:11:35 -05001475 to list the files that have been changed, added, or removed::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001476
1477 $ git status
1478
14792. *Commit the Changes:* You should commit those changes to the kernel
1480 source tree regardless of whether or not you will save, export, or
Andrew Geisslerc926e172021-05-07 16:11:35 -05001481 use the changes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001482
1483 $ git add
1484 $ git commit -s -a -m "getting rid of -dirty"
1485
14863. *Rebuild the Kernel Image:* Once you commit the changes, rebuild the
1487 kernel.
1488
1489 Depending on your particular kernel development workflow, the
1490 commands you use to rebuild the kernel might differ. For information
1491 on building the kernel image when using ``devtool``, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001492 ":ref:`kernel-dev/common:using \`\`devtool\`\` to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001493 section. For
Andrew Geisslerd5838332022-05-27 11:33:10 -05001494 information on building the kernel image when using BitBake, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001495 ":ref:`kernel-dev/common:using traditional kernel development to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001496 section.
1497
1498Working With Your Own Sources
1499=============================
1500
1501If you cannot work with one of the Linux kernel versions supported by
1502existing linux-yocto recipes, you can still make use of the Yocto
1503Project Linux kernel tooling by working with your own sources. When you
1504use your own sources, you will not be able to leverage the existing
1505kernel :term:`Metadata` and stabilization
1506work of the linux-yocto sources. However, you will be able to manage
1507your own Metadata in the same format as the linux-yocto sources.
1508Maintaining format compatibility facilitates converging with linux-yocto
1509on a future, mutually-supported kernel version.
1510
1511To help you use your own sources, the Yocto Project provides a
Andrew Geissler595f6302022-01-24 19:11:47 +00001512linux-yocto custom recipe that uses ``kernel.org`` sources and
1513the Yocto Project Linux kernel tools for managing kernel Metadata.
1514You can find this recipe in the ``poky`` Git repository:
1515:yocto_git:`meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb
1516</poky/tree/meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001517
1518Here are some basic steps you can use to work with your own sources:
1519
15201. *Create a Copy of the Kernel Recipe:* Copy the
1521 ``linux-yocto-custom.bb`` recipe to your layer and give it a
1522 meaningful name. The name should include the version of the Yocto
1523 Linux kernel you are using (e.g. ``linux-yocto-myproject_4.12.bb``,
1524 where "4.12" is the base version of the Linux kernel with which you
1525 would be working).
1526
15272. *Create a Directory for Your Patches:* In the same directory inside
1528 your layer, create a matching directory to store your patches and
1529 configuration files (e.g. ``linux-yocto-myproject``).
1530
15313. *Ensure You Have Configurations:* Make sure you have either a
1532 ``defconfig`` file or configuration fragment files in your layer.
1533 When you use the ``linux-yocto-custom.bb`` recipe, you must specify a
1534 configuration. If you do not have a ``defconfig`` file, you can run
Andrew Geisslerc926e172021-05-07 16:11:35 -05001535 the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001536
1537 $ make defconfig
1538
1539 After running the command, copy the
1540 resulting ``.config`` file to the ``files`` directory in your layer
1541 as "defconfig" and then add it to the
1542 :term:`SRC_URI` variable in the
1543 recipe.
1544
1545 Running the ``make defconfig`` command results in the default
1546 configuration for your architecture as defined by your kernel.
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001547 However, there is no guarantee that this configuration is valid for
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001548 your use case, or that your board will even boot. This is
1549 particularly true for non-x86 architectures.
1550
1551 To use non-x86 ``defconfig`` files, you need to be more specific and
1552 find one that matches your board (i.e. for arm, you look in
1553 ``arch/arm/configs`` and use the one that is the best starting point
1554 for your board).
1555
15564. *Edit the Recipe:* Edit the following variables in your recipe as
1557 appropriate for your project:
1558
1559 - :term:`SRC_URI`: The
Andrew Geissler09036742021-06-25 14:25:14 -05001560 :term:`SRC_URI` should specify a Git repository that uses one of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001561 supported Git fetcher protocols (i.e. ``file``, ``git``, ``http``,
Andrew Geissler09036742021-06-25 14:25:14 -05001562 and so forth). The :term:`SRC_URI` variable should also specify either
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001563 a ``defconfig`` file or some configuration fragment files. The
Andrew Geissler09036742021-06-25 14:25:14 -05001564 skeleton recipe provides an example :term:`SRC_URI` as a syntax
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001565 reference.
1566
1567 - :term:`LINUX_VERSION`:
1568 The Linux kernel version you are using (e.g. "4.12").
1569
1570 - :term:`LINUX_VERSION_EXTENSION`:
1571 The Linux kernel ``CONFIG_LOCALVERSION`` that is compiled into the
1572 resulting kernel and visible through the ``uname`` command.
1573
1574 - :term:`SRCREV`: The commit ID
1575 from which you want to build.
1576
1577 - :term:`PR`: Treat this variable the
1578 same as you would in any other recipe. Increment the variable to
1579 indicate to the OpenEmbedded build system that the recipe has
1580 changed.
1581
Andrew Geissler09036742021-06-25 14:25:14 -05001582 - :term:`PV`: The default :term:`PV`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001583 assignment is typically adequate. It combines the
Andrew Geissler09036742021-06-25 14:25:14 -05001584 :term:`LINUX_VERSION` with the Source Control Manager (SCM) revision
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001585 as derived from the :term:`SRCPV`
1586 variable. The combined results are a string with the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05001587 form::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001588
1589 3.19.11+git1+68a635bf8dfb64b02263c1ac80c948647cc76d5f_1+218bd8d2022b9852c60d32f0d770931e3cf343e2
1590
Andrew Geissler09036742021-06-25 14:25:14 -05001591 While lengthy, the extra verbosity in :term:`PV` helps ensure you are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001592 using the exact sources from which you intend to build.
1593
1594 - :term:`COMPATIBLE_MACHINE`:
1595 A list of the machines supported by your new recipe. This variable
1596 in the example recipe is set by default to a regular expression
1597 that matches only the empty string, "(^$)". This default setting
1598 triggers an explicit build failure. You must change it to match a
1599 list of the machines that your new recipe supports. For example,
1600 to support the ``qemux86`` and ``qemux86-64`` machines, use the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001601 following form::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001602
1603 COMPATIBLE_MACHINE = "qemux86|qemux86-64"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001604
16055. *Customize Your Recipe as Needed:* Provide further customizations to
1606 your recipe as needed just as you would customize an existing
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001607 linux-yocto recipe. See the
1608 ":ref:`ref-manual/devtool-reference:modifying an existing recipe`" section
1609 for information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001610
1611Working with Out-of-Tree Modules
1612================================
1613
1614This section describes steps to build out-of-tree modules on your target
1615and describes how to incorporate out-of-tree modules in the build.
1616
1617Building Out-of-Tree Modules on the Target
1618------------------------------------------
1619
1620While the traditional Yocto Project development model would be to
1621include kernel modules as part of the normal build process, you might
1622find it useful to build modules on the target. This could be the case if
1623your target system is capable and powerful enough to handle the
1624necessary compilation. Before deciding to build on your target, however,
1625you should consider the benefits of using a proper cross-development
1626environment from your build host.
1627
1628If you want to be able to build out-of-tree modules on the target, there
1629are some steps you need to take on the target that is running your SDK
1630image. Briefly, the ``kernel-dev`` package is installed by default on
1631all ``*.sdk`` images and the ``kernel-devsrc`` package is installed on
1632many of the ``*.sdk`` images. However, you need to create some scripts
1633prior to attempting to build the out-of-tree modules on the target that
1634is running that image.
1635
1636Prior to attempting to build the out-of-tree modules, you need to be on
1637the target as root and you need to change to the ``/usr/src/kernel``
1638directory. Next, ``make`` the scripts:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001639
1640.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001641
1642 # cd /usr/src/kernel
1643 # make scripts
1644
1645Because all SDK image recipes include ``dev-pkgs``, the
1646``kernel-dev`` packages will be installed as part of the SDK image and
1647the ``kernel-devsrc`` packages will be installed as part of applicable
1648SDK images. The SDK uses the scripts when building out-of-tree modules.
1649Once you have switched to that directory and created the scripts, you
1650should be able to build your out-of-tree modules on the target.
1651
1652Incorporating Out-of-Tree Modules
1653---------------------------------
1654
1655While it is always preferable to work with sources integrated into the
1656Linux kernel sources, if you need an external kernel module, the
1657``hello-mod.bb`` recipe is available as a template from which you can
1658create your own out-of-tree Linux kernel module recipe.
1659
1660This template recipe is located in the ``poky`` Git repository of the
Andrew Geissler595f6302022-01-24 19:11:47 +00001661Yocto Project:
1662:yocto_git:`meta-skeleton/recipes-kernel/hello-mod/hello-mod_0.1.bb
1663</poky/tree/meta-skeleton/recipes-kernel/hello-mod/hello-mod_0.1.bb>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001664
1665To get started, copy this recipe to your layer and give it a meaningful
1666name (e.g. ``mymodule_1.0.bb``). In the same directory, create a new
1667directory named ``files`` where you can store any source files, patches,
1668or other files necessary for building the module that do not come with
1669the sources. Finally, update the recipe as needed for the module.
1670Typically, you will need to set the following variables:
1671
1672- :term:`DESCRIPTION`
1673
1674- :term:`LICENSE* <LICENSE>`
1675
1676- :term:`SRC_URI`
1677
1678- :term:`PV`
1679
1680Depending on the build system used by the module sources, you might need
1681to make some adjustments. For example, a typical module ``Makefile``
Andrew Geisslerc926e172021-05-07 16:11:35 -05001682looks much like the one provided with the ``hello-mod`` template::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001683
1684 obj-m := hello.o
1685
1686 SRC := $(shell pwd)
1687
1688 all:
1689 $(MAKE) -C $(KERNEL_SRC) M=$(SRC)
1690
1691 modules_install:
1692 $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
1693 ...
1694
1695The important point to note here is the :term:`KERNEL_SRC` variable. The
1696:ref:`module <ref-classes-module>` class sets this variable and the
1697:term:`KERNEL_PATH` variable to
1698``${STAGING_KERNEL_DIR}`` with the necessary Linux kernel build
1699information to build modules. If your module ``Makefile`` uses a
1700different variable, you might want to override the
1701:ref:`ref-tasks-compile` step, or
1702create a patch to the ``Makefile`` to work with the more typical
Andrew Geissler09036742021-06-25 14:25:14 -05001703:term:`KERNEL_SRC` or :term:`KERNEL_PATH` variables.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001704
1705After you have prepared your recipe, you will likely want to include the
1706module in your images. To do this, see the documentation for the
1707following variables in the Yocto Project Reference Manual and set one of
1708them appropriately for your machine configuration file:
1709
1710- :term:`MACHINE_ESSENTIAL_EXTRA_RDEPENDS`
1711
1712- :term:`MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS`
1713
1714- :term:`MACHINE_EXTRA_RDEPENDS`
1715
1716- :term:`MACHINE_EXTRA_RRECOMMENDS`
1717
1718Modules are often not required for boot and can be excluded from certain
Andrew Geisslerc926e172021-05-07 16:11:35 -05001719build configurations. The following allows for the most flexibility::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001720
1721 MACHINE_EXTRA_RRECOMMENDS += "kernel-module-mymodule"
1722
1723The value is
1724derived by appending the module filename without the ``.ko`` extension
1725to the string "kernel-module-".
1726
1727Because the variable is
1728:term:`RRECOMMENDS` and not a
1729:term:`RDEPENDS` variable, the build
1730will not fail if this module is not available to include in the image.
1731
1732Inspecting Changes and Commits
1733==============================
1734
1735A common question when working with a kernel is: "What changes have been
1736applied to this tree?" Rather than using "grep" across directories to
1737see what has changed, you can use Git to inspect or search the kernel
1738tree. Using Git is an efficient way to see what has changed in the tree.
1739
1740What Changed in a Kernel?
1741-------------------------
1742
1743Following are a few examples that show how to use Git commands to
1744examine changes. These examples are by no means the only way to see
1745changes.
1746
1747.. note::
1748
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001749 In the following examples, unless you provide a commit range, ``kernel.org``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001750 history is blended with Yocto Project kernel changes. You can form
1751 ranges by using branch names from the kernel tree as the upper and
1752 lower commit markers with the Git commands. You can see the branch
1753 names through the web interface to the Yocto Project source
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001754 repositories at :yocto_git:`/`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001755
1756To see a full range of the changes, use the ``git whatchanged`` command
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001757and specify a commit range for the branch (`commit`\ ``..``\ `commit`).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001758
1759Here is an example that looks at what has changed in the ``emenlow``
1760branch of the ``linux-yocto-3.19`` kernel. The lower commit range is the
1761commit associated with the ``standard/base`` branch, while the upper
1762commit range is the commit associated with the ``standard/emenlow``
1763branch.
1764::
1765
1766 $ git whatchanged origin/standard/base..origin/standard/emenlow
1767
Andrew Geisslerc926e172021-05-07 16:11:35 -05001768To see short, one line summaries of changes use the ``git log`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001769
1770 $ git log --oneline origin/standard/base..origin/standard/emenlow
1771
Andrew Geisslerc926e172021-05-07 16:11:35 -05001772Use this command to see code differences for the changes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001773
1774 $ git diff origin/standard/base..origin/standard/emenlow
1775
1776Use this command to see the commit log messages and the text
Andrew Geisslerc926e172021-05-07 16:11:35 -05001777differences::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001778
1779 $ git show origin/standard/base..origin/standard/emenlow
1780
1781Use this command to create individual patches for each change. Here is
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001782an example that creates patch files for each commit and places them
Andrew Geisslerc926e172021-05-07 16:11:35 -05001783in your ``Documents`` directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001784
1785 $ git format-patch -o $HOME/Documents origin/standard/base..origin/standard/emenlow
1786
1787Showing a Particular Feature or Branch Change
1788---------------------------------------------
1789
1790Tags in the Yocto Project kernel tree divide changes for significant
1791features or branches. The ``git show`` tag command shows changes based
Andrew Geisslerc926e172021-05-07 16:11:35 -05001792on a tag. Here is an example that shows ``systemtap`` changes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001793
1794 $ git show systemtap
1795
1796You can use the ``git branch --contains`` tag command to
1797show the branches that contain a particular feature. This command shows
Andrew Geisslerc926e172021-05-07 16:11:35 -05001798the branches that contain the ``systemtap`` feature::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001799
1800 $ git branch --contains systemtap
1801
1802Adding Recipe-Space Kernel Features
1803===================================
1804
1805You can add kernel features in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001806:ref:`recipe-space <kernel-dev/advanced:recipe-space metadata>`
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001807by using the :term:`KERNEL_FEATURES`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001808variable and by specifying the feature's ``.scc`` file path in the
1809:term:`SRC_URI` statement. When you
1810add features using this method, the OpenEmbedded build system checks to
1811be sure the features are present. If the features are not present, the
1812build stops. Kernel features are the last elements processed for
1813configuring and patching the kernel. Therefore, adding features in this
1814manner is a way to enforce specific features are present and enabled
1815without needing to do a full audit of any other layer's additions to the
Andrew Geissler09036742021-06-25 14:25:14 -05001816:term:`SRC_URI` statement.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001817
1818You add a kernel feature by providing the feature as part of the
Andrew Geissler09036742021-06-25 14:25:14 -05001819:term:`KERNEL_FEATURES` variable and by providing the path to the feature's
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001820``.scc`` file, which is relative to the root of the kernel Metadata. The
1821OpenEmbedded build system searches all forms of kernel Metadata on the
Andrew Geissler09036742021-06-25 14:25:14 -05001822:term:`SRC_URI` statement regardless of whether the Metadata is in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001823"kernel-cache", system kernel Metadata, or a recipe-space Metadata (i.e.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001824part of the kernel recipe). See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001825":ref:`kernel-dev/advanced:kernel metadata location`" section for
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001826additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001827
Andrew Geissler09036742021-06-25 14:25:14 -05001828When you specify the feature's ``.scc`` file on the :term:`SRC_URI`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001829statement, the OpenEmbedded build system adds the directory of that
1830``.scc`` file along with all its subdirectories to the kernel feature
1831search path. Because subdirectories are searched, you can reference a
Andrew Geissler09036742021-06-25 14:25:14 -05001832single ``.scc`` file in the :term:`SRC_URI` statement to reference multiple
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001833kernel features.
1834
1835Consider the following example that adds the "test.scc" feature to the
1836build.
1837
18381. *Create the Feature File:* Create a ``.scc`` file and locate it just
1839 as you would any other patch file, ``.cfg`` file, or fetcher item you
Andrew Geissler09036742021-06-25 14:25:14 -05001840 specify in the :term:`SRC_URI` statement.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001841
1842 .. note::
1843
1844 - You must add the directory of the ``.scc`` file to the
1845 fetcher's search path in the same manner as you would add a
1846 ``.patch`` file.
1847
1848 - You can create additional ``.scc`` files beneath the directory
1849 that contains the file you are adding. All subdirectories are
1850 searched during the build as potential feature directories.
1851
1852 Continuing with the example, suppose the "test.scc" feature you are
Andrew Geisslerc926e172021-05-07 16:11:35 -05001853 adding has a ``test.scc`` file in the following directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001854
1855 my_recipe
1856 |
1857 +-linux-yocto
1858 |
1859 +-test.cfg
1860 +-test.scc
1861
1862 In this example, the
1863 ``linux-yocto`` directory has both the feature ``test.scc`` file and
1864 a similarly named configuration fragment file ``test.cfg``.
1865
18662. *Add the Feature File to SRC_URI:* Add the ``.scc`` file to the
Andrew Geissler09036742021-06-25 14:25:14 -05001867 recipe's :term:`SRC_URI` statement::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001868
Andrew Geissler87f5cff2022-09-30 13:13:31 -05001869 SRC_URI += "file://test.scc"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001870
1871 The leading space before the path is important as the path is
1872 appended to the existing path.
1873
18743. *Specify the Feature as a Kernel Feature:* Use the
Andrew Geissler09036742021-06-25 14:25:14 -05001875 :term:`KERNEL_FEATURES` statement to specify the feature as a kernel
Andrew Geisslerc926e172021-05-07 16:11:35 -05001876 feature::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001877
Andrew Geissler87f5cff2022-09-30 13:13:31 -05001878 KERNEL_FEATURES += "test.scc"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001879
1880 The OpenEmbedded build
1881 system processes the kernel feature when it builds the kernel.
1882
1883 .. note::
1884
1885 If other features are contained below "test.scc", then their
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001886 directories are relative to the directory containing the ``test.scc``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001887 file.