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