blob: 9052876122d22b5075703ff8afacc562c38b8ad1 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
2"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
3[<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
4
5<chapter id='kernel-dev-common'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006<title>Common Tasks</title>
7
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008 <para>
9 This chapter presents several common tasks you perform when you
10 work with the Yocto Project Linux kernel.
11 These tasks include preparing your host development system for
12 kernel development, preparing a layer, modifying an existing recipe,
13 patching the kernel, configuring the kernel, iterative development,
14 working with your own sources, and incorporating out-of-tree modules.
15 <note>
16 The examples presented in this chapter work with the Yocto Project
17 2.4 Release and forward.
18 </note>
19 </para>
20
21 <section id='preparing-the-build-host-to-work-on-the-kernel'>
22 <title>Preparing the Build Host to Work on the Kernel</title>
23
24 <para>
25 Before you can do any kernel development, you need to be
26 sure your build host is set up to use the Yocto Project.
27 For information on how to get set up, see the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080028 "<ulink url='&YOCTO_DOCS_DEV_URL;#dev-preparing-the-build-host'>Preparing the Build Host</ulink>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050029 section in the Yocto Project Development Tasks Manual.
30 Part of preparing the system is creating a local Git
31 repository of the
32 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
33 (<filename>poky</filename>) on your system.
34 Follow the steps in the
35 "<ulink url='&YOCTO_DOCS_DEV_URL;#cloning-the-poky-repository'>Cloning the <filename>poky</filename> Repository</ulink>"
36 section in the Yocto Project Development Tasks Manual to set up your
37 Source Directory.
38 <note>
39 Be sure you check out the appropriate development branch or
40 you create your local branch by checking out a specific tag
41 to get the desired version of Yocto Project.
42 See the
43 "<ulink url='&YOCTO_DOCS_DEV_URL;#checking-out-by-branch-in-poky'>Checking Out by Branch in Poky</ulink>"
44 and
45 "<ulink url='&YOCTO_DOCS_DEV_URL;#checkout-out-by-tag-in-poky'>Checking Out by Tag in Poky</ulink>"
46 sections in the Yocto Project Development Tasks Manual for more
47 information.
48 </note>
49 </para>
50
51 <para>
52 Kernel development is best accomplished using
53 <ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'><filename>devtool</filename></ulink>
54 and not through traditional kernel workflow methods.
55 The remainder of this section provides information for both
56 scenarios.
57 </para>
58
59 <section id='getting-ready-to-develop-using-devtool'>
60 <title>Getting Ready to Develop Using <filename>devtool</filename></title>
61
62 <para>
63 Follow these steps to prepare to update the kernel image using
64 <filename>devtool</filename>.
65 Completing this procedure leaves you with a clean kernel image
66 and ready to make modifications as described in the
67 "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>"
68 section:
69 <orderedlist>
70 <listitem><para>
71 <emphasis>Initialize the BitBake Environment:</emphasis>
72 Before building an extensible SDK, you need to
73 initialize the BitBake build environment by sourcing the
74 build environment script
75 (i.e. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>):
76 <literallayout class='monospaced'>
77 $ cd ~/poky
78 $ source oe-init-build-env
79 </literallayout>
80 <note>
81 The previous commands assume the
Brad Bishop316dfdd2018-06-25 12:45:53 -040082 <ulink url='&YOCTO_DOCS_OM_URL;#source-repositories'>Source Repositories</ulink>
Brad Bishopd7bf8c12018-02-25 22:55:05 -050083 (i.e. <filename>poky</filename>) have been cloned
84 using Git and the local repository is named
85 "poky".
86 </note>
87 </para></listitem>
88 <listitem><para>
89 <emphasis>Prepare Your <filename>local.conf</filename> File:</emphasis>
90 By default, the
91 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
92 variable is set to "qemux86", which is fine if you are
93 building for the QEMU emulator in 32-bit mode.
94 However, if you are not, you need to set the
95 <filename>MACHINE</filename> variable appropriately in
96 your <filename>conf/local.conf</filename> file found in
97 the
98 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
99 (i.e. <filename>~/poky/build</filename> in this
100 example).</para>
101
102 <para>Also, since you are preparing to work on the
103 kernel image, you need to set the
104 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink>
105 variable to include kernel modules.</para>
106
107 <para>This example uses the default "qemux86" for the
108 <filename>MACHINE</filename> variable but needs to
109 add the "kernel-modules":
110 <literallayout class='monospaced'>
111 MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules"
112 </literallayout>
113 </para></listitem>
114 <listitem><para>
115 <emphasis>Create a Layer for Patches:</emphasis>
116 You need to create a layer to hold patches created
117 for the kernel image.
118 You can use the
119 <filename>bitbake-layers create-layer</filename>
120 command as follows:
121 <literallayout class='monospaced'>
122 $ cd ~/poky/build
123 $ bitbake-layers create-layer ../../meta-mylayer
124 NOTE: Starting bitbake server...
125 Add your new layer with 'bitbake-layers add-layer ../../meta-mylayer'
126 $
127 </literallayout>
128 <note>
129 For background information on working with
130 common and BSP layers, see the
131 "<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>"
132 section in the Yocto Project Development Tasks
133 Manual and the
134 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
135 section in the Yocto Project Board Support (BSP)
136 Developer's Guide, respectively.
137 For information on how to use the
138 <filename>bitbake-layers create-layer</filename>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400139 command to quickly set up a layer, see the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500140 "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</ulink>"
141 section in the Yocto Project Development Tasks
142 Manual.
143 </note>
144 </para></listitem>
145 <listitem><para>
146 <emphasis>Inform the BitBake Build Environment About
147 Your Layer:</emphasis>
148 As directed when you created your layer, you need to
149 add the layer to the
150 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
151 variable in the <filename>bblayers.conf</filename> file
152 as follows:
153 <literallayout class='monospaced'>
154 $ cd ~/poky/build
155 $ bitbake-layers add-layer ../../meta-mylayer
156 NOTE: Starting bitbake server...
157 $
158 </literallayout>
159 </para></listitem>
160 <listitem><para>
161 <emphasis>Build the Extensible SDK:</emphasis>
162 Use BitBake to build the extensible SDK specifically
163 for use with images to be run using QEMU:
164 <literallayout class='monospaced'>
165 $ cd ~/poky/build
166 $ bitbake core-image-minimal -c populate_sdk_ext
167 </literallayout>
168 Once the build finishes, you can find the SDK installer
169 file (i.e. <filename>*.sh</filename> file) in the
170 following directory:
171 <literallayout class='monospaced'>
172 ~/poky/build/tmp/deploy/sdk
173 </literallayout>
174 For this example, the installer file is named
175 <filename>poky-glibc-x86_64-core-image-minimal-i586-toolchain-ext-&DISTRO;.sh</filename>
176 </para></listitem>
177 <listitem><para>
178 <emphasis>Install the Extensible SDK:</emphasis>
179 Use the following command to install the SDK.
180 For this example, install the SDK in the default
181 <filename>~/poky_sdk</filename> directory:
182 <literallayout class='monospaced'>
183 $ cd ~/poky/build/tmp/deploy/sdk
184 $ ./poky-glibc-x86_64-core-image-minimal-i586-toolchain-ext-&DISTRO;.sh
185 Poky (Yocto Project Reference Distro) Extensible SDK installer version &DISTRO;
186 ============================================================================
187 Enter target directory for SDK (default: ~/poky_sdk):
188 You are about to install the SDK to "/home/scottrif/poky_sdk". Proceed[Y/n]? Y
189 Extracting SDK......................................done
190 Setting it up...
191 Extracting buildtools...
192 Preparing build system...
193 Parsing recipes: 100% |#################################################################| Time: 0:00:52
194 Initializing tasks: 100% |############## ###############################################| Time: 0:00:04
195 Checking sstate mirror object availability: 100% |######################################| Time: 0:00:00
196 Parsing recipes: 100% |#################################################################| Time: 0:00:33
197 Initializing tasks: 100% |##############################################################| Time: 0:00:00
198 done
199 SDK has been successfully set up and is ready to be used.
200 Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
201 $ . /home/scottrif/poky_sdk/environment-setup-i586-poky-linux
202 </literallayout>
203 </para></listitem>
204 <listitem><para id='setting-up-the-esdk-terminal'>
205 <emphasis>Set Up a New Terminal to Work With the
206 Extensible SDK:</emphasis>
207 You must set up a new terminal to work with the SDK.
208 You cannot use the same BitBake shell used to build the
209 installer.</para>
210
211 <para>After opening a new shell, run the SDK environment
212 setup script as directed by the output from installing
213 the SDK:
214 <literallayout class='monospaced'>
215 $ source ~/poky_sdk/environment-setup-i586-poky-linux
216 "SDK environment now set up; additionally you may now run devtool to perform development tasks.
217 Run devtool --help for further details.
218 </literallayout>
219 <note>
220 If you get a warning about attempting to use the
221 extensible SDK in an environment set up to run
222 BitBake, you did not use a new shell.
223 </note>
224 </para></listitem>
225 <listitem><para>
226 <emphasis>Build the Clean Image:</emphasis>
227 The final step in preparing to work on the kernel is to
228 build an initial image using
229 <filename>devtool</filename> in the new terminal you
230 just set up and initialized for SDK work:
231 <literallayout class='monospaced'>
232 $ devtool build-image
233 Parsing recipes: 100% |##########################################| Time: 0:00:05
234 Parsing of 830 .bb files complete (0 cached, 830 parsed). 1299 targets, 47 skipped, 0 masked, 0 errors.
235 WARNING: No packages to add, building image core-image-minimal unmodified
236 Loading cache: 100% |############################################| Time: 0:00:00
237 Loaded 1299 entries from dependency cache.
238 NOTE: Resolving any missing task queue dependencies
239 Initializing tasks: 100% |#######################################| Time: 0:00:07
240 Checking sstate mirror object availability: 100% |###############| Time: 0:00:00
241 NOTE: Executing SetScene Tasks
242 NOTE: Executing RunQueue Tasks
243 NOTE: Tasks Summary: Attempted 2866 tasks of which 2604 didn't need to be rerun and all succeeded.
244 NOTE: Successfully built core-image-minimal. You can find output files in /home/scottrif/poky_sdk/tmp/deploy/images/qemux86
245 </literallayout>
246 If you were building for actual hardware and not for
247 emulation, you could flash the image to a USB stick
248 on <filename>/dev/sdd</filename> and boot your device.
249 For an example that uses a Minnowboard, see the
250 <ulink url='https://wiki.yoctoproject.org/wiki/TipsAndTricks/KernelDevelopmentWithEsdk'>TipsAndTricks/KernelDevelopmentWithEsdk</ulink>
251 Wiki page.
252 </para></listitem>
253 </orderedlist>
254 </para>
255
256 <para>
257 At this point you have set up to start making modifications to
258 the kernel by using the extensible SDK.
259 For a continued example, see the
260 "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>"
261 section.
262 </para>
263 </section>
264
265 <section id='getting-ready-for-traditional-kernel-development'>
266 <title>Getting Ready for Traditional Kernel Development</title>
267
268 <para>
269 Getting ready for traditional kernel development using the Yocto
270 Project involves many of the same steps as described in the
271 previous section.
272 However, you need to establish a local copy of the kernel source
273 since you will be editing these files.
274 </para>
275
276 <para>
277 Follow these steps to prepare to update the kernel image using
278 traditional kernel development flow with the Yocto Project.
279 Completing this procedure leaves you ready to make modifications
280 to the kernel source as described in the
281 "<link linkend='using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</link>"
282 section:
283 <orderedlist>
284 <listitem><para>
285 <emphasis>Initialize the BitBake Environment:</emphasis>
286 Before you can do anything using BitBake, you need to
287 initialize the BitBake build environment by sourcing the
288 build environment script
289 (i.e. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>).
290 Also, for this example, be sure that the local branch
291 you have checked out for <filename>poky</filename> is
292 the Yocto Project &DISTRO_NAME; branch.
293 If you need to checkout out the &DISTRO_NAME; branch,
294 see the
295 "<ulink url='&YOCTO_DOCS_DEV_URL;#checking-out-by-branch-in-poky'>Checking out by Branch in Poky</ulink>"
296 section in the Yocto Project Development Tasks Manual.
297 <literallayout class='monospaced'>
298 $ cd ~/poky
299 $ git branch
300 master
301 * &DISTRO_NAME;
302 $ source oe-init-build-env
303 </literallayout>
304 <note>
305 The previous commands assume the
Brad Bishop316dfdd2018-06-25 12:45:53 -0400306 <ulink url='&YOCTO_DOCS_OM_URL;#source-repositories'>Source Repositories</ulink>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500307 (i.e. <filename>poky</filename>) have been cloned
308 using Git and the local repository is named
309 "poky".
310 </note>
311 </para></listitem>
312 <listitem><para>
313 <emphasis>Prepare Your <filename>local.conf</filename>
314 File:</emphasis>
315 By default, the
316 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
317 variable is set to "qemux86", which is fine if you are
318 building for the QEMU emulator in 32-bit mode.
319 However, if you are not, you need to set the
320 <filename>MACHINE</filename> variable appropriately in
321 your <filename>conf/local.conf</filename> file found
322 in the
323 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
324 (i.e. <filename>~/poky/build</filename> in this
325 example).</para>
326
327 <para>Also, since you are preparing to work on the
328 kernel image, you need to set the
329 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink>
330 variable to include kernel modules.</para>
331
332 <para>This example uses the default "qemux86" for the
333 <filename>MACHINE</filename> variable but needs to
334 add the "kernel-modules":
335 <literallayout class='monospaced'>
336 MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules"
337 </literallayout>
338 </para></listitem>
339 <listitem><para>
340 <emphasis>Create a Layer for Patches:</emphasis>
341 You need to create a layer to hold patches created
342 for the kernel image.
343 You can use the
344 <filename>bitbake-layers create-layer</filename>
345 command as follows:
346 <literallayout class='monospaced'>
347 $ cd ~/poky/build
348 $ bitbake-layers create-layer ../../meta-mylayer
349 NOTE: Starting bitbake server...
350 Add your new layer with 'bitbake-layers add-layer ../../meta-mylayer'
351 </literallayout>
352 <note>
353 For background information on working with
354 common and BSP layers, see the
355 "<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>"
356 section in the Yocto Project Development Tasks
357 Manual and the
358 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
359 section in the Yocto Project Board Support (BSP)
360 Developer's Guide, respectively.
361 For information on how to use the
362 <filename>bitbake-layers create-layer</filename>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400363 command to quickly set up a layer, see the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500364 "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</ulink>"
365 section in the Yocto Project Development Tasks
366 Manual.
367 </note>
368 </para></listitem>
369 <listitem><para>
370 <emphasis>Inform the BitBake Build Environment About
371 Your Layer:</emphasis>
372 As directed when you created your layer, you need to add
373 the layer to the
374 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
375 variable in the <filename>bblayers.conf</filename> file
376 as follows:
377 <literallayout class='monospaced'>
378 $ cd ~/poky/build
379 $ bitbake-layers add-layer ../../meta-mylayer
380 NOTE: Starting bitbake server ...
381 $
382 </literallayout>
383 </para></listitem>
384 <listitem><para>
385 <emphasis>Create a Local Copy of the Kernel Git
386 Repository:</emphasis>
387 You can find Git repositories of supported Yocto Project
388 kernels organized under "Yocto Linux Kernel" in the
389 Yocto Project Source Repositories at
Brad Bishop316dfdd2018-06-25 12:45:53 -0400390 <ulink url='&YOCTO_GIT_URL;'></ulink>.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500391 </para>
392
393 <para>
394 For simplicity, it is recommended that you create your
395 copy of the kernel Git repository outside of the
396 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>,
397 which is usually named <filename>poky</filename>.
398 Also, be sure you are in the
399 <filename>standard/base</filename> branch.
400 </para>
401
402 <para>
403 The following commands show how to create a local copy
404 of the <filename>linux-yocto-4.12</filename> kernel and
405 be in the <filename>standard/base</filename> branch.
406 <note>
407 The <filename>linux-yocto-4.12</filename> kernel
408 can be used with the Yocto Project 2.4 release
409 and forward.
410 You cannot use the
411 <filename>linux-yocto-4.12</filename> kernel with
412 releases prior to Yocto Project 2.4:
413 </note>
414 <literallayout class='monospaced'>
415 $ cd ~
416 $ git clone git://git.yoctoproject.org/linux-yocto-4.12 --branch standard/base
417 Cloning into 'linux-yocto-4.12'...
418 remote: Counting objects: 6097195, done.
419 remote: Compressing objects: 100% (901026/901026), done.
420 remote: Total 6097195 (delta 5152604), reused 6096847 (delta 5152256)
421 Receiving objects: 100% (6097195/6097195), 1.24 GiB | 7.81 MiB/s, done.
422 Resolving deltas: 100% (5152604/5152604), done.
423 Checking connectivity... done.
424 Checking out files: 100% (59846/59846), done.
425 </literallayout>
426 </para></listitem>
427 <listitem><para>
428 <emphasis>Create a Local Copy of the Kernel Cache Git
429 Repository:</emphasis>
430 For simplicity, it is recommended that you create your
431 copy of the kernel cache Git repository outside of the
432 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>,
433 which is usually named <filename>poky</filename>.
434 Also, for this example, be sure you are in the
435 <filename>yocto-4.12</filename> branch.
436 </para>
437
438 <para>
439 The following commands show how to create a local copy
440 of the <filename>yocto-kernel-cache</filename> and
441 be in the <filename>yocto-4.12</filename> branch:
442 <literallayout class='monospaced'>
443 $ cd ~
444 $ git clone git://git.yoctoproject.org/yocto-kernel-cache --branch yocto-4.12
445 Cloning into 'yocto-kernel-cache'...
446 remote: Counting objects: 22639, done.
447 remote: Compressing objects: 100% (9761/9761), done.
448 remote: Total 22639 (delta 12400), reused 22586 (delta 12347)
449 Receiving objects: 100% (22639/22639), 22.34 MiB | 6.27 MiB/s, done.
450 Resolving deltas: 100% (12400/12400), done.
451 Checking connectivity... done.
452 </literallayout>
453 </para></listitem>
454 </orderedlist>
455 </para>
456
457 <para>
458 At this point, you are ready to start making modifications to
459 the kernel using traditional kernel development steps.
460 For a continued example, see the
461 "<link linkend='using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</link>"
462 section.
463 </para>
464 </section>
465 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500466
467 <section id='creating-and-preparing-a-layer'>
468 <title>Creating and Preparing a Layer</title>
469
470 <para>
471 If you are going to be modifying kernel recipes, it is recommended
472 that you create and prepare your own layer in which to do your
473 work.
474 Your layer contains its own
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500475 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
476 append files (<filename>.bbappend</filename>) and provides a
477 convenient mechanism to create your own recipe files
478 (<filename>.bb</filename>) as well as store and use kernel
479 patch files.
480 For background information on working with layers, see the
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500481 "<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500482 section in the Yocto Project Development Tasks Manual.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500483 <note><title>Tip</title>
484 The Yocto Project comes with many tools that simplify
485 tasks you need to perform.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500486 One such tool is the
487 <filename>bitbake-layers create-layer</filename>
488 command, which simplifies creating a new layer.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500489 See the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500490 "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</ulink>"
491 section in the Yocto Project Development Tasks Manual for
Brad Bishop316dfdd2018-06-25 12:45:53 -0400492 information on how to use this script to quick set up a
493 new layer.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500494 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500495 </para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500496
497 <para>
498 To better understand the layer you create for kernel development,
499 the following section describes how to create a layer
500 without the aid of tools.
501 These steps assume creation of a layer named
502 <filename>mylayer</filename> in your home directory:
503 <orderedlist>
504 <listitem><para>
505 <emphasis>Create Structure</emphasis>:
506 Create the layer's structure:
507 <literallayout class='monospaced'>
508 $ cd $HOME
509 $ mkdir meta-mylayer
510 $ mkdir meta-mylayer/conf
511 $ mkdir meta-mylayer/recipes-kernel
512 $ mkdir meta-mylayer/recipes-kernel/linux
513 $ mkdir meta-mylayer/recipes-kernel/linux/linux-yocto
514 </literallayout>
515 The <filename>conf</filename> directory holds your
516 configuration files, while the
517 <filename>recipes-kernel</filename> directory holds your
518 append file and eventual patch files.
519 </para></listitem>
520 <listitem><para>
521 <emphasis>Create the Layer Configuration File</emphasis>:
522 Move to the <filename>meta-mylayer/conf</filename>
523 directory and create the <filename>layer.conf</filename>
524 file as follows:
525 <literallayout class='monospaced'>
526 # We have a conf and classes directory, add to BBPATH
527 BBPATH .= ":${LAYERDIR}"
528
529 # We have recipes-* directories, add to BBFILES
530 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
531 ${LAYERDIR}/recipes-*/*/*.bbappend"
532
533 BBFILE_COLLECTIONS += "mylayer"
534 BBFILE_PATTERN_mylayer = "^${LAYERDIR}/"
535 BBFILE_PRIORITY_mylayer = "5"
536 </literallayout>
537 Notice <filename>mylayer</filename> as part of the last
538 three statements.
539 </para></listitem>
540 <listitem><para>
541 <emphasis>Create the Kernel Recipe Append File</emphasis>:
542 Move to the
543 <filename>meta-mylayer/recipes-kernel/linux</filename>
544 directory and create the kernel's append file.
545 This example uses the
546 <filename>linux-yocto-4.12</filename> kernel.
547 Thus, the name of the append file is
548 <filename>linux-yocto_4.12.bbappend</filename>:
549 <literallayout class='monospaced'>
550 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
551
552 SRC_URI_append += "file://<replaceable>patch-file-one</replaceable>"
553 SRC_URI_append += "file://<replaceable>patch-file-two</replaceable>"
554 SRC_URI_append += "file://<replaceable>patch-file-three</replaceable>"
555 </literallayout>
556 The
557 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
558 and
559 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
560 statements enable the OpenEmbedded build system to find
561 patch files.
562 For more information on using append files, see the
563 "<ulink url='&YOCTO_DOCS_DEV_URL;#using-bbappend-files'>Using .bbappend Files in Your Layer</ulink>"
564 section in the Yocto Project Development Tasks Manual.
565 </para></listitem>
566 </orderedlist>
567 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500568 </section>
569
570 <section id='modifying-an-existing-recipe'>
571 <title>Modifying an Existing Recipe</title>
572
573 <para>
574 In many cases, you can customize an existing linux-yocto recipe to
575 meet the needs of your project.
576 Each release of the Yocto Project provides a few Linux
577 kernel recipes from which you can choose.
578 These are located in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500579 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500580 in <filename>meta/recipes-kernel/linux</filename>.
581 </para>
582
583 <para>
584 Modifying an existing recipe can consist of the following:
585 <itemizedlist>
586 <listitem><para>Creating the append file</para></listitem>
587 <listitem><para>Applying patches</para></listitem>
588 <listitem><para>Changing the configuration</para></listitem>
589 </itemizedlist>
590 </para>
591
592 <para>
593 Before modifying an existing recipe, be sure that you have created
594 a minimal, custom layer from which you can work.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500595 See the
596 "<link linkend='creating-and-preparing-a-layer'>Creating and Preparing a Layer</link>"
597 section for information.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500598 </para>
599
600 <section id='creating-the-append-file'>
601 <title>Creating the Append File</title>
602
603 <para>
604 You create this file in your custom layer.
605 You also name it accordingly based on the linux-yocto recipe
606 you are using.
607 For example, if you are modifying the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500608 <filename>meta/recipes-kernel/linux/linux-yocto_4.12.bb</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500609 recipe, the append file will typically be located as follows
610 within your custom layer:
611 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500612 <replaceable>your-layer</replaceable>/recipes-kernel/linux/linux-yocto_4.12.bbappend
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500613 </literallayout>
614 The append file should initially extend the
615 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
616 search path by prepending the directory that contains your
617 files to the
618 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
619 variable as follows:
620 <literallayout class='monospaced'>
621 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
622 </literallayout>
623 The path <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-THISDIR'><filename>THISDIR</filename></ulink><filename>}/${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
624 expands to "linux-yocto" in the current directory for this
625 example.
626 If you add any new files that modify the kernel recipe and you
627 have extended <filename>FILESPATH</filename> as
628 described above, you must place the files in your layer in the
629 following area:
630 <literallayout class='monospaced'>
631 <replaceable>your-layer</replaceable>/recipes-kernel/linux/linux-yocto/
632 </literallayout>
633 <note>If you are working on a new machine Board Support Package
634 (BSP), be sure to refer to the
635 <ulink url='&YOCTO_DOCS_BSP_URL;'>Yocto Project Board Support Package (BSP) Developer's Guide</ulink>.
636 </note>
637 </para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500638
639 <para>
640 As an example, consider the following append file
641 used by the BSPs in <filename>meta-yocto-bsp</filename>:
642 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500643 meta-yocto-bsp/recipes-kernel/linux/linux-yocto_4.12.bbappend
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500644 </literallayout>
645 The following listing shows the file.
646 Be aware that the actual commit ID strings in this
647 example listing might be different than the actual strings
648 in the file from the <filename>meta-yocto-bsp</filename>
649 layer upstream.
650 <literallayout class='monospaced'>
651 KBRANCH_genericx86 = "standard/base"
652 KBRANCH_genericx86-64 = "standard/base"
653
654 KMACHINE_genericx86 ?= "common-pc"
655 KMACHINE_genericx86-64 ?= "common-pc-64"
656 KBRANCH_edgerouter = "standard/edgerouter"
657 KBRANCH_beaglebone = "standard/beaglebone"
658 KBRANCH_mpc8315e-rdb = "standard/fsl-mpc8315e-rdb"
659
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500660 SRCREV_machine_genericx86 ?= "d09f2ce584d60ecb7890550c22a80c48b83c2e19"
661 SRCREV_machine_genericx86-64 ?= "d09f2ce584d60ecb7890550c22a80c48b83c2e19"
662 SRCREV_machine_edgerouter ?= "b5c8cfda2dfe296410d51e131289fb09c69e1e7d"
663 SRCREV_machine_beaglebone ?= "b5c8cfda2dfe296410d51e131289fb09c69e1e7d"
664 SRCREV_machine_mpc8315e-rdb ?= "2d1d010240846d7bff15d1fcc0cb6eb8a22fc78a"
665
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500666
667 COMPATIBLE_MACHINE_genericx86 = "genericx86"
668 COMPATIBLE_MACHINE_genericx86-64 = "genericx86-64"
669 COMPATIBLE_MACHINE_edgerouter = "edgerouter"
670 COMPATIBLE_MACHINE_beaglebone = "beaglebone"
671 COMPATIBLE_MACHINE_mpc8315e-rdb = "mpc8315e-rdb"
672
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500673 LINUX_VERSION_genericx86 = "4.12.7"
674 LINUX_VERSION_genericx86-64 = "4.12.7"
675 LINUX_VERSION_edgerouter = "4.12.10"
676 LINUX_VERSION_beaglebone = "4.12.10"
677 LINUX_VERSION_mpc8315e-rdb = "4.12.10"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500678 </literallayout>
679 This append file contains statements used to support
680 several BSPs that ship with the Yocto Project.
681 The file defines machines using the
682 <ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'><filename>COMPATIBLE_MACHINE</filename></ulink>
683 variable and uses the
684 <ulink url='&YOCTO_DOCS_REF_URL;#var-KMACHINE'><filename>KMACHINE</filename></ulink>
685 variable to ensure the machine name used by the OpenEmbedded
686 build system maps to the machine name used by the Linux Yocto
687 kernel.
688 The file also uses the optional
689 <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'><filename>KBRANCH</filename></ulink>
690 variable to ensure the build process uses the
691 appropriate kernel branch.
692 </para>
693
694 <para>
695 Although this particular example does not use it, the
696 <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_FEATURES'><filename>KERNEL_FEATURES</filename></ulink>
697 variable could be used to enable features specific to
698 the kernel.
699 The append file points to specific commits in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500700 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500701 Git repository and the <filename>meta</filename> Git repository
702 branches to identify the exact kernel needed to build the
703 BSP.
704 </para>
705
706 <para>
707 One thing missing in this particular BSP, which you will
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500708 typically need when developing a BSP, is the kernel
709 configuration file (<filename>.config</filename>) for your BSP.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500710 When developing a BSP, you probably have a kernel configuration
711 file or a set of kernel configuration files that, when taken
712 together, define the kernel configuration for your BSP.
713 You can accomplish this definition by putting the configurations
714 in a file or a set of files inside a directory located at the
715 same level as your kernel's append file and having the same
716 name as the kernel's main recipe file.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500717 With all these conditions met, simply reference those files in
718 the
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500719 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
720 statement in the append file.
721 </para>
722
723 <para>
724 For example, suppose you had some configuration options
725 in a file called <filename>network_configs.cfg</filename>.
726 You can place that file inside a directory named
727 <filename>linux-yocto</filename> and then add
728 a <filename>SRC_URI</filename> statement such as the
729 following to the append file.
730 When the OpenEmbedded build system builds the kernel, the
731 configuration options are picked up and applied.
732 <literallayout class='monospaced'>
733 SRC_URI += "file://network_configs.cfg"
734 </literallayout>
735 </para>
736
737 <para>
738 To group related configurations into multiple files, you
739 perform a similar procedure.
740 Here is an example that groups separate configurations
741 specifically for Ethernet and graphics into their own
742 files and adds the configurations by using a
743 <filename>SRC_URI</filename> statement like the following
744 in your append file:
745 <literallayout class='monospaced'>
746 SRC_URI += "file://myconfig.cfg \
747 file://eth.cfg \
748 file://gfx.cfg"
749 </literallayout>
750 </para>
751
752 <para>
753 Another variable you can use in your kernel recipe append
754 file is the
755 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
756 variable.
757 When you use this statement, you are extending the locations
758 used by the OpenEmbedded system to look for files and
759 patches as the recipe is processed.
760 </para>
761
762 <note>
763 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500764 Other methods exist to accomplish grouping and defining
765 configuration options.
766 For example, if you are working with a local clone of the
767 kernel repository, you could checkout the kernel's
768 <filename>meta</filename> branch, make your changes, and
769 then push the changes to the local bare clone of the
770 kernel.
771 The result is that you directly add configuration options
772 to the <filename>meta</filename> branch for your BSP.
773 The configuration options will likely end up in that
774 location anyway if the BSP gets added to the Yocto Project.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500775 </para>
776
777 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500778 In general, however, the Yocto Project maintainers take
779 care of moving the <filename>SRC_URI</filename>-specified
780 configuration options to the kernel's
781 <filename>meta</filename> branch.
782 Not only is it easier for BSP developers to not have to
783 worry about putting those configurations in the branch,
784 but having the maintainers do it allows them to apply
785 'global' knowledge about the kinds of common configuration
786 options multiple BSPs in the tree are typically using.
787 This allows for promotion of common configurations into
788 common features.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500789 </para>
790 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500791 </section>
792
793 <section id='applying-patches'>
794 <title>Applying Patches</title>
795
796 <para>
797 If you have a single patch or a small series of patches
798 that you want to apply to the Linux kernel source, you
799 can do so just as you would with any other recipe.
800 You first copy the patches to the path added to
801 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
802 in your <filename>.bbappend</filename> file as described in
803 the previous section, and then reference them in
804 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
805 statements.
806 </para>
807
808 <para>
809 For example, you can apply a three-patch series by adding the
810 following lines to your linux-yocto
811 <filename>.bbappend</filename> file in your layer:
812 <literallayout class='monospaced'>
813 SRC_URI += "file://0001-first-change.patch"
814 SRC_URI += "file://0002-second-change.patch"
815 SRC_URI += "file://0003-third-change.patch"
816 </literallayout>
817 The next time you run BitBake to build the Linux kernel,
818 BitBake detects the change in the recipe and fetches and
819 applies the patches before building the kernel.
820 </para>
821
822 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500823 For a detailed example showing how to patch the kernel using
824 <filename>devtool</filename>, see the
825 "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>"
826 and
827 "<link linkend='using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</link>"
828 sections.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500829 </para>
830 </section>
831
832 <section id='changing-the-configuration'>
833 <title>Changing the Configuration</title>
834
835 <para>
836 You can make wholesale or incremental changes to the final
837 <filename>.config</filename> file used for the eventual
838 Linux kernel configuration by including a
839 <filename>defconfig</filename> file and by specifying
840 configuration fragments in the
841 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
842 to be applied to that file.
843 </para>
844
845 <para>
846 If you have a complete, working Linux kernel
847 <filename>.config</filename>
848 file you want to use for the configuration, as before, copy
849 that file to the appropriate <filename>${PN}</filename>
850 directory in your layer's
851 <filename>recipes-kernel/linux</filename> directory,
852 and rename the copied file to "defconfig".
853 Then, add the following lines to the linux-yocto
854 <filename>.bbappend</filename> file in your layer:
855 <literallayout class='monospaced'>
856 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
857 SRC_URI += "file://defconfig"
858 </literallayout>
859 The <filename>SRC_URI</filename> tells the build system how to
860 search for the file, while the
861 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
862 extends the
863 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
864 variable (search directories) to include the
865 <filename>${PN}</filename> directory you created to hold the
866 configuration changes.
867 </para>
868
869 <note>
870 The build system applies the configurations from the
871 <filename>defconfig</filename> file before applying any
872 subsequent configuration fragments.
873 The final kernel configuration is a combination of the
874 configurations in the <filename>defconfig</filename> file and
875 any configuration fragments you provide.
876 You need to realize that if you have any configuration
877 fragments, the build system applies these on top of and
878 after applying the existing <filename>defconfig</filename>
879 file configurations.
880 </note>
881
882 <para>
883 Generally speaking, the preferred approach is to determine the
884 incremental change you want to make and add that as a
885 configuration fragment.
886 For example, if you want to add support for a basic serial
887 console, create a file named <filename>8250.cfg</filename> in
888 the <filename>${PN}</filename> directory with the following
889 content (without indentation):
890 <literallayout class='monospaced'>
891 CONFIG_SERIAL_8250=y
892 CONFIG_SERIAL_8250_CONSOLE=y
893 CONFIG_SERIAL_8250_PCI=y
894 CONFIG_SERIAL_8250_NR_UARTS=4
895 CONFIG_SERIAL_8250_RUNTIME_UARTS=4
896 CONFIG_SERIAL_CORE=y
897 CONFIG_SERIAL_CORE_CONSOLE=y
898 </literallayout>
899 Next, include this configuration fragment and extend the
900 <filename>FILESPATH</filename> variable in your
901 <filename>.bbappend</filename> file:
902 <literallayout class='monospaced'>
903 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
904 SRC_URI += "file://8250.cfg"
905 </literallayout>
906 The next time you run BitBake to build the Linux kernel, BitBake
907 detects the change in the recipe and fetches and applies the
908 new configuration before building the kernel.
909 </para>
910
911 <para>
912 For a detailed example showing how to configure the kernel,
913 see the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500914 "<link linkend='configuring-the-kernel'>Configuring the Kernel</link>"
915 section.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500916 </para>
917 </section>
918
919 <section id='using-an-in-tree-defconfig-file'>
920 <title>Using an "In-Tree"&nbsp;&nbsp;<filename>defconfig</filename> File</title>
921
922 <para>
923 It might be desirable to have kernel configuration fragment
924 support through a <filename>defconfig</filename> file that
925 is pulled from the kernel source tree for the configured
926 machine.
927 By default, the OpenEmbedded build system looks for
928 <filename>defconfig</filename> files in the layer used for
929 Metadata, which is "out-of-tree", and then configures them
930 using the following:
931 <literallayout class='monospaced'>
932 SRC_URI += "file://defconfig"
933 </literallayout>
934 If you do not want to maintain copies of
935 <filename>defconfig</filename> files in your layer but would
936 rather allow users to use the default configuration from the
937 kernel tree and still be able to add configuration fragments
938 to the
939 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
940 through, for example, append files, you can direct the
941 OpenEmbedded build system to use a
942 <filename>defconfig</filename> file that is "in-tree".
943 </para>
944
945 <para>
946 To specify an "in-tree" <filename>defconfig</filename> file,
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500947 use the following statement form:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500948 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500949 KBUILD_DEFCONFIG_<replaceable>KMACHINE</replaceable> ?= <replaceable>defconfig_file</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500950 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500951 Here is an example that appends the
952 <filename>KBUILD_DEFCONFIG</filename> variable with
953 "common-pc" and provides the path to the "in-tree"
954 <filename>defconfig</filename> file:
955 <literallayout class='monospaced'>
956 KBUILD_DEFCONFIG_common-pc ?= "/home/scottrif/configfiles/my_defconfig_file"
957 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500958 </para>
959
960 <para>
961 Aside from modifying your kernel recipe and providing your own
962 <filename>defconfig</filename> file, you need to be sure no
963 files or statements set <filename>SRC_URI</filename> to use a
964 <filename>defconfig</filename> other than your "in-tree"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500965 file (e.g. a kernel's
966 <filename>linux-</filename><replaceable>machine</replaceable><filename>.inc</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500967 file).
968 In other words, if the build system detects a statement
969 that identifies an "out-of-tree"
970 <filename>defconfig</filename> file, that statement
971 will override your
972 <filename>KBUILD_DEFCONFIG</filename> variable.
973 </para>
974
975 <para>
976 See the
977 <ulink url='&YOCTO_DOCS_REF_URL;#var-KBUILD_DEFCONFIG'><filename>KBUILD_DEFCONFIG</filename></ulink>
978 variable description for more information.
979 </para>
980 </section>
981 </section>
982
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500983 <section id="using-devtool-to-patch-the-kernel">
984 <title>Using <filename>devtool</filename> to Patch the Kernel</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500985
986 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500987 The steps in this procedure show you how you can patch the
988 kernel using the extensible SDK and <filename>devtool</filename>.
989 <note>
990 Before attempting this procedure, be sure you have performed
991 the steps to get ready for updating the kernel as described
992 in the
993 "<link linkend='getting-ready-to-develop-using-devtool'>Getting Ready to Develop Using <filename>devtool</filename></link>"
994 section.
995 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500996 </para>
997
998 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500999 Patching the kernel involves changing or adding configurations
1000 to an existing kernel, changing or adding recipes to the kernel
1001 that are needed to support specific hardware features, or even
1002 altering the source code itself.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001003 </para>
1004
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001005 <para>
1006 This example creates a simple patch by adding some QEMU emulator
1007 console output at boot time through <filename>printk</filename>
1008 statements in the kernel's <filename>calibrate.c</filename> source
1009 code file.
1010 Applying the patch and booting the modified image causes the added
1011 messages to appear on the emulator's console.
1012 The example is a continuation of the setup procedure found in
1013 the
1014 "<link linkend='getting-ready-to-develop-using-devtool'>Getting Ready to Develop Using <filename>devtool</filename></link>"
1015 Section.
1016 <orderedlist>
1017 <listitem><para>
1018 <emphasis>Check Out the Kernel Source Files:</emphasis>
1019 First you must use <filename>devtool</filename> to checkout
1020 the kernel source code in its workspace.
1021 Be sure you are in the terminal set up to do work
1022 with the extensible SDK.
1023 <note>
1024 See this
1025 <link linkend='setting-up-the-esdk-terminal'>step</link>
1026 in the
1027 "<link linkend='getting-ready-to-develop-using-devtool'>Getting Ready to Develop Using <filename>devtool</filename></link>"
1028 section for more information.
1029 </note>
1030 Use the following <filename>devtool</filename> command
1031 to check out the code:
1032 <literallayout class='monospaced'>
1033 $ devtool modify linux-yocto
1034 </literallayout>
1035 <note>
1036 During the checkout operation, a bug exists that could
1037 cause errors such as the following to appear:
1038 <literallayout class='monospaced'>
1039 ERROR: Taskhash mismatch 2c793438c2d9f8c3681fd5f7bc819efa versus
1040 be3a89ce7c47178880ba7bf6293d7404 for
1041 /path/to/esdk/layers/poky/meta/recipes-kernel/linux/linux-yocto_4.10.bb.do_unpack
1042 </literallayout>
1043 You can safely ignore these messages.
1044 The source code is correctly checked out.
1045 </note>
1046 </para></listitem>
1047 <listitem><para>
1048 <emphasis>Edit the Source Files</emphasis>
1049 Follow these steps to make some simple changes to the source
1050 files:
1051 <orderedlist>
1052 <listitem><para>
1053 <emphasis>Change the working directory</emphasis>:
1054 In the previous step, the output noted where you can find
1055 the source files (e.g.
1056 <filename>~/poky_sdk/workspace/sources/linux-yocto</filename>).
1057 Change to where the kernel source code is before making
1058 your edits to the <filename>calibrate.c</filename> file:
1059 <literallayout class='monospaced'>
1060 $ cd ~/poky_sdk/workspace/sources/linux-yocto
1061 </literallayout>
1062 </para></listitem>
1063 <listitem><para>
1064 <emphasis>Edit the source file</emphasis>:
1065 Edit the <filename>init/calibrate.c</filename> file to have
1066 the following changes:
1067 <literallayout class='monospaced'>
1068 void calibrate_delay(void)
1069 {
1070 unsigned long lpj;
1071 static bool printed;
1072 int this_cpu = smp_processor_id();
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001073
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001074 printk("*************************************\n");
1075 printk("* *\n");
1076 printk("* HELLO YOCTO KERNEL *\n");
1077 printk("* *\n");
1078 printk("*************************************\n");
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001079
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001080 if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
1081 .
1082 .
1083 .
1084 </literallayout>
1085 </para></listitem>
1086 </orderedlist>
1087 </para></listitem>
1088 <listitem><para>
1089 <emphasis>Build the Updated Kernel Source:</emphasis>
1090 To build the updated kernel source, use
1091 <filename>devtool</filename>:
1092 <literallayout class='monospaced'>
1093 $ devtool build linux-yocto
1094 </literallayout>
1095 </para></listitem>
1096 <listitem><para>
1097 <emphasis>Create the Image With the New Kernel:</emphasis>
1098 Use the <filename>devtool build-image</filename> command
1099 to create a new image that has the new kernel.
1100 <note>
1101 If the image you originally created resulted in a Wic
1102 file, you can use an alternate method to create the new
1103 image with the updated kernel.
1104 For an example, see the steps in the
1105 <ulink url='https://wiki.yoctoproject.org/wiki/TipsAndTricks/KernelDevelopmentWithEsdk'>TipsAndTricks/KernelDevelopmentWithEsdk</ulink>
1106 Wiki Page.
1107 </note>
1108 <literallayout class='monospaced'>
1109 $ cd ~
1110 $ devtool build-image core-image-minimal
1111 </literallayout>
1112 </para></listitem>
1113 <listitem><para>
1114 <emphasis>Test the New Image:</emphasis>
1115 For this example, you can run the new image using QEMU
1116 to verify your changes:
1117 <orderedlist>
1118 <listitem><para>
1119 <emphasis>Boot the image</emphasis>:
1120 Boot the modified image in the QEMU emulator
1121 using this command:
1122 <literallayout class='monospaced'>
1123 $ runqemu qemux86
1124 </literallayout>
1125 </para></listitem>
1126 <listitem><para>
1127 <emphasis>Verify the changes</emphasis>:
1128 Log into the machine using <filename>root</filename>
1129 with no password and then use the following shell
1130 command to scroll through the console's boot output.
1131 <literallayout class='monospaced'>
1132 # dmesg | less
1133 </literallayout>
1134 You should see the results of your
1135 <filename>printk</filename> statements
1136 as part of the output when you scroll down the
1137 console window.
1138 </para></listitem>
1139 </orderedlist>
1140 </para></listitem>
1141 <listitem><para>
1142 <emphasis>Stage and commit your changes</emphasis>:
1143 Within your eSDK terminal, change your working directory to
1144 where you modified the <filename>calibrate.c</filename>
1145 file and use these Git commands to stage and commit your
1146 changes:
1147 <literallayout class='monospaced'>
1148 $ cd ~/poky_sdk/workspace/sources/linux-yocto
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001149 $ git status
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001150 $ git add init/calibrate.c
1151 $ git commit -m "calibrate: Add printk example"
1152 </literallayout>
1153 </para></listitem>
1154 <listitem><para>
1155 <emphasis>Export the Patches and Create an Append File:</emphasis>
1156 To export your commits as patches and create a
1157 <filename>.bbappend</filename> file, use the following
1158 command in the terminal used to work with the extensible
1159 SDK.
1160 This example uses the previously established layer named
1161 <filename>meta-mylayer</filename>.
1162 <note>
1163 See Step 3 of the
1164 "<link linkend='getting-ready-to-develop-using-devtool'>Getting Ready to Develop Using devtool</link>"
1165 section for information on setting up this layer.
1166 </note>
1167 <literallayout class='monospaced'>
1168 $ devtool finish linux-yocto ~/meta-mylayer
1169 </literallayout>
1170 Once the command finishes, the patches and the
1171 <filename>.bbappend</filename> file are located in the
1172 <filename>~/meta-mylayer/recipes-kernel/linux</filename>
1173 directory.
1174 </para></listitem>
1175 <listitem><para>
1176 <emphasis>Build the Image With Your Modified Kernel:</emphasis>
1177 You can now build an image that includes your kernel
1178 patches.
1179 Execute the following command from your
1180 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
1181 in the terminal set up to run BitBake:
1182 <literallayout class='monospaced'>
1183 $ cd ~/poky/build
1184 $ bitbake core-image-minimal
1185 </literallayout>
1186 </para></listitem>
1187 </orderedlist>
1188 </para>
1189 </section>
1190
1191 <section id="using-traditional-kernel-development-to-patch-the-kernel">
1192 <title>Using Traditional Kernel Development to Patch the Kernel</title>
1193
1194 <para>
1195 The steps in this procedure show you how you can patch the
1196 kernel using traditional kernel development (i.e. not using
1197 <filename>devtool</filename> and the extensible SDK as
1198 described in the
1199 "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>"
1200 section).
1201 <note>
1202 Before attempting this procedure, be sure you have performed
1203 the steps to get ready for updating the kernel as described
1204 in the
1205 "<link linkend='getting-ready-for-traditional-kernel-development'>Getting Ready for Traditional Kernel Development</link>"
1206 section.
1207 </note>
1208 </para>
1209
1210 <para>
1211 Patching the kernel involves changing or adding configurations
1212 to an existing kernel, changing or adding recipes to the kernel
1213 that are needed to support specific hardware features, or even
1214 altering the source code itself.
1215 </para>
1216
1217 <para>
1218 The example in this section creates a simple patch by adding some
1219 QEMU emulator console output at boot time through
1220 <filename>printk</filename> statements in the kernel's
1221 <filename>calibrate.c</filename> source code file.
1222 Applying the patch and booting the modified image causes the added
1223 messages to appear on the emulator's console.
1224 The example is a continuation of the setup procedure found in
1225 the
1226 "<link linkend='getting-ready-for-traditional-kernel-development'>Getting Ready for Traditional Kernel Development</link>"
1227 Section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001228 <orderedlist>
1229 <listitem><para>
1230 <emphasis>Edit the Source Files</emphasis>
1231 Prior to this step, you should have used Git to create a
1232 local copy of the repository for your kernel.
1233 Assuming you created the repository as directed in the
1234 "<link linkend='getting-ready-for-traditional-kernel-development'>Getting Ready for Traditional Kernel Development</link>"
1235 section, use the following commands to edit the
1236 <filename>calibrate.c</filename> file:
1237 <orderedlist>
1238 <listitem><para>
1239 <emphasis>Change the working directory</emphasis>:
1240 You need to locate the source files in the
1241 local copy of the kernel Git repository:
1242 Change to where the kernel source code is before making
1243 your edits to the <filename>calibrate.c</filename> file:
1244 <literallayout class='monospaced'>
1245 $ cd ~/linux-yocto-4.12/init
1246 </literallayout>
1247 </para></listitem>
1248 <listitem><para>
1249 <emphasis>Edit the source file</emphasis>:
1250 Edit the <filename>calibrate.c</filename> file to have
1251 the following changes:
1252 <literallayout class='monospaced'>
1253 void calibrate_delay(void)
1254 {
1255 unsigned long lpj;
1256 static bool printed;
1257 int this_cpu = smp_processor_id();
1258
1259 printk("*************************************\n");
1260 printk("* *\n");
1261 printk("* HELLO YOCTO KERNEL *\n");
1262 printk("* *\n");
1263 printk("*************************************\n");
1264
1265 if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
1266 .
1267 .
1268 .
1269 </literallayout>
1270 </para></listitem>
1271 </orderedlist>
1272 </para></listitem>
1273 <listitem><para>
1274 <emphasis>Stage and Commit Your Changes:</emphasis>
1275 Use standard Git commands to stage and commit the changes
1276 you just made:
1277 <literallayout class='monospaced'>
1278 $ git add calibrate.c
1279 $ git commit -m "calibrate.c - Added some printk statements"
1280 </literallayout>
1281 If you do not stage and commit your changes, the OpenEmbedded
1282 Build System will not pick up the changes.
1283 </para></listitem>
1284 <listitem><para>
1285 <emphasis>Update Your <filename>local.conf</filename> File
1286 to Point to Your Source Files:</emphasis>
1287 In addition to your <filename>local.conf</filename> file
1288 specifying to use "kernel-modules" and the "qemux86"
1289 machine, it must also point to the updated kernel source
1290 files.
1291 Add
1292 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1293 and
1294 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
1295 statements similar to the following to your
1296 <filename>local.conf</filename>:
1297 <literallayout class='monospaced'>
1298 $ cd ~/poky/build/conf
1299 </literallayout>
1300 Add the following to the <filename>local.conf</filename>:
1301 <literallayout class='monospaced'>
1302 SRC_URI_pn-linux-yocto = "git:///<replaceable>path-to</replaceable>/linux-yocto-4.12;protocol=file;name=machine;branch=standard/base; \
1303 git:///<replaceable>path-to</replaceable>/yocto-kernel-cache;protocol=file;type=kmeta;name=meta;branch=yocto-4.12;destsuffix=${KMETA}"
1304 SRCREV_meta_qemux86 = "${AUTOREV}"
1305 SRCREV_machine_qemux86 = "${AUTOREV}"
1306 </literallayout>
1307 <note>
1308 Be sure to replace
1309 <replaceable>path-to</replaceable> with the pathname
1310 to your local Git repositories.
1311 Also, you must be sure to specify the correct branch
1312 and machine types.
1313 For this example, the branch is
1314 <filename>standard/base</filename> and the machine is
1315 "qemux86".
1316 </note>
1317 </para></listitem>
1318 <listitem><para>
1319 <emphasis>Build the Image:</emphasis>
1320 With the source modified, your changes staged and
1321 committed, and the <filename>local.conf</filename> file
1322 pointing to the kernel files, you can now use BitBake to
1323 build the image:
1324 <literallayout class='monospaced'>
1325 $ cd ~/poky/build
1326 $ bitbake core-image-minimal
1327 </literallayout>
1328 </para></listitem>
1329 <listitem><para>
1330 <emphasis>Boot the image</emphasis>:
1331 Boot the modified image in the QEMU emulator
1332 using this command.
1333 When prompted to login to the QEMU console, use "root"
1334 with no password:
1335 <literallayout class='monospaced'>
1336 $ cd ~/poky/build
1337 $ runqemu qemux86
1338 </literallayout>
1339 </para></listitem>
1340 <listitem><para>
1341 <emphasis>Look for Your Changes:</emphasis>
1342 As QEMU booted, you might have seen your changes rapidly
1343 scroll by.
1344 If not, use these commands to see your changes:
1345 <literallayout class='monospaced'>
1346 # dmesg | less
1347 </literallayout>
1348 You should see the results of your
1349 <filename>printk</filename> statements
1350 as part of the output when you scroll down the
1351 console window.
1352 </para></listitem>
1353 <listitem><para>
1354 <emphasis>Generate the Patch File:</emphasis>
1355 Once you are sure that your patch works correctly, you
1356 can generate a <filename>*.patch</filename> file in the
1357 kernel source repository:
1358 <literallayout class='monospaced'>
1359 $ cd ~/linux-yocto-4.12/init
1360 $ git format-patch -1
1361 0001-calibrate.c-Added-some-printk-statements.patch
1362 </literallayout>
1363 </para></listitem>
1364 <listitem><para>
1365 <emphasis>Move the Patch File to Your Layer:</emphasis>
1366 In order for subsequent builds to pick up patches, you
1367 need to move the patch file you created in the previous
1368 step to your layer <filename>meta-mylayer</filename>.
1369 For this example, the layer created earlier is located
1370 in your home directory as <filename>meta-mylayer</filename>.
1371 When the layer was created using the
1372 <filename>yocto-create</filename> script, no additional
1373 hierarchy was created to support patches.
1374 Before moving the patch file, you need to add additional
1375 structure to your layer using the following commands:
1376 <literallayout class='monospaced'>
1377 $ cd ~/meta-mylayer
1378 $ mkdir recipes-kernel
1379 $ mkdir recipes-kernel/linux
1380 $ mkdir recipes-kernel/linux/linux-yocto
1381 </literallayout>
1382 Once you have created this hierarchy in your layer, you can
1383 move the patch file using the following command:
1384 <literallayout class='monospaced'>
1385 $ mv ~/linux-yocto-4.12/init/0001-calibrate.c-Added-some-printk-statements.patch ~/meta-mylayer/recipes-kernel/linux/linux-yocto
1386 </literallayout>
1387 </para></listitem>
1388 <listitem><para>
1389 <emphasis>Create the Append File:</emphasis>
1390 Finally, you need to create the
1391 <filename>linux-yocto_4.12.bbappend</filename> file and
1392 insert statements that allow the OpenEmbedded build
1393 system to find the patch.
1394 The append file needs to be in your layer's
1395 <filename>recipes-kernel/linux</filename>
1396 directory and it must be named
1397 <filename>linux-yocto_4.12.bbappend</filename> and have
1398 the following contents:
1399 <literallayout class='monospaced'>
1400 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
1401
1402 SRC_URI_append = " file://0001-calibrate.c-Added-some-printk-statements.patch"
1403 </literallayout>
1404 The
Brad Bishop316dfdd2018-06-25 12:45:53 -04001405 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001406 and
Brad Bishop316dfdd2018-06-25 12:45:53 -04001407 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001408 statements enable the OpenEmbedded build system to find
1409 the patch file.</para>
1410
1411 <para>For more information on append files and patches,
1412 see the
1413 "<link linkend='creating-the-append-file'>Creating the Append File</link>"
1414 and
1415 "<link linkend='applying-patches'>Applying Patches</link>"
1416 sections.
1417 You can also see the
1418 "<ulink url='&YOCTO_DOCS_DEV_URL;#using-bbappend-files'>Using .bbappend Files in Your Layer"</ulink>"
1419 section in the Yocto Project Development Tasks Manual.
1420 <note>
1421 To build <filename>core-image-minimal</filename>
1422 again and see the effects of your patch, you can
1423 essentially eliminate the temporary source files
1424 saved in <filename>poky/build/tmp/work/...</filename>
1425 and residual effects of the build by entering the
1426 following sequence of commands:
1427 <literallayout class='monospaced'>
1428 $ cd ~/poky/build
1429 $ bitbake -c cleanall yocto-linux
1430 $ bitbake core-image-minimal -c cleanall
1431 $ bitbake core-image-minimal
1432 $ runqemu qemux86
1433 </literallayout>
1434 </note>
1435 </para></listitem>
1436 </orderedlist>
1437 </para>
1438 </section>
1439
1440 <section id='configuring-the-kernel'>
1441 <title>Configuring the Kernel</title>
1442
1443 <para>
1444 Configuring the Yocto Project kernel consists of making sure the
1445 <filename>.config</filename> file has all the right information
1446 in it for the image you are building.
1447 You can use the <filename>menuconfig</filename> tool and
1448 configuration fragments to make sure your
1449 <filename>.config</filename> file is just how you need it.
1450 You can also save known configurations in a
1451 <filename>defconfig</filename> file that the build system can use
1452 for kernel configuration.
1453 </para>
1454
1455 <para>
1456 This section describes how to use <filename>menuconfig</filename>,
1457 create and use configuration fragments, and how to interactively
1458 modify your <filename>.config</filename> file to create the
1459 leanest kernel configuration file possible.
1460 </para>
1461
1462 <para>
1463 For more information on kernel configuration, see the
1464 "<link linkend='changing-the-configuration'>Changing the Configuration</link>"
1465 section.
1466 </para>
1467
1468 <section id='using-menuconfig'>
1469 <title>Using&nbsp;&nbsp;<filename>menuconfig</filename></title>
1470
1471 <para>
1472 The easiest way to define kernel configurations is to set
1473 them through the <filename>menuconfig</filename> tool.
1474 This tool provides an interactive method with which
1475 to set kernel configurations.
1476 For general information on <filename>menuconfig</filename>, see
1477 <ulink url='http://en.wikipedia.org/wiki/Menuconfig'></ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001478 </para>
1479
1480 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001481 To use the <filename>menuconfig</filename> tool in the Yocto
1482 Project development environment, you must launch it using
1483 BitBake.
1484 Thus, the environment must be set up using the
1485 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
1486 script found in the
1487 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
1488 You must also be sure of the state of your build's
1489 configuration in the
1490 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
1491 The following commands initialize the BitBake environment,
1492 run the
1493 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configme'><filename>do_kernel_configme</filename></ulink>
1494 task, and launch <filename>menuconfig</filename>.
1495 These commands assume the Source Directory's top-level folder
1496 is <filename>~/poky</filename>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001497 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001498 $ cd poky
1499 $ source oe-init-build-env
1500 $ bitbake linux-yocto -c kernel_configme -f
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001501 $ bitbake linux-yocto -c menuconfig
1502 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001503 Once <filename>menuconfig</filename> comes up, its standard
1504 interface allows you to interactively examine and configure
1505 all the kernel configuration parameters.
1506 After making your changes, simply exit the tool and save your
1507 changes to create an updated version of the
1508 <filename>.config</filename> configuration file.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001509 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001510 You can use the entire <filename>.config</filename> file
1511 as the <filename>defconfig</filename> file.
1512 For information on <filename>defconfig</filename> files,
1513 see the
1514 "<link linkend='changing-the-configuration'>Changing the Configuration</link>",
1515 "<link linkend='using-an-in-tree-defconfig-file'>Using an In-Tree <filename>defconfig</filename> File</link>,
1516 and
1517 "<link linkend='creating-a-defconfig-file'>Creating a <filename>defconfig</filename> File</link>"
1518 sections.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001519 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001520 </para>
1521
1522 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001523 Consider an example that configures the "CONFIG_SMP" setting
1524 for the <filename>linux-yocto-4.12</filename> kernel.
1525 <note>
1526 The OpenEmbedded build system recognizes this kernel as
1527 <filename>linux-yocto</filename> through Metadata (e.g.
1528 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_VERSION'><filename>PREFERRED_VERSION</filename></ulink><filename>_linux-yocto ?= "12.4%"</filename>).
1529 </note>
1530 Once <filename>menuconfig</filename> launches, use the
1531 interface to navigate through the selections to find the
1532 configuration settings in which you are interested.
1533 For this example, you deselect "CONFIG_SMP" by clearing the
1534 "Symmetric Multi-Processing Support" option.
1535 Using the interface, you can find the option under
1536 "Processor Type and Features".
1537 To deselect "CONFIG_SMP", use the arrow keys to
1538 highlight "Symmetric Multi-Processing Support" and enter "N"
1539 to clear the asterisk.
1540 When you are finished, exit out and save the change.
1541 </para>
1542
1543 <para>
1544 Saving the selections updates the <filename>.config</filename>
1545 configuration file.
1546 This is the file that the OpenEmbedded build system uses to
1547 configure the kernel during the build.
1548 You can find and examine this file in the Build Directory in
1549 <filename>tmp/work/</filename>.
1550 The actual <filename>.config</filename> is located in the
1551 area where the specific kernel is built.
1552 For example, if you were building a Linux Yocto kernel based
1553 on the <filename>linux-yocto-4.12</filename> kernel and you
1554 were building a QEMU image targeted for
1555 <filename>x86</filename> architecture, the
1556 <filename>.config</filename> file would be:
1557 <literallayout class='monospaced'>
1558 poky/build/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+gitAUTOINC+eda4d18...
1559 ...967-r0/linux-qemux86-standard-build/.config
1560 </literallayout>
1561 <note>
1562 The previous example directory is artificially split and
1563 many of the characters in the actual filename are omitted
1564 in order to make it more readable.
1565 Also, depending on the kernel you are using, the exact
1566 pathname might differ.
1567 </note>
1568 </para>
1569
1570 <para>
1571 Within the <filename>.config</filename> file, you can see the
1572 kernel settings.
1573 For example, the following entry shows that symmetric
1574 multi-processor support is not set:
1575 <literallayout class='monospaced'>
1576 # CONFIG_SMP is not set
1577 </literallayout>
1578 </para>
1579
1580 <para>
1581 A good method to isolate changed configurations is to use a
1582 combination of the <filename>menuconfig</filename> tool and
1583 simple shell commands.
1584 Before changing configurations with
1585 <filename>menuconfig</filename>, copy the existing
1586 <filename>.config</filename> and rename it to something else,
1587 use <filename>menuconfig</filename> to make as many changes as
1588 you want and save them, then compare the renamed configuration
1589 file against the newly created file.
1590 You can use the resulting differences as your base to create
1591 configuration fragments to permanently save in your kernel
1592 layer.
1593 <note>
1594 Be sure to make a copy of the <filename>.config</filename>
1595 file and do not just rename it.
1596 The build system needs an existing
1597 <filename>.config</filename> file from which to work.
1598 </note>
1599 </para>
1600 </section>
1601
1602 <section id='creating-a-defconfig-file'>
1603 <title>Creating a&nbsp;&nbsp;<filename>defconfig</filename> File</title>
1604
1605 <para>
Brad Bishopc4ea0752018-11-15 14:30:15 -08001606 A <filename>defconfig</filename> file in the context of
1607 the Yocto Project is often a <filename>.config</filename>
1608 file that is copied from a build or a
1609 <filename>defconfig</filename> taken from the kernel tree
1610 and moved into recipe space.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001611 You can use a <filename>defconfig</filename> file
1612 to retain a known set of kernel configurations from which the
1613 OpenEmbedded build system can draw to create the final
1614 <filename>.config</filename> file.
1615 <note>
1616 Out-of-the-box, the Yocto Project never ships a
1617 <filename>defconfig</filename> or
1618 <filename>.config</filename> file.
1619 The OpenEmbedded build system creates the final
1620 <filename>.config</filename> file used to configure the
1621 kernel.
1622 </note>
1623 </para>
1624
1625 <para>
1626 To create a <filename>defconfig</filename>, start with a
1627 complete, working Linux kernel <filename>.config</filename>
1628 file.
1629 Copy that file to the appropriate
1630 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
1631 directory in your layer's
1632 <filename>recipes-kernel/linux</filename> directory, and rename
1633 the copied file to "defconfig" (e.g.
1634 <filename>~/meta-mylayer/recipes-kernel/linux/linux-yocto/defconfig</filename>).
1635 Then, add the following lines to the linux-yocto
1636 <filename>.bbappend</filename> file in your layer:
1637 <literallayout class='monospaced'>
1638 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
1639 SRC_URI += "file://defconfig"
1640 </literallayout>
1641 The
1642 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1643 tells the build system how to search for the file, while the
1644 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
1645 extends the
1646 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
1647 variable (search directories) to include the
1648 <filename>${PN}</filename> directory you created to hold the
1649 configuration changes.
1650 <note>
1651 The build system applies the configurations from the
1652 <filename>defconfig</filename> file before applying any
1653 subsequent configuration fragments.
1654 The final kernel configuration is a combination of the
1655 configurations in the <filename>defconfig</filename>
1656 file and any configuration fragments you provide.
1657 You need to realize that if you have any configuration
1658 fragments, the build system applies these on top of and
1659 after applying the existing defconfig file configurations.
1660 </note>
1661 For more information on configuring the kernel, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001662 "<link linkend='changing-the-configuration'>Changing the Configuration</link>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001663 section.
1664 </para>
1665 </section>
1666
1667 <section id='creating-config-fragments'>
1668 <title>Creating Configuration Fragments</title>
1669
1670 <para>
1671 Configuration fragments are simply kernel options that
1672 appear in a file placed where the OpenEmbedded build system
1673 can find and apply them.
1674 The build system applies configuration fragments after
1675 applying configurations from a <filename>defconfig</filename>
1676 file.
1677 Thus, the final kernel configuration is a combination of the
1678 configurations in the <filename>defconfig</filename>
1679 file and then any configuration fragments you provide.
1680 The build system applies fragments on top of and
1681 after applying the existing defconfig file configurations.
1682 </para>
1683
1684 <para>
1685 Syntactically, the configuration statement is identical to
1686 what would appear in the <filename>.config</filename> file,
1687 which is in the
1688 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
1689 <note>
1690 For more information about where the
1691 <filename>.config</filename> file is located, see the
1692 example in the
1693 "<link linkend='using-menuconfig'>Using <filename>menuconfig</filename></link>"
1694 section.
1695 </note>
1696 </para>
1697
1698 <para>
1699 It is simple to create a configuration fragment.
1700 One method is to use shell commands.
1701 For example, issuing the following from the shell creates a
1702 configuration fragment file named
1703 <filename>my_smp.cfg</filename> that enables multi-processor
1704 support within the kernel:
1705 <literallayout class='monospaced'>
1706 $ echo "CONFIG_SMP=y" >> my_smp.cfg
1707 </literallayout>
1708 <note>
1709 All configuration fragment files must use the
1710 <filename>.cfg</filename> extension in order for the
1711 OpenEmbedded build system to recognize them as a
1712 configuration fragment.
1713 </note>
1714 </para>
1715
1716 <para>
1717 Another method is to create a configuration fragment using the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001718 differences between two configuration files: one previously
1719 created and saved, and one freshly created using the
1720 <filename>menuconfig</filename> tool.
1721 </para>
1722
1723 <para>
1724 To create a configuration fragment using this method, follow
1725 these steps:
1726 <orderedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001727 <listitem><para>
1728 <emphasis>Complete a Build Through Kernel Configuration:</emphasis>
1729 Complete a build at least through the kernel
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001730 configuration task as follows:
1731 <literallayout class='monospaced'>
1732 $ bitbake linux-yocto -c kernel_configme -f
1733 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001734 This step ensures that you create a
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001735 <filename>.config</filename> file from a known state.
1736 Because situations exist where your build state might
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001737 become unknown, it is best to run this task prior
1738 to starting <filename>menuconfig</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001739 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001740 <listitem><para>
1741 <emphasis>Launch <filename>menuconfig</filename>:</emphasis>
1742 Run the <filename>menuconfig</filename> command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001743 <literallayout class='monospaced'>
1744 $ bitbake linux-yocto -c menuconfig
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001745 </literallayout>
1746 </para></listitem>
1747 <listitem><para>
1748 <emphasis>Create the Configuration Fragment:</emphasis>
1749 Run the <filename>diffconfig</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001750 command to prepare a configuration fragment.
1751 The resulting file <filename>fragment.cfg</filename>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001752 is placed in the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001753 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename> directory:
1754 <literallayout class='monospaced'>
1755 $ bitbake linux-yocto -c diffconfig
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001756 </literallayout>
1757 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001758 </orderedlist>
1759 </para>
1760
1761 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001762 The <filename>diffconfig</filename> command creates a file
1763 that is a list of Linux kernel <filename>CONFIG_</filename>
1764 assignments.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001765 See the "<link linkend='changing-the-configuration'>Changing the Configuration</link>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001766 section for additional information on how to use the output
1767 as a configuration fragment.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001768 <note>
1769 You can also use this method to create configuration
1770 fragments for a BSP.
1771 See the "<link linkend='bsp-descriptions'>BSP Descriptions</link>"
1772 section for more information.
1773 </note>
1774 </para>
1775
1776 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001777 Where do you put your configuration fragment files?
1778 You can place these files in an area pointed to by
1779 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1780 as directed by your <filename>bblayers.conf</filename> file,
1781 which is located in your layer.
1782 The OpenEmbedded build system picks up the configuration and
1783 adds it to the kernel's configuration.
1784 For example, suppose you had a set of configuration options
1785 in a file called <filename>myconfig.cfg</filename>.
1786 If you put that file inside a directory named
1787 <filename>linux-yocto</filename> that resides in the same
1788 directory as the kernel's append file within your layer
1789 and then add the following statements to the kernel's append
1790 file, those configuration options will be picked up and applied
1791 when the kernel is built:
1792 <literallayout class='monospaced'>
1793 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
1794 SRC_URI += "file://myconfig.cfg"
1795 </literallayout>
1796 </para>
1797
1798 <para>
1799 As mentioned earlier, you can group related configurations
1800 into multiple files and name them all in the
1801 <filename>SRC_URI</filename> statement as well.
1802 For example, you could group separate configurations
1803 specifically for Ethernet and graphics into their own files
1804 and add those by using a <filename>SRC_URI</filename> statement
1805 like the following in your append file:
1806 <literallayout class='monospaced'>
1807 SRC_URI += "file://myconfig.cfg \
1808 file://eth.cfg \
1809 file://gfx.cfg"
1810 </literallayout>
1811 </para>
1812 </section>
1813
1814 <section id='validating-configuration'>
1815 <title>Validating Configuration</title>
1816
1817 <para>
1818 You can use the
1819 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configcheck'><filename>do_kernel_configcheck</filename></ulink>
1820 task to provide configuration validation:
1821 <literallayout class='monospaced'>
1822 $ bitbake linux-yocto -c kernel_configcheck -f
1823 </literallayout>
1824 Running this task produces warnings for when a
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001825 requested configuration does not appear in the final
1826 <filename>.config</filename> file or when you override a
1827 policy configuration in a hardware configuration fragment.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001828 </para>
1829
1830 <para>
1831 In order to run this task, you must have an existing
1832 <filename>.config</filename> file.
1833 See the
1834 "<link linkend='using-menuconfig'>Using <filename>menuconfig</filename></link>"
1835 section for information on how to create a configuration file.
1836 </para>
1837
1838 <para>
1839 Following is sample output from the
1840 <filename>do_kernel_configcheck</filename> task:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001841 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001842 Loading cache: 100% |########################################################| Time: 0:00:00
1843 Loaded 1275 entries from dependency cache.
1844 NOTE: Resolving any missing task queue dependencies
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001845
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001846 Build Configuration:
1847 .
1848 .
1849 .
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001850
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001851 NOTE: Executing SetScene Tasks
1852 NOTE: Executing RunQueue Tasks
1853 WARNING: linux-yocto-4.12.12+gitAUTOINC+eda4d18ce4_16de014967-r0 do_kernel_configcheck:
1854 [kernel config]: specified values did not make it into the kernel's final configuration:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001855
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001856 ---------- CONFIG_X86_TSC -----------------
1857 Config: CONFIG_X86_TSC
1858 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/bsp/common-pc/common-pc-cpu.cfg
1859 Requested value: CONFIG_X86_TSC=y
1860 Actual value:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001861
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001862
1863 ---------- CONFIG_X86_BIGSMP -----------------
1864 Config: CONFIG_X86_BIGSMP
1865 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
1866 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
1867 Requested value: # CONFIG_X86_BIGSMP is not set
1868 Actual value:
1869
1870
1871 ---------- CONFIG_NR_CPUS -----------------
1872 Config: CONFIG_NR_CPUS
1873 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
1874 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/bsp/common-pc/common-pc.cfg
1875 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
1876 Requested value: CONFIG_NR_CPUS=8
1877 Actual value: CONFIG_NR_CPUS=1
1878
1879
1880 ---------- CONFIG_SCHED_SMT -----------------
1881 Config: CONFIG_SCHED_SMT
1882 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
1883 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
1884 Requested value: CONFIG_SCHED_SMT=y
1885 Actual value:
1886
1887
1888
1889 NOTE: Tasks Summary: Attempted 288 tasks of which 285 didn't need to be rerun and all succeeded.
1890
1891 Summary: There were 3 WARNING messages shown.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001892 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001893 <note>
1894 The previous output example has artificial line breaks
1895 to make it more readable.
1896 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001897 </para>
1898
1899 <para>
1900 The output describes the various problems that you can
1901 encounter along with where to find the offending configuration
1902 items.
1903 You can use the information in the logs to adjust your
1904 configuration files and then repeat the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001905 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configme'><filename>do_kernel_configme</filename></ulink>
1906 and
1907 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configcheck'><filename>do_kernel_configcheck</filename></ulink>
1908 tasks until they produce no warnings.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001909 </para>
1910
1911 <para>
1912 For more information on how to use the
1913 <filename>menuconfig</filename> tool, see the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001914 "<link linkend='using-menuconfig'>Using <filename>menuconfig</filename></link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001915 section.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001916 </para>
1917 </section>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001918
1919 <section id='fine-tuning-the-kernel-configuration-file'>
1920 <title>Fine-Tuning the Kernel Configuration File</title>
1921
1922 <para>
1923 You can make sure the <filename>.config</filename> file is as
1924 lean or efficient as possible by reading the output of the
1925 kernel configuration fragment audit, noting any issues, making
1926 changes to correct the issues, and then repeating.
1927 </para>
1928
1929 <para>
1930 As part of the kernel build process, the
1931 <filename>do_kernel_configcheck</filename> task runs.
1932 This task validates the kernel configuration by checking the
1933 final <filename>.config</filename> file against the input
1934 files.
1935 During the check, the task produces warning messages for the
1936 following issues:
1937 <itemizedlist>
1938 <listitem><para>
1939 Requested options that did not make the final
1940 <filename>.config</filename> file.
1941 </para></listitem>
1942 <listitem><para>
1943 Configuration items that appear twice in the same
1944 configuration fragment.
1945 </para></listitem>
1946 <listitem><para>
1947 Configuration items tagged as "required" that were
1948 overridden.
1949 </para></listitem>
1950 <listitem><para>
1951 A board overrides a non-board specific option.
1952 </para></listitem>
1953 <listitem><para>
1954 Listed options not valid for the kernel being
1955 processed.
1956 In other words, the option does not appear anywhere.
1957 </para></listitem>
1958 </itemizedlist>
1959 <note>
1960 The <filename>do_kernel_configcheck</filename> task can
1961 also optionally report if an option is overridden during
1962 processing.
1963 </note>
1964 </para>
1965
1966 <para>
1967 For each output warning, a message points to the file
1968 that contains a list of the options and a pointer to the
1969 configuration fragment that defines them.
1970 Collectively, the files are the key to streamlining the
1971 configuration.
1972 </para>
1973
1974 <para>
1975 To streamline the configuration, do the following:
1976 <orderedlist>
1977 <listitem><para>
1978 <emphasis>Use a Working Configuration:</emphasis>
1979 Start with a full configuration that you
1980 know works.
1981 Be sure the configuration builds and boots
1982 successfully.
1983 Use this configuration file as your baseline.
1984 </para></listitem>
1985 <listitem><para>
1986 <emphasis>Run Configure and Check Tasks:</emphasis>
1987 Separately run the
1988 <filename>do_kernel_configme</filename> and
1989 <filename>do_kernel_configcheck</filename> tasks:
1990 <literallayout class='monospaced'>
1991 $ bitbake linux-yocto -c kernel_configme -f
1992 $ bitbake linux-yocto -c kernel_configcheck -f
1993 </literallayout>
1994 </para></listitem>
1995 <listitem><para>
1996 <emphasis>Process the Results:</emphasis>
1997 Take the resulting list of files from the
1998 <filename>do_kernel_configcheck</filename> task
1999 warnings and do the following:
2000 <itemizedlist>
2001 <listitem><para>
2002 Drop values that are redefined in the fragment
2003 but do not change the final
2004 <filename>.config</filename> file.
2005 </para></listitem>
2006 <listitem><para>
2007 Analyze and potentially drop values from the
2008 <filename>.config</filename> file that override
2009 required configurations.
2010 </para></listitem>
2011 <listitem><para>
2012 Analyze and potentially remove non-board
2013 specific options.
2014 </para></listitem>
2015 <listitem><para>
2016 Remove repeated and invalid options.
2017 </para></listitem>
2018 </itemizedlist>
2019 </para></listitem>
2020 <listitem><para>
2021 <emphasis>Re-Run Configure and Check Tasks:</emphasis>
2022 After you have worked through the output of the kernel
2023 configuration audit, you can re-run the
2024 <filename>do_kernel_configme</filename> and
2025 <filename>do_kernel_configcheck</filename> tasks to
2026 see the results of your changes.
2027 If you have more issues, you can deal with them as
2028 described in the previous step.
2029 </para></listitem>
2030 </orderedlist>
2031 </para>
2032
2033 <para>
2034 Iteratively working through steps two through four eventually
2035 yields a minimal, streamlined configuration file.
2036 Once you have the best <filename>.config</filename>, you can
2037 build the Linux Yocto kernel.
2038 </para>
2039 </section>
2040 </section>
2041
2042 <section id='expanding-variables'>
2043 <title>Expanding Variables</title>
2044
2045 <para>
2046 Sometimes it is helpful to determine what a variable expands
2047 to during a build.
2048 You can do examine the values of variables by examining the
2049 output of the <filename>bitbake -e</filename> command.
2050 The output is long and is more easily managed in a text file,
2051 which allows for easy searches:
2052 <literallayout class='monospaced'>
2053 $ bitbake -e virtual/kernel > <replaceable>some_text_file</replaceable>
2054 </literallayout>
2055 Within the text file, you can see exactly how each variable is
2056 expanded and used by the OpenEmbedded build system.
2057 </para>
2058 </section>
2059
2060 <section id='working-with-a-dirty-kernel-version-string'>
2061 <title>Working with a "Dirty" Kernel Version String</title>
2062
2063 <para>
2064 If you build a kernel image and the version string has a
2065 "+" or a "-dirty" at the end, uncommitted modifications exist
2066 in the kernel's source directory.
2067 Follow these steps to clean up the version string:
2068 <orderedlist>
2069 <listitem><para>
2070 <emphasis>Discover the Uncommitted Changes:</emphasis>
2071 Go to the kernel's locally cloned Git repository
2072 (source directory) and use the following Git command
2073 to list the files that have been changed, added, or
2074 removed:
2075 <literallayout class='monospaced'>
2076 $ git status
2077 </literallayout>
2078 </para></listitem>
2079 <listitem><para>
2080 <emphasis>Commit the Changes:</emphasis>
2081 You should commit those changes to the kernel source
2082 tree regardless of whether or not you will save,
2083 export, or use the changes:
2084 <literallayout class='monospaced'>
2085 $ git add
2086 $ git commit -s -a -m "getting rid of -dirty"
2087 </literallayout>
2088 </para></listitem>
2089 <listitem><para>
2090 <emphasis>Rebuild the Kernel Image:</emphasis>
2091 Once you commit the changes, rebuild the kernel.</para>
2092
2093 <para>Depending on your particular kernel development
2094 workflow, the commands you use to rebuild the
2095 kernel might differ.
2096 For information on building the kernel image when
2097 using <filename>devtool</filename>, see the
2098 "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>"
2099 section.
2100 For information on building the kernel image when
2101 using Bitbake, see the
2102 "<link linkend='using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</link>"
2103 section.
2104 </para></listitem>
2105 </orderedlist>
2106 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002107 </section>
2108
2109 <section id='working-with-your-own-sources'>
2110 <title>Working With Your Own Sources</title>
2111
2112 <para>
2113 If you cannot work with one of the Linux kernel
2114 versions supported by existing linux-yocto recipes, you can
2115 still make use of the Yocto Project Linux kernel tooling by
2116 working with your own sources.
2117 When you use your own sources, you will not be able to
2118 leverage the existing kernel
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002119 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink> and
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002120 stabilization work of the linux-yocto sources.
2121 However, you will be able to manage your own Metadata in the same
2122 format as the linux-yocto sources.
2123 Maintaining format compatibility facilitates converging with
2124 linux-yocto on a future, mutually-supported kernel version.
2125 </para>
2126
2127 <para>
2128 To help you use your own sources, the Yocto Project provides a
2129 linux-yocto custom recipe
2130 (<filename>linux-yocto-custom.bb</filename>) that uses
2131 <filename>kernel.org</filename> sources
2132 and the Yocto Project Linux kernel tools for managing
2133 kernel Metadata.
2134 You can find this recipe in the
2135 <filename>poky</filename> Git repository of the
2136 Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink>
2137 at:
2138 <literallayout class="monospaced">
2139 poky/meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb
2140 </literallayout>
2141 </para>
2142
2143 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002144 Here are some basic steps you can use to work with your own
2145 sources:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002146 <orderedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002147 <listitem><para>
2148 <emphasis>Create a Copy of the Kernel Recipe:</emphasis>
2149 Copy the <filename>linux-yocto-custom.bb</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002150 recipe to your layer and give it a meaningful name.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002151 The name should include the version of the Yocto Linux
2152 kernel you are using (e.g.
2153 <filename>linux-yocto-myproject_4.12.bb</filename>,
2154 where "4.12" is the base version of the Linux kernel
2155 with which you would be working).
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002156 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002157 <listitem><para>
2158 <emphasis>Create a Directory for Your Patches:</emphasis>
2159 In the same directory inside your layer, create a matching
2160 directory to store your patches and configuration files
2161 (e.g. <filename>linux-yocto-myproject</filename>).
2162 </para></listitem>
2163 <listitem><para>
2164 <emphasis>Ensure You Have Configurations:</emphasis>
2165 Make sure you have either a <filename>defconfig</filename>
2166 file or configuration fragment files in your layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002167 When you use the <filename>linux-yocto-custom.bb</filename>
2168 recipe, you must specify a configuration.
2169 If you do not have a <filename>defconfig</filename> file,
2170 you can run the following:
2171 <literallayout class='monospaced'>
2172 $ make defconfig
2173 </literallayout>
2174 After running the command, copy the resulting
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002175 <filename>.config</filename> file to the
2176 <filename>files</filename> directory in your layer
2177 as "defconfig" and then add it to the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002178 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
2179 variable in the recipe.</para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002180
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002181 <para>Running the <filename>make defconfig</filename>
2182 command results in the default configuration for your
2183 architecture as defined by your kernel.
2184 However, no guarantee exists that this configuration is
2185 valid for your use case, or that your board will even boot.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002186 This is particularly true for non-x86 architectures.</para>
2187
2188 <para>To use non-x86 <filename>defconfig</filename> files,
2189 you need to be more specific and find one that matches your
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002190 board (i.e. for arm, you look in
2191 <filename>arch/arm/configs</filename> and use the one that
2192 is the best starting point for your board).
2193 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002194 <listitem><para>
2195 <emphasis>Edit the Recipe:</emphasis>
2196 Edit the following variables in your recipe as appropriate
2197 for your project:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002198 <itemizedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002199 <listitem><para>
2200 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002201 The <filename>SRC_URI</filename> should specify
2202 a Git repository that uses one of the supported Git
2203 fetcher protocols (i.e. <filename>file</filename>,
2204 <filename>git</filename>, <filename>http</filename>,
2205 and so forth).
2206 The <filename>SRC_URI</filename> variable should
2207 also specify either a <filename>defconfig</filename>
2208 file or some configuration fragment files.
2209 The skeleton recipe provides an example
2210 <filename>SRC_URI</filename> as a syntax reference.
2211 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002212 <listitem><para>
2213 <ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION'><filename>LINUX_VERSION</filename></ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002214 The Linux kernel version you are using (e.g.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002215 "4.12").
2216 </para></listitem>
2217 <listitem><para>
2218 <ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION_EXTENSION'><filename>LINUX_VERSION_EXTENSION</filename></ulink>:
2219 The Linux kernel
2220 <filename>CONFIG_LOCALVERSION</filename> that is
2221 compiled into the resulting kernel and visible
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002222 through the <filename>uname</filename> command.
2223 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002224 <listitem><para>
2225 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002226 The commit ID from which you want to build.
2227 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002228 <listitem><para>
2229 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
2230 Treat this variable the same as you would in any
2231 other recipe.
2232 Increment the variable to indicate to the
2233 OpenEmbedded build system that the recipe has
2234 changed.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002235 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002236 <listitem><para>
2237 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002238 The default <filename>PV</filename> assignment is
2239 typically adequate.
2240 It combines the <filename>LINUX_VERSION</filename>
2241 with the Source Control Manager (SCM) revision
2242 as derived from the
2243 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>
2244 variable.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002245 The combined results are a string with the
2246 following form:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002247 <literallayout class='monospaced'>
2248 3.19.11+git1+68a635bf8dfb64b02263c1ac80c948647cc76d5f_1+218bd8d2022b9852c60d32f0d770931e3cf343e2
2249 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002250 While lengthy, the extra verbosity in
2251 <filename>PV</filename> helps ensure you are using
2252 the exact sources from which you intend to build.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002253 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002254 <listitem><para>
2255 <ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'><filename>COMPATIBLE_MACHINE</filename></ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002256 A list of the machines supported by your new recipe.
2257 This variable in the example recipe is set
2258 by default to a regular expression that matches
2259 only the empty string, "(^$)".
2260 This default setting triggers an explicit build
2261 failure.
2262 You must change it to match a list of the machines
2263 that your new recipe supports.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002264 For example, to support the
2265 <filename>qemux86</filename> and
2266 <filename>qemux86-64</filename> machines, use
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002267 the following form:
2268 <literallayout class='monospaced'>
2269 COMPATIBLE_MACHINE = "qemux86|qemux86-64"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002270 </literallayout>
2271 </para></listitem>
2272 </itemizedlist>
2273 </para></listitem>
2274 <listitem><para>
2275 <emphasis>Customize Your Recipe as Needed:</emphasis>
2276 Provide further customizations to your recipe
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002277 as needed just as you would customize an existing
2278 linux-yocto recipe.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002279 See the
2280 "<link linkend='modifying-an-existing-recipe'>Modifying an Existing Recipe</link>"
2281 section for information.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002282 </para></listitem>
2283 </orderedlist>
2284 </para>
2285 </section>
2286
2287 <section id='working-with-out-of-tree-modules'>
2288 <title>Working with Out-of-Tree Modules</title>
2289
2290 <para>
2291 This section describes steps to build out-of-tree modules on
2292 your target and describes how to incorporate out-of-tree modules
2293 in the build.
2294 </para>
2295
2296 <section id='building-out-of-tree-modules-on-the-target'>
2297 <title>Building Out-of-Tree Modules on the Target</title>
2298
2299 <para>
2300 While the traditional Yocto Project development model would be
2301 to include kernel modules as part of the normal build
2302 process, you might find it useful to build modules on the
2303 target.
2304 This could be the case if your target system is capable
2305 and powerful enough to handle the necessary compilation.
2306 Before deciding to build on your target, however, you should
2307 consider the benefits of using a proper cross-development
2308 environment from your build host.
2309 </para>
2310
2311 <para>
2312 If you want to be able to build out-of-tree modules on
2313 the target, there are some steps you need to take
2314 on the target that is running your SDK image.
2315 Briefly, the <filename>kernel-dev</filename> package
2316 is installed by default on all
2317 <filename>*.sdk</filename> images and the
2318 <filename>kernel-devsrc</filename> package is installed
2319 on many of the <filename>*.sdk</filename> images.
2320 However, you need to create some scripts prior to
2321 attempting to build the out-of-tree modules on the target
2322 that is running that image.
2323 </para>
2324
2325 <para>
2326 Prior to attempting to build the out-of-tree modules,
2327 you need to be on the target as root and you need to
2328 change to the <filename>/usr/src/kernel</filename> directory.
2329 Next, <filename>make</filename> the scripts:
2330 <literallayout class='monospaced'>
2331 # cd /usr/src/kernel
2332 # make scripts
2333 </literallayout>
2334 Because all SDK image recipes include
2335 <filename>dev-pkgs</filename>, the
2336 <filename>kernel-dev</filename> packages will be installed
2337 as part of the SDK image and the
2338 <filename>kernel-devsrc</filename> packages will be installed
2339 as part of applicable SDK images.
2340 The SDK uses the scripts when building out-of-tree
2341 modules.
2342 Once you have switched to that directory and created the
2343 scripts, you should be able to build your out-of-tree modules
2344 on the target.
2345 </para>
2346 </section>
2347
2348 <section id='incorporating-out-of-tree-modules'>
2349 <title>Incorporating Out-of-Tree Modules</title>
2350
2351 <para>
2352 While it is always preferable to work with sources integrated
2353 into the Linux kernel sources, if you need an external kernel
2354 module, the <filename>hello-mod.bb</filename> recipe is
2355 available as a template from which you can create your
2356 own out-of-tree Linux kernel module recipe.
2357 </para>
2358
2359 <para>
2360 This template recipe is located in the
2361 <filename>poky</filename> Git repository of the
2362 Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink>
2363 at:
2364 <literallayout class="monospaced">
2365 poky/meta-skeleton/recipes-kernel/hello-mod/hello-mod_0.1.bb
2366 </literallayout>
2367 </para>
2368
2369 <para>
2370 To get started, copy this recipe to your layer and give it a
2371 meaningful name (e.g. <filename>mymodule_1.0.bb</filename>).
2372 In the same directory, create a new directory named
2373 <filename>files</filename> where you can store any source files,
2374 patches, or other files necessary for building
2375 the module that do not come with the sources.
2376 Finally, update the recipe as needed for the module.
2377 Typically, you will need to set the following variables:
2378 <itemizedlist>
2379 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
2380 </para></listitem>
2381 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE*</filename></ulink>
2382 </para></listitem>
2383 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
2384 </para></listitem>
2385 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
2386 </para></listitem>
2387 </itemizedlist>
2388 </para>
2389
2390 <para>
2391 Depending on the build system used by the module sources,
2392 you might need to make some adjustments.
2393 For example, a typical module <filename>Makefile</filename>
2394 looks much like the one provided with the
2395 <filename>hello-mod</filename> template:
2396 <literallayout class='monospaced'>
2397 obj-m := hello.o
2398
2399 SRC := $(shell pwd)
2400
2401 all:
2402 $(MAKE) -C $(KERNEL_SRC) M=$(SRC)
2403
2404 modules_install:
2405 $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
2406 ...
2407 </literallayout>
2408 </para>
2409
2410 <para>
2411 The important point to note here is the
2412 <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_SRC'><filename>KERNEL_SRC</filename></ulink>
2413 variable.
2414 The
2415 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-module'><filename>module</filename></ulink>
2416 class sets this variable and the
2417 <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_PATH'><filename>KERNEL_PATH</filename></ulink>
2418 variable to
2419 <filename>${<ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_KERNEL_DIR'><filename>STAGING_KERNEL_DIR</filename></ulink>}</filename>
2420 with the necessary Linux kernel build information to build
2421 modules.
2422 If your module <filename>Makefile</filename> uses a different
2423 variable, you might want to override the
Brad Bishop316dfdd2018-06-25 12:45:53 -04002424 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002425 step, or create a patch to
2426 the <filename>Makefile</filename> to work with the more typical
2427 <filename>KERNEL_SRC</filename> or
2428 <filename>KERNEL_PATH</filename> variables.
2429 </para>
2430
2431 <para>
2432 After you have prepared your recipe, you will likely want to
2433 include the module in your images.
2434 To do this, see the documentation for the following variables in
2435 the Yocto Project Reference Manual and set one of them
2436 appropriately for your machine configuration file:
2437 <itemizedlist>
2438 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RDEPENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RDEPENDS</filename></ulink>
2439 </para></listitem>
2440 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink>
2441 </para></listitem>
2442 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RDEPENDS'><filename>MACHINE_EXTRA_RDEPENDS</filename></ulink>
2443 </para></listitem>
2444 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RRECOMMENDS'><filename>MACHINE_EXTRA_RRECOMMENDS</filename></ulink>
2445 </para></listitem>
2446 </itemizedlist>
2447 </para>
2448
2449 <para>
2450 Modules are often not required for boot and can be excluded from
2451 certain build configurations.
2452 The following allows for the most flexibility:
2453 <literallayout class='monospaced'>
2454 MACHINE_EXTRA_RRECOMMENDS += "kernel-module-mymodule"
2455 </literallayout>
2456 The value is derived by appending the module filename without
2457 the <filename>.ko</filename> extension to the string
2458 "kernel-module-".
2459 </para>
2460
2461 <para>
2462 Because the variable is
2463 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
2464 and not a
2465 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
2466 variable, the build will not fail if this module is not
2467 available to include in the image.
2468 </para>
2469 </section>
2470 </section>
2471
2472
2473 <section id='inspecting-changes-and-commits'>
2474 <title>Inspecting Changes and Commits</title>
2475
2476 <para>
2477 A common question when working with a kernel is:
2478 "What changes have been applied to this tree?"
2479 Rather than using "grep" across directories to see what has
2480 changed, you can use Git to inspect or search the kernel tree.
2481 Using Git is an efficient way to see what has changed in the tree.
2482 </para>
2483
2484 <section id='what-changed-in-a-kernel'>
2485 <title>What Changed in a Kernel?</title>
2486
2487 <para>
2488 Following are a few examples that show how to use Git
2489 commands to examine changes.
2490 These examples are by no means the only way to see changes.
2491 <note>
2492 In the following examples, unless you provide a commit
2493 range, <filename>kernel.org</filename> history is blended
2494 with Yocto Project kernel changes.
2495 You can form ranges by using branch names from the
2496 kernel tree as the upper and lower commit markers with
2497 the Git commands.
2498 You can see the branch names through the web interface
2499 to the Yocto Project source repositories at
Brad Bishop316dfdd2018-06-25 12:45:53 -04002500 <ulink url='&YOCTO_GIT_URL;'></ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002501 </note>
2502 To see a full range of the changes, use the
2503 <filename>git whatchanged</filename> command and specify a
2504 commit range for the branch
2505 (<replaceable>commit</replaceable><filename>..</filename><replaceable>commit</replaceable>).
2506 </para>
2507
2508 <para>
2509 Here is an example that looks at what has changed in the
2510 <filename>emenlow</filename> branch of the
2511 <filename>linux-yocto-3.19</filename> kernel.
2512 The lower commit range is the commit associated with the
2513 <filename>standard/base</filename> branch, while
2514 the upper commit range is the commit associated with the
2515 <filename>standard/emenlow</filename> branch.
2516 <literallayout class='monospaced'>
2517 $ git whatchanged origin/standard/base..origin/standard/emenlow
2518 </literallayout>
2519 </para>
2520
2521 <para>
2522 To see short, one line summaries of changes use the
2523 <filename>git log</filename> command:
2524 <literallayout class='monospaced'>
2525 $ git log --oneline origin/standard/base..origin/standard/emenlow
2526 </literallayout>
2527 </para>
2528
2529 <para>
2530 Use this command to see code differences for the changes:
2531 <literallayout class='monospaced'>
2532 $ git diff origin/standard/base..origin/standard/emenlow
2533 </literallayout>
2534 </para>
2535
2536 <para>
2537 Use this command to see the commit log messages and the
2538 text differences:
2539 <literallayout class='monospaced'>
2540 $ git show origin/standard/base..origin/standard/emenlow
2541 </literallayout>
2542 </para>
2543
2544 <para>
2545 Use this command to create individual patches for
2546 each change.
2547 Here is an example that that creates patch files for each
2548 commit and places them in your <filename>Documents</filename>
2549 directory:
2550 <literallayout class='monospaced'>
2551 $ git format-patch -o $HOME/Documents origin/standard/base..origin/standard/emenlow
2552 </literallayout>
2553 </para>
2554 </section>
2555
2556 <section id='showing-a-particular-feature-or-branch-change'>
2557 <title>Showing a Particular Feature or Branch Change</title>
2558
2559 <para>
2560 Tags in the Yocto Project kernel tree divide changes for
2561 significant features or branches.
2562 The <filename>git show</filename>&nbsp;<replaceable>tag</replaceable>
2563 command shows changes based on a tag.
2564 Here is an example that shows <filename>systemtap</filename>
2565 changes:
2566 <literallayout class='monospaced'>
2567 $ git show systemtap
2568 </literallayout>
2569 You can use the
2570 <filename>git branch --contains</filename>&nbsp;<replaceable>tag</replaceable>
2571 command to show the branches that contain a particular feature.
2572 This command shows the branches that contain the
2573 <filename>systemtap</filename> feature:
2574 <literallayout class='monospaced'>
2575 $ git branch --contains systemtap
2576 </literallayout>
2577 </para>
2578 </section>
2579 </section>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05002580
2581 <section id='adding-recipe-space-kernel-features'>
2582 <title>Adding Recipe-Space Kernel Features</title>
2583
2584 <para>
2585 You can add kernel features in the
2586 <link linkend='recipe-space-metadata'>recipe-space</link> by
2587 using the
2588 <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_FEATURES'><filename>KERNEL_FEATURES</filename></ulink>
2589 variable and by specifying the feature's <filename>.scc</filename>
2590 file path in the
2591 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
2592 statement.
2593 When you add features using this method, the OpenEmbedded build
2594 system checks to be sure the features are present.
2595 If the features are not present, the build stops.
2596 Kernel features are the last elements processed for configuring
2597 and patching the kernel.
2598 Therefore, adding features in this manner is a way
2599 to enforce specific features are present and enabled
2600 without needing to do a full audit of any other layer's additions
2601 to the <filename>SRC_URI</filename> statement.
2602 </para>
2603
2604 <para>
2605 You add a kernel feature by providing the feature as part of the
2606 <filename>KERNEL_FEATURES</filename> variable and by providing the
2607 path to the feature's <filename>.scc</filename> file, which is
2608 relative to the root of the kernel Metadata.
2609 The OpenEmbedded build system searches all forms of kernel
2610 Metadata on the <filename>SRC_URI</filename> statement regardless
2611 of whether the Metadata is in the "kernel-cache", system kernel
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002612 Metadata, or a recipe-space Metadata (i.e. part of the kernel
2613 recipe).
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05002614 See the
2615 "<link linkend='kernel-metadata-location'>Kernel Metadata Location</link>"
2616 section for additional information.
2617 </para>
2618
2619 <para>
2620 When you specify the feature's <filename>.scc</filename> file
2621 on the <filename>SRC_URI</filename> statement, the OpenEmbedded
2622 build system adds the directory of that
2623 <filename>.scc</filename> file along with all its subdirectories
2624 to the kernel feature search path.
2625 Because subdirectories are searched, you can reference a single
2626 <filename>.scc</filename> file in the
2627 <filename>SRC_URI</filename> statement to reference multiple kernel
2628 features.
2629 </para>
2630
2631 <para>
2632 Consider the following example that adds the "test.scc" feature
2633 to the build.
2634 <orderedlist>
2635 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002636 <emphasis>Create the Feature File:</emphasis>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05002637 Create a <filename>.scc</filename> file and locate it
2638 just as you would any other patch file,
2639 <filename>.cfg</filename> file, or fetcher item
2640 you specify in the <filename>SRC_URI</filename>
2641 statement.
2642 <note><title>Notes</title>
2643 <itemizedlist>
2644 <listitem><para>
2645 You must add the directory of the
2646 <filename>.scc</filename> file to the fetcher's
2647 search path in the same manner as you would
2648 add a <filename>.patch</filename> file.
2649 </para></listitem>
2650 <listitem><para>
2651 You can create additional
2652 <filename>.scc</filename> files beneath the
2653 directory that contains the file you are
2654 adding.
2655 All subdirectories are searched during the
2656 build as potential feature directories.
2657 </para></listitem>
2658 </itemizedlist>
2659 </note>
2660 Continuing with the example, suppose the "test.scc"
2661 feature you are adding has a
2662 <filename>test.scc</filename> file in the following
2663 directory:
2664 <literallayout class='monospaced'>
2665 <replaceable>my_recipe</replaceable>
2666 |
2667 +-linux-yocto
2668 |
2669 +-test.cfg
2670 +-test.scc
2671 </literallayout>
2672 In this example, the <filename>linux-yocto</filename>
2673 directory has both the feature
2674 <filename>test.scc</filename> file and a similarly
2675 named configuration fragment file
2676 <filename>test.cfg</filename>.
2677 </para></listitem>
2678 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002679 <emphasis>Add the Feature File to <filename>SRC_URI</filename>:</emphasis>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05002680 Add the <filename>.scc</filename> file to the
2681 recipe's <filename>SRC_URI</filename> statement:
2682 <literallayout class='monospaced'>
2683 SRC_URI_append = " file://test.scc"
2684 </literallayout>
2685 The leading space before the path is important as the
2686 path is appended to the existing path.
2687 </para></listitem>
2688 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002689 <emphasis>Specify the Feature as a Kernel Feature:</emphasis>
2690 Use the <filename>KERNEL_FEATURES</filename> statement
2691 to specify the feature as a kernel feature:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05002692 <literallayout class='monospaced'>
2693 KERNEL_FEATURES_append = " test.scc"
2694 </literallayout>
2695 The OpenEmbedded build system processes the kernel feature
2696 when it builds the kernel.
2697 <note>
2698 If other features are contained below "test.scc",
2699 then their directories are relative to the directory
2700 containing the <filename>test.scc</filename> file.
2701 </note>
2702 </para></listitem>
2703 </orderedlist>
2704 </para>
2705 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002706</chapter>
2707<!--
2708vim: expandtab tw=80 ts=4
2709-->