summaryrefslogtreecommitdiffstats
path: root/documentation/kernel-dev/kernel-dev-common.xml
diff options
context:
space:
mode:
authorAdrian Dudau <adrian.dudau@enea.com>2014-06-26 14:38:37 +0200
committerAdrian Dudau <adrian.dudau@enea.com>2014-06-26 14:38:37 +0200
commit067445c1487c1a73e0ee8a9ae3e82d446406ab57 (patch)
treed47aa232ce1c82cf47aa348f20902937e073239a /documentation/kernel-dev/kernel-dev-common.xml
downloadyocto-docs-daisy.tar.gz
initial commit for Enea Linux 4.0daisy
Migrated from the internal git server on the daisy-enea branch Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'documentation/kernel-dev/kernel-dev-common.xml')
-rw-r--r--documentation/kernel-dev/kernel-dev-common.xml914
1 files changed, 914 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 0000000..555c8d8
--- /dev/null
+++ b/documentation/kernel-dev/kernel-dev-common.xml
@@ -0,0 +1,914 @@
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 typical be located as follows
89 within your custom layer:
90 <literallayout class='monospaced'>
91 &lt;your-layer&gt;/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 &lt;your-layer&gt;/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 section
506 "<link linkend='applying-patches'>Applying Patches</link>" section.
507 If you are not familiar with generating patches, refer to the
508 "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-the-patch'>Creating the Patch</ulink>"
509 section in the Yocto Project Development Manual.
510 </para>
511 </section>
512 </section>
513
514 <section id='working-with-your-own-sources'>
515 <title>Working With Your Own Sources</title>
516
517 <para>
518 If you cannot work with one of the Linux kernel
519 versions supported by existing linux-yocto recipes, you can
520 still make use of the Yocto Project Linux kernel tooling by
521 working with your own sources.
522 When you use your own sources, you will not be able to
523 leverage the existing kernel
524 <ulink url='&YOCTO_DOCS_DEV_URL;#metadata'>Metadata</ulink> and
525 stabilization work of the linux-yocto sources.
526 However, you will be able to manage your own Metadata in the same
527 format as the linux-yocto sources.
528 Maintaining format compatibility facilitates converging with
529 linux-yocto on a future, mutually-supported kernel version.
530 </para>
531
532 <para>
533 To help you use your own sources, the Yocto Project provides a
534 linux-yocto custom recipe
535 (<filename>linux-yocto-custom.bb</filename>) that uses
536 <filename>kernel.org</filename> sources
537 and the Yocto Project Linux kernel tools for managing
538 kernel Metadata.
539 You can find this recipe in the
540 <filename>poky</filename> Git repository of the
541 Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink>
542 at:
543 <literallayout class="monospaced">
544 poky/meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb
545 </literallayout>
546 </para>
547
548 <para>
549 Here are some basic steps you can use to work with your own sources:
550 <orderedlist>
551 <listitem><para>Copy the <filename>linux-yocto-custom.bb</filename>
552 recipe to your layer and give it a meaningful name.
553 The name should include the version of the Linux kernel you
554 are using (e.g. <filename>linux-yocto-myproject_3.5.bb</filename>,
555 where "3.5" is the base version of the Linux kernel
556 with which you would be working).</para></listitem>
557 <listitem><para>In the same directory inside your layer,
558 create a matching directory
559 to store your patches and configuration files (e.g.
560 <filename>linux-yocto-myproject</filename>).
561 </para></listitem>
562 <listitem><para>Edit the following variables in your recipe
563 as appropriate for your project:
564 <itemizedlist>
565 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>:
566 The <filename>SRC_URI</filename> should be a Git
567 repository that uses one of the supported Git fetcher
568 protocols (i.e. <filename>file</filename>,
569 <filename>git</filename>, <filename>http</filename>,
570 and so forth).
571 The skeleton recipe provides an example
572 <filename>SRC_URI</filename> as a syntax reference.
573 </para></listitem>
574 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION'><filename>LINUX_VERSION</filename></ulink>:
575 The Linux kernel version you are using (e.g.
576 "3.4").</para></listitem>
577 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION_EXTENSION'><filename>LINUX_VERSION_EXTENSION</filename></ulink>:
578 The Linux kernel <filename>CONFIG_LOCALVERSION</filename>
579 that is compiled into the resulting kernel and visible
580 through the <filename>uname</filename> command.
581 </para></listitem>
582 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>:
583 The commit ID from which you want to build.
584 </para></listitem>
585 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
586 Treat this variable the same as you would in any other
587 recipe.
588 Increment the variable to indicate to the OpenEmbedded
589 build system that the recipe has changed.
590 </para></listitem>
591 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
592 The default <filename>PV</filename> assignment is
593 typically adequate.
594 It combines the <filename>LINUX_VERSION</filename>
595 with the Source Control Manager (SCM) revision
596 as derived from the
597 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>
598 variable.
599 The combined results are a string with
600 the following form:
601 <literallayout class='monospaced'>
602 3.4.11+git1+68a635bf8dfb64b02263c1ac80c948647cc76d5f_1+218bd8d2022b9852c60d32f0d770931e3cf343e2
603 </literallayout>
604 While lengthy, the extra verbosity in <filename>PV</filename>
605 helps ensure you are using the exact
606 sources from which you intend to build.
607 </para></listitem>
608 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'><filename>COMPATIBLE_MACHINE</filename></ulink>:
609 A list of the machines supported by your new recipe.
610 This variable in the example recipe is set
611 by default to a regular expression that matches
612 only the empty string, "(^$)".
613 This default setting triggers an explicit build
614 failure.
615 You must change it to match a list of the machines
616 that your new recipe supports.
617 For example, to support the <filename>qemux86</filename>
618 and <filename>qemux86-64</filename> machines, use
619 the following form:
620 <literallayout class='monospaced'>
621 COMPATIBLE_MACHINE = "qemux86|qemux86-64"
622 </literallayout></para></listitem>
623 </itemizedlist></para></listitem>
624 <listitem><para>Provide further customizations to your recipe
625 as needed just as you would customize an existing
626 linux-yocto recipe.
627 See the "<link linkend='modifying-an-existing-recipe'>Modifying
628 an Existing Recipe</link>" section for information.
629 </para></listitem>
630 </orderedlist>
631 </para>
632 </section>
633
634 <section id='working-with-out-of-tree-modules'>
635 <title>Working with Out-of-Tree Modules</title>
636
637 <para>
638 This section describes steps to build out-of-tree modules on
639 your target and describes how to incorporate out-of-tree modules
640 in the build.
641 </para>
642
643 <section id='building-out-of-tree-modules-on-the-target'>
644 <title>Building Out-of-Tree Modules on the Target</title>
645
646 <para>
647 If you want to be able to build out-of-tree modules on
648 the target, there are some steps you need to take
649 on the target that is running your SDK image.
650 Briefly, the <filename>kernel-dev</filename> package
651 is installed by default on all
652 <filename>*.sdk</filename> images.
653 However, you need to create some scripts prior to
654 attempting to build the out-of-tree modules on the target
655 that is running that image.
656 </para>
657
658 <para>
659 Prior to attempting to build the out-of-tree modules,
660 you need to be on the target as root and you need to
661 change to the <filename>/usr/src/kernel</filename> directory.
662 Next, <filename>make</filename> the scripts:
663 <literallayout class='monospaced'>
664 # cd /usr/src/kernel
665 # make scripts
666 </literallayout>
667 Because all SDK image recipes include
668 <filename>dev-pkgs</filename>, the
669 <filename>kernel-dev</filename> packages will be installed
670 as part of the SDK image.
671 The SDK uses the scripts when building out-of-tree
672 modules.
673 Once you have switched to that directory and created the
674 scripts, you should be able to build your out-of-tree modules
675 on the target.
676 </para>
677 </section>
678
679 <section id='incorporating-out-of-tree-modules'>
680 <title>Incorporating Out-of-Tree Modules</title>
681
682 <para>
683 While it is always preferable to work with sources integrated
684 into the Linux kernel sources, if you need an external kernel
685 module, the <filename>hello-mod.bb</filename> recipe is
686 available as a template from which you can create your
687 own out-of-tree Linux kernel module recipe.
688 </para>
689
690 <para>
691 This template recipe is located in the
692 <filename>poky</filename> Git repository of the
693 Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink>
694 at:
695 <literallayout class="monospaced">
696 poky/meta-skeleton/recipes-kernel/hello-mod/hello-mod_0.1.bb
697 </literallayout>
698 </para>
699
700 <para>
701 To get started, copy this recipe to your layer and give it a
702 meaningful name (e.g. <filename>mymodule_1.0.bb</filename>).
703 In the same directory, create a new directory named
704 <filename>files</filename> where you can store any source files,
705 patches, or other files necessary for building
706 the module that do not come with the sources.
707 Finally, update the recipe as needed for the module.
708 Typically, you will need to set the following variables:
709 <itemizedlist>
710 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
711 </para></listitem>
712 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE*</filename></ulink>
713 </para></listitem>
714 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
715 </para></listitem>
716 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
717 </para></listitem>
718 </itemizedlist>
719 </para>
720
721 <para>
722 Depending on the build system used by the module sources,
723 you might need to make some adjustments.
724 For example, a typical module <filename>Makefile</filename>
725 looks much like the one provided with the
726 <filename>hello-mod</filename> template:
727 <literallayout class='monospaced'>
728 obj-m := hello.o
729
730 SRC := $(shell pwd)
731
732 all:
733 $(MAKE) -C $(KERNEL_SRC) M=$(SRC)
734
735 modules_install:
736 $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
737 ...
738 </literallayout>
739 </para>
740
741 <para>
742 The important point to note here is the
743 <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_SRC'><filename>KERNEL_SRC</filename></ulink>
744 variable.
745 The
746 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-module'><filename>module</filename></ulink>
747 class sets this variable and the
748 <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_PATH'><filename>KERNEL_PATH</filename></ulink>
749 variable to
750 <filename>${<ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_KERNEL_DIR'><filename>STAGING_KERNEL_DIR</filename></ulink>}</filename>
751 with the necessary Linux kernel build information to build
752 modules.
753 If your module <filename>Makefile</filename> uses a different
754 variable, you might want to override the
755 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile()</filename></ulink>
756 step, or create a patch to
757 the <filename>Makefile</filename> to work with the more typical
758 <filename>KERNEL_SRC</filename> or
759 <filename>KERNEL_PATH</filename> variables.
760 </para>
761
762 <para>
763 After you have prepared your recipe, you will likely want to
764 include the module in your images.
765 To do this, see the documentation for the following variables in
766 the Yocto Project Reference Manual and set one of them
767 appropriately for your machine configuration file:
768 <itemizedlist>
769 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RDEPENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RDEPENDS</filename></ulink>
770 </para></listitem>
771 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink>
772 </para></listitem>
773 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RDEPENDS'><filename>MACHINE_EXTRA_RDEPENDS</filename></ulink>
774 </para></listitem>
775 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RRECOMMENDS'><filename>MACHINE_EXTRA_RRECOMMENDS</filename></ulink>
776 </para></listitem>
777 </itemizedlist>
778 </para>
779
780 <para>
781 Modules are often not required for boot and can be excluded from
782 certain build configurations.
783 The following allows for the most flexibility:
784 <literallayout class='monospaced'>
785 MACHINE_EXTRA_RRECOMMENDS += "kernel-module-mymodule"
786 </literallayout>
787 The value is derived by appending the module filename without
788 the <filename>.ko</filename> extension to the string
789 "kernel-module-".
790 </para>
791
792 <para>
793 Because the variable is
794 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
795 and not a
796 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
797 variable, the build will not fail if this module is not
798 available to include in the image.
799 </para>
800 </section>
801 </section>
802
803
804 <section id='inspecting-changes-and-commits'>
805 <title>Inspecting Changes and Commits</title>
806
807 <para>
808 A common question when working with a kernel is:
809 "What changes have been applied to this tree?"
810 Rather than using "grep" across directories to see what has
811 changed, you can use Git to inspect or search the kernel tree.
812 Using Git is an efficient way to see what has changed in the tree.
813 </para>
814
815 <section id='what-changed-in-a-kernel'>
816 <title>What Changed in a Kernel?</title>
817
818 <para>
819 Following are a few examples that show how to use Git
820 commands to examine changes.
821 These examples are by no means the only way to see changes.
822 <note>
823 In the following examples, unless you provide a commit
824 range, <filename>kernel.org</filename> history is blended
825 with Yocto Project kernel changes.
826 You can form ranges by using branch names from the
827 kernel tree as the upper and lower commit markers with
828 the Git commands.
829 You can see the branch names through the web interface
830 to the Yocto Project source repositories at
831 <ulink url='http://git.yoctoproject.org/cgit.cgi'></ulink>.
832 </note>
833 To see a full range of the changes, use the
834 <filename>git whatchanged</filename> command and specify a
835 commit range for the branch
836 (<filename>&lt;commit&gt;..&lt;commit&gt;</filename>).
837 </para>
838
839 <para>
840 Here is an example that looks at what has changed in the
841 <filename>emenlow</filename> branch of the
842 <filename>linux-yocto-3.4</filename> kernel.
843 The lower commit range is the commit associated with the
844 <filename>standard/base</filename> branch, while
845 the upper commit range is the commit associated with the
846 <filename>standard/emenlow</filename> branch.
847 <literallayout class='monospaced'>
848 $ git whatchanged origin/standard/base..origin/standard/emenlow
849 </literallayout>
850 </para>
851
852 <para>
853 To see short, one line summaries of changes use the
854 <filename>git log</filename> command:
855 <literallayout class='monospaced'>
856 $ git log --oneline origin/standard/base..origin/standard/emenlow
857 </literallayout>
858 </para>
859
860 <para>
861 Use this command to see code differences for the changes:
862 <literallayout class='monospaced'>
863 $ git diff origin/standard/base..origin/standard/emenlow
864 </literallayout>
865 </para>
866
867 <para>
868 Use this command to see the commit log messages and the
869 text differences:
870 <literallayout class='monospaced'>
871 $ git show origin/standard/base..origin/standard/emenlow
872 </literallayout>
873 </para>
874
875 <para>
876 Use this command to create individual patches for
877 each change.
878 Here is an example that that creates patch files for each
879 commit and places them in your <filename>Documents</filename>
880 directory:
881 <literallayout class='monospaced'>
882 $ git format-patch -o $HOME/Documents origin/standard/base..origin/standard/emenlow
883 </literallayout>
884 </para>
885 </section>
886
887 <section id='showing-a-particular-feature-or-branch-change'>
888 <title>Showing a Particular Feature or Branch Change</title>
889
890 <para>
891 Tags in the Yocto Project kernel tree divide changes for
892 significant features or branches.
893 The <filename>git show &lt;tag&gt;</filename> command shows
894 changes based on a tag.
895 Here is an example that shows <filename>systemtap</filename>
896 changes:
897 <literallayout class='monospaced'>
898 $ git show systemtap
899 </literallayout>
900 You can use the
901 <filename>git branch --contains &lt;tag&gt;</filename> command
902 to show the branches that contain a particular feature.
903 This command shows the branches that contain the
904 <filename>systemtap</filename> feature:
905 <literallayout class='monospaced'>
906 $ git branch --contains systemtap
907 </literallayout>
908 </para>
909 </section>
910 </section>
911</chapter>
912<!--
913vim: expandtab tw=80 ts=4
914-->