1*4882a593Smuzhiyun.. SPDX-License-Identifier: CC-BY-SA-2.0-UK 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun****************** 4*4882a593SmuzhiyunKernel Maintenance 5*4882a593Smuzhiyun****************** 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunTree Construction 8*4882a593Smuzhiyun================= 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunThis section describes construction of the Yocto Project kernel source 11*4882a593Smuzhiyunrepositories as accomplished by the Yocto Project team to create Yocto 12*4882a593SmuzhiyunLinux kernel repositories. These kernel repositories are found under the 13*4882a593Smuzhiyunheading "Yocto Linux Kernel" at :yocto_git:`/` and 14*4882a593Smuzhiyunare shipped as part of a Yocto Project release. The team creates these 15*4882a593Smuzhiyunrepositories by compiling and executing the set of feature descriptions 16*4882a593Smuzhiyunfor every BSP and feature in the product. Those feature descriptions 17*4882a593Smuzhiyunlist all necessary patches, configurations, branches, tags, and feature 18*4882a593Smuzhiyundivisions found in a Yocto Linux kernel. Thus, the Yocto Project Linux 19*4882a593Smuzhiyunkernel repository (or tree) and accompanying Metadata in the 20*4882a593Smuzhiyun``yocto-kernel-cache`` are built. 21*4882a593Smuzhiyun 22*4882a593SmuzhiyunThe existence of these repositories allow you to access and clone a 23*4882a593Smuzhiyunparticular Yocto Project Linux kernel repository and use it to build 24*4882a593Smuzhiyunimages based on their configurations and features. 25*4882a593Smuzhiyun 26*4882a593SmuzhiyunYou can find the files used to describe all the valid features and BSPs 27*4882a593Smuzhiyunin the Yocto Project Linux kernel in any clone of the Yocto Project 28*4882a593SmuzhiyunLinux kernel source repository and ``yocto-kernel-cache`` Git trees. For 29*4882a593Smuzhiyunexample, the following commands clone the Yocto Project baseline Linux 30*4882a593Smuzhiyunkernel that branches off ``linux.org`` version 4.12 and the 31*4882a593Smuzhiyun``yocto-kernel-cache``, which contains stores of kernel Metadata:: 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun $ git clone git://git.yoctoproject.org/linux-yocto-4.12 34*4882a593Smuzhiyun $ git clone git://git.yoctoproject.org/linux-kernel-cache 35*4882a593Smuzhiyun 36*4882a593SmuzhiyunFor more information on 37*4882a593Smuzhiyunhow to set up a local Git repository of the Yocto Project Linux kernel 38*4882a593Smuzhiyunfiles, see the 39*4882a593Smuzhiyun":ref:`kernel-dev/common:preparing the build host to work on the kernel`" 40*4882a593Smuzhiyunsection. 41*4882a593Smuzhiyun 42*4882a593SmuzhiyunOnce you have cloned the kernel Git repository and the cache of Metadata 43*4882a593Smuzhiyunon your local machine, you can discover the branches that are available 44*4882a593Smuzhiyunin the repository using the following Git command:: 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun $ git branch -a 47*4882a593Smuzhiyun 48*4882a593SmuzhiyunChecking out a branch allows you to work with a particular Yocto Linux 49*4882a593Smuzhiyunkernel. For example, the following commands check out the 50*4882a593Smuzhiyun"standard/beagleboard" branch of the Yocto Linux kernel repository and 51*4882a593Smuzhiyunthe "yocto-4.12" branch of the ``yocto-kernel-cache`` repository:: 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun $ cd ~/linux-yocto-4.12 54*4882a593Smuzhiyun $ git checkout -b my-kernel-4.12 remotes/origin/standard/beagleboard 55*4882a593Smuzhiyun $ cd ~/linux-kernel-cache 56*4882a593Smuzhiyun $ git checkout -b my-4.12-metadata remotes/origin/yocto-4.12 57*4882a593Smuzhiyun 58*4882a593Smuzhiyun.. note:: 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun Branches in the ``yocto-kernel-cache`` repository correspond to Yocto Linux 61*4882a593Smuzhiyun kernel versions (e.g. "yocto-4.12", "yocto-4.10", "yocto-4.9", and so forth). 62*4882a593Smuzhiyun 63*4882a593SmuzhiyunOnce you have checked out and switched to appropriate branches, you can 64*4882a593Smuzhiyunsee a snapshot of all the kernel source files used to build that 65*4882a593Smuzhiyunparticular Yocto Linux kernel for a particular board. 66*4882a593Smuzhiyun 67*4882a593SmuzhiyunTo see the features and configurations for a particular Yocto Linux 68*4882a593Smuzhiyunkernel, you need to examine the ``yocto-kernel-cache`` Git repository. 69*4882a593SmuzhiyunAs mentioned, branches in the ``yocto-kernel-cache`` repository 70*4882a593Smuzhiyuncorrespond to Yocto Linux kernel versions (e.g. ``yocto-4.12``). 71*4882a593SmuzhiyunBranches contain descriptions in the form of ``.scc`` and ``.cfg`` 72*4882a593Smuzhiyunfiles. 73*4882a593Smuzhiyun 74*4882a593SmuzhiyunYou should realize, however, that browsing your local 75*4882a593Smuzhiyun``yocto-kernel-cache`` repository for feature descriptions and patches 76*4882a593Smuzhiyunis not an effective way to determine what is in a particular kernel 77*4882a593Smuzhiyunbranch. Instead, you should use Git directly to discover the changes in 78*4882a593Smuzhiyuna branch. Using Git is an efficient and flexible way to inspect changes 79*4882a593Smuzhiyunto the kernel. 80*4882a593Smuzhiyun 81*4882a593Smuzhiyun.. note:: 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun Ground up reconstruction of the complete kernel tree is an action 84*4882a593Smuzhiyun only taken by the Yocto Project team during an active development 85*4882a593Smuzhiyun cycle. When you create a clone of the kernel Git repository, you are 86*4882a593Smuzhiyun simply making it efficiently available for building and development. 87*4882a593Smuzhiyun 88*4882a593SmuzhiyunThe following steps describe what happens when the Yocto Project Team 89*4882a593Smuzhiyunconstructs the Yocto Project kernel source Git repository (or tree) 90*4882a593Smuzhiyunfound at :yocto_git:`/` given the introduction of a new 91*4882a593Smuzhiyuntop-level kernel feature or BSP. The following actions effectively 92*4882a593Smuzhiyunprovide the Metadata and create the tree that includes the new feature, 93*4882a593Smuzhiyunpatch, or BSP: 94*4882a593Smuzhiyun 95*4882a593Smuzhiyun1. *Pass Feature to the OpenEmbedded Build System:* A top-level kernel 96*4882a593Smuzhiyun feature is passed to the kernel build subsystem. Normally, this 97*4882a593Smuzhiyun feature is a BSP for a particular kernel type. 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun2. *Locate Feature:* The file that describes the top-level feature is 100*4882a593Smuzhiyun located by searching these system directories: 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun - The in-tree kernel-cache directories, which are located in the 103*4882a593Smuzhiyun :yocto_git:`yocto-kernel-cache </yocto-kernel-cache/tree/bsp>` 104*4882a593Smuzhiyun repository organized under the "Yocto Linux Kernel" heading in the 105*4882a593Smuzhiyun :yocto_git:`Yocto Project Source Repositories <>`. 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun - Areas pointed to by :term:`SRC_URI` statements found in kernel recipes. 108*4882a593Smuzhiyun 109*4882a593Smuzhiyun For a typical build, the target of the search is a feature 110*4882a593Smuzhiyun description in an ``.scc`` file whose name follows this format (e.g. 111*4882a593Smuzhiyun ``beaglebone-standard.scc`` and ``beaglebone-preempt-rt.scc``):: 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun bsp_root_name-kernel_type.scc 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun3. *Expand Feature:* Once located, the feature description is either 116*4882a593Smuzhiyun expanded into a simple script of actions, or into an existing 117*4882a593Smuzhiyun equivalent script that is already part of the shipped kernel. 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun4. *Append Extra Features:* Extra features are appended to the top-level 120*4882a593Smuzhiyun feature description. These features can come from the 121*4882a593Smuzhiyun :term:`KERNEL_FEATURES` 122*4882a593Smuzhiyun variable in recipes. 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun5. *Locate, Expand, and Append Each Feature:* Each extra feature is 125*4882a593Smuzhiyun located, expanded and appended to the script as described in step 126*4882a593Smuzhiyun three. 127*4882a593Smuzhiyun 128*4882a593Smuzhiyun6. *Execute the Script:* The script is executed to produce files 129*4882a593Smuzhiyun ``.scc`` and ``.cfg`` files in appropriate directories of the 130*4882a593Smuzhiyun ``yocto-kernel-cache`` repository. These files are descriptions of 131*4882a593Smuzhiyun all the branches, tags, patches and configurations that need to be 132*4882a593Smuzhiyun applied to the base Git repository to completely create the source 133*4882a593Smuzhiyun (build) branch for the new BSP or feature. 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun7. *Clone Base Repository:* The base repository is cloned, and the 136*4882a593Smuzhiyun actions listed in the ``yocto-kernel-cache`` directories are applied 137*4882a593Smuzhiyun to the tree. 138*4882a593Smuzhiyun 139*4882a593Smuzhiyun8. *Perform Cleanup:* The Git repositories are left with the desired 140*4882a593Smuzhiyun branches checked out and any required branching, patching and tagging 141*4882a593Smuzhiyun has been performed. 142*4882a593Smuzhiyun 143*4882a593SmuzhiyunThe kernel tree and cache are ready for developer consumption to be 144*4882a593Smuzhiyunlocally cloned, configured, and built into a Yocto Project kernel 145*4882a593Smuzhiyunspecific to some target hardware. 146*4882a593Smuzhiyun 147*4882a593Smuzhiyun.. note:: 148*4882a593Smuzhiyun 149*4882a593Smuzhiyun - The generated ``yocto-kernel-cache`` repository adds to the kernel 150*4882a593Smuzhiyun as shipped with the Yocto Project release. Any add-ons and 151*4882a593Smuzhiyun configuration data are applied to the end of an existing branch. 152*4882a593Smuzhiyun The full repository generation that is found in the official Yocto 153*4882a593Smuzhiyun Project kernel repositories at :yocto_git:`/` is the 154*4882a593Smuzhiyun combination of all supported boards and configurations. 155*4882a593Smuzhiyun 156*4882a593Smuzhiyun - The technique the Yocto Project team uses is flexible and allows 157*4882a593Smuzhiyun for seamless blending of an immutable history with additional 158*4882a593Smuzhiyun patches specific to a deployment. Any additions to the kernel 159*4882a593Smuzhiyun become an integrated part of the branches. 160*4882a593Smuzhiyun 161*4882a593Smuzhiyun - The full kernel tree that you see on :yocto_git:`/` is 162*4882a593Smuzhiyun generated through repeating the above steps for all valid BSPs. 163*4882a593Smuzhiyun The end result is a branched, clean history tree that makes up the 164*4882a593Smuzhiyun kernel for a given release. You can see the script (``kgit-scc``) 165*4882a593Smuzhiyun responsible for this in the 166*4882a593Smuzhiyun :yocto_git:`yocto-kernel-tools </yocto-kernel-tools/tree/tools>` 167*4882a593Smuzhiyun repository. 168*4882a593Smuzhiyun 169*4882a593Smuzhiyun - The steps used to construct the full kernel tree are the same 170*4882a593Smuzhiyun steps that BitBake uses when it builds a kernel image. 171*4882a593Smuzhiyun 172*4882a593SmuzhiyunBuild Strategy 173*4882a593Smuzhiyun============== 174*4882a593Smuzhiyun 175*4882a593SmuzhiyunOnce you have cloned a Yocto Linux kernel repository and the cache 176*4882a593Smuzhiyunrepository (``yocto-kernel-cache``) onto your development system, you 177*4882a593Smuzhiyuncan consider the compilation phase of kernel development, which is 178*4882a593Smuzhiyunbuilding a kernel image. Some prerequisites are validated by 179*4882a593Smuzhiyunthe build process before compilation starts: 180*4882a593Smuzhiyun 181*4882a593Smuzhiyun- The :term:`SRC_URI` points to the 182*4882a593Smuzhiyun kernel Git repository. 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun- A BSP build branch with Metadata exists in the ``yocto-kernel-cache`` 185*4882a593Smuzhiyun repository. The branch is based on the Yocto Linux kernel version and 186*4882a593Smuzhiyun has configurations and features grouped under the 187*4882a593Smuzhiyun ``yocto-kernel-cache/bsp`` directory. For example, features and 188*4882a593Smuzhiyun configurations for the BeagleBone Board assuming a 189*4882a593Smuzhiyun ``linux-yocto_4.12`` kernel reside in the following area of the 190*4882a593Smuzhiyun ``yocto-kernel-cache`` repository: yocto-kernel-cache/bsp/beaglebone 191*4882a593Smuzhiyun 192*4882a593Smuzhiyun .. note:: 193*4882a593Smuzhiyun 194*4882a593Smuzhiyun In the previous example, the "yocto-4.12" branch is checked out in 195*4882a593Smuzhiyun the ``yocto-kernel-cache`` repository. 196*4882a593Smuzhiyun 197*4882a593SmuzhiyunThe OpenEmbedded build system makes sure these conditions are satisfied before 198*4882a593Smuzhiyunattempting compilation. Other means, however, do exist, such as 199*4882a593Smuzhiyunbootstrapping a BSP. 200*4882a593Smuzhiyun 201*4882a593SmuzhiyunBefore building a kernel, the build process verifies the tree and 202*4882a593Smuzhiyunconfigures the kernel by processing all of the configuration "fragments" 203*4882a593Smuzhiyunspecified by feature descriptions in the ``.scc`` files. As the features 204*4882a593Smuzhiyunare compiled, associated kernel configuration fragments are noted and 205*4882a593Smuzhiyunrecorded in the series of directories in their compilation order. The 206*4882a593Smuzhiyunfragments are migrated, pre-processed and passed to the Linux Kernel 207*4882a593SmuzhiyunConfiguration subsystem (``lkc``) as raw input in the form of a 208*4882a593Smuzhiyun``.config`` file. The ``lkc`` uses its own internal dependency 209*4882a593Smuzhiyunconstraints to do the final processing of that information and generates 210*4882a593Smuzhiyunthe final ``.config`` file that is used during compilation. 211*4882a593Smuzhiyun 212*4882a593SmuzhiyunUsing the board's architecture and other relevant values from the 213*4882a593Smuzhiyunboard's template, kernel compilation is started and a kernel image is 214*4882a593Smuzhiyunproduced. 215*4882a593Smuzhiyun 216*4882a593SmuzhiyunThe other thing that you notice once you configure a kernel is that the 217*4882a593Smuzhiyunbuild process generates a build tree that is separate from your kernel's 218*4882a593Smuzhiyunlocal Git source repository tree. This build tree has a name that uses 219*4882a593Smuzhiyunthe following form, where ``${MACHINE}`` is the metadata name of the 220*4882a593Smuzhiyunmachine (BSP) and "kernel_type" is one of the Yocto Project supported 221*4882a593Smuzhiyunkernel types (e.g. "standard"):: 222*4882a593Smuzhiyun 223*4882a593Smuzhiyun linux-${MACHINE}-kernel_type-build 224*4882a593Smuzhiyun 225*4882a593SmuzhiyunThe existing support in the ``kernel.org`` tree achieves this default 226*4882a593Smuzhiyunfunctionality. 227*4882a593Smuzhiyun 228*4882a593SmuzhiyunThis behavior means that all the generated files for a particular 229*4882a593Smuzhiyunmachine or BSP are now in the build tree directory. The files include 230*4882a593Smuzhiyunthe final ``.config`` file, all the ``.o`` files, the ``.a`` files, and 231*4882a593Smuzhiyunso forth. Since each machine or BSP has its own separate 232*4882a593Smuzhiyun:term:`Build Directory` in its own separate 233*4882a593Smuzhiyunbranch of the Git repository, you can easily switch between different 234*4882a593Smuzhiyunbuilds. 235