advanced.rst 35 KB

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