kernel-dev-concepts-appx.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. ************************
  3. Advanced Kernel Concepts
  4. ************************
  5. .. _kernel-big-picture:
  6. Yocto Project Kernel Development and Maintenance
  7. ================================================
  8. Kernels available through the Yocto Project (Yocto Linux kernels), like
  9. other kernels, are based off the Linux kernel releases from
  10. http://www.kernel.org. At the beginning of a major Linux kernel
  11. development cycle, the Yocto Project team chooses a Linux kernel based
  12. on factors such as release timing, the anticipated release timing of
  13. final upstream ``kernel.org`` versions, and Yocto Project feature
  14. requirements. Typically, the Linux kernel chosen is in the final stages
  15. of development by the Linux community. In other words, the Linux kernel
  16. is in the release candidate or "rc" phase and has yet to reach final
  17. release. But, by being in the final stages of external development, the
  18. team knows that the ``kernel.org`` final release will clearly be within
  19. the early stages of the Yocto Project development window.
  20. This balance allows the Yocto Project team to deliver the most
  21. up-to-date Yocto Linux kernel possible, while still ensuring that the
  22. team has a stable official release for the baseline Linux kernel
  23. version.
  24. As implied earlier, the ultimate source for Yocto Linux kernels are
  25. released kernels from ``kernel.org``. In addition to a foundational
  26. kernel from ``kernel.org``, the available Yocto Linux kernels contain a
  27. mix of important new mainline developments, non-mainline developments
  28. (when no alternative exists), Board Support Package (BSP) developments,
  29. and custom features. These additions result in a commercially released
  30. Yocto Project Linux kernel that caters to specific embedded designer
  31. needs for targeted hardware.
  32. You can find a web interface to the Yocto Linux kernels in the
  33. :ref:`overview-manual/overview-manual-development-environment:yocto project source repositories`
  34. at :yocto_git:`/`. If you look at the interface, you will see to
  35. the left a grouping of Git repositories titled "Yocto Linux Kernel".
  36. Within this group, you will find several Linux Yocto kernels developed
  37. and included with Yocto Project releases:
  38. - *linux-yocto-4.1:* The stable Yocto Project kernel to use with
  39. the Yocto Project Release 2.0. This kernel is based on the Linux 4.1
  40. released kernel.
  41. - *linux-yocto-4.4:* The stable Yocto Project kernel to use with
  42. the Yocto Project Release 2.1. This kernel is based on the Linux 4.4
  43. released kernel.
  44. - *linux-yocto-4.6:* A temporary kernel that is not tied to any
  45. Yocto Project release.
  46. - *linux-yocto-4.8:* The stable yocto Project kernel to use with
  47. the Yocto Project Release 2.2.
  48. - *linux-yocto-4.9:* The stable Yocto Project kernel to use with
  49. the Yocto Project Release 2.3. This kernel is based on the Linux 4.9
  50. released kernel.
  51. - *linux-yocto-4.10:* The default stable Yocto Project kernel to
  52. use with the Yocto Project Release 2.3. This kernel is based on the
  53. Linux 4.10 released kernel.
  54. - *linux-yocto-4.12:* The default stable Yocto Project kernel to
  55. use with the Yocto Project Release 2.4. This kernel is based on the
  56. Linux 4.12 released kernel.
  57. - *yocto-kernel-cache:* The ``linux-yocto-cache`` contains patches
  58. and configurations for the linux-yocto kernel tree. This repository
  59. is useful when working on the linux-yocto kernel. For more
  60. information on this "Advanced Kernel Metadata", see the
  61. ":doc:`kernel-dev-advanced`" Chapter.
  62. - *linux-yocto-dev:* A development kernel based on the latest
  63. upstream release candidate available.
  64. .. note::
  65. Long Term Support Initiative (LTSI) for Yocto Linux kernels is as
  66. follows:
  67. - For Yocto Project releases 1.7, 1.8, and 2.0, the LTSI kernel is
  68. ``linux-yocto-3.14``.
  69. - For Yocto Project releases 2.1, 2.2, and 2.3, the LTSI kernel is
  70. ``linux-yocto-4.1``.
  71. - For Yocto Project release 2.4, the LTSI kernel is
  72. ``linux-yocto-4.9``
  73. - ``linux-yocto-4.4`` is an LTS kernel.
  74. Once a Yocto Linux kernel is officially released, the Yocto Project team
  75. goes into their next development cycle, or upward revision (uprev)
  76. cycle, while still continuing maintenance on the released kernel. It is
  77. important to note that the most sustainable and stable way to include
  78. feature development upstream is through a kernel uprev process.
  79. Back-porting hundreds of individual fixes and minor features from
  80. various kernel versions is not sustainable and can easily compromise
  81. quality.
  82. During the uprev cycle, the Yocto Project team uses an ongoing analysis
  83. of Linux kernel development, BSP support, and release timing to select
  84. the best possible ``kernel.org`` Linux kernel version on which to base
  85. subsequent Yocto Linux kernel development. The team continually monitors
  86. Linux community kernel development to look for significant features of
  87. interest. The team does consider back-porting large features if they
  88. have a significant advantage. User or community demand can also trigger
  89. a back-port or creation of new functionality in the Yocto Project
  90. baseline kernel during the uprev cycle.
  91. Generally speaking, every new Linux kernel both adds features and
  92. introduces new bugs. These consequences are the basic properties of
  93. upstream Linux kernel development and are managed by the Yocto Project
  94. team's Yocto Linux kernel development strategy. It is the Yocto Project
  95. team's policy to not back-port minor features to the released Yocto
  96. Linux kernel. They only consider back-porting significant technological
  97. jumps DASH and, that is done after a complete gap analysis. The reason
  98. for this policy is that back-porting any small to medium sized change
  99. from an evolving Linux kernel can easily create mismatches,
  100. incompatibilities and very subtle errors.
  101. The policies described in this section result in both a stable and a
  102. cutting edge Yocto Linux kernel that mixes forward ports of existing
  103. Linux kernel features and significant and critical new functionality.
  104. Forward porting Linux kernel functionality into the Yocto Linux kernels
  105. available through the Yocto Project can be thought of as a "micro
  106. uprev." The many "micro uprevs" produce a Yocto Linux kernel version
  107. with a mix of important new mainline, non-mainline, BSP developments and
  108. feature integrations. This Yocto Linux kernel gives insight into new
  109. features and allows focused amounts of testing to be done on the kernel,
  110. which prevents surprises when selecting the next major uprev. The
  111. quality of these cutting edge Yocto Linux kernels is evolving and the
  112. kernels are used in leading edge feature and BSP development.
  113. Yocto Linux Kernel Architecture and Branching Strategies
  114. ========================================================
  115. As mentioned earlier, a key goal of the Yocto Project is to present the
  116. developer with a kernel that has a clear and continuous history that is
  117. visible to the user. The architecture and mechanisms, in particular the
  118. branching strategies, used achieve that goal in a manner similar to
  119. upstream Linux kernel development in ``kernel.org``.
  120. You can think of a Yocto Linux kernel as consisting of a baseline Linux
  121. kernel with added features logically structured on top of the baseline.
  122. The features are tagged and organized by way of a branching strategy
  123. implemented by the Yocto Project team using the Source Code Manager
  124. (SCM) Git.
  125. .. note::
  126. - Git is the obvious SCM for meeting the Yocto Linux kernel
  127. organizational and structural goals described in this section. Not
  128. only is Git the SCM for Linux kernel development in ``kernel.org``
  129. but, Git continues to grow in popularity and supports many
  130. different work flows, front-ends and management techniques.
  131. - You can find documentation on Git at
  132. http://git-scm.com/documentation. You can also get an
  133. introduction to Git as it applies to the Yocto Project in the
  134. ":ref:`overview-manual/overview-manual-development-environment:git`" section in the Yocto Project
  135. Overview and Concepts Manual. The latter reference provides an
  136. overview of Git and presents a minimal set of Git commands that
  137. allows you to be functional using Git. You can use as much, or as
  138. little, of what Git has to offer to accomplish what you need for
  139. your project. You do not have to be a "Git Expert" in order to use
  140. it with the Yocto Project.
  141. Using Git's tagging and branching features, the Yocto Project team
  142. creates kernel branches at points where functionality is no longer
  143. shared and thus, needs to be isolated. For example, board-specific
  144. incompatibilities would require different functionality and would
  145. require a branch to separate the features. Likewise, for specific kernel
  146. features, the same branching strategy is used.
  147. This "tree-like" architecture results in a structure that has features
  148. organized to be specific for particular functionality, single kernel
  149. types, or a subset of kernel types. Thus, the user has the ability to
  150. see the added features and the commits that make up those features. In
  151. addition to being able to see added features, the user can also view the
  152. history of what made up the baseline Linux kernel.
  153. Another consequence of this strategy results in not having to store the
  154. same feature twice internally in the tree. Rather, the kernel team
  155. stores the unique differences required to apply the feature onto the
  156. kernel type in question.
  157. .. note::
  158. The Yocto Project team strives to place features in the tree such
  159. that features can be shared by all boards and kernel types where
  160. possible. However, during development cycles or when large features
  161. are merged, the team cannot always follow this practice. In those
  162. cases, the team uses isolated branches to merge features.
  163. BSP-specific code additions are handled in a similar manner to
  164. kernel-specific additions. Some BSPs only make sense given certain
  165. kernel types. So, for these types, the team creates branches off the end
  166. of that kernel type for all of the BSPs that are supported on that
  167. kernel type. From the perspective of the tools that create the BSP
  168. branch, the BSP is really no different than a feature. Consequently, the
  169. same branching strategy applies to BSPs as it does to kernel features.
  170. So again, rather than store the BSP twice, the team only stores the
  171. unique differences for the BSP across the supported multiple kernels.
  172. While this strategy can result in a tree with a significant number of
  173. branches, it is important to realize that from the developer's point of
  174. view, there is a linear path that travels from the baseline
  175. ``kernel.org``, through a select group of features and ends with their
  176. BSP-specific commits. In other words, the divisions of the kernel are
  177. transparent and are not relevant to the developer on a day-to-day basis.
  178. From the developer's perspective, this path is the "master" branch in
  179. Git terms. The developer does not need to be aware of the existence of
  180. any other branches at all. Of course, value exists in the having these
  181. branches in the tree, should a person decide to explore them. For
  182. example, a comparison between two BSPs at either the commit level or at
  183. the line-by-line code ``diff`` level is now a trivial operation.
  184. The following illustration shows the conceptual Yocto Linux kernel.
  185. .. image:: figures/kernel-architecture-overview.png
  186. :align: center
  187. In the illustration, the "Kernel.org Branch Point" marks the specific
  188. spot (or Linux kernel release) from which the Yocto Linux kernel is
  189. created. From this point forward in the tree, features and differences
  190. are organized and tagged.
  191. The "Yocto Project Baseline Kernel" contains functionality that is
  192. common to every kernel type and BSP that is organized further along in
  193. the tree. Placing these common features in the tree this way means
  194. features do not have to be duplicated along individual branches of the
  195. tree structure.
  196. From the "Yocto Project Baseline Kernel", branch points represent
  197. specific functionality for individual Board Support Packages (BSPs) as
  198. well as real-time kernels. The illustration represents this through
  199. three BSP-specific branches and a real-time kernel branch. Each branch
  200. represents some unique functionality for the BSP or for a real-time
  201. Yocto Linux kernel.
  202. In this example structure, the "Real-time (rt) Kernel" branch has common
  203. features for all real-time Yocto Linux kernels and contains more
  204. branches for individual BSP-specific real-time kernels. The illustration
  205. shows three branches as an example. Each branch points the way to
  206. specific, unique features for a respective real-time kernel as they
  207. apply to a given BSP.
  208. The resulting tree structure presents a clear path of markers (or
  209. branches) to the developer that, for all practical purposes, is the
  210. Yocto Linux kernel needed for any given set of requirements.
  211. .. note::
  212. Keep in mind the figure does not take into account all the supported
  213. Yocto Linux kernels, but rather shows a single generic kernel just
  214. for conceptual purposes. Also keep in mind that this structure
  215. represents the Yocto Project
  216. Source Repositories
  217. that are either pulled from during the build or established on the
  218. host development system prior to the build by either cloning a
  219. particular kernel's Git repository or by downloading and unpacking a
  220. tarball.
  221. Working with the kernel as a structured tree follows recognized
  222. community best practices. In particular, the kernel as shipped with the
  223. product, should be considered an "upstream source" and viewed as a
  224. series of historical and documented modifications (commits). These
  225. modifications represent the development and stabilization done by the
  226. Yocto Project kernel development team.
  227. Because commits only change at significant release points in the product
  228. life cycle, developers can work on a branch created from the last
  229. relevant commit in the shipped Yocto Project Linux kernel. As mentioned
  230. previously, the structure is transparent to the developer because the
  231. kernel tree is left in this state after cloning and building the kernel.
  232. Kernel Build File Hierarchy
  233. ===========================
  234. Upstream storage of all the available kernel source code is one thing,
  235. while representing and using the code on your host development system is
  236. another. Conceptually, you can think of the kernel source repositories
  237. as all the source files necessary for all the supported Yocto Linux
  238. kernels. As a developer, you are just interested in the source files for
  239. the kernel on which you are working. And, furthermore, you need them
  240. available on your host system.
  241. Kernel source code is available on your host system several different
  242. ways:
  243. - *Files Accessed While using devtool:* ``devtool``, which is
  244. available with the Yocto Project, is the preferred method by which to
  245. modify the kernel. See the ":ref:`kernel-dev/kernel-dev-intro:kernel modification workflow`" section.
  246. - *Cloned Repository:* If you are working in the kernel all the time,
  247. you probably would want to set up your own local Git repository of
  248. the Yocto Linux kernel tree. For information on how to clone a Yocto
  249. Linux kernel Git repository, see the
  250. ":ref:`kernel-dev/kernel-dev-common:preparing the build host to work on the kernel`"
  251. section.
  252. - *Temporary Source Files from a Build:* If you just need to make some
  253. patches to the kernel using a traditional BitBake workflow (i.e. not
  254. using the ``devtool``), you can access temporary kernel source files
  255. that were extracted and used during a kernel build.
  256. The temporary kernel source files resulting from a build using BitBake
  257. have a particular hierarchy. When you build the kernel on your
  258. development system, all files needed for the build are taken from the
  259. source repositories pointed to by the
  260. :term:`SRC_URI` variable and gathered
  261. in a temporary work area where they are subsequently used to create the
  262. unique kernel. Thus, in a sense, the process constructs a local source
  263. tree specific to your kernel from which to generate the new kernel
  264. image.
  265. The following figure shows the temporary file structure created on your
  266. host system when you build the kernel using Bitbake. This
  267. :term:`Build Directory` contains all the
  268. source files used during the build.
  269. .. image:: figures/kernel-overview-2-generic.png
  270. :align: center
  271. Again, for additional information on the Yocto Project kernel's
  272. architecture and its branching strategy, see the
  273. ":ref:`kernel-dev/kernel-dev-concepts-appx:yocto linux kernel architecture and branching strategies`"
  274. section. You can also reference the
  275. ":ref:`kernel-dev/kernel-dev-common:using \`\`devtool\`\` to patch the kernel`"
  276. and
  277. ":ref:`kernel-dev/kernel-dev-common:using traditional kernel development to patch the kernel`"
  278. sections for detailed example that modifies the kernel.
  279. Determining Hardware and Non-Hardware Features for the Kernel Configuration Audit Phase
  280. =======================================================================================
  281. This section describes part of the kernel configuration audit phase that
  282. most developers can ignore. For general information on kernel
  283. configuration including ``menuconfig``, ``defconfig`` files, and
  284. configuration fragments, see the
  285. ":ref:`kernel-dev/kernel-dev-common:configuring the kernel`" section.
  286. During this part of the audit phase, the contents of the final
  287. ``.config`` file are compared against the fragments specified by the
  288. system. These fragments can be system fragments, distro fragments, or
  289. user-specified configuration elements. Regardless of their origin, the
  290. OpenEmbedded build system warns the user if a specific option is not
  291. included in the final kernel configuration.
  292. By default, in order to not overwhelm the user with configuration
  293. warnings, the system only reports missing "hardware" options as they
  294. could result in a boot failure or indicate that important hardware is
  295. not available.
  296. To determine whether or not a given option is "hardware" or
  297. "non-hardware", the kernel Metadata in ``yocto-kernel-cache`` contains
  298. files that classify individual or groups of options as either hardware
  299. or non-hardware. To better show this, consider a situation where the
  300. ``yocto-kernel-cache`` contains the following files:
  301. ::
  302. yocto-kernel-cache/features/drm-psb/hardware.cfg
  303. yocto-kernel-cache/features/kgdb/hardware.cfg
  304. yocto-kernel-cache/ktypes/base/hardware.cfg
  305. yocto-kernel-cache/bsp/mti-malta32/hardware.cfg
  306. yocto-kernel-cache/bsp/qemu-ppc32/hardware.cfg
  307. yocto-kernel-cache/bsp/qemuarma9/hardware.cfg
  308. yocto-kernel-cache/bsp/mti-malta64/hardware.cfg
  309. yocto-kernel-cache/bsp/arm-versatile-926ejs/hardware.cfg
  310. yocto-kernel-cache/bsp/common-pc/hardware.cfg
  311. yocto-kernel-cache/bsp/common-pc-64/hardware.cfg
  312. yocto-kernel-cache/features/rfkill/non-hardware.cfg
  313. yocto-kernel-cache/ktypes/base/non-hardware.cfg
  314. yocto-kernel-cache/features/aufs/non-hardware.kcf
  315. yocto-kernel-cache/features/ocf/non-hardware.kcf
  316. yocto-kernel-cache/ktypes/base/non-hardware.kcf
  317. yocto-kernel-cache/ktypes/base/hardware.kcf
  318. yocto-kernel-cache/bsp/qemu-ppc32/hardware.kcf
  319. The following list
  320. provides explanations for the various files:
  321. - ``hardware.kcf``: Specifies a list of kernel Kconfig files that
  322. contain hardware options only.
  323. - ``non-hardware.kcf``: Specifies a list of kernel Kconfig files that
  324. contain non-hardware options only.
  325. - ``hardware.cfg``: Specifies a list of kernel ``CONFIG_`` options that
  326. are hardware, regardless of whether or not they are within a Kconfig
  327. file specified by a hardware or non-hardware Kconfig file (i.e.
  328. ``hardware.kcf`` or ``non-hardware.kcf``).
  329. - ``non-hardware.cfg``: Specifies a list of kernel ``CONFIG_`` options
  330. that are not hardware, regardless of whether or not they are within a
  331. Kconfig file specified by a hardware or non-hardware Kconfig file
  332. (i.e. ``hardware.kcf`` or ``non-hardware.kcf``).
  333. Here is a specific example using the
  334. ``kernel-cache/bsp/mti-malta32/hardware.cfg``:
  335. ::
  336. CONFIG_SERIAL_8250
  337. CONFIG_SERIAL_8250_CONSOLE
  338. CONFIG_SERIAL_8250_NR_UARTS
  339. CONFIG_SERIAL_8250_PCI
  340. CONFIG_SERIAL_CORE
  341. CONFIG_SERIAL_CORE_CONSOLE
  342. CONFIG_VGA_ARB
  343. The kernel configuration audit automatically detects
  344. these files (hence the names must be exactly the ones discussed here),
  345. and uses them as inputs when generating warnings about the final
  346. ``.config`` file.
  347. A user-specified kernel Metadata repository, or recipe space feature,
  348. can use these same files to classify options that are found within its
  349. ``.cfg`` files as hardware or non-hardware, to prevent the OpenEmbedded
  350. build system from producing an error or warning when an option is not in
  351. the final ``.config`` file.