xref: /OK3568_Linux_fs/yocto/poky/documentation/kernel-dev/intro.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: CC-BY-SA-2.0-UK
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun************
4*4882a593SmuzhiyunIntroduction
5*4882a593Smuzhiyun************
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunOverview
8*4882a593Smuzhiyun========
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunRegardless of how you intend to make use of the Yocto Project, chances
11*4882a593Smuzhiyunare you will work with the Linux kernel. This manual describes how to
12*4882a593Smuzhiyunset up your build host to support kernel development, introduces the
13*4882a593Smuzhiyunkernel development process, provides background information on the Yocto
14*4882a593SmuzhiyunLinux kernel :term:`Metadata`, describes
15*4882a593Smuzhiyuncommon tasks you can perform using the kernel tools, shows you how to
16*4882a593Smuzhiyunuse the kernel Metadata needed to work with the kernel inside the Yocto
17*4882a593SmuzhiyunProject, and provides insight into how the Yocto Project team develops
18*4882a593Smuzhiyunand maintains Yocto Linux kernel Git repositories and Metadata.
19*4882a593Smuzhiyun
20*4882a593SmuzhiyunEach Yocto Project release has a set of Yocto Linux kernel recipes,
21*4882a593Smuzhiyunwhose Git repositories you can view in the Yocto
22*4882a593Smuzhiyun:yocto_git:`Source Repositories <>` under the "Yocto Linux Kernel"
23*4882a593Smuzhiyunheading. New recipes for the release track the latest Linux kernel
24*4882a593Smuzhiyunupstream developments from https://www.kernel.org and introduce
25*4882a593Smuzhiyunnewly-supported platforms. Previous recipes in the release are refreshed
26*4882a593Smuzhiyunand supported for at least one additional Yocto Project release. As they
27*4882a593Smuzhiyunalign, these previous releases are updated to include the latest from
28*4882a593Smuzhiyunthe Long Term Support Initiative (LTSI) project. You can learn more
29*4882a593Smuzhiyunabout Yocto Linux kernels and LTSI in the
30*4882a593Smuzhiyun":ref:`kernel-dev/concepts-appx:yocto project kernel development and maintenance`" section.
31*4882a593Smuzhiyun
32*4882a593SmuzhiyunAlso included is a Yocto Linux kernel development recipe
33*4882a593Smuzhiyun(``linux-yocto-dev.bb``) should you want to work with the very latest in
34*4882a593Smuzhiyunupstream Yocto Linux kernel development and kernel Metadata development.
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun.. note::
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun   For more on Yocto Linux kernels, see the
39*4882a593Smuzhiyun   ":ref:`kernel-dev/concepts-appx:yocto project kernel development and maintenance`"
40*4882a593Smuzhiyun   section.
41*4882a593Smuzhiyun
42*4882a593SmuzhiyunThe Yocto Project also provides a powerful set of kernel tools for
43*4882a593Smuzhiyunmanaging Yocto Linux kernel sources and configuration data. You can use
44*4882a593Smuzhiyunthese tools to make a single configuration change, apply multiple
45*4882a593Smuzhiyunpatches, or work with your own kernel sources.
46*4882a593Smuzhiyun
47*4882a593SmuzhiyunIn particular, the kernel tools allow you to generate configuration
48*4882a593Smuzhiyunfragments that specify only what you must, and nothing more.
49*4882a593SmuzhiyunConfiguration fragments only need to contain the highest level visible
50*4882a593Smuzhiyun``CONFIG`` options as presented by the Yocto Linux kernel ``menuconfig``
51*4882a593Smuzhiyunsystem. Contrast this against a complete Yocto Linux kernel ``.config``
52*4882a593Smuzhiyunfile, which includes all the automatically selected ``CONFIG`` options.
53*4882a593SmuzhiyunThis efficiency reduces your maintenance effort and allows you to
54*4882a593Smuzhiyunfurther separate your configuration in ways that make sense for your
55*4882a593Smuzhiyunproject. A common split separates policy and hardware. For example, all
56*4882a593Smuzhiyunyour kernels might support the ``proc`` and ``sys`` filesystems, but
57*4882a593Smuzhiyunonly specific boards require sound, USB, or specific drivers. Specifying
58*4882a593Smuzhiyunthese configurations individually allows you to aggregate them together
59*4882a593Smuzhiyunas needed, but maintains them in only one place. Similar logic applies
60*4882a593Smuzhiyunto separating source changes.
61*4882a593Smuzhiyun
62*4882a593SmuzhiyunIf you do not maintain your own kernel sources and need to make only
63*4882a593Smuzhiyunminimal changes to the sources, the released recipes provide a vetted
64*4882a593Smuzhiyunbase upon which to layer your changes. Doing so allows you to benefit
65*4882a593Smuzhiyunfrom the continual kernel integration and testing performed during
66*4882a593Smuzhiyundevelopment of the Yocto Project.
67*4882a593Smuzhiyun
68*4882a593SmuzhiyunIf, instead, you have a very specific Linux kernel source tree and are
69*4882a593Smuzhiyununable to align with one of the official Yocto Linux kernel recipes,
70*4882a593Smuzhiyunyou have a way to use the Yocto Project Linux kernel tools with your
71*4882a593Smuzhiyunown kernel sources.
72*4882a593Smuzhiyun
73*4882a593SmuzhiyunThe remainder of this manual provides instructions for completing
74*4882a593Smuzhiyunspecific Linux kernel development tasks. These instructions assume you
75*4882a593Smuzhiyunare comfortable working with :oe_wiki:`BitBake </Bitbake>` recipes and basic
76*4882a593Smuzhiyunopen-source development tools. Understanding these concepts will
77*4882a593Smuzhiyunfacilitate the process of working with the kernel recipes. If you find
78*4882a593Smuzhiyunyou need some additional background, please be sure to review and
79*4882a593Smuzhiyununderstand the following documentation:
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun-  :doc:`/brief-yoctoprojectqs/index` document.
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun-  :doc:`/overview-manual/index`.
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun-  :ref:`devtool
86*4882a593Smuzhiyun   workflow <sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow>`
87*4882a593Smuzhiyun   as described in the Yocto Project Application Development and the
88*4882a593Smuzhiyun   Extensible Software Development Kit (eSDK) manual.
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun-  The ":ref:`dev-manual/common-tasks:understanding and creating layers`"
91*4882a593Smuzhiyun   section in the Yocto Project Development Tasks Manual.
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun-  The ":ref:`kernel-dev/intro:kernel modification workflow`" section.
94*4882a593Smuzhiyun
95*4882a593SmuzhiyunKernel Modification Workflow
96*4882a593Smuzhiyun============================
97*4882a593Smuzhiyun
98*4882a593SmuzhiyunKernel modification involves changing the Yocto Project kernel, which
99*4882a593Smuzhiyuncould involve changing configuration options as well as adding new
100*4882a593Smuzhiyunkernel recipes. Configuration changes can be added in the form of
101*4882a593Smuzhiyunconfiguration fragments, while recipe modification comes through the
102*4882a593Smuzhiyunkernel's ``recipes-kernel`` area in a kernel layer you create.
103*4882a593Smuzhiyun
104*4882a593SmuzhiyunThis section presents a high-level overview of the Yocto Project kernel
105*4882a593Smuzhiyunmodification workflow. The illustration and accompanying list provide
106*4882a593Smuzhiyungeneral information and references for further information.
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun.. image:: figures/kernel-dev-flow.png
109*4882a593Smuzhiyun   :align: center
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun1. *Set up Your Host Development System to Support Development Using the
112*4882a593Smuzhiyun   Yocto Project*: See the ":doc:`/dev-manual/start`" section in
113*4882a593Smuzhiyun   the Yocto Project Development Tasks Manual for options on how to get
114*4882a593Smuzhiyun   a build host ready to use the Yocto Project.
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun2. *Set Up Your Host Development System for Kernel Development:* It is
117*4882a593Smuzhiyun   recommended that you use ``devtool`` and an extensible SDK for kernel
118*4882a593Smuzhiyun   development. Alternatively, you can use traditional kernel
119*4882a593Smuzhiyun   development methods with the Yocto Project. Either way, there are
120*4882a593Smuzhiyun   steps you need to take to get the development environment ready.
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun   Using ``devtool`` and the eSDK requires that you have a clean build
123*4882a593Smuzhiyun   of the image and that you are set up with the appropriate eSDK. For
124*4882a593Smuzhiyun   more information, see the
125*4882a593Smuzhiyun   ":ref:`kernel-dev/common:getting ready to develop using \`\`devtool\`\``"
126*4882a593Smuzhiyun   section.
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun   Using traditional kernel development requires that you have the
129*4882a593Smuzhiyun   kernel source available in an isolated local Git repository. For more
130*4882a593Smuzhiyun   information, see the
131*4882a593Smuzhiyun   ":ref:`kernel-dev/common:getting ready for traditional kernel development`"
132*4882a593Smuzhiyun   section.
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun3. *Make Changes to the Kernel Source Code if applicable:* Modifying the
135*4882a593Smuzhiyun   kernel does not always mean directly changing source files. However,
136*4882a593Smuzhiyun   if you have to do this, you make the changes to the files in the
137*4882a593Smuzhiyun   eSDK's Build Directory if you are using ``devtool``. For more
138*4882a593Smuzhiyun   information, see the
139*4882a593Smuzhiyun   ":ref:`kernel-dev/common:using \`\`devtool\`\` to patch the kernel`"
140*4882a593Smuzhiyun   section.
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun   If you are using traditional kernel development, you edit the source
143*4882a593Smuzhiyun   files in the kernel's local Git repository. For more information, see the
144*4882a593Smuzhiyun   ":ref:`kernel-dev/common:using traditional kernel development to patch the kernel`"
145*4882a593Smuzhiyun   section.
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun4. *Make Kernel Configuration Changes if Applicable:* If your situation
148*4882a593Smuzhiyun   calls for changing the kernel's configuration, you can use
149*4882a593Smuzhiyun   :ref:`menuconfig <kernel-dev/common:using \`\`menuconfig\`\`>`,
150*4882a593Smuzhiyun   which allows you to
151*4882a593Smuzhiyun   interactively develop and test the configuration changes you are
152*4882a593Smuzhiyun   making to the kernel. Saving changes you make with ``menuconfig``
153*4882a593Smuzhiyun   updates the kernel's ``.config`` file.
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun   .. note::
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun      Try to resist the temptation to directly edit an existing ``.config``
158*4882a593Smuzhiyun      file, which is found in the Build Directory among the source code
159*4882a593Smuzhiyun      used for the build. Doing so, can produce unexpected results when
160*4882a593Smuzhiyun      the OpenEmbedded build system regenerates the configuration file.
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun   Once you are satisfied with the configuration changes made using
163*4882a593Smuzhiyun   ``menuconfig`` and you have saved them, you can directly compare the
164*4882a593Smuzhiyun   resulting ``.config`` file against an existing original and gather
165*4882a593Smuzhiyun   those changes into a
166*4882a593Smuzhiyun   :ref:`configuration fragment file <kernel-dev/common:creating configuration fragments>` to be
167*4882a593Smuzhiyun   referenced from within the kernel's ``.bbappend`` file.
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun   Additionally, if you are working in a BSP layer and need to modify
170*4882a593Smuzhiyun   the BSP's kernel's configuration, you can use ``menuconfig``.
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun5. *Rebuild the Kernel Image With Your Changes:* Rebuilding the kernel
173*4882a593Smuzhiyun   image applies your changes. Depending on your target hardware, you
174*4882a593Smuzhiyun   can verify your changes on actual hardware or perhaps QEMU.
175*4882a593Smuzhiyun
176*4882a593SmuzhiyunThe remainder of this developer's guide covers common tasks typically
177*4882a593Smuzhiyunused during kernel development, advanced Metadata usage, and Yocto Linux
178*4882a593Smuzhiyunkernel maintenance concepts.
179