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