summaryrefslogtreecommitdiffstats
path: root/documentation/kernel-dev/kernel-dev-common.xml
diff options
context:
space:
mode:
authorTudor Florea <tudor.florea@enea.com>2015-10-09 22:59:03 +0200
committerTudor Florea <tudor.florea@enea.com>2015-10-09 22:59:03 +0200
commit972dcfcdbfe75dcfeb777150c136576cf1a71e99 (patch)
tree97a61cd7e293d7ae9d56ef7ed0f81253365bb026 /documentation/kernel-dev/kernel-dev-common.xml
downloadpoky-972dcfcdbfe75dcfeb777150c136576cf1a71e99.tar.gz
initial commit for Enea Linux 5.0 arm
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'documentation/kernel-dev/kernel-dev-common.xml')
-rw-r--r--documentation/kernel-dev/kernel-dev-common.xml915
1 files changed, 915 insertions, 0 deletions
diff --git a/documentation/kernel-dev/kernel-dev-common.xml b/documentation/kernel-dev/kernel-dev-common.xml
new file mode 100644
index 0000000000..58cc98ddff
--- /dev/null
+++ b/documentation/kernel-dev/kernel-dev-common.xml
@@ -0,0 +1,915 @@
1<!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'>
6
7<title>Common Tasks</title>
8
9<para>
10 This chapter presents several common tasks you perform when you
11 work with the Yocto Project Linux kernel.
12 These tasks include preparing a layer, modifying an existing recipe,
13 iterative development, working with your own sources, and incorporating
14 out-of-tree modules.
15 <note>
16 The examples presented in this chapter work with the Yocto Project
17 1.2.2 Release and forward.
18 </note>
19</para>
20
21 <section id='creating-and-preparing-a-layer'>
22 <title>Creating and Preparing a Layer</title>
23
24 <para>
25 If you are going to be modifying kernel recipes, it is recommended
26 that you create and prepare your own layer in which to do your
27 work.
28 Your layer contains its own
29 <ulink url='&YOCTO_DOCS_DEV_URL;#bitbake-term'>BitBake</ulink>
30 append files
31 (<filename>.bbappend</filename>) and provides a convenient
32 mechanism to create your own recipe files
33 (<filename>.bb</filename>).
34 For details on how to create and work with layers, see the following
35 sections in the Yocto Project Development Manual:
36 <itemizedlist>
37 <listitem><para>"<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>" for
38 general information on layers and how to create layers.</para></listitem>
39 <listitem><para>"<ulink url='&YOCTO_DOCS_DEV_URL;#set-up-your-layer-for-the-build'>Set Up Your Layer for the Build</ulink>" for
40 specific instructions on setting up a layer for kernel
41 development.</para></listitem>
42 </itemizedlist>
43 </para>
44 </section>
45
46 <section id='modifying-an-existing-recipe'>
47 <title>Modifying an Existing Recipe</title>
48
49 <para>
50 In many cases, you can customize an existing linux-yocto recipe to
51 meet the needs of your project.
52 Each release of the Yocto Project provides a few Linux
53 kernel recipes from which you can choose.
54 These are located in the
55 <ulink url='&YOCTO_DOCS_DEV_URL;#source-directory'>Source Directory</ulink>
56 in <filename>meta/recipes-kernel/linux</filename>.
57 </para>
58
59 <para>
60 Modifying an existing recipe can consist of the following:
61 <itemizedlist>
62 <listitem><para>Creating the append file</para></listitem>
63 <listitem><para>Applying patches</para></listitem>
64 <listitem><para>Changing the configuration</para></listitem>
65 </itemizedlist>
66 </para>
67
68 <para>
69 Before modifying an existing recipe, be sure that you have created
70 a minimal, custom layer from which you can work.
71 See the "<link linkend='creating-and-preparing-a-layer'>Creating and Preparing a Layer</link>"
72 section for some general resources.
73 You can also see the
74 "<ulink url='&YOCTO_DOCS_DEV_URL;#set-up-your-layer-for-the-build'>Set Up Your Layer for the Build</ulink>" section
75 of the Yocto Project Development Manual for a detailed
76 example.
77 </para>
78
79 <section id='creating-the-append-file'>
80 <title>Creating the Append File</title>
81
82 <para>
83 You create this file in your custom layer.
84 You also name it accordingly based on the linux-yocto recipe
85 you are using.
86 For example, if you are modifying the
87 <filename>meta/recipes-kernel/linux/linux-yocto_3.4.bb</filename>
88 recipe, the append file will typically be located as follows
89 within your custom layer:
90 <literallayout class='monospaced'>
91 <replaceable>your-layer</replaceable>/recipes-kernel/linux/linux-yocto_3.4.bbappend
92 </literallayout>
93 The append file should initially extend the
94 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
95 search path by prepending the directory that contains your
96 files to the
97 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
98 variable as follows:
99 <literallayout class='monospaced'>
100 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
101 </literallayout>
102 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>
103 expands to "linux-yocto" in the current directory for this
104 example.
105 If you add any new files that modify the kernel recipe and you
106 have extended <filename>FILESPATH</filename> as
107 described above, you must place the files in your layer in the
108 following area:
109 <literallayout class='monospaced'>
110 <replaceable>your-layer</replaceable>/recipes-kernel/linux/linux-yocto/
111 </literallayout>
112 <note>If you are working on a new machine Board Support Package
113 (BSP), be sure to refer to the
114 <ulink url='&YOCTO_DOCS_BSP_URL;'>Yocto Project Board Support Package (BSP) Developer's Guide</ulink>.
115 </note>
116 </para>
117 </section>
118
119 <section id='applying-patches'>
120 <title>Applying Patches</title>
121
122 <para>
123 If you have a single patch or a small series of patches
124 that you want to apply to the Linux kernel source, you
125 can do so just as you would with any other recipe.
126 You first copy the patches to the path added to
127 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
128 in your <filename>.bbappend</filename> file as described in
129 the previous section, and then reference them in
130 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
131 statements.
132 </para>
133
134 <para>
135 For example, you can apply a three-patch series by adding the
136 following lines to your linux-yocto <filename>.bbappend</filename>
137 file in your layer:
138 <literallayout class='monospaced'>
139 SRC_URI += "file://0001-first-change.patch"
140 SRC_URI += "file://0002-first-change.patch"
141 SRC_URI += "file://0003-first-change.patch"
142 </literallayout>
143 The next time you run BitBake to build the Linux kernel, BitBake
144 detects the change in the recipe and fetches and applies the patches
145 before building the kernel.
146 </para>
147
148 <para>
149 For a detailed example showing how to patch the kernel, see the
150 "<ulink url='&YOCTO_DOCS_DEV_URL;#patching-the-kernel'>Patching the Kernel</ulink>"
151 section in the Yocto Project Development Manual.
152 </para>
153 </section>
154
155 <section id='changing-the-configuration'>
156 <title>Changing the Configuration</title>
157
158 <para>
159 You can make wholesale or incremental changes to the Linux
160 kernel <filename>.config</filename> file by including a
161 <filename>defconfig</filename> and by specifying
162 configuration fragments in the
163 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
164 </para>
165
166 <para>
167 If you have a final Linux kernel <filename>.config</filename>
168 file you want to use, copy it to a directory named
169 <filename>files</filename>, which must be in
170 your layer's <filename>recipes-kernel/linux</filename>
171 directory, and name the file "defconfig".
172 Then, add the following lines to your linux-yocto
173 <filename>.bbappend</filename> file in your layer:
174 <literallayout class='monospaced'>
175 FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
176 SRC_URI += "file://defconfig"
177 </literallayout>
178 The <filename>SRC_URI</filename> tells the build system how to
179 search for the file, while the
180 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
181 extends the
182 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
183 variable (search directories) to include the
184 <filename>files</filename> directory you created for the
185 configuration changes.
186 </para>
187
188 <note>
189 The build system applies the configurations from the
190 <filename>.config</filename> file before applying any
191 subsequent configuration fragments.
192 The final kernel configuration is a combination of the
193 configurations in the <filename>.config</filename> file and
194 any configuration fragments you provide.
195 You need to realize that if you have any configuration
196 fragments, the build system applies these on top of and
197 after applying the existing <filename>.config</filename>
198 file configurations.
199 </note>
200
201 <para>
202 Generally speaking, the preferred approach is to determine the
203 incremental change you want to make and add that as a
204 configuration fragment.
205 For example, if you want to add support for a basic serial
206 console, create a file named <filename>8250.cfg</filename> in
207 the <filename>files</filename> directory with the following
208 content (without indentation):
209 <literallayout class='monospaced'>
210 CONFIG_SERIAL_8250=y
211 CONFIG_SERIAL_8250_CONSOLE=y
212 CONFIG_SERIAL_8250_PCI=y
213 CONFIG_SERIAL_8250_NR_UARTS=4
214 CONFIG_SERIAL_8250_RUNTIME_UARTS=4
215 CONFIG_SERIAL_CORE=y
216 CONFIG_SERIAL_CORE_CONSOLE=y
217 </literallayout>
218 Next, include this configuration fragment and extend the
219 <filename>FILESPATH</filename> variable in your
220 <filename>.bbappend</filename> file:
221 <literallayout class='monospaced'>
222 FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
223 SRC_URI += "file://8250.cfg"
224 </literallayout>
225 The next time you run BitBake to build the Linux kernel, BitBake
226 detects the change in the recipe and fetches and applies the
227 new configuration before building the kernel.
228 </para>
229
230 <para>
231 For a detailed example showing how to configure the kernel,
232 see the
233 "<ulink url='&YOCTO_DOCS_DEV_URL;#configuring-the-kernel'>Configuring the Kernel</ulink>"
234 section in the Yocto Project Development Manual.
235 </para>
236 </section>
237 </section>
238
239 <section id='using-an-iterative-development-process'>
240 <title>Using an Iterative Development Process</title>
241
242 <para>
243 If you do not have existing patches or configuration files,
244 you can iteratively generate them from within the BitBake build
245 environment as described within this section.
246 During an iterative workflow, running a previously completed BitBake
247 task causes BitBake to invalidate the tasks that follow the
248 completed task in the build sequence.
249 Invalidated tasks rebuild the next time you run the build using
250 BitBake.
251 </para>
252
253 <para>
254 As you read this section, be sure to substitute the name
255 of your Linux kernel recipe for the term
256 "linux-yocto".
257 </para>
258
259 <section id='tip-dirty-string'>
260 <title>"-dirty" String</title>
261
262<!--
263 <para>
264 <emphasis>AR - Darren Hart:</emphasis> This section
265 originated from the old Yocto Project Kernel Architecture
266 and Use Manual.
267 It was decided we need to put it in this section here.
268 Darren needs to figure out where we want it and what part
269 of it we want (all, revision???)
270 </para>
271-->
272
273 <para>
274 If kernel images are being built with "-dirty" on the
275 end of the version string, this simply means that
276 modifications in the source directory have not been committed.
277 <literallayout class='monospaced'>
278 $ git status
279 </literallayout>
280 </para>
281
282 <para>
283 You can use the above Git command to report modified,
284 removed, or added files.
285 You should commit those changes to the tree regardless of
286 whether they will be saved, exported, or used.
287 Once you commit the changes, you need to rebuild the kernel.
288 </para>
289
290 <para>
291 To force a pickup and commit of all such pending changes,
292 enter the following:
293 <literallayout class='monospaced'>
294 $ git add .
295 $ git commit -s -a -m "getting rid of -dirty"
296 </literallayout>
297 </para>
298
299 <para>
300 Next, rebuild the kernel.
301 </para>
302 </section>
303
304 <section id='generating-configuration-files'>
305 <title>Generating Configuration Files</title>
306
307 <para>
308 You can manipulate the <filename>.config</filename> file
309 used to build a linux-yocto recipe with the
310 <filename>menuconfig</filename> command as follows:
311 <literallayout class='monospaced'>
312 $ bitbake linux-yocto -c menuconfig
313 </literallayout>
314 This command starts the Linux kernel configuration tool,
315 which allows you to prepare a new
316 <filename>.config</filename> file for the build.
317 When you exit the tool, be sure to save your changes
318 at the prompt.
319 </para>
320
321 <para>
322 The resulting <filename>.config</filename> file is
323 located in
324 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename> under the
325 <filename>linux-${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink><filename>}-${<ulink url='&YOCTO_DOCS_REF_URL;#var-KTYPE'><filename>KTYPE</filename></ulink>}-build</filename> directory.
326 You can use the entire <filename>.config</filename> file as the
327 <filename>defconfig</filename> file as described in the
328 "<link linkend='changing-the-configuration'>Changing the Configuration</link>" section.
329 </para>
330
331 <para>
332 A better method is to create a configuration fragment using the
333 differences between two configuration files: one previously
334 created and saved, and one freshly created using the
335 <filename>menuconfig</filename> tool.
336 </para>
337
338 <para>
339 To create a configuration fragment using this method, follow
340 these steps:
341 <orderedlist>
342 <listitem><para>Complete a build at least through the kernel
343 configuration task as follows:
344 <literallayout class='monospaced'>
345 $ bitbake linux-yocto -c kernel_configme -f
346 </literallayout></para></listitem>
347 <listitem><para>Run the <filename>menuconfig</filename>
348 command:
349 <literallayout class='monospaced'>
350 $ bitbake linux-yocto -c menuconfig
351 </literallayout></para></listitem>
352 <listitem><para>Run the <filename>diffconfig</filename>
353 command to prepare a configuration fragment.
354 The resulting file <filename>fragment.cfg</filename>
355 will be placed in the
356 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename> directory:
357 <literallayout class='monospaced'>
358 $ bitbake linux-yocto -c diffconfig
359 </literallayout></para></listitem>
360 </orderedlist>
361 </para>
362
363 <para>
364 The <filename>diffconfig</filename> command creates a file that is a
365 list of Linux kernel <filename>CONFIG_</filename> assignments.
366 See the "<link linkend='changing-the-configuration'>Changing the Configuration</link>"
367 section for information on how to use the output as a
368 configuration fragment.
369 <note>
370 You can also use this method to create configuration
371 fragments for a BSP.
372 See the "<link linkend='bsp-descriptions'>BSP Descriptions</link>"
373 section for more information.
374 </note>
375 </para>
376
377 <para>
378 The kernel tools also provide configuration validation.
379 You can use these tools to produce warnings for when a
380 requested configuration does not appear in the final
381 <filename>.config</filename> file or when you override a
382 policy configuration in a hardware configuration fragment.
383 Here is an example with some sample output of the command
384 that runs these tools:
385 <literallayout class='monospaced'>
386 $ bitbake linux-yocto -c kernel_configcheck -f
387
388 ...
389
390 NOTE: validating kernel configuration
391 This BSP sets 3 invalid/obsolete kernel options.
392 These config options are not offered anywhere within this kernel.
393 The full list can be found in your kernel src dir at:
394 meta/cfg/standard/mybsp/invalid.cfg
395
396 This BSP sets 21 kernel options that are possibly non-hardware related.
397 The full list can be found in your kernel src dir at:
398 meta/cfg/standard/mybsp/specified_non_hdw.cfg
399
400 WARNING: There were 2 hardware options requested that do not
401 have a corresponding value present in the final ".config" file.
402 This probably means you are not't getting the config you wanted.
403 The full list can be found in your kernel src dir at:
404 meta/cfg/standard/mybsp/mismatch.cfg
405 </literallayout>
406 </para>
407
408 <para>
409 The output describes the various problems that you can
410 encounter along with where to find the offending configuration
411 items.
412 You can use the information in the logs to adjust your
413 configuration files and then repeat the
414 <filename>kernel_configme</filename> and
415 <filename>kernel_configcheck</filename> commands until
416 they produce no warnings.
417 </para>
418
419 <para>
420 For more information on how to use the
421 <filename>menuconfig</filename> tool, see the
422 "<ulink url='&YOCTO_DOCS_DEV_URL;#using-menuconfig'>Using <filename>menuconfig</filename></ulink>"
423 section in the Yocto Project Development Manual.
424 </para>
425 </section>
426
427 <section id='modifying-source-code'>
428 <title>Modifying Source Code</title>
429
430 <para>
431 You can experiment with source code changes and create a
432 simple patch without leaving the BitBake environment.
433 To get started, be sure to complete a build at
434 least through the kernel configuration task:
435 <literallayout class='monospaced'>
436 $ bitbake linux-yocto -c kernel_configme -f
437 </literallayout>
438 Taking this step ensures you have the sources prepared
439 and the configuration completed.
440 You can find the sources in the
441 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/linux</filename> directory.
442 </para>
443
444 <para>
445 You can edit the sources as you would any other Linux source
446 tree.
447 However, keep in mind that you will lose changes if you
448 trigger the
449 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
450 task for the recipe.
451 You can avoid triggering this task by not using BitBake to
452 run the
453 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>cleanall</filename></ulink>,
454 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleansstate'><filename>cleansstate</filename></ulink>,
455 or forced
456 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>fetch</filename></ulink>
457 commands.
458 Also, do not modify the recipe itself while working
459 with temporary changes or BitBake might run the
460 <filename>fetch</filename> command depending on the
461 changes to the recipe.
462 </para>
463
464 <para>
465 To test your temporary changes, instruct BitBake to run the
466 <filename>compile</filename> again.
467 The <filename>-f</filename> option forces the command to run
468 even though BitBake might think it has already done so:
469 <literallayout class='monospaced'>
470 $ bitbake linux-yocto -c compile -f
471 </literallayout>
472 If the compile fails, you can update the sources and repeat
473 the <filename>compile</filename>.
474 Once compilation is successful, you can inspect and test
475 the resulting build (i.e. kernel, modules, and so forth) from
476 the <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>:
477 <literallayout class='monospaced'>
478 ${WORKDIR}/linux-${MACHINE}-${KTYPE}-build
479 </literallayout>
480 Alternatively, you can run the <filename>deploy</filename>
481 command to place the kernel image in the
482 <filename>tmp/deploy/images</filename> directory:
483 <literallayout class='monospaced'>
484 $ bitbake linux-yocto -c deploy
485 </literallayout>
486 And, of course, you can perform the remaining installation and
487 packaging steps by issuing:
488 <literallayout class='monospaced'>
489 $ bitbake linux-yocto
490 </literallayout>
491 </para>
492
493 <para>
494 For rapid iterative development, the edit-compile-repeat loop
495 described in this section is preferable to rebuilding the
496 entire recipe because the installation and packaging tasks
497 are very time consuming.
498 </para>
499
500 <para>
501 Once you are satisfied with your source code modifications,
502 you can make them permanent by generating patches and
503 applying them to the
504 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
505 statement as described in the
506 "<link linkend='applying-patches'>Applying Patches</link>"
507 section.
508 If you are not familiar with generating patches, refer to the
509 "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-the-patch'>Creating the Patch</ulink>"
510 section in the Yocto Project Development Manual.
511 </para>
512 </section>
513 </section>
514
515 <section id='working-with-your-own-sources'>
516 <title>Working With Your Own Sources</title>
517
518 <para>
519 If you cannot work with one of the Linux kernel
520 versions supported by existing linux-yocto recipes, you can
521 still make use of the Yocto Project Linux kernel tooling by
522 working with your own sources.
523 When you use your own sources, you will not be able to
524 leverage the existing kernel
525 <ulink url='&YOCTO_DOCS_DEV_URL;#metadata'>Metadata</ulink> and
526 stabilization work of the linux-yocto sources.
527 However, you will be able to manage your own Metadata in the same
528 format as the linux-yocto sources.
529 Maintaining format compatibility facilitates converging with
530 linux-yocto on a future, mutually-supported kernel version.
531 </para>
532
533 <para>
534 To help you use your own sources, the Yocto Project provides a
535 linux-yocto custom recipe
536 (<filename>linux-yocto-custom.bb</filename>) that uses
537 <filename>kernel.org</filename> sources
538 and the Yocto Project Linux kernel tools for managing
539 kernel Metadata.
540 You can find this recipe in the
541 <filename>poky</filename> Git repository of the
542 Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink>
543 at:
544 <literallayout class="monospaced">
545 poky/meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb
546 </literallayout>
547 </para>
548
549 <para>
550 Here are some basic steps you can use to work with your own sources:
551 <orderedlist>
552 <listitem><para>Copy the <filename>linux-yocto-custom.bb</filename>
553 recipe to your layer and give it a meaningful name.
554 The name should include the version of the Linux kernel you
555 are using (e.g. <filename>linux-yocto-myproject_3.5.bb</filename>,
556 where "3.5" is the base version of the Linux kernel
557 with which you would be working).</para></listitem>
558 <listitem><para>In the same directory inside your layer,
559 create a matching directory
560 to store your patches and configuration files (e.g.
561 <filename>linux-yocto-myproject</filename>).
562 </para></listitem>
563 <listitem><para>Edit the following variables in your recipe
564 as appropriate for your project:
565 <itemizedlist>
566 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>:
567 The <filename>SRC_URI</filename> should be a Git
568 repository that uses one of the supported Git fetcher
569 protocols (i.e. <filename>file</filename>,
570 <filename>git</filename>, <filename>http</filename>,
571 and so forth).
572 The skeleton recipe provides an example
573 <filename>SRC_URI</filename> as a syntax reference.
574 </para></listitem>
575 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION'><filename>LINUX_VERSION</filename></ulink>:
576 The Linux kernel version you are using (e.g.
577 "3.4").</para></listitem>
578 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION_EXTENSION'><filename>LINUX_VERSION_EXTENSION</filename></ulink>:
579 The Linux kernel <filename>CONFIG_LOCALVERSION</filename>
580 that is compiled into the resulting kernel and visible
581 through the <filename>uname</filename> command.
582 </para></listitem>
583 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>:
584 The commit ID from which you want to build.
585 </para></listitem>
586 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
587 Treat this variable the same as you would in any other
588 recipe.
589 Increment the variable to indicate to the OpenEmbedded
590 build system that the recipe has changed.
591 </para></listitem>
592 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
593 The default <filename>PV</filename> assignment is
594 typically adequate.
595 It combines the <filename>LINUX_VERSION</filename>
596 with the Source Control Manager (SCM) revision
597 as derived from the
598 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>
599 variable.
600 The combined results are a string with
601 the following form:
602 <literallayout class='monospaced'>
603 3.4.11+git1+68a635bf8dfb64b02263c1ac80c948647cc76d5f_1+218bd8d2022b9852c60d32f0d770931e3cf343e2
604 </literallayout>
605 While lengthy, the extra verbosity in <filename>PV</filename>
606 helps ensure you are using the exact
607 sources from which you intend to build.
608 </para></listitem>
609 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'><filename>COMPATIBLE_MACHINE</filename></ulink>:
610 A list of the machines supported by your new recipe.
611 This variable in the example recipe is set
612 by default to a regular expression that matches
613 only the empty string, "(^$)".
614 This default setting triggers an explicit build
615 failure.
616 You must change it to match a list of the machines
617 that your new recipe supports.
618 For example, to support the <filename>qemux86</filename>
619 and <filename>qemux86-64</filename> machines, use
620 the following form:
621 <literallayout class='monospaced'>
622 COMPATIBLE_MACHINE = "qemux86|qemux86-64"
623 </literallayout></para></listitem>
624 </itemizedlist></para></listitem>
625 <listitem><para>Provide further customizations to your recipe
626 as needed just as you would customize an existing
627 linux-yocto recipe.
628 See the "<link linkend='modifying-an-existing-recipe'>Modifying
629 an Existing Recipe</link>" section for information.
630 </para></listitem>
631 </orderedlist>
632 </para>
633 </section>
634
635 <section id='working-with-out-of-tree-modules'>
636 <title>Working with Out-of-Tree Modules</title>
637
638 <para>
639 This section describes steps to build out-of-tree modules on
640 your target and describes how to incorporate out-of-tree modules
641 in the build.
642 </para>
643
644 <section id='building-out-of-tree-modules-on-the-target'>
645 <title>Building Out-of-Tree Modules on the Target</title>
646
647 <para>
648 If you want to be able to build out-of-tree modules on
649 the target, there are some steps you need to take
650 on the target that is running your SDK image.
651 Briefly, the <filename>kernel-dev</filename> package
652 is installed by default on all
653 <filename>*.sdk</filename> images.
654 However, you need to create some scripts prior to
655 attempting to build the out-of-tree modules on the target
656 that is running that image.
657 </para>
658
659 <para>
660 Prior to attempting to build the out-of-tree modules,
661 you need to be on the target as root and you need to
662 change to the <filename>/usr/src/kernel</filename> directory.
663 Next, <filename>make</filename> the scripts:
664 <literallayout class='monospaced'>
665 # cd /usr/src/kernel
666 # make scripts
667 </literallayout>
668 Because all SDK image recipes include
669 <filename>dev-pkgs</filename>, the
670 <filename>kernel-dev</filename> packages will be installed
671 as part of the SDK image.
672 The SDK uses the scripts when building out-of-tree
673 modules.
674 Once you have switched to that directory and created the
675 scripts, you should be able to build your out-of-tree modules
676 on the target.
677 </para>
678 </section>
679
680 <section id='incorporating-out-of-tree-modules'>
681 <title>Incorporating Out-of-Tree Modules</title>
682
683 <para>
684 While it is always preferable to work with sources integrated
685 into the Linux kernel sources, if you need an external kernel
686 module, the <filename>hello-mod.bb</filename> recipe is
687 available as a template from which you can create your
688 own out-of-tree Linux kernel module recipe.
689 </para>
690
691 <para>
692 This template recipe is located in the
693 <filename>poky</filename> Git repository of the
694 Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink>
695 at:
696 <literallayout class="monospaced">
697 poky/meta-skeleton/recipes-kernel/hello-mod/hello-mod_0.1.bb
698 </literallayout>
699 </para>
700
701 <para>
702 To get started, copy this recipe to your layer and give it a
703 meaningful name (e.g. <filename>mymodule_1.0.bb</filename>).
704 In the same directory, create a new directory named
705 <filename>files</filename> where you can store any source files,
706 patches, or other files necessary for building
707 the module that do not come with the sources.
708 Finally, update the recipe as needed for the module.
709 Typically, you will need to set the following variables:
710 <itemizedlist>
711 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
712 </para></listitem>
713 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE*</filename></ulink>
714 </para></listitem>
715 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
716 </para></listitem>
717 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
718 </para></listitem>
719 </itemizedlist>
720 </para>
721
722 <para>
723 Depending on the build system used by the module sources,
724 you might need to make some adjustments.
725 For example, a typical module <filename>Makefile</filename>
726 looks much like the one provided with the
727 <filename>hello-mod</filename> template:
728 <literallayout class='monospaced'>
729 obj-m := hello.o
730
731 SRC := $(shell pwd)
732
733 all:
734 $(MAKE) -C $(KERNEL_SRC) M=$(SRC)
735
736 modules_install:
737 $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
738 ...
739 </literallayout>
740 </para>
741
742 <para>
743 The important point to note here is the
744 <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_SRC'><filename>KERNEL_SRC</filename></ulink>
745 variable.
746 The
747 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-module'><filename>module</filename></ulink>
748 class sets this variable and the
749 <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_PATH'><filename>KERNEL_PATH</filename></ulink>
750 variable to
751 <filename>${<ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_KERNEL_DIR'><filename>STAGING_KERNEL_DIR</filename></ulink>}</filename>
752 with the necessary Linux kernel build information to build
753 modules.
754 If your module <filename>Makefile</filename> uses a different
755 variable, you might want to override the
756 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile()</filename></ulink>
757 step, or create a patch to
758 the <filename>Makefile</filename> to work with the more typical
759 <filename>KERNEL_SRC</filename> or
760 <filename>KERNEL_PATH</filename> variables.
761 </para>
762
763 <para>
764 After you have prepared your recipe, you will likely want to
765 include the module in your images.
766 To do this, see the documentation for the following variables in
767 the Yocto Project Reference Manual and set one of them
768 appropriately for your machine configuration file:
769 <itemizedlist>
770 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RDEPENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RDEPENDS</filename></ulink>
771 </para></listitem>
772 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink>
773 </para></listitem>
774 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RDEPENDS'><filename>MACHINE_EXTRA_RDEPENDS</filename></ulink>
775 </para></listitem>
776 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RRECOMMENDS'><filename>MACHINE_EXTRA_RRECOMMENDS</filename></ulink>
777 </para></listitem>
778 </itemizedlist>
779 </para>
780
781 <para>
782 Modules are often not required for boot and can be excluded from
783 certain build configurations.
784 The following allows for the most flexibility:
785 <literallayout class='monospaced'>
786 MACHINE_EXTRA_RRECOMMENDS += "kernel-module-mymodule"
787 </literallayout>
788 The value is derived by appending the module filename without
789 the <filename>.ko</filename> extension to the string
790 "kernel-module-".
791 </para>
792
793 <para>
794 Because the variable is
795 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
796 and not a
797 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
798 variable, the build will not fail if this module is not
799 available to include in the image.
800 </para>
801 </section>
802 </section>
803
804
805 <section id='inspecting-changes-and-commits'>
806 <title>Inspecting Changes and Commits</title>
807
808 <para>
809 A common question when working with a kernel is:
810 "What changes have been applied to this tree?"
811 Rather than using "grep" across directories to see what has
812 changed, you can use Git to inspect or search the kernel tree.
813 Using Git is an efficient way to see what has changed in the tree.
814 </para>
815
816 <section id='what-changed-in-a-kernel'>
817 <title>What Changed in a Kernel?</title>
818
819 <para>
820 Following are a few examples that show how to use Git
821 commands to examine changes.
822 These examples are by no means the only way to see changes.
823 <note>
824 In the following examples, unless you provide a commit
825 range, <filename>kernel.org</filename> history is blended
826 with Yocto Project kernel changes.
827 You can form ranges by using branch names from the
828 kernel tree as the upper and lower commit markers with
829 the Git commands.
830 You can see the branch names through the web interface
831 to the Yocto Project source repositories at
832 <ulink url='http://git.yoctoproject.org/cgit.cgi'></ulink>.
833 </note>
834 To see a full range of the changes, use the
835 <filename>git whatchanged</filename> command and specify a
836 commit range for the branch
837 (<filename>&lt;commit&gt;..&lt;commit&gt;</filename>).
838 </para>
839
840 <para>
841 Here is an example that looks at what has changed in the
842 <filename>emenlow</filename> branch of the
843 <filename>linux-yocto-3.4</filename> kernel.
844 The lower commit range is the commit associated with the
845 <filename>standard/base</filename> branch, while
846 the upper commit range is the commit associated with the
847 <filename>standard/emenlow</filename> branch.
848 <literallayout class='monospaced'>
849 $ git whatchanged origin/standard/base..origin/standard/emenlow
850 </literallayout>
851 </para>
852
853 <para>
854 To see short, one line summaries of changes use the
855 <filename>git log</filename> command:
856 <literallayout class='monospaced'>
857 $ git log --oneline origin/standard/base..origin/standard/emenlow
858 </literallayout>
859 </para>
860
861 <para>
862 Use this command to see code differences for the changes:
863 <literallayout class='monospaced'>
864 $ git diff origin/standard/base..origin/standard/emenlow
865 </literallayout>
866 </para>
867
868 <para>
869 Use this command to see the commit log messages and the
870 text differences:
871 <literallayout class='monospaced'>
872 $ git show origin/standard/base..origin/standard/emenlow
873 </literallayout>
874 </para>
875
876 <para>
877 Use this command to create individual patches for
878 each change.
879 Here is an example that that creates patch files for each
880 commit and places them in your <filename>Documents</filename>
881 directory:
882 <literallayout class='monospaced'>
883 $ git format-patch -o $HOME/Documents origin/standard/base..origin/standard/emenlow
884 </literallayout>
885 </para>
886 </section>
887
888 <section id='showing-a-particular-feature-or-branch-change'>
889 <title>Showing a Particular Feature or Branch Change</title>
890
891 <para>
892 Tags in the Yocto Project kernel tree divide changes for
893 significant features or branches.
894 The <filename>git show &lt;tag&gt;</filename> command shows
895 changes based on a tag.
896 Here is an example that shows <filename>systemtap</filename>
897 changes:
898 <literallayout class='monospaced'>
899 $ git show systemtap
900 </literallayout>
901 You can use the
902 <filename>git branch --contains &lt;tag&gt;</filename> command
903 to show the branches that contain a particular feature.
904 This command shows the branches that contain the
905 <filename>systemtap</filename> feature:
906 <literallayout class='monospaced'>
907 $ git branch --contains systemtap
908 </literallayout>
909 </para>
910 </section>
911 </section>
912</chapter>
913<!--
914vim: expandtab tw=80 ts=4
915-->