blob: 2ea5d3f38e211f7019e41660876dd1b2932b26bf [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):
Brad Bishopd89cb5f2019-04-10 09:02:41 -0400188 You are about to install the SDK to "/home/scottrif/poky_sdk". Proceed [Y/n]? Y
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500189 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
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400552 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>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500555 </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
Brad Bishop19323692019-04-05 15:28:33 -04001482 Project development environment, you must do the following:
1483 <itemizedlist>
1484 <listitem><para>
1485 Because you launch <filename>menuconfig</filename>
1486 using BitBake, you must be sure to set up your
1487 environment by running the
1488 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
1489 script found in the
1490 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
1491 </para></listitem>
1492 <listitem><para>
1493 You must be sure of the state of your build's
1494 configuration in the
1495 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
1496 </para></listitem>
1497 <listitem><para>
1498 Your build host must have the following two packages
1499 installed:
1500 <literallayout class='monospaced'>
1501 libncurses5-dev
1502 libtinfo-dev
1503 </literallayout>
1504 </para></listitem>
1505 </itemizedlist>
1506 </para>
1507
1508 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001509 The following commands initialize the BitBake environment,
1510 run the
1511 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configme'><filename>do_kernel_configme</filename></ulink>
1512 task, and launch <filename>menuconfig</filename>.
1513 These commands assume the Source Directory's top-level folder
1514 is <filename>~/poky</filename>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001515 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001516 $ cd poky
1517 $ source oe-init-build-env
1518 $ bitbake linux-yocto -c kernel_configme -f
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001519 $ bitbake linux-yocto -c menuconfig
1520 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001521 Once <filename>menuconfig</filename> comes up, its standard
1522 interface allows you to interactively examine and configure
1523 all the kernel configuration parameters.
1524 After making your changes, simply exit the tool and save your
1525 changes to create an updated version of the
1526 <filename>.config</filename> configuration file.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001527 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001528 You can use the entire <filename>.config</filename> file
1529 as the <filename>defconfig</filename> file.
1530 For information on <filename>defconfig</filename> files,
1531 see the
1532 "<link linkend='changing-the-configuration'>Changing the Configuration</link>",
1533 "<link linkend='using-an-in-tree-defconfig-file'>Using an In-Tree <filename>defconfig</filename> File</link>,
1534 and
1535 "<link linkend='creating-a-defconfig-file'>Creating a <filename>defconfig</filename> File</link>"
1536 sections.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001537 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001538 </para>
1539
1540 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001541 Consider an example that configures the "CONFIG_SMP" setting
1542 for the <filename>linux-yocto-4.12</filename> kernel.
1543 <note>
1544 The OpenEmbedded build system recognizes this kernel as
1545 <filename>linux-yocto</filename> through Metadata (e.g.
1546 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_VERSION'><filename>PREFERRED_VERSION</filename></ulink><filename>_linux-yocto ?= "12.4%"</filename>).
1547 </note>
1548 Once <filename>menuconfig</filename> launches, use the
1549 interface to navigate through the selections to find the
1550 configuration settings in which you are interested.
1551 For this example, you deselect "CONFIG_SMP" by clearing the
1552 "Symmetric Multi-Processing Support" option.
1553 Using the interface, you can find the option under
1554 "Processor Type and Features".
1555 To deselect "CONFIG_SMP", use the arrow keys to
1556 highlight "Symmetric Multi-Processing Support" and enter "N"
1557 to clear the asterisk.
1558 When you are finished, exit out and save the change.
1559 </para>
1560
1561 <para>
1562 Saving the selections updates the <filename>.config</filename>
1563 configuration file.
1564 This is the file that the OpenEmbedded build system uses to
1565 configure the kernel during the build.
1566 You can find and examine this file in the Build Directory in
1567 <filename>tmp/work/</filename>.
1568 The actual <filename>.config</filename> is located in the
1569 area where the specific kernel is built.
1570 For example, if you were building a Linux Yocto kernel based
1571 on the <filename>linux-yocto-4.12</filename> kernel and you
1572 were building a QEMU image targeted for
1573 <filename>x86</filename> architecture, the
1574 <filename>.config</filename> file would be:
1575 <literallayout class='monospaced'>
1576 poky/build/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+gitAUTOINC+eda4d18...
1577 ...967-r0/linux-qemux86-standard-build/.config
1578 </literallayout>
1579 <note>
1580 The previous example directory is artificially split and
1581 many of the characters in the actual filename are omitted
1582 in order to make it more readable.
1583 Also, depending on the kernel you are using, the exact
1584 pathname might differ.
1585 </note>
1586 </para>
1587
1588 <para>
1589 Within the <filename>.config</filename> file, you can see the
1590 kernel settings.
1591 For example, the following entry shows that symmetric
1592 multi-processor support is not set:
1593 <literallayout class='monospaced'>
1594 # CONFIG_SMP is not set
1595 </literallayout>
1596 </para>
1597
1598 <para>
1599 A good method to isolate changed configurations is to use a
1600 combination of the <filename>menuconfig</filename> tool and
1601 simple shell commands.
1602 Before changing configurations with
1603 <filename>menuconfig</filename>, copy the existing
1604 <filename>.config</filename> and rename it to something else,
1605 use <filename>menuconfig</filename> to make as many changes as
1606 you want and save them, then compare the renamed configuration
1607 file against the newly created file.
1608 You can use the resulting differences as your base to create
1609 configuration fragments to permanently save in your kernel
1610 layer.
1611 <note>
1612 Be sure to make a copy of the <filename>.config</filename>
1613 file and do not just rename it.
1614 The build system needs an existing
1615 <filename>.config</filename> file from which to work.
1616 </note>
1617 </para>
1618 </section>
1619
1620 <section id='creating-a-defconfig-file'>
1621 <title>Creating a&nbsp;&nbsp;<filename>defconfig</filename> File</title>
1622
1623 <para>
Brad Bishopc4ea0752018-11-15 14:30:15 -08001624 A <filename>defconfig</filename> file in the context of
1625 the Yocto Project is often a <filename>.config</filename>
1626 file that is copied from a build or a
1627 <filename>defconfig</filename> taken from the kernel tree
1628 and moved into recipe space.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001629 You can use a <filename>defconfig</filename> file
1630 to retain a known set of kernel configurations from which the
1631 OpenEmbedded build system can draw to create the final
1632 <filename>.config</filename> file.
1633 <note>
1634 Out-of-the-box, the Yocto Project never ships a
1635 <filename>defconfig</filename> or
1636 <filename>.config</filename> file.
1637 The OpenEmbedded build system creates the final
1638 <filename>.config</filename> file used to configure the
1639 kernel.
1640 </note>
1641 </para>
1642
1643 <para>
1644 To create a <filename>defconfig</filename>, start with a
1645 complete, working Linux kernel <filename>.config</filename>
1646 file.
1647 Copy that file to the appropriate
1648 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
1649 directory in your layer's
1650 <filename>recipes-kernel/linux</filename> directory, and rename
1651 the copied file to "defconfig" (e.g.
1652 <filename>~/meta-mylayer/recipes-kernel/linux/linux-yocto/defconfig</filename>).
1653 Then, add the following lines to the linux-yocto
1654 <filename>.bbappend</filename> file in your layer:
1655 <literallayout class='monospaced'>
1656 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
1657 SRC_URI += "file://defconfig"
1658 </literallayout>
1659 The
1660 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1661 tells the build system how to search for the file, while the
1662 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
1663 extends the
1664 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
1665 variable (search directories) to include the
1666 <filename>${PN}</filename> directory you created to hold the
1667 configuration changes.
1668 <note>
1669 The build system applies the configurations from the
1670 <filename>defconfig</filename> file before applying any
1671 subsequent configuration fragments.
1672 The final kernel configuration is a combination of the
1673 configurations in the <filename>defconfig</filename>
1674 file and any configuration fragments you provide.
1675 You need to realize that if you have any configuration
1676 fragments, the build system applies these on top of and
1677 after applying the existing defconfig file configurations.
1678 </note>
1679 For more information on configuring the kernel, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001680 "<link linkend='changing-the-configuration'>Changing the Configuration</link>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001681 section.
1682 </para>
1683 </section>
1684
1685 <section id='creating-config-fragments'>
1686 <title>Creating Configuration Fragments</title>
1687
1688 <para>
1689 Configuration fragments are simply kernel options that
1690 appear in a file placed where the OpenEmbedded build system
1691 can find and apply them.
1692 The build system applies configuration fragments after
1693 applying configurations from a <filename>defconfig</filename>
1694 file.
1695 Thus, the final kernel configuration is a combination of the
1696 configurations in the <filename>defconfig</filename>
1697 file and then any configuration fragments you provide.
1698 The build system applies fragments on top of and
1699 after applying the existing defconfig file configurations.
1700 </para>
1701
1702 <para>
1703 Syntactically, the configuration statement is identical to
1704 what would appear in the <filename>.config</filename> file,
1705 which is in the
1706 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
1707 <note>
1708 For more information about where the
1709 <filename>.config</filename> file is located, see the
1710 example in the
1711 "<link linkend='using-menuconfig'>Using <filename>menuconfig</filename></link>"
1712 section.
1713 </note>
1714 </para>
1715
1716 <para>
1717 It is simple to create a configuration fragment.
1718 One method is to use shell commands.
1719 For example, issuing the following from the shell creates a
1720 configuration fragment file named
1721 <filename>my_smp.cfg</filename> that enables multi-processor
1722 support within the kernel:
1723 <literallayout class='monospaced'>
1724 $ echo "CONFIG_SMP=y" >> my_smp.cfg
1725 </literallayout>
1726 <note>
1727 All configuration fragment files must use the
1728 <filename>.cfg</filename> extension in order for the
1729 OpenEmbedded build system to recognize them as a
1730 configuration fragment.
1731 </note>
1732 </para>
1733
1734 <para>
1735 Another method is to create a configuration fragment using the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001736 differences between two configuration files: one previously
1737 created and saved, and one freshly created using the
1738 <filename>menuconfig</filename> tool.
1739 </para>
1740
1741 <para>
1742 To create a configuration fragment using this method, follow
1743 these steps:
1744 <orderedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001745 <listitem><para>
1746 <emphasis>Complete a Build Through Kernel Configuration:</emphasis>
1747 Complete a build at least through the kernel
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001748 configuration task as follows:
1749 <literallayout class='monospaced'>
1750 $ bitbake linux-yocto -c kernel_configme -f
1751 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001752 This step ensures that you create a
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001753 <filename>.config</filename> file from a known state.
1754 Because situations exist where your build state might
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001755 become unknown, it is best to run this task prior
1756 to starting <filename>menuconfig</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001757 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001758 <listitem><para>
1759 <emphasis>Launch <filename>menuconfig</filename>:</emphasis>
1760 Run the <filename>menuconfig</filename> command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001761 <literallayout class='monospaced'>
1762 $ bitbake linux-yocto -c menuconfig
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001763 </literallayout>
1764 </para></listitem>
1765 <listitem><para>
1766 <emphasis>Create the Configuration Fragment:</emphasis>
1767 Run the <filename>diffconfig</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001768 command to prepare a configuration fragment.
1769 The resulting file <filename>fragment.cfg</filename>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001770 is placed in the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001771 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename> directory:
1772 <literallayout class='monospaced'>
1773 $ bitbake linux-yocto -c diffconfig
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001774 </literallayout>
1775 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001776 </orderedlist>
1777 </para>
1778
1779 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001780 The <filename>diffconfig</filename> command creates a file
1781 that is a list of Linux kernel <filename>CONFIG_</filename>
1782 assignments.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001783 See the "<link linkend='changing-the-configuration'>Changing the Configuration</link>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001784 section for additional information on how to use the output
1785 as a configuration fragment.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001786 <note>
1787 You can also use this method to create configuration
1788 fragments for a BSP.
1789 See the "<link linkend='bsp-descriptions'>BSP Descriptions</link>"
1790 section for more information.
1791 </note>
1792 </para>
1793
1794 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001795 Where do you put your configuration fragment files?
1796 You can place these files in an area pointed to by
1797 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1798 as directed by your <filename>bblayers.conf</filename> file,
1799 which is located in your layer.
1800 The OpenEmbedded build system picks up the configuration and
1801 adds it to the kernel's configuration.
1802 For example, suppose you had a set of configuration options
1803 in a file called <filename>myconfig.cfg</filename>.
1804 If you put that file inside a directory named
1805 <filename>linux-yocto</filename> that resides in the same
1806 directory as the kernel's append file within your layer
1807 and then add the following statements to the kernel's append
1808 file, those configuration options will be picked up and applied
1809 when the kernel is built:
1810 <literallayout class='monospaced'>
1811 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
1812 SRC_URI += "file://myconfig.cfg"
1813 </literallayout>
1814 </para>
1815
1816 <para>
1817 As mentioned earlier, you can group related configurations
1818 into multiple files and name them all in the
1819 <filename>SRC_URI</filename> statement as well.
1820 For example, you could group separate configurations
1821 specifically for Ethernet and graphics into their own files
1822 and add those by using a <filename>SRC_URI</filename> statement
1823 like the following in your append file:
1824 <literallayout class='monospaced'>
1825 SRC_URI += "file://myconfig.cfg \
1826 file://eth.cfg \
1827 file://gfx.cfg"
1828 </literallayout>
1829 </para>
1830 </section>
1831
1832 <section id='validating-configuration'>
1833 <title>Validating Configuration</title>
1834
1835 <para>
1836 You can use the
1837 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configcheck'><filename>do_kernel_configcheck</filename></ulink>
1838 task to provide configuration validation:
1839 <literallayout class='monospaced'>
1840 $ bitbake linux-yocto -c kernel_configcheck -f
1841 </literallayout>
1842 Running this task produces warnings for when a
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001843 requested configuration does not appear in the final
1844 <filename>.config</filename> file or when you override a
1845 policy configuration in a hardware configuration fragment.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001846 </para>
1847
1848 <para>
1849 In order to run this task, you must have an existing
1850 <filename>.config</filename> file.
1851 See the
1852 "<link linkend='using-menuconfig'>Using <filename>menuconfig</filename></link>"
1853 section for information on how to create a configuration file.
1854 </para>
1855
1856 <para>
1857 Following is sample output from the
1858 <filename>do_kernel_configcheck</filename> task:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001859 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001860 Loading cache: 100% |########################################################| Time: 0:00:00
1861 Loaded 1275 entries from dependency cache.
1862 NOTE: Resolving any missing task queue dependencies
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001863
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001864 Build Configuration:
1865 .
1866 .
1867 .
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001868
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001869 NOTE: Executing SetScene Tasks
1870 NOTE: Executing RunQueue Tasks
1871 WARNING: linux-yocto-4.12.12+gitAUTOINC+eda4d18ce4_16de014967-r0 do_kernel_configcheck:
1872 [kernel config]: specified values did not make it into the kernel's final configuration:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001873
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001874 ---------- CONFIG_X86_TSC -----------------
1875 Config: CONFIG_X86_TSC
1876 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/bsp/common-pc/common-pc-cpu.cfg
1877 Requested value: CONFIG_X86_TSC=y
1878 Actual value:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001879
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001880
1881 ---------- CONFIG_X86_BIGSMP -----------------
1882 Config: CONFIG_X86_BIGSMP
1883 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
1884 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
1885 Requested value: # CONFIG_X86_BIGSMP is not set
1886 Actual value:
1887
1888
1889 ---------- CONFIG_NR_CPUS -----------------
1890 Config: CONFIG_NR_CPUS
1891 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
1892 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/bsp/common-pc/common-pc.cfg
1893 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
1894 Requested value: CONFIG_NR_CPUS=8
1895 Actual value: CONFIG_NR_CPUS=1
1896
1897
1898 ---------- CONFIG_SCHED_SMT -----------------
1899 Config: CONFIG_SCHED_SMT
1900 From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
1901 /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
1902 Requested value: CONFIG_SCHED_SMT=y
1903 Actual value:
1904
1905
1906
1907 NOTE: Tasks Summary: Attempted 288 tasks of which 285 didn't need to be rerun and all succeeded.
1908
1909 Summary: There were 3 WARNING messages shown.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001910 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001911 <note>
1912 The previous output example has artificial line breaks
1913 to make it more readable.
1914 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001915 </para>
1916
1917 <para>
1918 The output describes the various problems that you can
1919 encounter along with where to find the offending configuration
1920 items.
1921 You can use the information in the logs to adjust your
1922 configuration files and then repeat the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001923 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configme'><filename>do_kernel_configme</filename></ulink>
1924 and
1925 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configcheck'><filename>do_kernel_configcheck</filename></ulink>
1926 tasks until they produce no warnings.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001927 </para>
1928
1929 <para>
1930 For more information on how to use the
1931 <filename>menuconfig</filename> tool, see the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001932 "<link linkend='using-menuconfig'>Using <filename>menuconfig</filename></link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001933 section.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001934 </para>
1935 </section>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001936
1937 <section id='fine-tuning-the-kernel-configuration-file'>
1938 <title>Fine-Tuning the Kernel Configuration File</title>
1939
1940 <para>
1941 You can make sure the <filename>.config</filename> file is as
1942 lean or efficient as possible by reading the output of the
1943 kernel configuration fragment audit, noting any issues, making
1944 changes to correct the issues, and then repeating.
1945 </para>
1946
1947 <para>
1948 As part of the kernel build process, the
1949 <filename>do_kernel_configcheck</filename> task runs.
1950 This task validates the kernel configuration by checking the
1951 final <filename>.config</filename> file against the input
1952 files.
1953 During the check, the task produces warning messages for the
1954 following issues:
1955 <itemizedlist>
1956 <listitem><para>
1957 Requested options that did not make the final
1958 <filename>.config</filename> file.
1959 </para></listitem>
1960 <listitem><para>
1961 Configuration items that appear twice in the same
1962 configuration fragment.
1963 </para></listitem>
1964 <listitem><para>
1965 Configuration items tagged as "required" that were
1966 overridden.
1967 </para></listitem>
1968 <listitem><para>
1969 A board overrides a non-board specific option.
1970 </para></listitem>
1971 <listitem><para>
1972 Listed options not valid for the kernel being
1973 processed.
1974 In other words, the option does not appear anywhere.
1975 </para></listitem>
1976 </itemizedlist>
1977 <note>
1978 The <filename>do_kernel_configcheck</filename> task can
1979 also optionally report if an option is overridden during
1980 processing.
1981 </note>
1982 </para>
1983
1984 <para>
1985 For each output warning, a message points to the file
1986 that contains a list of the options and a pointer to the
1987 configuration fragment that defines them.
1988 Collectively, the files are the key to streamlining the
1989 configuration.
1990 </para>
1991
1992 <para>
1993 To streamline the configuration, do the following:
1994 <orderedlist>
1995 <listitem><para>
1996 <emphasis>Use a Working Configuration:</emphasis>
1997 Start with a full configuration that you
1998 know works.
1999 Be sure the configuration builds and boots
2000 successfully.
2001 Use this configuration file as your baseline.
2002 </para></listitem>
2003 <listitem><para>
2004 <emphasis>Run Configure and Check Tasks:</emphasis>
2005 Separately run the
2006 <filename>do_kernel_configme</filename> and
2007 <filename>do_kernel_configcheck</filename> tasks:
2008 <literallayout class='monospaced'>
2009 $ bitbake linux-yocto -c kernel_configme -f
2010 $ bitbake linux-yocto -c kernel_configcheck -f
2011 </literallayout>
2012 </para></listitem>
2013 <listitem><para>
2014 <emphasis>Process the Results:</emphasis>
2015 Take the resulting list of files from the
2016 <filename>do_kernel_configcheck</filename> task
2017 warnings and do the following:
2018 <itemizedlist>
2019 <listitem><para>
2020 Drop values that are redefined in the fragment
2021 but do not change the final
2022 <filename>.config</filename> file.
2023 </para></listitem>
2024 <listitem><para>
2025 Analyze and potentially drop values from the
2026 <filename>.config</filename> file that override
2027 required configurations.
2028 </para></listitem>
2029 <listitem><para>
2030 Analyze and potentially remove non-board
2031 specific options.
2032 </para></listitem>
2033 <listitem><para>
2034 Remove repeated and invalid options.
2035 </para></listitem>
2036 </itemizedlist>
2037 </para></listitem>
2038 <listitem><para>
2039 <emphasis>Re-Run Configure and Check Tasks:</emphasis>
2040 After you have worked through the output of the kernel
2041 configuration audit, you can re-run the
2042 <filename>do_kernel_configme</filename> and
2043 <filename>do_kernel_configcheck</filename> tasks to
2044 see the results of your changes.
2045 If you have more issues, you can deal with them as
2046 described in the previous step.
2047 </para></listitem>
2048 </orderedlist>
2049 </para>
2050
2051 <para>
2052 Iteratively working through steps two through four eventually
2053 yields a minimal, streamlined configuration file.
2054 Once you have the best <filename>.config</filename>, you can
2055 build the Linux Yocto kernel.
2056 </para>
2057 </section>
2058 </section>
2059
2060 <section id='expanding-variables'>
2061 <title>Expanding Variables</title>
2062
2063 <para>
2064 Sometimes it is helpful to determine what a variable expands
2065 to during a build.
2066 You can do examine the values of variables by examining the
2067 output of the <filename>bitbake -e</filename> command.
2068 The output is long and is more easily managed in a text file,
2069 which allows for easy searches:
2070 <literallayout class='monospaced'>
2071 $ bitbake -e virtual/kernel > <replaceable>some_text_file</replaceable>
2072 </literallayout>
2073 Within the text file, you can see exactly how each variable is
2074 expanded and used by the OpenEmbedded build system.
2075 </para>
2076 </section>
2077
2078 <section id='working-with-a-dirty-kernel-version-string'>
2079 <title>Working with a "Dirty" Kernel Version String</title>
2080
2081 <para>
2082 If you build a kernel image and the version string has a
2083 "+" or a "-dirty" at the end, uncommitted modifications exist
2084 in the kernel's source directory.
2085 Follow these steps to clean up the version string:
2086 <orderedlist>
2087 <listitem><para>
2088 <emphasis>Discover the Uncommitted Changes:</emphasis>
2089 Go to the kernel's locally cloned Git repository
2090 (source directory) and use the following Git command
2091 to list the files that have been changed, added, or
2092 removed:
2093 <literallayout class='monospaced'>
2094 $ git status
2095 </literallayout>
2096 </para></listitem>
2097 <listitem><para>
2098 <emphasis>Commit the Changes:</emphasis>
2099 You should commit those changes to the kernel source
2100 tree regardless of whether or not you will save,
2101 export, or use the changes:
2102 <literallayout class='monospaced'>
2103 $ git add
2104 $ git commit -s -a -m "getting rid of -dirty"
2105 </literallayout>
2106 </para></listitem>
2107 <listitem><para>
2108 <emphasis>Rebuild the Kernel Image:</emphasis>
2109 Once you commit the changes, rebuild the kernel.</para>
2110
2111 <para>Depending on your particular kernel development
2112 workflow, the commands you use to rebuild the
2113 kernel might differ.
2114 For information on building the kernel image when
2115 using <filename>devtool</filename>, see the
2116 "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>"
2117 section.
2118 For information on building the kernel image when
2119 using Bitbake, see the
2120 "<link linkend='using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</link>"
2121 section.
2122 </para></listitem>
2123 </orderedlist>
2124 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002125 </section>
2126
2127 <section id='working-with-your-own-sources'>
2128 <title>Working With Your Own Sources</title>
2129
2130 <para>
2131 If you cannot work with one of the Linux kernel
2132 versions supported by existing linux-yocto recipes, you can
2133 still make use of the Yocto Project Linux kernel tooling by
2134 working with your own sources.
2135 When you use your own sources, you will not be able to
2136 leverage the existing kernel
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002137 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink> and
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002138 stabilization work of the linux-yocto sources.
2139 However, you will be able to manage your own Metadata in the same
2140 format as the linux-yocto sources.
2141 Maintaining format compatibility facilitates converging with
2142 linux-yocto on a future, mutually-supported kernel version.
2143 </para>
2144
2145 <para>
2146 To help you use your own sources, the Yocto Project provides a
2147 linux-yocto custom recipe
2148 (<filename>linux-yocto-custom.bb</filename>) that uses
2149 <filename>kernel.org</filename> sources
2150 and the Yocto Project Linux kernel tools for managing
2151 kernel Metadata.
2152 You can find this recipe in the
2153 <filename>poky</filename> Git repository of the
2154 Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink>
2155 at:
2156 <literallayout class="monospaced">
2157 poky/meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb
2158 </literallayout>
2159 </para>
2160
2161 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002162 Here are some basic steps you can use to work with your own
2163 sources:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002164 <orderedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002165 <listitem><para>
2166 <emphasis>Create a Copy of the Kernel Recipe:</emphasis>
2167 Copy the <filename>linux-yocto-custom.bb</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002168 recipe to your layer and give it a meaningful name.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002169 The name should include the version of the Yocto Linux
2170 kernel you are using (e.g.
2171 <filename>linux-yocto-myproject_4.12.bb</filename>,
2172 where "4.12" is the base version of the Linux kernel
2173 with which you would be working).
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002174 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002175 <listitem><para>
2176 <emphasis>Create a Directory for Your Patches:</emphasis>
2177 In the same directory inside your layer, create a matching
2178 directory to store your patches and configuration files
2179 (e.g. <filename>linux-yocto-myproject</filename>).
2180 </para></listitem>
2181 <listitem><para>
2182 <emphasis>Ensure You Have Configurations:</emphasis>
2183 Make sure you have either a <filename>defconfig</filename>
2184 file or configuration fragment files in your layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002185 When you use the <filename>linux-yocto-custom.bb</filename>
2186 recipe, you must specify a configuration.
2187 If you do not have a <filename>defconfig</filename> file,
2188 you can run the following:
2189 <literallayout class='monospaced'>
2190 $ make defconfig
2191 </literallayout>
2192 After running the command, copy the resulting
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002193 <filename>.config</filename> file to the
2194 <filename>files</filename> directory in your layer
2195 as "defconfig" and then add it to the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002196 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
2197 variable in the recipe.</para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002198
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002199 <para>Running the <filename>make defconfig</filename>
2200 command results in the default configuration for your
2201 architecture as defined by your kernel.
2202 However, no guarantee exists that this configuration is
2203 valid for your use case, or that your board will even boot.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002204 This is particularly true for non-x86 architectures.</para>
2205
2206 <para>To use non-x86 <filename>defconfig</filename> files,
2207 you need to be more specific and find one that matches your
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002208 board (i.e. for arm, you look in
2209 <filename>arch/arm/configs</filename> and use the one that
2210 is the best starting point for your board).
2211 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002212 <listitem><para>
2213 <emphasis>Edit the Recipe:</emphasis>
2214 Edit the following variables in your recipe as appropriate
2215 for your project:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002216 <itemizedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002217 <listitem><para>
2218 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002219 The <filename>SRC_URI</filename> should specify
2220 a Git repository that uses one of the supported Git
2221 fetcher protocols (i.e. <filename>file</filename>,
2222 <filename>git</filename>, <filename>http</filename>,
2223 and so forth).
2224 The <filename>SRC_URI</filename> variable should
2225 also specify either a <filename>defconfig</filename>
2226 file or some configuration fragment files.
2227 The skeleton recipe provides an example
2228 <filename>SRC_URI</filename> as a syntax reference.
2229 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002230 <listitem><para>
2231 <ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION'><filename>LINUX_VERSION</filename></ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002232 The Linux kernel version you are using (e.g.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002233 "4.12").
2234 </para></listitem>
2235 <listitem><para>
2236 <ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION_EXTENSION'><filename>LINUX_VERSION_EXTENSION</filename></ulink>:
2237 The Linux kernel
2238 <filename>CONFIG_LOCALVERSION</filename> that is
2239 compiled into the resulting kernel and visible
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002240 through the <filename>uname</filename> command.
2241 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002242 <listitem><para>
2243 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002244 The commit ID from which you want to build.
2245 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002246 <listitem><para>
2247 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
2248 Treat this variable the same as you would in any
2249 other recipe.
2250 Increment the variable to indicate to the
2251 OpenEmbedded build system that the recipe has
2252 changed.
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-PV'><filename>PV</filename></ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002256 The default <filename>PV</filename> assignment is
2257 typically adequate.
2258 It combines the <filename>LINUX_VERSION</filename>
2259 with the Source Control Manager (SCM) revision
2260 as derived from the
2261 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>
2262 variable.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002263 The combined results are a string with the
2264 following form:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002265 <literallayout class='monospaced'>
2266 3.19.11+git1+68a635bf8dfb64b02263c1ac80c948647cc76d5f_1+218bd8d2022b9852c60d32f0d770931e3cf343e2
2267 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002268 While lengthy, the extra verbosity in
2269 <filename>PV</filename> helps ensure you are using
2270 the exact sources from which you intend to build.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002271 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002272 <listitem><para>
2273 <ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'><filename>COMPATIBLE_MACHINE</filename></ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002274 A list of the machines supported by your new recipe.
2275 This variable in the example recipe is set
2276 by default to a regular expression that matches
2277 only the empty string, "(^$)".
2278 This default setting triggers an explicit build
2279 failure.
2280 You must change it to match a list of the machines
2281 that your new recipe supports.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002282 For example, to support the
2283 <filename>qemux86</filename> and
2284 <filename>qemux86-64</filename> machines, use
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002285 the following form:
2286 <literallayout class='monospaced'>
2287 COMPATIBLE_MACHINE = "qemux86|qemux86-64"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002288 </literallayout>
2289 </para></listitem>
2290 </itemizedlist>
2291 </para></listitem>
2292 <listitem><para>
2293 <emphasis>Customize Your Recipe as Needed:</emphasis>
2294 Provide further customizations to your recipe
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002295 as needed just as you would customize an existing
2296 linux-yocto recipe.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002297 See the
2298 "<link linkend='modifying-an-existing-recipe'>Modifying an Existing Recipe</link>"
2299 section for information.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002300 </para></listitem>
2301 </orderedlist>
2302 </para>
2303 </section>
2304
2305 <section id='working-with-out-of-tree-modules'>
2306 <title>Working with Out-of-Tree Modules</title>
2307
2308 <para>
2309 This section describes steps to build out-of-tree modules on
2310 your target and describes how to incorporate out-of-tree modules
2311 in the build.
2312 </para>
2313
2314 <section id='building-out-of-tree-modules-on-the-target'>
2315 <title>Building Out-of-Tree Modules on the Target</title>
2316
2317 <para>
2318 While the traditional Yocto Project development model would be
2319 to include kernel modules as part of the normal build
2320 process, you might find it useful to build modules on the
2321 target.
2322 This could be the case if your target system is capable
2323 and powerful enough to handle the necessary compilation.
2324 Before deciding to build on your target, however, you should
2325 consider the benefits of using a proper cross-development
2326 environment from your build host.
2327 </para>
2328
2329 <para>
2330 If you want to be able to build out-of-tree modules on
2331 the target, there are some steps you need to take
2332 on the target that is running your SDK image.
2333 Briefly, the <filename>kernel-dev</filename> package
2334 is installed by default on all
2335 <filename>*.sdk</filename> images and the
2336 <filename>kernel-devsrc</filename> package is installed
2337 on many of the <filename>*.sdk</filename> images.
2338 However, you need to create some scripts prior to
2339 attempting to build the out-of-tree modules on the target
2340 that is running that image.
2341 </para>
2342
2343 <para>
2344 Prior to attempting to build the out-of-tree modules,
2345 you need to be on the target as root and you need to
2346 change to the <filename>/usr/src/kernel</filename> directory.
2347 Next, <filename>make</filename> the scripts:
2348 <literallayout class='monospaced'>
2349 # cd /usr/src/kernel
2350 # make scripts
2351 </literallayout>
2352 Because all SDK image recipes include
2353 <filename>dev-pkgs</filename>, the
2354 <filename>kernel-dev</filename> packages will be installed
2355 as part of the SDK image and the
2356 <filename>kernel-devsrc</filename> packages will be installed
2357 as part of applicable SDK images.
2358 The SDK uses the scripts when building out-of-tree
2359 modules.
2360 Once you have switched to that directory and created the
2361 scripts, you should be able to build your out-of-tree modules
2362 on the target.
2363 </para>
2364 </section>
2365
2366 <section id='incorporating-out-of-tree-modules'>
2367 <title>Incorporating Out-of-Tree Modules</title>
2368
2369 <para>
2370 While it is always preferable to work with sources integrated
2371 into the Linux kernel sources, if you need an external kernel
2372 module, the <filename>hello-mod.bb</filename> recipe is
2373 available as a template from which you can create your
2374 own out-of-tree Linux kernel module recipe.
2375 </para>
2376
2377 <para>
2378 This template recipe is located in the
2379 <filename>poky</filename> Git repository of the
2380 Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink>
2381 at:
2382 <literallayout class="monospaced">
2383 poky/meta-skeleton/recipes-kernel/hello-mod/hello-mod_0.1.bb
2384 </literallayout>
2385 </para>
2386
2387 <para>
2388 To get started, copy this recipe to your layer and give it a
2389 meaningful name (e.g. <filename>mymodule_1.0.bb</filename>).
2390 In the same directory, create a new directory named
2391 <filename>files</filename> where you can store any source files,
2392 patches, or other files necessary for building
2393 the module that do not come with the sources.
2394 Finally, update the recipe as needed for the module.
2395 Typically, you will need to set the following variables:
2396 <itemizedlist>
2397 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
2398 </para></listitem>
2399 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE*</filename></ulink>
2400 </para></listitem>
2401 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
2402 </para></listitem>
2403 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
2404 </para></listitem>
2405 </itemizedlist>
2406 </para>
2407
2408 <para>
2409 Depending on the build system used by the module sources,
2410 you might need to make some adjustments.
2411 For example, a typical module <filename>Makefile</filename>
2412 looks much like the one provided with the
2413 <filename>hello-mod</filename> template:
2414 <literallayout class='monospaced'>
2415 obj-m := hello.o
2416
2417 SRC := $(shell pwd)
2418
2419 all:
2420 $(MAKE) -C $(KERNEL_SRC) M=$(SRC)
2421
2422 modules_install:
2423 $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
2424 ...
2425 </literallayout>
2426 </para>
2427
2428 <para>
2429 The important point to note here is the
2430 <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_SRC'><filename>KERNEL_SRC</filename></ulink>
2431 variable.
2432 The
2433 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-module'><filename>module</filename></ulink>
2434 class sets this variable and the
2435 <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_PATH'><filename>KERNEL_PATH</filename></ulink>
2436 variable to
2437 <filename>${<ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_KERNEL_DIR'><filename>STAGING_KERNEL_DIR</filename></ulink>}</filename>
2438 with the necessary Linux kernel build information to build
2439 modules.
2440 If your module <filename>Makefile</filename> uses a different
2441 variable, you might want to override the
Brad Bishop316dfdd2018-06-25 12:45:53 -04002442 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002443 step, or create a patch to
2444 the <filename>Makefile</filename> to work with the more typical
2445 <filename>KERNEL_SRC</filename> or
2446 <filename>KERNEL_PATH</filename> variables.
2447 </para>
2448
2449 <para>
2450 After you have prepared your recipe, you will likely want to
2451 include the module in your images.
2452 To do this, see the documentation for the following variables in
2453 the Yocto Project Reference Manual and set one of them
2454 appropriately for your machine configuration file:
2455 <itemizedlist>
2456 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RDEPENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RDEPENDS</filename></ulink>
2457 </para></listitem>
2458 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink>
2459 </para></listitem>
2460 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RDEPENDS'><filename>MACHINE_EXTRA_RDEPENDS</filename></ulink>
2461 </para></listitem>
2462 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RRECOMMENDS'><filename>MACHINE_EXTRA_RRECOMMENDS</filename></ulink>
2463 </para></listitem>
2464 </itemizedlist>
2465 </para>
2466
2467 <para>
2468 Modules are often not required for boot and can be excluded from
2469 certain build configurations.
2470 The following allows for the most flexibility:
2471 <literallayout class='monospaced'>
2472 MACHINE_EXTRA_RRECOMMENDS += "kernel-module-mymodule"
2473 </literallayout>
2474 The value is derived by appending the module filename without
2475 the <filename>.ko</filename> extension to the string
2476 "kernel-module-".
2477 </para>
2478
2479 <para>
2480 Because the variable is
2481 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
2482 and not a
2483 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
2484 variable, the build will not fail if this module is not
2485 available to include in the image.
2486 </para>
2487 </section>
2488 </section>
2489
2490
2491 <section id='inspecting-changes-and-commits'>
2492 <title>Inspecting Changes and Commits</title>
2493
2494 <para>
2495 A common question when working with a kernel is:
2496 "What changes have been applied to this tree?"
2497 Rather than using "grep" across directories to see what has
2498 changed, you can use Git to inspect or search the kernel tree.
2499 Using Git is an efficient way to see what has changed in the tree.
2500 </para>
2501
2502 <section id='what-changed-in-a-kernel'>
2503 <title>What Changed in a Kernel?</title>
2504
2505 <para>
2506 Following are a few examples that show how to use Git
2507 commands to examine changes.
2508 These examples are by no means the only way to see changes.
2509 <note>
2510 In the following examples, unless you provide a commit
2511 range, <filename>kernel.org</filename> history is blended
2512 with Yocto Project kernel changes.
2513 You can form ranges by using branch names from the
2514 kernel tree as the upper and lower commit markers with
2515 the Git commands.
2516 You can see the branch names through the web interface
2517 to the Yocto Project source repositories at
Brad Bishop316dfdd2018-06-25 12:45:53 -04002518 <ulink url='&YOCTO_GIT_URL;'></ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002519 </note>
2520 To see a full range of the changes, use the
2521 <filename>git whatchanged</filename> command and specify a
2522 commit range for the branch
2523 (<replaceable>commit</replaceable><filename>..</filename><replaceable>commit</replaceable>).
2524 </para>
2525
2526 <para>
2527 Here is an example that looks at what has changed in the
2528 <filename>emenlow</filename> branch of the
2529 <filename>linux-yocto-3.19</filename> kernel.
2530 The lower commit range is the commit associated with the
2531 <filename>standard/base</filename> branch, while
2532 the upper commit range is the commit associated with the
2533 <filename>standard/emenlow</filename> branch.
2534 <literallayout class='monospaced'>
2535 $ git whatchanged origin/standard/base..origin/standard/emenlow
2536 </literallayout>
2537 </para>
2538
2539 <para>
2540 To see short, one line summaries of changes use the
2541 <filename>git log</filename> command:
2542 <literallayout class='monospaced'>
2543 $ git log --oneline origin/standard/base..origin/standard/emenlow
2544 </literallayout>
2545 </para>
2546
2547 <para>
2548 Use this command to see code differences for the changes:
2549 <literallayout class='monospaced'>
2550 $ git diff origin/standard/base..origin/standard/emenlow
2551 </literallayout>
2552 </para>
2553
2554 <para>
2555 Use this command to see the commit log messages and the
2556 text differences:
2557 <literallayout class='monospaced'>
2558 $ git show origin/standard/base..origin/standard/emenlow
2559 </literallayout>
2560 </para>
2561
2562 <para>
2563 Use this command to create individual patches for
2564 each change.
2565 Here is an example that that creates patch files for each
2566 commit and places them in your <filename>Documents</filename>
2567 directory:
2568 <literallayout class='monospaced'>
2569 $ git format-patch -o $HOME/Documents origin/standard/base..origin/standard/emenlow
2570 </literallayout>
2571 </para>
2572 </section>
2573
2574 <section id='showing-a-particular-feature-or-branch-change'>
2575 <title>Showing a Particular Feature or Branch Change</title>
2576
2577 <para>
2578 Tags in the Yocto Project kernel tree divide changes for
2579 significant features or branches.
2580 The <filename>git show</filename>&nbsp;<replaceable>tag</replaceable>
2581 command shows changes based on a tag.
2582 Here is an example that shows <filename>systemtap</filename>
2583 changes:
2584 <literallayout class='monospaced'>
2585 $ git show systemtap
2586 </literallayout>
2587 You can use the
2588 <filename>git branch --contains</filename>&nbsp;<replaceable>tag</replaceable>
2589 command to show the branches that contain a particular feature.
2590 This command shows the branches that contain the
2591 <filename>systemtap</filename> feature:
2592 <literallayout class='monospaced'>
2593 $ git branch --contains systemtap
2594 </literallayout>
2595 </para>
2596 </section>
2597 </section>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05002598
2599 <section id='adding-recipe-space-kernel-features'>
2600 <title>Adding Recipe-Space Kernel Features</title>
2601
2602 <para>
2603 You can add kernel features in the
2604 <link linkend='recipe-space-metadata'>recipe-space</link> by
2605 using the
2606 <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_FEATURES'><filename>KERNEL_FEATURES</filename></ulink>
2607 variable and by specifying the feature's <filename>.scc</filename>
2608 file path in the
2609 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
2610 statement.
2611 When you add features using this method, the OpenEmbedded build
2612 system checks to be sure the features are present.
2613 If the features are not present, the build stops.
2614 Kernel features are the last elements processed for configuring
2615 and patching the kernel.
2616 Therefore, adding features in this manner is a way
2617 to enforce specific features are present and enabled
2618 without needing to do a full audit of any other layer's additions
2619 to the <filename>SRC_URI</filename> statement.
2620 </para>
2621
2622 <para>
2623 You add a kernel feature by providing the feature as part of the
2624 <filename>KERNEL_FEATURES</filename> variable and by providing the
2625 path to the feature's <filename>.scc</filename> file, which is
2626 relative to the root of the kernel Metadata.
2627 The OpenEmbedded build system searches all forms of kernel
2628 Metadata on the <filename>SRC_URI</filename> statement regardless
2629 of whether the Metadata is in the "kernel-cache", system kernel
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002630 Metadata, or a recipe-space Metadata (i.e. part of the kernel
2631 recipe).
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05002632 See the
2633 "<link linkend='kernel-metadata-location'>Kernel Metadata Location</link>"
2634 section for additional information.
2635 </para>
2636
2637 <para>
2638 When you specify the feature's <filename>.scc</filename> file
2639 on the <filename>SRC_URI</filename> statement, the OpenEmbedded
2640 build system adds the directory of that
2641 <filename>.scc</filename> file along with all its subdirectories
2642 to the kernel feature search path.
2643 Because subdirectories are searched, you can reference a single
2644 <filename>.scc</filename> file in the
2645 <filename>SRC_URI</filename> statement to reference multiple kernel
2646 features.
2647 </para>
2648
2649 <para>
2650 Consider the following example that adds the "test.scc" feature
2651 to the build.
2652 <orderedlist>
2653 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002654 <emphasis>Create the Feature File:</emphasis>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05002655 Create a <filename>.scc</filename> file and locate it
2656 just as you would any other patch file,
2657 <filename>.cfg</filename> file, or fetcher item
2658 you specify in the <filename>SRC_URI</filename>
2659 statement.
2660 <note><title>Notes</title>
2661 <itemizedlist>
2662 <listitem><para>
2663 You must add the directory of the
2664 <filename>.scc</filename> file to the fetcher's
2665 search path in the same manner as you would
2666 add a <filename>.patch</filename> file.
2667 </para></listitem>
2668 <listitem><para>
2669 You can create additional
2670 <filename>.scc</filename> files beneath the
2671 directory that contains the file you are
2672 adding.
2673 All subdirectories are searched during the
2674 build as potential feature directories.
2675 </para></listitem>
2676 </itemizedlist>
2677 </note>
2678 Continuing with the example, suppose the "test.scc"
2679 feature you are adding has a
2680 <filename>test.scc</filename> file in the following
2681 directory:
2682 <literallayout class='monospaced'>
2683 <replaceable>my_recipe</replaceable>
2684 |
2685 +-linux-yocto
2686 |
2687 +-test.cfg
2688 +-test.scc
2689 </literallayout>
2690 In this example, the <filename>linux-yocto</filename>
2691 directory has both the feature
2692 <filename>test.scc</filename> file and a similarly
2693 named configuration fragment file
2694 <filename>test.cfg</filename>.
2695 </para></listitem>
2696 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002697 <emphasis>Add the Feature File to <filename>SRC_URI</filename>:</emphasis>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05002698 Add the <filename>.scc</filename> file to the
2699 recipe's <filename>SRC_URI</filename> statement:
2700 <literallayout class='monospaced'>
2701 SRC_URI_append = " file://test.scc"
2702 </literallayout>
2703 The leading space before the path is important as the
2704 path is appended to the existing path.
2705 </para></listitem>
2706 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002707 <emphasis>Specify the Feature as a Kernel Feature:</emphasis>
2708 Use the <filename>KERNEL_FEATURES</filename> statement
2709 to specify the feature as a kernel feature:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05002710 <literallayout class='monospaced'>
2711 KERNEL_FEATURES_append = " test.scc"
2712 </literallayout>
2713 The OpenEmbedded build system processes the kernel feature
2714 when it builds the kernel.
2715 <note>
2716 If other features are contained below "test.scc",
2717 then their directories are relative to the directory
2718 containing the <filename>test.scc</filename> file.
2719 </note>
2720 </para></listitem>
2721 </orderedlist>
2722 </para>
2723 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002724</chapter>
2725<!--
2726vim: expandtab tw=80 ts=4
2727-->