advanced.rst 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  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:edgerouter = "standard/edgerouter"
  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
  277. non-hardware configuration fragments with patches you want to use when
  278. building a Linux kernel of a specific type (e.g. a real-time kernel).
  279. Syntactically, kernel types are no different than features as described
  280. in the ":ref:`kernel-dev/advanced:features`" section. The
  281. :term:`LINUX_KERNEL_TYPE`
  282. variable in the kernel recipe selects the kernel type. For example, in
  283. the ``linux-yocto_4.12.bb`` kernel recipe found in
  284. ``poky/meta/recipes-kernel/linux``, a
  285. :ref:`require <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:\`\`require\`\` directive>` directive
  286. includes the ``poky/meta/recipes-kernel/linux/linux-yocto.inc`` file,
  287. which has the following statement that defines the default kernel type::
  288. LINUX_KERNEL_TYPE ??= "standard"
  289. Another example would be the real-time kernel (i.e.
  290. ``linux-yocto-rt_4.12.bb``). This kernel recipe directly sets the kernel
  291. type as follows::
  292. LINUX_KERNEL_TYPE = "preempt-rt"
  293. .. note::
  294. You can find kernel recipes in the ``meta/recipes-kernel/linux`` directory
  295. of the :ref:`overview-manual/development-environment:yocto project source repositories`
  296. (e.g. ``poky/meta/recipes-kernel/linux/linux-yocto_4.12.bb``). See the
  297. ":ref:`kernel-dev/advanced:using kernel metadata in a recipe`"
  298. section for more information.
  299. Three kernel types ("standard", "tiny", and "preempt-rt") are supported
  300. for Linux Yocto kernels:
  301. - "standard": Includes the generic Linux kernel policy of the Yocto
  302. Project linux-yocto kernel recipes. This policy includes, among other
  303. things, which file systems, networking options, core kernel features,
  304. and debugging and tracing options are supported.
  305. - "preempt-rt": Applies the ``PREEMPT_RT`` patches and the
  306. configuration options required to build a real-time Linux kernel.
  307. This kernel type inherits from the "standard" kernel type.
  308. - "tiny": Defines a bare minimum configuration meant to serve as a base
  309. for very small Linux kernels. The "tiny" kernel type is independent
  310. from the "standard" configuration. Although the "tiny" kernel type
  311. does not currently include any source changes, it might in the
  312. future.
  313. For any given kernel type, the Metadata is defined by the ``.scc`` (e.g.
  314. ``standard.scc``). Here is a partial listing for the ``standard.scc``
  315. file, which is found in the ``ktypes/standard`` directory of the
  316. ``yocto-kernel-cache`` Git repository::
  317. # Include this kernel type fragment to get the standard features and
  318. # configuration values.
  319. # Note: if only the features are desired, but not the configuration
  320. # then this should be included as:
  321. # include ktypes/standard/standard.scc nocfg
  322. # if no chained configuration is desired, include it as:
  323. # include ktypes/standard/standard.scc nocfg inherit
  324. include ktypes/base/base.scc
  325. branch standard
  326. kconf non-hardware standard.cfg
  327. include features/kgdb/kgdb.scc
  328. .
  329. .
  330. .
  331. include cfg/net/ip6_nf.scc
  332. include cfg/net/bridge.scc
  333. include cfg/systemd.scc
  334. include features/rfkill/rfkill.scc
  335. As with any ``.scc`` file, a kernel type definition can aggregate other
  336. ``.scc`` files with ``include`` commands. These definitions can also
  337. directly pull in configuration fragments and patches with the ``kconf``
  338. and ``patch`` commands, respectively.
  339. .. note::
  340. It is not strictly necessary to create a kernel type ``.scc``
  341. file. The Board Support Package (BSP) file can implicitly define the
  342. kernel type using a ``define`` :term:`KTYPE` ``myktype`` line. See the
  343. ":ref:`kernel-dev/advanced:bsp descriptions`" section for more
  344. information.
  345. BSP Descriptions
  346. ----------------
  347. BSP descriptions (i.e. ``*.scc`` files) combine kernel types with
  348. hardware-specific features. The hardware-specific Metadata is typically
  349. defined independently in the BSP layer, and then aggregated with each
  350. supported kernel type.
  351. .. note::
  352. For BSPs supported by the Yocto Project, the BSP description files
  353. are located in the ``bsp`` directory of the ``yocto-kernel-cache``
  354. repository organized under the "Yocto Linux Kernel" heading in the
  355. :yocto_git:`Yocto Project Source Repositories <>`.
  356. This section overviews the BSP description structure, the aggregation
  357. concepts, and presents a detailed example using a BSP supported by the
  358. Yocto Project (i.e. BeagleBone Board). For complete information on BSP
  359. layer file hierarchy, see the :doc:`/bsp-guide/index`.
  360. Description Overview
  361. ~~~~~~~~~~~~~~~~~~~~
  362. For simplicity, consider the following root BSP layer description files
  363. for the BeagleBone board. These files employ both a structure and naming
  364. convention for consistency. The naming convention for the file is as
  365. follows::
  366. bsp_root_name-kernel_type.scc
  367. Here are some example root layer
  368. BSP filenames for the BeagleBone Board BSP, which is supported by the
  369. Yocto Project::
  370. beaglebone-standard.scc
  371. beaglebone-preempt-rt.scc
  372. Each file uses the root name (i.e "beaglebone") BSP name followed by the
  373. kernel type.
  374. Examine the ``beaglebone-standard.scc`` file::
  375. define KMACHINE beaglebone
  376. define KTYPE standard
  377. define KARCH arm
  378. include ktypes/standard/standard.scc
  379. branch beaglebone
  380. include beaglebone.scc
  381. # default policy for standard kernels
  382. include features/latencytop/latencytop.scc
  383. include features/profiling/profiling.scc
  384. Every top-level BSP description file
  385. should define the :term:`KMACHINE`,
  386. :term:`KTYPE`, and
  387. :term:`KARCH` variables. These
  388. variables allow the OpenEmbedded build system to identify the
  389. description as meeting the criteria set by the recipe being built. This
  390. example supports the "beaglebone" machine for the "standard" kernel and
  391. the "arm" architecture.
  392. Be aware that there is no hard link between the :term:`KTYPE` variable and a kernel
  393. type description file. Thus, if you do not have the
  394. kernel type defined in your kernel Metadata as it is here, you only need
  395. to ensure that the
  396. :term:`LINUX_KERNEL_TYPE`
  397. variable in the kernel recipe and the :term:`KTYPE` variable in the BSP
  398. description file match.
  399. To separate your kernel policy from your hardware configuration, you
  400. include a kernel type (``ktype``), such as "standard". In the previous
  401. example, this is done using the following::
  402. include ktypes/standard/standard.scc
  403. This file aggregates all the configuration
  404. fragments, patches, and features that make up your standard kernel
  405. policy. See the ":ref:`kernel-dev/advanced:kernel types`" section for more
  406. information.
  407. To aggregate common configurations and features specific to the kernel
  408. for `mybsp`, use the following::
  409. include mybsp.scc
  410. You can see that in the BeagleBone example with the following::
  411. include beaglebone.scc
  412. For information on how to break a complete ``.config`` file into the various
  413. configuration fragments, see the ":ref:`kernel-dev/common:creating configuration fragments`" section.
  414. Finally, if you have any configurations specific to the hardware that
  415. are not in a ``*.scc`` file, you can include them as follows::
  416. kconf hardware mybsp-extra.cfg
  417. The BeagleBone example does not include these
  418. types of configurations. However, the Malta 32-bit board does
  419. ("mti-malta32"). Here is the ``mti-malta32-le-standard.scc`` file::
  420. define KMACHINE mti-malta32-le
  421. define KMACHINE qemumipsel
  422. define KTYPE standard
  423. define KARCH mips
  424. include ktypes/standard/standard.scc
  425. branch mti-malta32
  426. include mti-malta32.scc
  427. kconf hardware mti-malta32-le.cfg
  428. Example
  429. ~~~~~~~
  430. Many real-world examples are more complex. Like any other ``.scc`` file,
  431. BSP descriptions can aggregate features. Consider the Minnow BSP
  432. definition given the ``linux-yocto-4.4`` branch of the
  433. ``yocto-kernel-cache`` (i.e.
  434. ``yocto-kernel-cache/bsp/minnow/minnow.scc``):
  435. .. note::
  436. Although the Minnow Board BSP is unused, the Metadata remains and is
  437. being used here just as an example.
  438. ::
  439. include cfg/x86.scc
  440. include features/eg20t/eg20t.scc
  441. include cfg/dmaengine.scc
  442. include features/power/intel.scc
  443. include cfg/efi.scc
  444. include features/usb/ehci-hcd.scc
  445. include features/usb/ohci-hcd.scc
  446. include features/usb/usb-gadgets.scc
  447. include features/usb/touchscreen-composite.scc
  448. include cfg/timer/hpet.scc
  449. include features/leds/leds.scc
  450. include features/spi/spidev.scc
  451. include features/i2c/i2cdev.scc
  452. include features/mei/mei-txe.scc
  453. # Earlyprintk and port debug requires 8250
  454. kconf hardware cfg/8250.cfg
  455. kconf hardware minnow.cfg
  456. kconf hardware minnow-dev.cfg
  457. The ``minnow.scc`` description file includes a hardware configuration
  458. fragment (``minnow.cfg``) specific to the Minnow BSP as well as several
  459. more general configuration fragments and features enabling hardware
  460. found on the machine. This ``minnow.scc`` description file is then
  461. included in each of the three "minnow" description files for the
  462. supported kernel types (i.e. "standard", "preempt-rt", and "tiny").
  463. Consider the "minnow" description for the "standard" kernel type (i.e.
  464. ``minnow-standard.scc``)::
  465. define KMACHINE minnow
  466. define KTYPE standard
  467. define KARCH i386
  468. include ktypes/standard
  469. include minnow.scc
  470. # Extra minnow configs above the minimal defined in minnow.scc
  471. include cfg/efi-ext.scc
  472. include features/media/media-all.scc
  473. include features/sound/snd_hda_intel.scc
  474. # The following should really be in standard.scc
  475. # USB live-image support
  476. include cfg/usb-mass-storage.scc
  477. include cfg/boot-live.scc
  478. # Basic profiling
  479. include features/latencytop/latencytop.scc
  480. include features/profiling/profiling.scc
  481. # Requested drivers that don't have an existing scc
  482. kconf hardware minnow-drivers-extra.cfg
  483. The ``include`` command midway through the file includes the ``minnow.scc`` description
  484. that defines all enabled hardware for the BSP that is common to all
  485. kernel types. Using this command significantly reduces duplication.
  486. Now consider the "minnow" description for the "tiny" kernel type (i.e.
  487. ``minnow-tiny.scc``)::
  488. define KMACHINE minnow
  489. define KTYPE tiny
  490. define KARCH i386
  491. include ktypes/tiny
  492. include minnow.scc
  493. As you might expect,
  494. the "tiny" description includes quite a bit less. In fact, it includes
  495. only the minimal policy defined by the "tiny" kernel type and the
  496. hardware-specific configuration required for booting the machine along
  497. with the most basic functionality of the system as defined in the base
  498. "minnow" description file.
  499. Notice again the three critical variables:
  500. :term:`KMACHINE`,
  501. :term:`KTYPE`, and
  502. :term:`KARCH`. Of these variables, only
  503. :term:`KTYPE` has changed to specify the "tiny" kernel type.
  504. Kernel Metadata Location
  505. ========================
  506. Kernel Metadata always exists outside of the kernel tree either defined
  507. in a kernel recipe (recipe-space) or outside of the recipe. Where you
  508. choose to define the Metadata depends on what you want to do and how you
  509. intend to work. Regardless of where you define the kernel Metadata, the
  510. syntax used applies equally.
  511. If you are unfamiliar with the Linux kernel and only wish to apply a
  512. configuration and possibly a couple of patches provided to you by
  513. others, the recipe-space method is recommended. This method is also a
  514. good approach if you are working with Linux kernel sources you do not
  515. control or if you just do not want to maintain a Linux kernel Git
  516. repository on your own. For partial information on how you can define
  517. kernel Metadata in the recipe-space, see the
  518. ":ref:`kernel-dev/common:modifying an existing recipe`" section.
  519. Conversely, if you are actively developing a kernel and are already
  520. maintaining a Linux kernel Git repository of your own, you might find it
  521. more convenient to work with kernel Metadata kept outside the
  522. recipe-space. Working with Metadata in this area can make iterative
  523. development of the Linux kernel more efficient outside of the BitBake
  524. environment.
  525. Recipe-Space Metadata
  526. ---------------------
  527. When stored in recipe-space, the kernel Metadata files reside in a
  528. directory hierarchy below :term:`FILESEXTRAPATHS`. For
  529. a linux-yocto recipe or for a Linux kernel recipe derived by copying
  530. :oe_git:`meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb
  531. </openembedded-core/tree/meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb>`
  532. into your layer and modifying it, :term:`FILESEXTRAPATHS` is typically set to
  533. ``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``.
  534. See the ":ref:`kernel-dev/common:modifying an existing recipe`"
  535. section for more information.
  536. Here is an example that shows a trivial tree of kernel Metadata stored
  537. in recipe-space within a BSP layer::
  538. meta-my_bsp_layer/
  539. `-- recipes-kernel
  540. `-- linux
  541. `-- linux-yocto
  542. |-- bsp-standard.scc
  543. |-- bsp.cfg
  544. `-- standard.cfg
  545. When the Metadata is stored in recipe-space, you must take steps to
  546. ensure BitBake has the necessary information to decide what files to
  547. fetch and when they need to be fetched again. It is only necessary to
  548. specify the ``.scc`` files on the
  549. :term:`SRC_URI`. BitBake parses them
  550. and fetches any files referenced in the ``.scc`` files by the
  551. ``include``, ``patch``, or ``kconf`` commands. Because of this, it is
  552. necessary to bump the recipe :term:`PR`
  553. value when changing the content of files not explicitly listed in the
  554. :term:`SRC_URI`.
  555. If the BSP description is in recipe space, you cannot simply list the
  556. ``*.scc`` in the :term:`SRC_URI` statement. You need to use the following
  557. form from your kernel append file::
  558. SRC_URI:append:myplatform = " \
  559. file://myplatform;type=kmeta;destsuffix=myplatform \
  560. "
  561. Metadata Outside the Recipe-Space
  562. ---------------------------------
  563. When stored outside of the recipe-space, the kernel Metadata files
  564. reside in a separate repository. The OpenEmbedded build system adds the
  565. Metadata to the build as a "type=kmeta" repository through the
  566. :term:`SRC_URI` variable. As an
  567. example, consider the following :term:`SRC_URI` statement from the
  568. ``linux-yocto_4.12.bb`` kernel recipe::
  569. SRC_URI = "git://git.yoctoproject.org/linux-yocto-4.12.git;name=machine;branch=${KBRANCH}; \
  570. git://git.yoctoproject.org/yocto-kernel-cache;type=kmeta;name=meta;branch=yocto-4.12;destsuffix=${KMETA}"
  571. ``${KMETA}``, in this context, is simply used to name the directory into
  572. which the Git fetcher places the Metadata. This behavior is no different
  573. than any multi-repository :term:`SRC_URI` statement used in a recipe (e.g.
  574. see the previous section).
  575. You can keep kernel Metadata in a "kernel-cache", which is a directory
  576. containing configuration fragments. As with any Metadata kept outside
  577. the recipe-space, you simply need to use the :term:`SRC_URI` statement with
  578. the "type=kmeta" attribute. Doing so makes the kernel Metadata available
  579. during the configuration phase.
  580. If you modify the Metadata, you must not forget to update the :term:`SRCREV`
  581. statements in the kernel's recipe. In particular, you need to update the
  582. ``SRCREV_meta`` variable to match the commit in the ``KMETA`` branch you
  583. wish to use. Changing the data in these branches and not updating the
  584. :term:`SRCREV` statements to match will cause the build to fetch an older
  585. commit.
  586. Organizing Your Source
  587. ======================
  588. Many recipes based on the ``linux-yocto-custom.bb`` recipe use Linux
  589. kernel sources that have only a single branch. This type of
  590. repository structure is fine for linear development supporting a single
  591. machine and architecture. However, if you work with multiple boards and
  592. architectures, a kernel source repository with multiple branches is more
  593. efficient. For example, suppose you need a series of patches for one
  594. board to boot. Sometimes, these patches are works-in-progress or
  595. fundamentally wrong, yet they are still necessary for specific boards.
  596. In these situations, you most likely do not want to include these
  597. patches in every kernel you build (i.e. have the patches as part of the
  598. default branch). It is situations like these that give rise to
  599. multiple branches used within a Linux kernel sources Git repository.
  600. Here are repository organization strategies maximizing source reuse,
  601. removing redundancy, and logically ordering your changes. This section
  602. presents strategies for the following cases:
  603. - Encapsulating patches in a feature description and only including the
  604. patches in the BSP descriptions of the applicable boards.
  605. - Creating a machine branch in your kernel source repository and
  606. applying the patches on that branch only.
  607. - Creating a feature branch in your kernel source repository and
  608. merging that branch into your BSP when needed.
  609. The approach you take is entirely up to you and depends on what works
  610. best for your development model.
  611. Encapsulating Patches
  612. ---------------------
  613. If you are reusing patches from an external tree and are not working on
  614. the patches, you might find the encapsulated feature to be appropriate.
  615. Given this scenario, you do not need to create any branches in the
  616. source repository. Rather, you just take the static patches you need and
  617. encapsulate them within a feature description. Once you have the feature
  618. description, you simply include that into the BSP description as
  619. described in the ":ref:`kernel-dev/advanced:bsp descriptions`" section.
  620. You can find information on how to create patches and BSP descriptions
  621. in the ":ref:`kernel-dev/advanced:patches`" and
  622. ":ref:`kernel-dev/advanced:bsp descriptions`" sections.
  623. Machine Branches
  624. ----------------
  625. When you have multiple machines and architectures to support, or you are
  626. actively working on board support, it is more efficient to create
  627. branches in the repository based on individual machines. Having machine
  628. branches allows common source to remain in the development branch with any
  629. features specific to a machine stored in the appropriate machine branch.
  630. This organization method frees you from continually reintegrating your
  631. patches into a feature.
  632. Once you have a new branch, you can set up your kernel Metadata to use
  633. the branch a couple different ways. In the recipe, you can specify the
  634. new branch as the :term:`KBRANCH` to use for the board as follows::
  635. KBRANCH = "mynewbranch"
  636. Another method is to use the ``branch`` command in the BSP
  637. description::
  638. mybsp.scc:
  639. define KMACHINE mybsp
  640. define KTYPE standard
  641. define KARCH i386
  642. include standard.scc
  643. branch mynewbranch
  644. include mybsp-hw.scc
  645. If you find yourself with numerous branches, you might consider using a
  646. hierarchical branching system similar to what the Yocto Linux Kernel Git
  647. repositories use::
  648. common/kernel_type/machine
  649. If you had two kernel types, "standard" and "small" for instance, three
  650. machines, and common as ``mydir``, the branches in your Git repository
  651. might look like this::
  652. mydir/base
  653. mydir/standard/base
  654. mydir/standard/machine_a
  655. mydir/standard/machine_b
  656. mydir/standard/machine_c
  657. mydir/small/base
  658. mydir/small/machine_a
  659. This organization can help clarify the branch relationships. In this
  660. case, ``mydir/standard/machine_a`` includes everything in ``mydir/base``
  661. and ``mydir/standard/base``. The "standard" and "small" branches add
  662. sources specific to those kernel types that for whatever reason are not
  663. appropriate for the other branches.
  664. .. note::
  665. The "base" branches are an artifact of the way Git manages its data
  666. internally on the filesystem: Git will not allow you to use
  667. ``mydir/standard`` and ``mydir/standard/machine_a`` because it would have to
  668. create a file and a directory named "standard".
  669. Feature Branches
  670. ----------------
  671. When you are actively developing new features, it can be more efficient
  672. to work with that feature as a branch, rather than as a set of patches
  673. that have to be regularly updated. The Yocto Project Linux kernel tools
  674. provide for this with the ``git merge`` command.
  675. To merge a feature branch into a BSP, insert the ``git merge`` command
  676. after any ``branch`` commands::
  677. mybsp.scc:
  678. define KMACHINE mybsp
  679. define KTYPE standard
  680. define KARCH i386
  681. include standard.scc
  682. branch mynewbranch
  683. git merge myfeature
  684. include mybsp-hw.scc
  685. SCC Description File Reference
  686. ==============================
  687. This section provides a brief reference for the commands you can use
  688. within an SCC description file (``.scc``):
  689. - ``branch [ref]``: Creates a new branch relative to the current branch
  690. (typically ``${KTYPE}``) using the currently checked-out branch, or
  691. "ref" if specified.
  692. - ``define``: Defines variables, such as
  693. :term:`KMACHINE`,
  694. :term:`KTYPE`,
  695. :term:`KARCH`, and
  696. :term:`KFEATURE_DESCRIPTION`.
  697. - ``include SCC_FILE``: Includes an SCC file in the current file. The
  698. file is parsed as if you had inserted it inline.
  699. - ``kconf [hardware|non-hardware] CFG_FILE``: Queues a configuration
  700. fragment for merging into the final Linux ``.config`` file.
  701. - ``git merge GIT_BRANCH``: Merges the feature branch into the current
  702. branch.
  703. - ``patch PATCH_FILE``: Applies the patch to the current Git branch.