blob: 9e15f178a6cde47b1c82e9731c8a0748c83e0b6c [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-advanced'>
6<title>Working with Advanced Metadata</title>
7
8<section id='kernel-dev-advanced-overview'>
9 <title>Overview</title>
10
11 <para>
12 In addition to supporting configuration fragments and patches, the
13 Yocto Project kernel tools also support rich
14 <ulink url='&YOCTO_DOCS_DEV_URL;#metadata'>Metadata</ulink> that you can
15 use to define complex policies and Board Support Package (BSP) support.
16 The purpose of the Metadata and the tools that manage it, known as
17 the kern-tools (<filename>kern-tools-native_git.bb</filename>), is
18 to help you manage the complexity of the configuration and sources
19 used to support multiple BSPs and Linux kernel types.
20 </para>
21</section>
22
23<section id='using-kernel-metadata-in-a-recipe'>
24 <title>Using Kernel Metadata in a Recipe</title>
25
26 <para>
27 The kernel sources in the Yocto Project contain kernel Metadata, which
28 is located in the <filename>meta</filename> branches of the kernel
29 source Git repositories.
30 This Metadata defines Board Support Packages (BSPs) that
31 correspond to definitions in linux-yocto recipes for the same BSPs.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050032 A BSP consists of an aggregation of kernel policy and enabled
33 hardware-specific features.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034 The BSP can be influenced from within the linux-yocto recipe.
35 <note>
36 Linux kernel source that contains kernel Metadata is said to be
37 "linux-yocto style" kernel source.
38 A Linux kernel recipe that inherits from the
39 <filename>linux-yocto.inc</filename> include file is said to be a
40 "linux-yocto style" recipe.
41 </note>
42 </para>
43
44 <para>
45 Every linux-yocto style recipe must define the
46 <ulink url='&YOCTO_DOCS_REF_URL;#var-KMACHINE'><filename>KMACHINE</filename></ulink>
47 variable.
48 This variable is typically set to the same value as the
49 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
50 variable, which is used by
51 <ulink url='&YOCTO_DOCS_DEV_URL;#bitbake-term'>BitBake</ulink>.
52 However, in some cases, the variable might instead refer to the
53 underlying platform of the <filename>MACHINE</filename>.
54 </para>
55
56 <para>
57 Multiple BSPs can reuse the same <filename>KMACHINE</filename>
58 name if they are built using the same BSP description.
59 The "ep108-zynqmp" and "qemuzynqmp" BSP combination
60 in the <filename>meta-xilinx</filename>
61 layer is a good example of two BSPs using the same
62 <filename>KMACHINE</filename> value (i.e. "zynqmp").
63 See the <link linkend='bsp-descriptions'>BSP Descriptions</link> section
64 for more information.
65 </para>
66
67 <para>
68 Every linux-yocto style recipe must also indicate the Linux kernel
69 source repository branch used to build the Linux kernel.
70 The <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'><filename>KBRANCH</filename></ulink>
71 variable must be set to indicate the branch.
72 <note>
73 You can use the <filename>KBRANCH</filename> value to define an
74 alternate branch typically with a machine override as shown here
75 from the <filename>meta-emenlow</filename> layer:
76 <literallayout class='monospaced'>
77 KBRANCH_emenlow-noemgd = "standard/base"
78 </literallayout>
79 </note>
80 </para>
81
82 <para>
83 The linux-yocto style recipes can optionally define the following
84 variables:
85 <literallayout class='monospaced'>
86 <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_FEATURES'>KERNEL_FEATURES</ulink>
87 <ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_KERNEL_TYPE'>LINUX_KERNEL_TYPE</ulink>
88 </literallayout>
89 </para>
90
91 <para>
92 <filename>LINUX_KERNEL_TYPE</filename> defines the kernel type to be
93 used in assembling the configuration.
94 If you do not specify a <filename>LINUX_KERNEL_TYPE</filename>,
95 it defaults to "standard".
96 Together with
97 <ulink url='&YOCTO_DOCS_REF_URL;#var-KMACHINE'><filename>KMACHINE</filename></ulink>,
98 <filename>LINUX_KERNEL_TYPE</filename> defines the search
99 arguments used by the kernel tools to find the
100 appropriate description within the kernel Metadata with which to
101 build out the sources and configuration.
102 The linux-yocto recipes define "standard", "tiny", and "preempt-rt"
103 kernel types.
104 See the "<link linkend='kernel-types'>Kernel Types</link>" section
105 for more information on kernel types.
106 </para>
107
108 <para>
109 During the build, the kern-tools search for the BSP description
110 file that most closely matches the <filename>KMACHINE</filename>
111 and <filename>LINUX_KERNEL_TYPE</filename> variables passed in from the
112 recipe.
113 The tools use the first BSP description it finds that match
114 both variables.
115 If the tools cannot find a match, they issue a warning such as
116 the following:
117 <literallayout class='monospaced'>
118 WARNING: Can't find any BSP hardware or required configuration fragments.
119 WARNING: Looked at meta/cfg/broken/emenlow-broken/hdw_frags.txt and
120 meta/cfg/broken/emenlow-broken/required_frags.txt in directory:
121 meta/cfg/broken/emenlow-broken
122 </literallayout>
123 In this example, <filename>KMACHINE</filename> was set to "emenlow-broken"
124 and <filename>LINUX_KERNEL_TYPE</filename> was set to "broken".
125 </para>
126
127 <para>
128 The tools first search for the <filename>KMACHINE</filename> and
129 then for the <filename>LINUX_KERNEL_TYPE</filename>.
130 If the tools cannot find a partial match, they will use the
131 sources from the <filename>KBRANCH</filename> and any configuration
132 specified in the
133 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
134 </para>
135
136 <para>
137 You can use the <filename>KERNEL_FEATURES</filename> variable
138 to include features (configuration fragments, patches, or both) that
139 are not already included by the <filename>KMACHINE</filename> and
140 <filename>LINUX_KERNEL_TYPE</filename> variable combination.
141 For example, to include a feature specified as
142 "features/netfilter/netfilter.scc",
143 specify:
144 <literallayout class='monospaced'>
145 KERNEL_FEATURES += "features/netfilter/netfilter.scc"
146 </literallayout>
147 To include a feature called "cfg/sound.scc" just for the
148 <filename>qemux86</filename> machine, specify:
149 <literallayout class='monospaced'>
150 KERNEL_FEATURES_append_qemux86 = " cfg/sound.scc"
151 </literallayout>
152 The value of the entries in <filename>KERNEL_FEATURES</filename>
153 are dependent on their location within the kernel Metadata itself.
154 The examples here are taken from the <filename>meta</filename>
155 branch of the <filename>linux-yocto-3.19</filename> repository.
156 Within that branch, "features" and "cfg" are subdirectories of the
157 <filename>meta/cfg/kernel-cache</filename> directory.
158 For more information, see the
159 "<link linkend='kernel-metadata-syntax'>Kernel Metadata Syntax</link>" section.
160 <note>
161 The processing of the these variables has evolved some between the
162 0.9 and 1.3 releases of the Yocto Project and associated
163 kern-tools sources.
164 The descriptions in this section are accurate for 1.3 and later
165 releases of the Yocto Project.
166 </note>
167 </para>
168</section>
169
170<section id='kernel-metadata-location'>
171 <title>Kernel Metadata Location</title>
172
173 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500174 Kernel Metadata always exists outside of the kernel tree either
175 defined in a kernel recipe (recipe-space) or outside of the recipe.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500176 Where you choose to define the Metadata depends on what you want
177 to do and how you intend to work.
178 Regardless of where you define the kernel Metadata, the syntax used
179 applies equally.
180 </para>
181
182 <para>
183 If you are unfamiliar with the Linux kernel and only wish
184 to apply a configuration and possibly a couple of patches provided to
185 you by others, the recipe-space method is recommended.
186 This method is also a good approach if you are working with Linux kernel
187 sources you do not control or if you just do not want to maintain a
188 Linux kernel Git repository on your own.
189 For partial information on how you can define kernel Metadata in
190 the recipe-space, see the
191 "<link linkend='modifying-an-existing-recipe'>Modifying an Existing Recipe</link>"
192 section.
193 </para>
194
195 <para>
196 Conversely, if you are actively developing a kernel and are already
197 maintaining a Linux kernel Git repository of your own, you might find
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500198 it more convenient to work with kernel Metadata kept outside the
199 recipe-space.
200 Working with Metadata in this area can make iterative development of
201 the Linux kernel more efficient outside of the BitBake environment.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500202 </para>
203
204 <section id='recipe-space-metadata'>
205 <title>Recipe-Space Metadata</title>
206
207 <para>
208 When stored in recipe-space, the kernel Metadata files reside in a
209 directory hierarchy below
210 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>.
211 For a linux-yocto recipe or for a Linux kernel recipe derived
212 by copying and modifying
213 <filename>oe-core/meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb</filename>
214 to a recipe in your layer, <filename>FILESEXTRAPATHS</filename>
215 is typically set to
216 <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>.
217 See the "<link linkend='modifying-an-existing-recipe'>Modifying an Existing Recipe</link>"
218 section for more information.
219 </para>
220
221 <para>
222 Here is an example that shows a trivial tree of kernel Metadata
223 stored in recipe-space within a BSP layer:
224 <literallayout class='monospaced'>
225 meta-<replaceable>my_bsp_layer</replaceable>/
226 `-- recipes-kernel
227 `-- linux
228 `-- linux-yocto
229 |-- bsp-standard.scc
230 |-- bsp.cfg
231 `-- standard.cfg
232 </literallayout>
233 </para>
234
235 <para>
236 When the Metadata is stored in recipe-space, you must take
237 steps to ensure BitBake has the necessary information to decide
238 what files to fetch and when they need to be fetched again.
239 It is only necessary to specify the <filename>.scc</filename>
240 files on the
241 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
242 BitBake parses them and fetches any files referenced in the
243 <filename>.scc</filename> files by the <filename>include</filename>,
244 <filename>patch</filename>, or <filename>kconf</filename> commands.
245 Because of this, it is necessary to bump the recipe
246 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
247 value when changing the content of files not explicitly listed
248 in the <filename>SRC_URI</filename>.
249 </para>
250 </section>
251
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500252 <section id='metadata-outside-the-recipe-space'>
253 <title>Metadata Outside the Recipe-Space</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500254
255 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500256 When stored outside of the recipe-space, the kernel Metadata
257 files reside in a separate repository.
258 The OpenEmbedded build system adds the Metadata to the build as
259 a "ktype=meta" repository through the
260 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
261 variable.
262 As an example, consider the following <filename>SRC_URI</filename>
263 statement from the <filename>linux-yocto_4.4.bb</filename>
264 kernel recipe:
265 <literallayout class='monospaced'>
266 SRC_URI = "git://git.yoctoproject.org/linux-yocto-4.4.git;name=machine;branch=${KBRANCH}; \
267 git://git.yoctoproject.org/yocto-kernel-cache;type=kmeta;name=meta;branch=yocto-4.4;destsuffix=${KMETA}"
268 </literallayout>
269 <filename>${KMETA}</filename>, in this context, is simply used to
270 name the directory into which the Git fetcher places the Metadata.
271 This behavior is no different than any multi-repository
272 <filename>SRC_URI</filename> statement used in a recipe.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500273 </para>
274
275 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500276 You can keep kernel Metadata in a "kernel-cache", which is a
277 directory containing configuration fragments.
278 As with any Metadata kept outside the recipe-space, you simply
279 need to use the <filename>SRC_URI</filename> statement with the
280 "type=kmeta" attribute.
281 Doing so makes the kernel Metadata available during the
282 configuration phase.
283 </para>
284
285<!--
286
287
288 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500289 Following is an example that shows how a trivial tree of Metadata
290 is stored in a custom Linux kernel Git repository:
291 <literallayout class='monospaced'>
292 meta/
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500293 `&dash;&dash; cfg
294 `&dash;&dash; kernel-cache
295 |&dash;&dash; bsp-standard.scc
296 |&dash;&dash; bsp.cfg
297 `&dash;&dash; standard.cfg
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500298 </literallayout>
299 </para>
300
301 <para>
302 To use a branch different from where the sources reside,
303 specify the branch in the <filename>KMETA</filename> variable
304 in your Linux kernel recipe.
305 Here is an example:
306 <literallayout class='monospaced'>
307 KMETA = "meta"
308 </literallayout>
309 To use the same branch as the sources, set
310 <filename>KMETA</filename> to an empty string:
311 <literallayout class='monospaced'>
312 KMETA = ""
313 </literallayout>
314 If you are working with your own sources and want to create an
315 orphan <filename>meta</filename> branch, use these commands
316 from within your Linux kernel Git repository:
317 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500318 $ git checkout &dash;&dash;orphan meta
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500319 $ git rm -rf .
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500320 $ git commit &dash;&dash;allow-empty -m "Create orphan meta branch"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500321 </literallayout>
322 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500323-->
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500324
325 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500326 If you modify the Metadata, you must not forget to update the
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500327 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
328 statements in the kernel's recipe.
329 In particular, you need to update the
330 <filename>SRCREV_meta</filename> variable to match the commit in
331 the <filename>KMETA</filename> branch you wish to use.
332 Changing the data in these branches and not updating the
333 <filename>SRCREV</filename> statements to match will cause the
334 build to fetch an older commit.
335 </para>
336 </section>
337</section>
338
339<section id='kernel-metadata-syntax'>
340 <title>Kernel Metadata Syntax</title>
341
342 <para>
343 The kernel Metadata consists of three primary types of files:
344 <filename>scc</filename>
345 <footnote>
346 <para>
347 <filename>scc</filename> stands for Series Configuration
348 Control, but the naming has less significance in the
349 current implementation of the tooling than it had in the
350 past.
351 Consider <filename>scc</filename> files to be description files.
352 </para>
353 </footnote>
354 description files, configuration fragments, and patches.
355 The <filename>scc</filename> files define variables and include or
356 otherwise reference any of the three file types.
357 The description files are used to aggregate all types of kernel
358 Metadata into
359 what ultimately describes the sources and the configuration required
360 to build a Linux kernel tailored to a specific machine.
361 </para>
362
363 <para>
364 The <filename>scc</filename> description files are used to define two
365 fundamental types of kernel Metadata:
366 <itemizedlist>
367 <listitem><para>Features</para></listitem>
368 <listitem><para>Board Support Packages (BSPs)</para></listitem>
369 </itemizedlist>
370 </para>
371
372 <para>
373 Features aggregate sources in the form of patches and configuration
374 fragments into a modular reusable unit.
375 You can use features to implement conceptually separate kernel
376 Metadata descriptions such as pure configuration fragments,
377 simple patches, complex features, and kernel types.
378 <link linkend='kernel-types'>Kernel types</link> define general
379 kernel features and policy to be reused in the BSPs.
380 </para>
381
382 <para>
383 BSPs define hardware-specific features and aggregate them with kernel
384 types to form the final description of what will be assembled and built.
385 </para>
386
387 <para>
388 While the kernel Metadata syntax does not enforce any logical
389 separation of configuration fragments, patches, features or kernel
390 types, best practices dictate a logical separation of these types
391 of Metadata.
392 The following Metadata file hierarchy is recommended:
393 <literallayout class='monospaced'>
394 <replaceable>base</replaceable>/
395 bsp/
396 cfg/
397 features/
398 ktypes/
399 patches/
400 </literallayout>
401 </para>
402
403 <para>
404 The <filename>bsp</filename> directory contains the
405 <link linkend='bsp-descriptions'>BSP descriptions</link>.
406 The remaining directories all contain "features".
407 Separating <filename>bsp</filename> from the rest of the structure
408 aids conceptualizing intended usage.
409 </para>
410
411 <para>
412 Use these guidelines to help place your <filename>scc</filename>
413 description files within the structure:
414 <itemizedlist>
415 <listitem><para>If your file contains
416 only configuration fragments, place the file in the
417 <filename>cfg</filename> directory.</para></listitem>
418 <listitem><para>If your file contains
419 only source-code fixes, place the file in the
420 <filename>patches</filename> directory.</para></listitem>
421 <listitem><para>If your file encapsulates
422 a major feature, often combining sources and configurations,
423 place the file in <filename>features</filename> directory.
424 </para></listitem>
425 <listitem><para>If your file aggregates
426 non-hardware configuration and patches in order to define a
427 base kernel policy or major kernel type to be reused across
428 multiple BSPs, place the file in <filename>ktypes</filename>
429 directory.
430 </para></listitem>
431 </itemizedlist>
432 </para>
433
434 <para>
435 These distinctions can easily become blurred - especially as
436 out-of-tree features slowly merge upstream over time.
437 Also, remember that how the description files are placed is
438 a purely logical organization and has no impact on the functionality
439 of the kernel Metadata.
440 There is no impact because all of <filename>cfg</filename>,
441 <filename>features</filename>, <filename>patches</filename>, and
442 <filename>ktypes</filename>, contain "features" as far as the kernel
443 tools are concerned.
444 </para>
445
446 <para>
447 Paths used in kernel Metadata files are relative to
448 <filename>&lt;base&gt;</filename>, which is either
449 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
450 if you are creating Metadata in
451 <link linkend='recipe-space-metadata'>recipe-space</link>,
452 or <filename>meta/cfg/kernel-cache/</filename> if you are creating
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500453 <link linkend='metadata-outside-the-recipe-space'>Metadata outside of the recipe-space</link>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500454 </para>
455
456 <section id='configuration'>
457 <title>Configuration</title>
458
459 <para>
460 The simplest unit of kernel Metadata is the configuration-only
461 feature.
462 This feature consists of one or more Linux kernel configuration
463 parameters in a configuration fragment file
464 (<filename>.cfg</filename>) and a <filename>.scc</filename> file
465 that describes the fragment.
466 </para>
467
468 <para>
469 The Symmetric Multi-Processing (SMP) fragment included in the
470 <filename>linux-yocto-3.19</filename> Git repository
471 consists of the following two files:
472 <literallayout class='monospaced'>
473 cfg/smp.scc:
474 define KFEATURE_DESCRIPTION "Enable SMP"
475 define KFEATURE_COMPATIBILITY all
476
477 kconf hardware smp.cfg
478
479 cfg/smp.cfg:
480 CONFIG_SMP=y
481 CONFIG_SCHED_SMT=y
482 # Increase default NR_CPUS from 8 to 64 so that platform with
483 # more than 8 processors can be all activated at boot time
484 CONFIG_NR_CPUS=64
485 </literallayout>
486 You can find information on configuration fragment files in the
487 "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-config-fragments'>Creating Configuration Fragments</ulink>"
488 section of the Yocto Project Development Manual and in
489 the "<link linkend='generating-configuration-files'>Generating Configuration Files</link>"
490 section earlier in this manual.
491 </para>
492
493 <para>
494 <ulink url='&YOCTO_DOCS_REF_URL;#var-KFEATURE_DESCRIPTION'><filename>KFEATURE_DESCRIPTION</filename></ulink>
495 provides a short description of the fragment.
496 Higher level kernel tools use this description.
497 </para>
498
499 <para>
500 The <filename>kconf</filename> command is used to include the
501 actual configuration fragment in an <filename>.scc</filename>
502 file, and the "hardware" keyword identifies the fragment as
503 being hardware enabling, as opposed to general policy,
504 which would use the "non-hardware" keyword.
505 The distinction is made for the benefit of the configuration
506 validation tools, which warn you if a hardware fragment
507 overrides a policy set by a non-hardware fragment.
508 <note>
509 The description file can include multiple
510 <filename>kconf</filename> statements, one per fragment.
511 </note>
512 </para>
513
514 <para>
515 As described in the
516 "<link linkend='generating-configuration-files'>Generating Configuration Files</link>"
517 section, you can use the following BitBake command to audit your
518 configuration:
519 <literallayout class='monospaced'>
520 $ bitbake linux-yocto -c kernel_configcheck -f
521 </literallayout>
522 </para>
523 </section>
524
525 <section id='patches'>
526 <title>Patches</title>
527
528 <para>
529 Patch descriptions are very similar to configuration fragment
530 descriptions, which are described in the previous section.
531 However, instead of a <filename>.cfg</filename> file, these
532 descriptions work with source patches.
533 </para>
534
535 <para>
536 A typical patch includes a description file and the patch itself:
537 <literallayout class='monospaced'>
538 patches/mypatch.scc:
539 patch mypatch.patch
540
541 patches/mypatch.patch:
542 <replaceable>typical-patch</replaceable>
543 </literallayout>
544 You can create the typical <filename>.patch</filename>
545 file using <filename>diff -Nurp</filename> or
546 <filename>git format-patch</filename>.
547 </para>
548
549 <para>
550 The description file can include multiple patch statements,
551 one per patch.
552 </para>
553 </section>
554
555 <section id='features'>
556 <title>Features</title>
557
558 <para>
559 Features are complex kernel Metadata types that consist
560 of configuration fragments (<filename>kconf</filename>), patches
561 (<filename>patch</filename>), and possibly other feature
562 description files (<filename>include</filename>).
563 </para>
564
565 <para>
566 Here is an example that shows a feature description file:
567 <literallayout class='monospaced'>
568 features/myfeature.scc
569 define KFEATURE_DESCRIPTION "Enable myfeature"
570
571 patch 0001-myfeature-core.patch
572 patch 0002-myfeature-interface.patch
573
574 include cfg/myfeature_dependency.scc
575 kconf non-hardware myfeature.cfg
576 </literallayout>
577 This example shows how the <filename>patch</filename> and
578 <filename>kconf</filename> commands are used as well as
579 how an additional feature description file is included.
580 </para>
581
582 <para>
583 Typically, features are less granular than configuration
584 fragments and are more likely than configuration fragments
585 and patches to be the types of things you want to specify
586 in the <filename>KERNEL_FEATURES</filename> variable of the
587 Linux kernel recipe.
588 See the "<link linkend='using-kernel-metadata-in-a-recipe'>Using Kernel Metadata in a Recipe</link>"
589 section earlier in the manual.
590 </para>
591 </section>
592
593 <section id='kernel-types'>
594 <title>Kernel Types</title>
595
596 <para>
597 A kernel type defines a high-level kernel policy by
598 aggregating non-hardware configuration fragments with
599 patches you want to use when building a Linux kernels of a
600 specific type.
601 Syntactically, kernel types are no different than features
602 as described in the "<link linkend='features'>Features</link>"
603 section.
604 The <filename>LINUX_KERNEL_TYPE</filename> variable in the kernel
605 recipe selects the kernel type.
606 See the "<link linkend='using-kernel-metadata-in-a-recipe'>Using Kernel Metadata in a Recipe</link>"
607 section for more information.
608 </para>
609
610 <para>
611 As an example, the <filename>linux-yocto-3.19</filename>
612 tree defines three kernel types: "standard",
613 "tiny", and "preempt-rt":
614 <itemizedlist>
615 <listitem><para>"standard":
616 Includes the generic Linux kernel policy of the Yocto
617 Project linux-yocto kernel recipes.
618 This policy includes, among other things, which file
619 systems, networking options, core kernel features, and
620 debugging and tracing options are supported.
621 </para></listitem>
622 <listitem><para>"preempt-rt":
623 Applies the <filename>PREEMPT_RT</filename>
624 patches and the configuration options required to
625 build a real-time Linux kernel.
626 This kernel type inherits from the "standard" kernel type.
627 </para></listitem>
628 <listitem><para>"tiny":
629 Defines a bare minimum configuration meant to serve as a
630 base for very small Linux kernels.
631 The "tiny" kernel type is independent from the "standard"
632 configuration.
633 Although the "tiny" kernel type does not currently include
634 any source changes, it might in the future.
635 </para></listitem>
636 </itemizedlist>
637 </para>
638
639 <para>
640 The "standard" kernel type is defined by
641 <filename>standard.scc</filename>:
642 <literallayout class='monospaced'>
643 # Include this kernel type fragment to get the standard features and
644 # configuration values.
645
646 # Include all standard features
647 include standard-nocfg.scc
648
649 kconf non-hardware standard.cfg
650
651 # individual cfg block section
652 include cfg/fs/devtmpfs.scc
653 include cfg/fs/debugfs.scc
654 include cfg/fs/btrfs.scc
655 include cfg/fs/ext2.scc
656 include cfg/fs/ext3.scc
657 include cfg/fs/ext4.scc
658
659 include cfg/net/ipv6.scc
660 include cfg/net/ip_nf.scc
661 include cfg/net/ip6_nf.scc
662 include cfg/net/bridge.scc
663 </literallayout>
664 </para>
665
666 <para>
667 As with any <filename>.scc</filename> file, a
668 kernel type definition can aggregate other
669 <filename>.scc</filename> files with
670 <filename>include</filename> commands.
671 These definitions can also directly pull in
672 configuration fragments and patches with the
673 <filename>kconf</filename> and <filename>patch</filename>
674 commands, respectively.
675 </para>
676
677 <note>
678 It is not strictly necessary to create a kernel type
679 <filename>.scc</filename> file.
680 The Board Support Package (BSP) file can implicitly define
681 the kernel type using a <filename>define
682 <ulink url='&YOCTO_DOCS_REF_URL;#var-KTYPE'>KTYPE</ulink> myktype</filename>
683 line.
684 See the "<link linkend='bsp-descriptions'>BSP Descriptions</link>"
685 section for more information.
686 </note>
687 </section>
688
689 <section id='bsp-descriptions'>
690 <title>BSP Descriptions</title>
691
692 <para>
693 BSP descriptions combine kernel types with hardware-specific
694 features.
695 The hardware-specific portion is typically defined
696 independently, and then aggregated with each supported kernel
697 type.
698 Consider this simple BSP description that supports the
699 <replaceable>mybsp</replaceable> machine:
700 <literallayout class='monospaced'>
701 <replaceable>mybsp</replaceable>.scc:
702 define KMACHINE <replaceable>mybsp</replaceable>
703 define KTYPE standard
704 define KARCH i386
705
706 kconf <replaceable>mybsp</replaceable>.cfg
707 </literallayout>
708 Every BSP description should define the
709 <ulink url='&YOCTO_DOCS_REF_URL;#var-KMACHINE'><filename>KMACHINE</filename></ulink>,
710 <ulink url='&YOCTO_DOCS_REF_URL;#var-KTYPE'><filename>KTYPE</filename></ulink>,
711 and <ulink url='&YOCTO_DOCS_REF_URL;#var-KARCH'><filename>KARCH</filename></ulink>
712 variables.
713 These variables allow the OpenEmbedded build system to identify
714 the description as meeting the criteria set by the recipe being
715 built.
716 This simple example supports the "mybsp" machine for the "standard"
717 kernel and the "i386" architecture.
718 </para>
719
720 <para>
721 Be aware that a hard link between the
722 <filename>KTYPE</filename> variable and a kernel type
723 description file does not exist.
724 Thus, if you do not have kernel types defined in your kernel
725 Metadata, you only need to ensure that the kernel recipe's
726 <ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_KERNEL_TYPE'><filename>LINUX_KERNEL_TYPE</filename></ulink>
727 variable and the <filename>KTYPE</filename> variable in the
728 BSP description file match.
729 <note>
730 Future versions of the tooling make the specification of
731 <filename>KTYPE</filename> in the BSP optional.
732 </note>
733 </para>
734
735 <para>
736 If you did want to separate your kernel policy from your
737 hardware configuration, you could do so by specifying a kernel
738 type, such as "standard" and including that description file
739 in the BSP description file.
740 See the "<link linkend='kernel-types'>Kernel Types</link>" section
741 for more information.
742 </para>
743
744 <para>
745 You might also have multiple hardware configurations that you
746 aggregate into a single hardware description file that you
747 could include in the BSP description file, rather than referencing
748 a single <filename>.cfg</filename> file.
749 Consider the following:
750 <literallayout class='monospaced'>
751 <replaceable>mybsp</replaceable>.scc:
752 define KMACHINE mybsp
753 define KTYPE standard
754 define KARCH i386
755
756 include standard.scc
757 include <replaceable>mybsp</replaceable>-hw.scc
758 </literallayout>
759 </para>
760
761 <para>
762 In the above example, <filename>standard.scc</filename>
763 aggregates all the configuration fragments, patches, and
764 features that make up your standard kernel policy whereas
765 <replaceable>mybsp</replaceable><filename>-hw.scc</filename>
766 aggregates all those necessary
767 to support the hardware available on the
768 <replaceable>mybsp</replaceable> machine.
769 For information on how to break a complete
770 <filename>.config</filename> file into the various
771 configuration fragments, see the
772 "<link linkend='generating-configuration-files'>Generating Configuration Files</link>"
773 section.
774 </para>
775
776 <para>
777 Many real-world examples are more complex.
778 Like any other <filename>.scc</filename> file, BSP
779 descriptions can aggregate features.
780 Consider the Minnow BSP definition from the
781 <filename>linux-yocto-3.19</filename>
782 Git repository:
783 <literallayout class='monospaced'>
784 minnow.scc:
785 include cfg/x86.scc
786 include features/eg20t/eg20t.scc
787 include cfg/dmaengine.scc
788 include features/power/intel.scc
789 include cfg/efi.scc
790 include features/usb/ehci-hcd.scc
791 include features/usb/ohci-hcd.scc
792 include features/usb/usb-gadgets.scc
793 include features/usb/touchscreen-composite.scc
794 include cfg/timer/hpet.scc
795 include cfg/timer/rtc.scc
796 include features/leds/leds.scc
797 include features/spi/spidev.scc
798 include features/i2c/i2cdev.scc
799
800 # Earlyprintk and port debug requires 8250
801 kconf hardware cfg/8250.cfg
802
803 kconf hardware minnow.cfg
804 kconf hardware minnow-dev.cfg
805 </literallayout>
806 </para>
807
808 <para>
809 The <filename>minnow.scc</filename> description file includes
810 a hardware configuration fragment
811 (<filename>minnow.cfg</filename>) specific to the Minnow
812 BSP as well as several more general configuration
813 fragments and features enabling hardware found on the
814 machine.
815 This description file is then included in each of the three
816 "minnow" description files for the supported kernel types
817 (i.e. "standard", "preempt-rt", and "tiny").
818 Consider the "minnow" description for the "standard" kernel
819 type:
820 <literallayout class='monospaced'>
821 minnow-standard.scc:
822 define KMACHINE minnow
823 define KTYPE standard
824 define KARCH i386
825
826 include ktypes/standard
827
828 include minnow.scc
829
830 # Extra minnow configs above the minimal defined in minnow.scc
831 include cfg/efi-ext.scc
832 include features/media/media-all.scc
833 include features/sound/snd_hda_intel.scc
834
835 # The following should really be in standard.scc
836 # USB live-image support
837 include cfg/usb-mass-storage.scc
838 include cfg/boot-live.scc
839
840 # Basic profiling
841 include features/latencytop/latencytop.scc
842 include features/profiling/profiling.scc
843
844 # Requested drivers that don't have an existing scc
845 kconf hardware minnow-drivers-extra.cfg
846 </literallayout>
847 The <filename>include</filename> command midway through the file
848 includes the <filename>minnow.scc</filename> description that
849 defines all hardware enablements for the BSP that is common to all
850 kernel types.
851 Using this command significantly reduces duplication.
852 </para>
853
854 <para>
855 Now consider the "minnow" description for the "tiny" kernel type:
856 <literallayout class='monospaced'>
857 minnow-tiny.scc:
858 define KMACHINE minnow
859 define KTYPE tiny
860 define KARCH i386
861
862 include ktypes/tiny
863
864 include minnow.scc
865 </literallayout>
866 As you might expect, the "tiny" description includes quite a
867 bit less.
868 In fact, it includes only the minimal policy defined by the
869 "tiny" kernel type and the hardware-specific configuration required
870 for booting the machine along with the most basic functionality of
871 the system as defined in the base "minnow" description file.
872 </para>
873
874 <para>
875 Notice again the three critical variables:
876 <filename>KMACHINE</filename>, <filename>KTYPE</filename>,
877 and <filename>KARCH</filename>.
878 Of these variables, only the <filename>KTYPE</filename> has changed.
879 It is now set to "tiny".
880 </para>
881 </section>
882</section>
883
884<section id='organizing-your-source'>
885 <title>Organizing Your Source</title>
886
887 <para>
888 Many recipes based on the <filename>linux-yocto-custom.bb</filename>
889 recipe use Linux kernel sources that have only a single
890 branch - "master".
891 This type of repository structure is fine for linear development
892 supporting a single machine and architecture.
893 However, if you work with multiple boards and architectures,
894 a kernel source repository with multiple branches is more
895 efficient.
896 For example, suppose you need a series of patches for one board to boot.
897 Sometimes, these patches are works-in-progress or fundamentally wrong,
898 yet they are still necessary for specific boards.
899 In these situations, you most likely do not want to include these
900 patches in every kernel you build (i.e. have the patches as part of
901 the lone "master" branch).
902 It is situations like these that give rise to multiple branches used
903 within a Linux kernel sources Git repository.
904 </para>
905
906 <para>
907 Repository organization strategies exist that maximize source reuse,
908 remove redundancy, and logically order your changes.
909 This section presents strategies for the following cases:
910 <itemizedlist>
911 <listitem><para>Encapsulating patches in a feature description
912 and only including the patches in the BSP descriptions of
913 the applicable boards.</para></listitem>
914 <listitem><para>Creating a machine branch in your
915 kernel source repository and applying the patches on that
916 branch only.</para></listitem>
917 <listitem><para>Creating a feature branch in your
918 kernel source repository and merging that branch into your
919 BSP when needed.</para></listitem>
920 </itemizedlist>
921 </para>
922
923 <para>
924 The approach you take is entirely up to you
925 and depends on what works best for your development model.
926 </para>
927
928 <section id='encapsulating-patches'>
929 <title>Encapsulating Patches</title>
930
931 <para>
932 if you are reusing patches from an external tree and are not
933 working on the patches, you might find the encapsulated feature
934 to be appropriate.
935 Given this scenario, you do not need to create any branches in the
936 source repository.
937 Rather, you just take the static patches you need and encapsulate
938 them within a feature description.
939 Once you have the feature description, you simply include that into
940 the BSP description as described in the
941 "<link linkend='bsp-descriptions'>BSP Descriptions</link>"
942 section.
943 </para>
944
945 <para>
946 You can find information on how to create patches and BSP
947 descriptions in the "<link linkend='patches'>Patches</link>" and
948 "<link linkend='bsp-descriptions'>BSP Descriptions</link>"
949 sections.
950 </para>
951 </section>
952
953 <section id='machine-branches'>
954 <title>Machine Branches</title>
955
956 <para>
957 When you have multiple machines and architectures to support,
958 or you are actively working on board support, it is more
959 efficient to create branches in the repository based on
960 individual machines.
961 Having machine branches allows common source to remain in the
962 "master" branch with any features specific to a machine stored
963 in the appropriate machine branch.
964 This organization method frees you from continually reintegrating
965 your patches into a feature.
966 </para>
967
968 <para>
969 Once you have a new branch, you can set up your kernel Metadata
970 to use the branch a couple different ways.
971 In the recipe, you can specify the new branch as the
972 <filename>KBRANCH</filename> to use for the board as
973 follows:
974 <literallayout class='monospaced'>
975 KBRANCH = "mynewbranch"
976 </literallayout>
977 Another method is to use the <filename>branch</filename> command
978 in the BSP description:
979 <literallayout class='monospaced'>
980 mybsp.scc:
981 define KMACHINE mybsp
982 define KTYPE standard
983 define KARCH i386
984 include standard.scc
985
986 branch mynewbranch
987
988 include mybsp-hw.scc
989 </literallayout>
990 </para>
991
992 <para>
993 If you find
994 yourself with numerous branches, you might consider using a
995 hierarchical branching system similar to what the linux-yocto Linux
996 kernel repositories use:
997 <literallayout class='monospaced'>
998 <replaceable>common</replaceable>/<replaceable>kernel_type</replaceable>/<replaceable>machine</replaceable>
999 </literallayout>
1000 </para>
1001
1002 <para>
1003 If you had two kernel types, "standard" and "small" for
1004 instance, three machines, and <replaceable>common</replaceable>
1005 as <filename>mydir</filename>, the branches in your
1006 Git repository might look like this:
1007 <literallayout class='monospaced'>
1008 mydir/base
1009 mydir/standard/base
1010 mydir/standard/machine_a
1011 mydir/standard/machine_b
1012 mydir/standard/machine_c
1013 mydir/small/base
1014 mydir/small/machine_a
1015 </literallayout>
1016 </para>
1017
1018 <para>
1019 This organization can help clarify the branch relationships.
1020 In this case, <filename>mydir/standard/machine_a</filename>
1021 includes everything in <filename>mydir/base</filename> and
1022 <filename>mydir/standard/base</filename>.
1023 The "standard" and "small" branches add sources specific to those
1024 kernel types that for whatever reason are not appropriate for the
1025 other branches.
1026 <note>The "base" branches are an artifact of the way Git manages
1027 its data internally on the filesystem: Git will not allow you
1028 to use <filename>mydir/standard</filename> and
1029 <filename>mydir/standard/machine_a</filename> because it
1030 would have to create a file and a directory named "standard".
1031 </note>
1032 </para>
1033 </section>
1034
1035 <section id='feature-branches'>
1036 <title>Feature Branches</title>
1037
1038 <para>
1039 When you are actively developing new features, it can be more
1040 efficient to work with that feature as a branch, rather than
1041 as a set of patches that have to be regularly updated.
1042 The Yocto Project Linux kernel tools provide for this with
1043 the <filename>git merge</filename> command.
1044 </para>
1045
1046 <para>
1047 To merge a feature branch into a BSP, insert the
1048 <filename>git merge</filename> command after any
1049 <filename>branch</filename> commands:
1050 <literallayout class='monospaced'>
1051 mybsp.scc:
1052 define KMACHINE mybsp
1053 define KTYPE standard
1054 define KARCH i386
1055 include standard.scc
1056
1057 branch mynewbranch
1058 git merge myfeature
1059
1060 include mybsp-hw.scc
1061 </literallayout>
1062 </para>
1063 </section>
1064</section>
1065
1066<section id='scc-reference'>
1067 <title>SCC Description File Reference</title>
1068
1069 <para>
1070 This section provides a brief reference for the commands you can use
1071 within an SCC description file (<filename>.scc</filename>):
1072 <itemizedlist>
1073 <listitem><para><filename>branch [ref]</filename>:
1074 Creates a new branch relative to the current branch
1075 (typically <filename>${KTYPE}</filename>) using
1076 the currently checked-out branch, or "ref" if specified.
1077 </para></listitem>
1078 <listitem><para><filename>define</filename>:
1079 Defines variables, such as <filename>KMACHINE</filename>,
1080 <filename>KTYPE</filename>, <filename>KARCH</filename>,
1081 and <filename>KFEATURE_DESCRIPTION</filename>.</para></listitem>
1082 <listitem><para><filename>include SCC_FILE</filename>:
1083 Includes an SCC file in the current file.
1084 The file is parsed as if you had inserted it inline.
1085 </para></listitem>
1086 <listitem><para><filename>kconf [hardware|non-hardware] CFG_FILE</filename>:
1087 Queues a configuration fragment for merging into the final
1088 Linux <filename>.config</filename> file.</para></listitem>
1089 <listitem><para><filename>git merge GIT_BRANCH</filename>:
1090 Merges the feature branch into the current branch.
1091 </para></listitem>
1092 <listitem><para><filename>patch PATCH_FILE</filename>:
1093 Applies the patch to the current Git branch.</para></listitem>
1094 </itemizedlist>
1095 </para>
1096</section>
1097
1098</chapter>
1099<!--
1100vim: expandtab tw=80 ts=4
1101-->