blob: 444037c3a7968c88a90c7e050d84559a11fe3897 [file] [log] [blame]
Andrew Geisslerf0343792020-11-18 10:42:21 -06001.. SPDX-License-Identifier: CC-BY-SA-2.0-UK
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002
3*******************************************************
4Working with Advanced Metadata (``yocto-kernel-cache``)
5*******************************************************
6
7.. _kernel-dev-advanced-overview:
8
9Overview
10========
11
12In addition to supporting configuration fragments and patches, the Yocto
13Project kernel tools also support rich
14:term:`Metadata` that you can use to define
15complex policies and Board Support Package (BSP) support. The purpose of
16the Metadata and the tools that manage it is to help you manage the
17complexity of the configuration and sources used to support multiple
18BSPs and Linux kernel types.
19
20Kernel Metadata exists in many places. One area in the
21:ref:`overview-manual/overview-manual-development-environment:yocto project source repositories`
22is the ``yocto-kernel-cache`` Git repository. You can find this repository
23grouped under the "Yocto Linux Kernel" heading in the
24:yocto_git:`Yocto Project Source Repositories <>`.
25
26Kernel development tools ("kern-tools") exist also in the Yocto Project
27Source Repositories under the "Yocto Linux Kernel" heading in the
28``yocto-kernel-tools`` Git repository. The recipe that builds these
29tools is ``meta/recipes-kernel/kern-tools/kern-tools-native_git.bb`` in
30the :term:`Source Directory` (e.g.
31``poky``).
32
33Using Kernel Metadata in a Recipe
34=================================
35
36As mentioned in the introduction, the Yocto Project contains kernel
37Metadata, which is located in the ``yocto-kernel-cache`` Git repository.
38This Metadata defines Board Support Packages (BSPs) that correspond to
39definitions in linux-yocto recipes for corresponding BSPs. A BSP
40consists of an aggregation of kernel policy and enabled
41hardware-specific features. The BSP can be influenced from within the
42linux-yocto recipe.
43
44.. note::
45
46 A Linux kernel recipe that contains kernel Metadata (e.g. inherits
Andrew Geissler4c19ea12020-10-27 13:52:24 -050047 from the ``linux-yocto.inc`` file) is said to be a "linux-yocto style" recipe.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050048
49Every linux-yocto style recipe must define the
50:term:`KMACHINE` variable. This
51variable is typically set to the same value as the ``MACHINE`` variable,
52which is used by :term:`BitBake`.
53However, in some cases, the variable might instead refer to the
54underlying platform of the ``MACHINE``.
55
56Multiple BSPs can reuse the same ``KMACHINE`` name if they are built
57using the same BSP description. Multiple Corei7-based BSPs could share
58the same "intel-corei7-64" value for ``KMACHINE``. It is important to
59realize that ``KMACHINE`` is just for kernel mapping, while ``MACHINE``
60is the machine type within a BSP Layer. Even with this distinction,
61however, these two variables can hold the same value. See the `BSP
62Descriptions <#bsp-descriptions>`__ section for more information.
63
64Every linux-yocto style recipe must also indicate the Linux kernel
65source repository branch used to build the Linux kernel. The
66:term:`KBRANCH` variable must be set
67to indicate the branch.
68
69.. note::
70
Andrew Geissler4c19ea12020-10-27 13:52:24 -050071 You can use the ``KBRANCH`` value to define an alternate branch typically
72 with a machine override as shown here from the ``meta-yocto-bsp`` layer:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050073 ::
74
75 KBRANCH_edgerouter = "standard/edgerouter"
76
77
78The linux-yocto style recipes can optionally define the following
79variables:
80
81 - :term:`KERNEL_FEATURES`
82
83 - :term:`LINUX_KERNEL_TYPE`
84
85:term:`LINUX_KERNEL_TYPE`
86defines the kernel type to be used in assembling the configuration. If
87you do not specify a ``LINUX_KERNEL_TYPE``, it defaults to "standard".
88Together with ``KMACHINE``, ``LINUX_KERNEL_TYPE`` defines the search
89arguments used by the kernel tools to find the appropriate description
90within the kernel Metadata with which to build out the sources and
91configuration. The linux-yocto recipes define "standard", "tiny", and
92"preempt-rt" kernel types. See the "`Kernel Types <#kernel-types>`__"
93section for more information on kernel types.
94
95During the build, the kern-tools search for the BSP description file
96that most closely matches the ``KMACHINE`` and ``LINUX_KERNEL_TYPE``
97variables passed in from the recipe. The tools use the first BSP
Andrew Geissler4c19ea12020-10-27 13:52:24 -050098description they find that matches both variables. If the tools cannot find
Andrew Geisslerc9f78652020-09-18 14:11:35 -050099a match, they issue a warning.
100
101The tools first search for the ``KMACHINE`` and then for the
102``LINUX_KERNEL_TYPE``. If the tools cannot find a partial match, they
103will use the sources from the ``KBRANCH`` and any configuration
104specified in the :term:`SRC_URI`.
105
106You can use the
107:term:`KERNEL_FEATURES`
108variable to include features (configuration fragments, patches, or both)
109that are not already included by the ``KMACHINE`` and
110``LINUX_KERNEL_TYPE`` variable combination. For example, to include a
111feature specified as "features/netfilter/netfilter.scc", specify:
112::
113
114 KERNEL_FEATURES += "features/netfilter/netfilter.scc"
115
116To include a
117feature called "cfg/sound.scc" just for the ``qemux86`` machine,
118specify:
119::
120
121 KERNEL_FEATURES_append_qemux86 = " cfg/sound.scc"
122
123The value of
124the entries in ``KERNEL_FEATURES`` are dependent on their location
125within the kernel Metadata itself. The examples here are taken from the
126``yocto-kernel-cache`` repository. Each branch of this repository
127contains "features" and "cfg" subdirectories at the top-level. For more
128information, see the "`Kernel Metadata
129Syntax <#kernel-metadata-syntax>`__" section.
130
131Kernel Metadata Syntax
132======================
133
134The kernel Metadata consists of three primary types of files: ``scc``
135[1]_ description files, configuration fragments, and patches. The
136``scc`` files define variables and include or otherwise reference any of
137the three file types. The description files are used to aggregate all
138types of kernel Metadata into what ultimately describes the sources and
139the configuration required to build a Linux kernel tailored to a
140specific machine.
141
142The ``scc`` description files are used to define two fundamental types
143of kernel Metadata:
144
145- Features
146
147- Board Support Packages (BSPs)
148
149Features aggregate sources in the form of patches and configuration
150fragments into a modular reusable unit. You can use features to
151implement conceptually separate kernel Metadata descriptions such as
152pure configuration fragments, simple patches, complex features, and
153kernel types. `Kernel types <#kernel-types>`__ define general kernel
154features and policy to be reused in the BSPs.
155
156BSPs define hardware-specific features and aggregate them with kernel
157types to form the final description of what will be assembled and built.
158
159While the kernel Metadata syntax does not enforce any logical separation
160of configuration fragments, patches, features or kernel types, best
161practices dictate a logical separation of these types of Metadata. The
162following Metadata file hierarchy is recommended:
163::
164
165 base/
166 bsp/
167 cfg/
168 features/
169 ktypes/
170 patches/
171
172The ``bsp`` directory contains the `BSP
173descriptions <#bsp-descriptions>`__. The remaining directories all
174contain "features". Separating ``bsp`` from the rest of the structure
175aids conceptualizing intended usage.
176
177Use these guidelines to help place your ``scc`` description files within
178the structure:
179
180- If your file contains only configuration fragments, place the file in
181 the ``cfg`` directory.
182
183- If your file contains only source-code fixes, place the file in the
184 ``patches`` directory.
185
186- If your file encapsulates a major feature, often combining sources
187 and configurations, place the file in ``features`` directory.
188
189- If your file aggregates non-hardware configuration and patches in
190 order to define a base kernel policy or major kernel type to be
191 reused across multiple BSPs, place the file in ``ktypes`` directory.
192
193These distinctions can easily become blurred - especially as out-of-tree
194features slowly merge upstream over time. Also, remember that how the
195description files are placed is a purely logical organization and has no
196impact on the functionality of the kernel Metadata. There is no impact
197because all of ``cfg``, ``features``, ``patches``, and ``ktypes``,
198contain "features" as far as the kernel tools are concerned.
199
200Paths used in kernel Metadata files are relative to base, which is
201either
202:term:`FILESEXTRAPATHS` if
203you are creating Metadata in `recipe-space <#recipe-space-metadata>`__,
204or the top level of
205:yocto_git:`yocto-kernel-cache </cgit/cgit.cgi/yocto-kernel-cache/tree/>`
206if you are creating `Metadata outside of the
207recipe-space <#metadata-outside-the-recipe-space>`__.
208
209.. [1]
210 ``scc`` stands for Series Configuration Control, but the naming has
211 less significance in the current implementation of the tooling than
212 it had in the past. Consider ``scc`` files to be description files.
213
214Configuration
215-------------
216
217The simplest unit of kernel Metadata is the configuration-only feature.
218This feature consists of one or more Linux kernel configuration
219parameters in a configuration fragment file (``.cfg``) and a ``.scc``
220file that describes the fragment.
221
222As an example, consider the Symmetric Multi-Processing (SMP) fragment
223used with the ``linux-yocto-4.12`` kernel as defined outside of the
224recipe space (i.e. ``yocto-kernel-cache``). This Metadata consists of
225two files: ``smp.scc`` and ``smp.cfg``. You can find these files in the
226``cfg`` directory of the ``yocto-4.12`` branch in the
227``yocto-kernel-cache`` Git repository:
228::
229
230 cfg/smp.scc:
231 define KFEATURE_DESCRIPTION "Enable SMP for 32 bit builds"
232 define KFEATURE_COMPATIBILITY all
233
234 kconf hardware smp.cfg
235
236 cfg/smp.cfg:
237 CONFIG_SMP=y
238 CONFIG_SCHED_SMT=y
239 # Increase default NR_CPUS from 8 to 64 so that platform with
240 # more than 8 processors can be all activated at boot time
241 CONFIG_NR_CPUS=64
242 # The following is needed when setting NR_CPUS to something
243 # greater than 8 on x86 architectures, it should be automatically
244 # disregarded by Kconfig when using a different arch
245 CONFIG_X86_BIGSMP=y
246
247You can find general information on configuration
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500248fragment files in the ":ref:`creating-config-fragments`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500249
250Within the ``smp.scc`` file, the
251:term:`KFEATURE_DESCRIPTION`
252statement provides a short description of the fragment. Higher level
253kernel tools use this description.
254
255Also within the ``smp.scc`` file, the ``kconf`` command includes the
256actual configuration fragment in an ``.scc`` file, and the "hardware"
257keyword identifies the fragment as being hardware enabling, as opposed
258to general policy, which would use the "non-hardware" keyword. The
259distinction is made for the benefit of the configuration validation
260tools, which warn you if a hardware fragment overrides a policy set by a
261non-hardware fragment.
262
263.. note::
264
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500265 The description file can include multiple ``kconf`` statements, one per
266 fragment.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500267
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500268As described in the
269":ref:`kernel-dev/kernel-dev-common:validating configuration`" section, you can
270use the following BitBake command to audit your configuration:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500271::
272
273 $ bitbake linux-yocto -c kernel_configcheck -f
274
275Patches
276-------
277
278Patch descriptions are very similar to configuration fragment
279descriptions, which are described in the previous section. However,
280instead of a ``.cfg`` file, these descriptions work with source patches
281(i.e. ``.patch`` files).
282
283A typical patch includes a description file and the patch itself. As an
284example, consider the build patches used with the ``linux-yocto-4.12``
285kernel as defined outside of the recipe space (i.e.
286``yocto-kernel-cache``). This Metadata consists of several files:
287``build.scc`` and a set of ``*.patch`` files. You can find these files
288in the ``patches/build`` directory of the ``yocto-4.12`` branch in the
289``yocto-kernel-cache`` Git repository.
290
291The following listings show the ``build.scc`` file and part of the
292``modpost-mask-trivial-warnings.patch`` file:
293::
294
295 patches/build/build.scc:
296 patch arm-serialize-build-targets.patch
297 patch powerpc-serialize-image-targets.patch
298 patch kbuild-exclude-meta-directory-from-distclean-processi.patch
299
300 # applied by kgit
301 # patch kbuild-add-meta-files-to-the-ignore-li.patch
302
303 patch modpost-mask-trivial-warnings.patch
304 patch menuconfig-check-lxdiaglog.sh-Allow-specification-of.patch
305
306 patches/build/modpost-mask-trivial-warnings.patch:
307 From bd48931bc142bdd104668f3a062a1f22600aae61 Mon Sep 17 00:00:00 2001
308 From: Paul Gortmaker <paul.gortmaker@windriver.com>
309 Date: Sun, 25 Jan 2009 17:58:09 -0500
310 Subject: [PATCH] modpost: mask trivial warnings
311
312 Newer HOSTCC will complain about various stdio fcns because
313 .
314 .
315 .
316 char *dump_write = NULL, *files_source = NULL;
317 int opt;
318 --
319 2.10.1
320
321 generated by cgit v0.10.2 at 2017-09-28 15:23:23 (GMT)
322
323The description file can
324include multiple patch statements where each statement handles a single
325patch. In the example ``build.scc`` file, five patch statements exist
326for the five patches in the directory.
327
328You can create a typical ``.patch`` file using ``diff -Nurp`` or
329``git format-patch`` commands. For information on how to create patches,
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500330see the ":ref:`kernel-dev/kernel-dev-common:using \`\`devtool\`\` to patch the kernel`"
331and ":ref:`kernel-dev/kernel-dev-common:using traditional kernel development to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500332sections.
333
334Features
335--------
336
337Features are complex kernel Metadata types that consist of configuration
338fragments, patches, and possibly other feature description files. As an
339example, consider the following generic listing:
340::
341
342 features/myfeature.scc
343 define KFEATURE_DESCRIPTION "Enable myfeature"
344
345 patch 0001-myfeature-core.patch
346 patch 0002-myfeature-interface.patch
347
348 include cfg/myfeature_dependency.scc
349 kconf non-hardware myfeature.cfg
350
351This example shows how the ``patch`` and ``kconf`` commands are used as well
352as how an additional feature description file is included with the
353``include`` command.
354
355Typically, features are less granular than configuration fragments and
356are more likely than configuration fragments and patches to be the types
357of things you want to specify in the ``KERNEL_FEATURES`` variable of the
358Linux kernel recipe. See the "`Using Kernel Metadata in a
359Recipe <#using-kernel-metadata-in-a-recipe>`__" section earlier in the
360manual.
361
362Kernel Types
363------------
364
365A kernel type defines a high-level kernel policy by aggregating
366non-hardware configuration fragments with patches you want to use when
367building a Linux kernel of a specific type (e.g. a real-time kernel).
368Syntactically, kernel types are no different than features as described
369in the "`Features <#features>`__" section. The
370:term:`LINUX_KERNEL_TYPE`
371variable in the kernel recipe selects the kernel type. For example, in
372the ``linux-yocto_4.12.bb`` kernel recipe found in
373``poky/meta/recipes-kernel/linux``, a
374:ref:`require <bitbake:require-inclusion>` directive
375includes the ``poky/meta/recipes-kernel/linux/linux-yocto.inc`` file,
376which has the following statement that defines the default kernel type:
377::
378
379 LINUX_KERNEL_TYPE ??= "standard"
380
381Another example would be the real-time kernel (i.e.
382``linux-yocto-rt_4.12.bb``). This kernel recipe directly sets the kernel
383type as follows:
384::
385
386 LINUX_KERNEL_TYPE = "preempt-rt"
387
388.. note::
389
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500390 You can find kernel recipes in the ``meta/recipes-kernel/linux`` directory
391 of the :ref:`overview-manual/overview-manual-development-environment:yocto project source repositories`
392 (e.g. ``poky/meta/recipes-kernel/linux/linux-yocto_4.12.bb``). See the
393 ":ref:`kernel-dev/kernel-dev-advanced:using kernel metadata in a recipe`"
394 section for more information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500395
396Three kernel types ("standard", "tiny", and "preempt-rt") are supported
397for Linux Yocto kernels:
398
399- "standard": Includes the generic Linux kernel policy of the Yocto
400 Project linux-yocto kernel recipes. This policy includes, among other
401 things, which file systems, networking options, core kernel features,
402 and debugging and tracing options are supported.
403
404- "preempt-rt": Applies the ``PREEMPT_RT`` patches and the
405 configuration options required to build a real-time Linux kernel.
406 This kernel type inherits from the "standard" kernel type.
407
408- "tiny": Defines a bare minimum configuration meant to serve as a base
409 for very small Linux kernels. The "tiny" kernel type is independent
410 from the "standard" configuration. Although the "tiny" kernel type
411 does not currently include any source changes, it might in the
412 future.
413
414For any given kernel type, the Metadata is defined by the ``.scc`` (e.g.
415``standard.scc``). Here is a partial listing for the ``standard.scc``
416file, which is found in the ``ktypes/standard`` directory of the
417``yocto-kernel-cache`` Git repository:
418::
419
420 # Include this kernel type fragment to get the standard features and
421 # configuration values.
422
423 # Note: if only the features are desired, but not the configuration
424 # then this should be included as:
425 # include ktypes/standard/standard.scc nocfg
426 # if no chained configuration is desired, include it as:
427 # include ktypes/standard/standard.scc nocfg inherit
428
429
430
431 include ktypes/base/base.scc
432 branch standard
433
434 kconf non-hardware standard.cfg
435
436 include features/kgdb/kgdb.scc
437 .
438 .
439 .
440
441 include cfg/net/ip6_nf.scc
442 include cfg/net/bridge.scc
443
444 include cfg/systemd.scc
445
446 include features/rfkill/rfkill.scc
447
448As with any ``.scc`` file, a kernel type definition can aggregate other
449``.scc`` files with ``include`` commands. These definitions can also
450directly pull in configuration fragments and patches with the ``kconf``
451and ``patch`` commands, respectively.
452
453.. note::
454
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500455 It is not strictly necessary to create a kernel type ``.scc``
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500456 file. The Board Support Package (BSP) file can implicitly define the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500457 kernel type using a ``define`` :term:`KTYPE` ``myktype`` line. See the
458 ":ref:`kernel-dev/kernel-dev-advanced:bsp descriptions`" section for more
459 information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500460
461BSP Descriptions
462----------------
463
464BSP descriptions (i.e. ``*.scc`` files) combine kernel types with
465hardware-specific features. The hardware-specific Metadata is typically
466defined independently in the BSP layer, and then aggregated with each
467supported kernel type.
468
469.. note::
470
471 For BSPs supported by the Yocto Project, the BSP description files
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500472 are located in the ``bsp`` directory of the ``yocto-kernel-cache``
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500473 repository organized under the "Yocto Linux Kernel" heading in the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500474 :yocto_git:`Yocto Project Source Repositories </>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500475
476This section overviews the BSP description structure, the aggregation
477concepts, and presents a detailed example using a BSP supported by the
478Yocto Project (i.e. BeagleBone Board). For complete information on BSP
479layer file hierarchy, see the :doc:`../bsp-guide/bsp-guide`.
480
481.. _bsp-description-file-overview:
482
483Description Overview
484~~~~~~~~~~~~~~~~~~~~
485
486For simplicity, consider the following root BSP layer description files
487for the BeagleBone board. These files employ both a structure and naming
488convention for consistency. The naming convention for the file is as
489follows:
490::
491
492 bsp_root_name-kernel_type.scc
493
494Here are some example root layer
495BSP filenames for the BeagleBone Board BSP, which is supported by the
496Yocto Project:
497::
498
499 beaglebone-standard.scc
500 beaglebone-preempt-rt.scc
501
502Each file uses the root name (i.e "beaglebone") BSP name followed by the
503kernel type.
504
505Examine the ``beaglebone-standard.scc`` file:
506::
507
508 define KMACHINE beaglebone
509 define KTYPE standard
510 define KARCH arm
511
512 include ktypes/standard/standard.scc
513 branch beaglebone
514
515 include beaglebone.scc
516
517 # default policy for standard kernels
518 include features/latencytop/latencytop.scc
519 include features/profiling/profiling.scc
520
521Every top-level BSP description file
522should define the :term:`KMACHINE`,
523:term:`KTYPE`, and
524:term:`KARCH` variables. These
525variables allow the OpenEmbedded build system to identify the
526description as meeting the criteria set by the recipe being built. This
527example supports the "beaglebone" machine for the "standard" kernel and
528the "arm" architecture.
529
530Be aware that a hard link between the ``KTYPE`` variable and a kernel
531type description file does not exist. Thus, if you do not have the
532kernel type defined in your kernel Metadata as it is here, you only need
533to ensure that the
534:term:`LINUX_KERNEL_TYPE`
535variable in the kernel recipe and the ``KTYPE`` variable in the BSP
536description file match.
537
538To separate your kernel policy from your hardware configuration, you
539include a kernel type (``ktype``), such as "standard". In the previous
540example, this is done using the following:
541::
542
543 include ktypes/standard/standard.scc
544
545This file aggregates all the configuration
546fragments, patches, and features that make up your standard kernel
547policy. See the "`Kernel Types <#kernel-types>`__" section for more
548information.
549
550To aggregate common configurations and features specific to the kernel
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500551for `mybsp`, use the following:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500552::
553
554 include mybsp.scc
555
556You can see that in the BeagleBone example with the following:
557::
558
559 include beaglebone.scc
560
561For information on how to break a complete ``.config`` file into the various
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500562configuration fragments, see the ":ref:`creating-config-fragments`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500563
564Finally, if you have any configurations specific to the hardware that
565are not in a ``*.scc`` file, you can include them as follows:
566::
567
568 kconf hardware mybsp-extra.cfg
569
570The BeagleBone example does not include these
571types of configurations. However, the Malta 32-bit board does
572("mti-malta32"). Here is the ``mti-malta32-le-standard.scc`` file:
573::
574
575 define KMACHINE mti-malta32-le
576 define KMACHINE qemumipsel
577 define KTYPE standard
578 define KARCH mips
579
580 include ktypes/standard/standard.scc
581 branch mti-malta32
582
583 include mti-malta32.scc
584 kconf hardware mti-malta32-le.cfg
585
586.. _bsp-description-file-example-minnow:
587
588Example
589~~~~~~~
590
591Many real-world examples are more complex. Like any other ``.scc`` file,
592BSP descriptions can aggregate features. Consider the Minnow BSP
593definition given the ``linux-yocto-4.4`` branch of the
594``yocto-kernel-cache`` (i.e.
595``yocto-kernel-cache/bsp/minnow/minnow.scc``):
596
597.. note::
598
599 Although the Minnow Board BSP is unused, the Metadata remains and is
600 being used here just as an example.
601
602::
603
604 include cfg/x86.scc
605 include features/eg20t/eg20t.scc
606 include cfg/dmaengine.scc
607 include features/power/intel.scc
608 include cfg/efi.scc
609 include features/usb/ehci-hcd.scc
610 include features/usb/ohci-hcd.scc
611 include features/usb/usb-gadgets.scc
612 include features/usb/touchscreen-composite.scc
613 include cfg/timer/hpet.scc
614 include features/leds/leds.scc
615 include features/spi/spidev.scc
616 include features/i2c/i2cdev.scc
617 include features/mei/mei-txe.scc
618
619 # Earlyprintk and port debug requires 8250
620 kconf hardware cfg/8250.cfg
621
622 kconf hardware minnow.cfg
623 kconf hardware minnow-dev.cfg
624
625The ``minnow.scc`` description file includes a hardware configuration
626fragment (``minnow.cfg``) specific to the Minnow BSP as well as several
627more general configuration fragments and features enabling hardware
628found on the machine. This ``minnow.scc`` description file is then
629included in each of the three "minnow" description files for the
630supported kernel types (i.e. "standard", "preempt-rt", and "tiny").
631Consider the "minnow" description for the "standard" kernel type (i.e.
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500632``minnow-standard.scc``):
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500633::
634
635 define KMACHINE minnow
636 define KTYPE standard
637 define KARCH i386
638
639 include ktypes/standard
640
641 include minnow.scc
642
643 # Extra minnow configs above the minimal defined in minnow.scc
644 include cfg/efi-ext.scc
645 include features/media/media-all.scc
646 include features/sound/snd_hda_intel.scc
647
648 # The following should really be in standard.scc
649 # USB live-image support
650 include cfg/usb-mass-storage.scc
651 include cfg/boot-live.scc
652
653 # Basic profiling
654 include features/latencytop/latencytop.scc
655 include features/profiling/profiling.scc
656
657 # Requested drivers that don't have an existing scc
658 kconf hardware minnow-drivers-extra.cfg
659
660The ``include`` command midway through the file includes the ``minnow.scc`` description
661that defines all enabled hardware for the BSP that is common to all
662kernel types. Using this command significantly reduces duplication.
663
664Now consider the "minnow" description for the "tiny" kernel type (i.e.
665``minnow-tiny.scc``):
666::
667
668 define KMACHINE minnow
669 define KTYPE tiny
670 define KARCH i386
671
672 include ktypes/tiny
673
674 include minnow.scc
675
676As you might expect,
677the "tiny" description includes quite a bit less. In fact, it includes
678only the minimal policy defined by the "tiny" kernel type and the
679hardware-specific configuration required for booting the machine along
680with the most basic functionality of the system as defined in the base
681"minnow" description file.
682
683Notice again the three critical variables:
684:term:`KMACHINE`,
685:term:`KTYPE`, and
686:term:`KARCH`. Of these variables, only
687``KTYPE`` has changed to specify the "tiny" kernel type.
688
689Kernel Metadata Location
690========================
691
692Kernel Metadata always exists outside of the kernel tree either defined
693in a kernel recipe (recipe-space) or outside of the recipe. Where you
694choose to define the Metadata depends on what you want to do and how you
695intend to work. Regardless of where you define the kernel Metadata, the
696syntax used applies equally.
697
698If you are unfamiliar with the Linux kernel and only wish to apply a
699configuration and possibly a couple of patches provided to you by
700others, the recipe-space method is recommended. This method is also a
701good approach if you are working with Linux kernel sources you do not
702control or if you just do not want to maintain a Linux kernel Git
703repository on your own. For partial information on how you can define
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500704kernel Metadata in the recipe-space, see the
705":ref:`kernel-dev/kernel-dev-common:modifying an existing recipe`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500706
707Conversely, if you are actively developing a kernel and are already
708maintaining a Linux kernel Git repository of your own, you might find it
709more convenient to work with kernel Metadata kept outside the
710recipe-space. Working with Metadata in this area can make iterative
711development of the Linux kernel more efficient outside of the BitBake
712environment.
713
714Recipe-Space Metadata
715---------------------
716
717When stored in recipe-space, the kernel Metadata files reside in a
718directory hierarchy below
719:term:`FILESEXTRAPATHS`. For
720a linux-yocto recipe or for a Linux kernel recipe derived by copying and
721modifying
722``oe-core/meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb`` to
723a recipe in your layer, ``FILESEXTRAPATHS`` is typically set to
724``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``.
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500725See the ":ref:`kernel-dev/kernel-dev-common:modifying an existing recipe`"
726section for more information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500727
728Here is an example that shows a trivial tree of kernel Metadata stored
729in recipe-space within a BSP layer:
730::
731
732 meta-my_bsp_layer/
733 `-- recipes-kernel
734 `-- linux
735 `-- linux-yocto
736 |-- bsp-standard.scc
737 |-- bsp.cfg
738 `-- standard.cfg
739
740When the Metadata is stored in recipe-space, you must take steps to
741ensure BitBake has the necessary information to decide what files to
742fetch and when they need to be fetched again. It is only necessary to
743specify the ``.scc`` files on the
744:term:`SRC_URI`. BitBake parses them
745and fetches any files referenced in the ``.scc`` files by the
746``include``, ``patch``, or ``kconf`` commands. Because of this, it is
747necessary to bump the recipe :term:`PR`
748value when changing the content of files not explicitly listed in the
749``SRC_URI``.
750
751If the BSP description is in recipe space, you cannot simply list the
752``*.scc`` in the ``SRC_URI`` statement. You need to use the following
753form from your kernel append file:
754::
755
756 SRC_URI_append_myplatform = " \
757 file://myplatform;type=kmeta;destsuffix=myplatform \
758 "
759
760Metadata Outside the Recipe-Space
761---------------------------------
762
763When stored outside of the recipe-space, the kernel Metadata files
764reside in a separate repository. The OpenEmbedded build system adds the
765Metadata to the build as a "type=kmeta" repository through the
766:term:`SRC_URI` variable. As an
767example, consider the following ``SRC_URI`` statement from the
768``linux-yocto_4.12.bb`` kernel recipe:
769::
770
771 SRC_URI = "git://git.yoctoproject.org/linux-yocto-4.12.git;name=machine;branch=${KBRANCH}; \
772 git://git.yoctoproject.org/yocto-kernel-cache;type=kmeta;name=meta;branch=yocto-4.12;destsuffix=${KMETA}"
773
774
775``${KMETA}``, in this context, is simply used to name the directory into
776which the Git fetcher places the Metadata. This behavior is no different
777than any multi-repository ``SRC_URI`` statement used in a recipe (e.g.
778see the previous section).
779
780You can keep kernel Metadata in a "kernel-cache", which is a directory
781containing configuration fragments. As with any Metadata kept outside
782the recipe-space, you simply need to use the ``SRC_URI`` statement with
783the "type=kmeta" attribute. Doing so makes the kernel Metadata available
784during the configuration phase.
785
786If you modify the Metadata, you must not forget to update the ``SRCREV``
787statements in the kernel's recipe. In particular, you need to update the
788``SRCREV_meta`` variable to match the commit in the ``KMETA`` branch you
789wish to use. Changing the data in these branches and not updating the
790``SRCREV`` statements to match will cause the build to fetch an older
791commit.
792
793Organizing Your Source
794======================
795
796Many recipes based on the ``linux-yocto-custom.bb`` recipe use Linux
797kernel sources that have only a single branch - "master". This type of
798repository structure is fine for linear development supporting a single
799machine and architecture. However, if you work with multiple boards and
800architectures, a kernel source repository with multiple branches is more
801efficient. For example, suppose you need a series of patches for one
802board to boot. Sometimes, these patches are works-in-progress or
803fundamentally wrong, yet they are still necessary for specific boards.
804In these situations, you most likely do not want to include these
805patches in every kernel you build (i.e. have the patches as part of the
806lone "master" branch). It is situations like these that give rise to
807multiple branches used within a Linux kernel sources Git repository.
808
809Repository organization strategies exist that maximize source reuse,
810remove redundancy, and logically order your changes. This section
811presents strategies for the following cases:
812
813- Encapsulating patches in a feature description and only including the
814 patches in the BSP descriptions of the applicable boards.
815
816- Creating a machine branch in your kernel source repository and
817 applying the patches on that branch only.
818
819- Creating a feature branch in your kernel source repository and
820 merging that branch into your BSP when needed.
821
822The approach you take is entirely up to you and depends on what works
823best for your development model.
824
825Encapsulating Patches
826---------------------
827
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500828If you are reusing patches from an external tree and are not working on
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500829the patches, you might find the encapsulated feature to be appropriate.
830Given this scenario, you do not need to create any branches in the
831source repository. Rather, you just take the static patches you need and
832encapsulate them within a feature description. Once you have the feature
833description, you simply include that into the BSP description as
834described in the "`BSP Descriptions <#bsp-descriptions>`__" section.
835
836You can find information on how to create patches and BSP descriptions
837in the "`Patches <#patches>`__" and "`BSP
838Descriptions <#bsp-descriptions>`__" sections.
839
840Machine Branches
841----------------
842
843When you have multiple machines and architectures to support, or you are
844actively working on board support, it is more efficient to create
845branches in the repository based on individual machines. Having machine
846branches allows common source to remain in the "master" branch with any
847features specific to a machine stored in the appropriate machine branch.
848This organization method frees you from continually reintegrating your
849patches into a feature.
850
851Once you have a new branch, you can set up your kernel Metadata to use
852the branch a couple different ways. In the recipe, you can specify the
853new branch as the ``KBRANCH`` to use for the board as follows:
854::
855
856 KBRANCH = "mynewbranch"
857
858Another method is to use the ``branch`` command in the BSP
859description:
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500860::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500861
862 mybsp.scc:
863 define KMACHINE mybsp
864 define KTYPE standard
865 define KARCH i386
866 include standard.scc
867
868 branch mynewbranch
869
870 include mybsp-hw.scc
871
872If you find yourself with numerous branches, you might consider using a
873hierarchical branching system similar to what the Yocto Linux Kernel Git
874repositories use:
875::
876
877 common/kernel_type/machine
878
879If you had two kernel types, "standard" and "small" for instance, three
880machines, and common as ``mydir``, the branches in your Git repository
881might look like this:
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500882::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500883
884 mydir/base
885 mydir/standard/base
886 mydir/standard/machine_a
887 mydir/standard/machine_b
888 mydir/standard/machine_c
889 mydir/small/base
890 mydir/small/machine_a
891
892This organization can help clarify the branch relationships. In this
893case, ``mydir/standard/machine_a`` includes everything in ``mydir/base``
894and ``mydir/standard/base``. The "standard" and "small" branches add
895sources specific to those kernel types that for whatever reason are not
896appropriate for the other branches.
897
898.. note::
899
900 The "base" branches are an artifact of the way Git manages its data
901 internally on the filesystem: Git will not allow you to use
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500902 ``mydir/standard`` and ``mydir/standard/machine_a`` because it would have to
903 create a file and a directory named "standard".
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500904
905Feature Branches
906----------------
907
908When you are actively developing new features, it can be more efficient
909to work with that feature as a branch, rather than as a set of patches
910that have to be regularly updated. The Yocto Project Linux kernel tools
911provide for this with the ``git merge`` command.
912
913To merge a feature branch into a BSP, insert the ``git merge`` command
914after any ``branch`` commands:
915::
916
917 mybsp.scc:
918 define KMACHINE mybsp
919 define KTYPE standard
920 define KARCH i386
921 include standard.scc
922
923 branch mynewbranch
924 git merge myfeature
925
926 include mybsp-hw.scc
927
928.. _scc-reference:
929
930SCC Description File Reference
931==============================
932
933This section provides a brief reference for the commands you can use
934within an SCC description file (``.scc``):
935
936- ``branch [ref]``: Creates a new branch relative to the current branch
937 (typically ``${KTYPE}``) using the currently checked-out branch, or
938 "ref" if specified.
939
940- ``define``: Defines variables, such as
941 :term:`KMACHINE`,
942 :term:`KTYPE`,
943 :term:`KARCH`, and
944 :term:`KFEATURE_DESCRIPTION`.
945
946- ``include SCC_FILE``: Includes an SCC file in the current file. The
947 file is parsed as if you had inserted it inline.
948
949- ``kconf [hardware|non-hardware] CFG_FILE``: Queues a configuration
950 fragment for merging into the final Linux ``.config`` file.
951
952- ``git merge GIT_BRANCH``: Merges the feature branch into the current
953 branch.
954
955- ``patch PATCH_FILE``: Applies the patch to the current Git branch.
956
957