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