kernel-dev-advanced.xml 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  2. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
  3. [<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
  4. <chapter id='kernel-dev-advanced'>
  5. <title>Working with Advanced Metadata</title>
  6. <section id='kernel-dev-advanced-overview'>
  7. <title>Overview</title>
  8. <para>
  9. In addition to supporting configuration fragments and patches, the
  10. Yocto Project kernel tools also support rich
  11. <ulink url='&YOCTO_DOCS_DEV_URL;#metadata'>Metadata</ulink> that you can
  12. use to define complex policies and Board Support Package (BSP) support.
  13. The purpose of the Metadata and the tools that manage it, known as
  14. the kern-tools (<filename>kern-tools-native_git.bb</filename>), is
  15. to help you manage the complexity of the configuration and sources
  16. used to support multiple BSPs and Linux kernel types.
  17. </para>
  18. </section>
  19. <section id='using-kernel-metadata-in-a-recipe'>
  20. <title>Using Kernel Metadata in a Recipe</title>
  21. <para>
  22. The kernel sources in the Yocto Project contain kernel Metadata, which is
  23. located in the <filename>meta</filename> branches of the kernel source
  24. Git repositories.
  25. This Metadata defines Board Support Packages (BSPs) that
  26. correspond to definitions in linux-yocto recipes for the same BSPs.
  27. A BSP consists of an aggregation of kernel policy and hardware-specific
  28. feature enablements.
  29. The BSP can be influenced from within the linux-yocto recipe.
  30. <note>
  31. Linux kernel source that contains kernel Metadata is said to be
  32. "linux-yocto style" kernel source.
  33. A Linux kernel recipe that inherits from the
  34. <filename>linux-yocto.inc</filename> include file is said to be a
  35. "linux-yocto style" recipe.
  36. </note>
  37. </para>
  38. <para>
  39. Every linux-yocto style recipe must define the
  40. <ulink url='&YOCTO_DOCS_REF_URL;#var-KMACHINE'><filename>KMACHINE</filename></ulink>
  41. variable.
  42. This variable is typically set to the same value as the
  43. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
  44. variable, which is used by BitBake (e.g. "routerstationpro" or "fri2").
  45. Multiple BSPs can reuse the same <filename>KMACHINE</filename>
  46. name if they are built using the same BSP description.
  47. The "fri2" and "fri2-noemgd" BSP combination
  48. in the <filename>meta-intel</filename>
  49. layer is a good example of two BSPs using the same
  50. <filename>KMACHINE</filename> value (i.e. "fri2").
  51. See the <link linkend='bsp-descriptions'>BSP Descriptions</link> section
  52. for more information.
  53. </para>
  54. <para>
  55. The linux-yocto style recipes can optionally define the following
  56. variables:
  57. <literallayout class='monospaced'>
  58. <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'>KBRANCH</ulink>
  59. <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_FEATURES'>KERNEL_FEATURES</ulink>
  60. <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH_DEFAULT'>KBRANCH_DEFAULT</ulink>
  61. <ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_KERNEL_TYPE'>LINUX_KERNEL_TYPE</ulink>
  62. </literallayout>
  63. <filename>KBRANCH_DEFAULT</filename> defines the Linux kernel source
  64. repository's default branch to use to build the Linux kernel.
  65. The value is used as the default for <filename>KBRANCH</filename>, which
  66. can define an alternate branch typically with a machine override as
  67. follows:
  68. <literallayout class='monospaced'>
  69. KBRANCH_fri2 = "standard/fri2"
  70. </literallayout>
  71. Unless you specify otherwise, <filename>KBRANCH_DEFAULT</filename>
  72. initializes to "master".
  73. </para>
  74. <para>
  75. <filename>LINUX_KERNEL_TYPE</filename> defines the kernel type to be
  76. used in assembling the configuration.
  77. If you do not specify a <filename>LINUX_KERNEL_TYPE</filename>,
  78. it defaults to "standard".
  79. Together with
  80. <ulink url='&YOCTO_DOCS_REF_URL;#var-KMACHINE'><filename>KMACHINE</filename></ulink>,
  81. <filename>LINUX_KERNEL_TYPE</filename> defines the search
  82. arguments used by the kernel tools to find the
  83. appropriate description within the kernel Metadata with which to
  84. build out the sources and configuration.
  85. The linux-yocto recipes define "standard", "tiny", and "preempt-rt"
  86. kernel types.
  87. See the <link linkend='kernel-types'>Kernel Types</link> section
  88. for more information on kernel types.
  89. </para>
  90. <para>
  91. During the build, the kern-tools search for the BSP description
  92. file that most closely matches the <filename>KMACHINE</filename>
  93. and <filename>LINUX_KERNEL_TYPE</filename> variables passed in from the
  94. recipe.
  95. The tools use the first BSP description it finds that match
  96. both variables.
  97. If the tools cannot find a match, they issue a warning such as
  98. the following:
  99. <literallayout class='monospaced'>
  100. WARNING: Can't find any BSP hardware or required configuration fragments.
  101. WARNING: Looked at meta/cfg/broken/fri2-broken/hdw_frags.txt and
  102. meta/cfg/broken/fri2-broken/required_frags.txt in directory:
  103. meta/cfg/broken/fri2-broken
  104. </literallayout>
  105. In this example, <filename>KMACHINE</filename> was set to "fri2-broken"
  106. and <filename>LINUX_KERNEL_TYPE</filename> was set to "broken".
  107. </para>
  108. <para>
  109. The tools first search for the <filename>KMACHINE</filename> and
  110. then for the <filename>LINUX_KERNEL_TYPE</filename>.
  111. If the tools cannot find a partial match, they will use the
  112. sources from the <filename>KBRANCH</filename> and any configuration
  113. specified in the
  114. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
  115. </para>
  116. <para>
  117. You can use the <filename>KERNEL_FEATURES</filename> variable
  118. to include features (configuration fragments, patches, or both) that
  119. are not already included by the <filename>KMACHINE</filename> and
  120. <filename>LINUX_KERNEL_TYPE</filename> variable combination.
  121. For example, to include a feature specified as "features/netfilter.scc",
  122. specify:
  123. <literallayout class='monospaced'>
  124. KERNEL_FEATURES += "features/netfilter.scc"
  125. </literallayout>
  126. To include a feature called "cfg/sound.scc" just for the
  127. <filename>qemux86</filename> machine, specify:
  128. <literallayout class='monospaced'>
  129. KERNEL_FEATURES_append_qemux86 = "cfg/sound.scc"
  130. </literallayout>
  131. The value of the entries in <filename>KERNEL_FEATURES</filename>
  132. are dependent on their location within the kernel Metadata itself.
  133. The examples here are taken from the
  134. <filename>linux-yocto-3.4</filename> repository where "features"
  135. and "cfg" are subdirectories within the
  136. <filename>meta/cfg/kernel-cache</filename> directory.
  137. For more information, see the
  138. "<link linkend='kernel-metadata-syntax'>Kernel Metadata Syntax</link>" section.
  139. <note>
  140. The processing of the these variables has evolved some between the
  141. 0.9 and 1.3 releases of the Yocto Project and associated
  142. kern-tools sources.
  143. The descriptions in this section are accurate for 1.3 and later
  144. releases of the Yocto Project.
  145. </note>
  146. </para>
  147. </section>
  148. <section id='kernel-metadata-location'>
  149. <title>Kernel Metadata Location</title>
  150. <para>
  151. Kernel Metadata can be defined in either the kernel recipe
  152. (recipe-space) or in the kernel tree (in-tree).
  153. Where you choose to define the Metadata depends on what you want
  154. to do and how you intend to work.
  155. Regardless of where you define the kernel Metadata, the syntax used
  156. applies equally.
  157. </para>
  158. <para>
  159. If you are unfamiliar with the Linux kernel and only wish
  160. to apply a configuration and possibly a couple of patches provided to
  161. you by others, the recipe-space method is recommended.
  162. This method is also a good approach if you are working with Linux kernel
  163. sources you do not control or if you just do not want to maintain a
  164. Linux kernel Git repository on your own.
  165. For partial information on how you can define kernel Metadata in
  166. the recipe-space, see the
  167. "<link linkend='modifying-an-existing-recipe'>Modifying an Existing Recipe</link>"
  168. section.
  169. </para>
  170. <para>
  171. Conversely, if you are actively developing a kernel and are already
  172. maintaining a Linux kernel Git repository of your own, you might find
  173. it more convenient to work with the kernel Metadata in the same
  174. repository as the Linux kernel sources.
  175. This method can make iterative development of the Linux kernel
  176. more efficient outside of the BitBake environment.
  177. </para>
  178. <section id='recipe-space-metadata'>
  179. <title>Recipe-Space Metadata</title>
  180. <para>
  181. When stored in recipe-space, the kernel Metadata files reside in a
  182. directory hierarchy below
  183. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>.
  184. For a linux-yocto recipe or for a Linux kernel recipe derived
  185. by copying and modifying
  186. <filename>oe-core/meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb</filename>
  187. to a recipe in your layer, <filename>FILESEXTRAPATHS</filename>
  188. is typically set to
  189. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-THISDIR'><filename>THISDIR</filename></ulink><filename>}/${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>.
  190. See the "<link linkend='modifying-an-existing-recipe'>Modifying an Existing Recipe</link>"
  191. section for more information.
  192. </para>
  193. <para>
  194. Here is an example that shows a trivial tree of kernel Metadata
  195. stored in recipe-space within a BSP layer:
  196. <literallayout class='monospaced'>
  197. meta-my_bsp_layer/
  198. `-- recipes-kernel
  199. `-- linux
  200. `-- linux-yocto
  201. |-- bsp-standard.scc
  202. |-- bsp.cfg
  203. `-- standard.cfg
  204. </literallayout>
  205. </para>
  206. <para>
  207. When the Metadata is stored in recipe-space, you must take
  208. steps to ensure BitBake has the necessary information to decide
  209. what files to fetch and when they need to be fetched again.
  210. It is only necessary to specify the <filename>.scc</filename>
  211. files on the
  212. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
  213. BitBake parses them and fetches any files referenced in the
  214. <filename>.scc</filename> files by the <filename>include</filename>,
  215. <filename>patch</filename>, or <filename>kconf</filename> commands.
  216. Because of this, it is necessary to bump the recipe
  217. <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
  218. value when changing the content of files not explicitly listed
  219. in the <filename>SRC_URI</filename>.
  220. </para>
  221. </section>
  222. <section id='in-tree-metadata'>
  223. <title>In-Tree Metadata</title>
  224. <para>
  225. When stored in-tree, the kernel Metadata files reside in the
  226. <filename>meta</filename> directory of the Linux kernel sources.
  227. The <filename>meta</filename> directory can be present in the
  228. same repository branch as the sources,
  229. such as "master", or <filename>meta</filename> can be its own
  230. orphan branch.
  231. <note>
  232. An orphan branch in Git is a branch with unique history and
  233. content to the other branches in the repository.
  234. Orphan branches are useful to track Metadata changes
  235. independently from the sources of the Linux kernel, while
  236. still keeping them together in the same repository.
  237. </note>
  238. For the purposes of this document, we will discuss all
  239. in-tree Metadata as residing below the
  240. <filename>meta/cfg/kernel-cache</filename> directory.
  241. </para>
  242. <para>
  243. Following is an example that shows how a trivial tree of Metadata
  244. is stored in a custom Linux kernel Git repository:
  245. <literallayout class='monospaced'>
  246. meta/
  247. `-- cfg
  248. `-- kernel-cache
  249. |-- bsp-standard.scc
  250. |-- bsp.cfg
  251. `-- standard.cfg
  252. </literallayout>
  253. </para>
  254. <para>
  255. To use a branch different from where the sources reside,
  256. specify the branch in the <filename>KMETA</filename> variable
  257. in your Linux kernel recipe.
  258. Here is an example:
  259. <literallayout class='monospaced'>
  260. KMETA = "meta"
  261. </literallayout>
  262. To use the same branch as the sources, set
  263. <filename>KMETA</filename> to an empty string:
  264. <literallayout class='monospaced'>
  265. KMETA = ""
  266. </literallayout>
  267. If you are working with your own sources and want to create an
  268. orphan <filename>meta</filename> branch, use these commands
  269. from within your Linux kernel Git repository:
  270. <literallayout class='monospaced'>
  271. $ git checkout --orphan meta
  272. $ git rm -rf .
  273. $ git commit --allow-empty -m "Create orphan meta branch"
  274. </literallayout>
  275. </para>
  276. <para>
  277. If you modify the Metadata in the linux-yocto
  278. <filename>meta</filename> branch, you must not forget to update
  279. the
  280. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
  281. statements in the kernel's recipe.
  282. In particular, you need to update the
  283. <filename>SRCREV_meta</filename> variable to match the commit in
  284. the <filename>KMETA</filename> branch you wish to use.
  285. Changing the data in these branches and not updating the
  286. <filename>SRCREV</filename> statements to match will cause the
  287. build to fetch an older commit.
  288. </para>
  289. </section>
  290. </section>
  291. <section id='kernel-metadata-syntax'>
  292. <title>Kernel Metadata Syntax</title>
  293. <para>
  294. The kernel Metadata consists of three primary types of files:
  295. <filename>scc</filename>
  296. <footnote>
  297. <para>
  298. <filename>scc</filename> stands for Series Configuration
  299. Control, but the naming has less significance in the
  300. current implementation of the tooling than it had in the
  301. past.
  302. Consider <filename>scc</filename> files to be description files.
  303. </para>
  304. </footnote>
  305. description files, configuration fragments, and patches.
  306. The <filename>scc</filename> files define variables and include or
  307. otherwise reference any of the three file types.
  308. The description files are used to aggregate all types of kernel
  309. Metadata into
  310. what ultimately describes the sources and the configuration required
  311. to build a Linux kernel tailored to a specific machine.
  312. </para>
  313. <para>
  314. The <filename>scc</filename> description files are used to define two
  315. fundamental types of kernel Metadata:
  316. <itemizedlist>
  317. <listitem><para>Features</para></listitem>
  318. <listitem><para>Board Support Packages (BSPs)</para></listitem>
  319. </itemizedlist>
  320. </para>
  321. <para>
  322. Features aggregate sources in the form of patches and configuration
  323. fragments into a modular reusable unit.
  324. You can use features to implement conceptually separate kernel
  325. Metadata descriptions such as pure configuration fragments,
  326. simple patches, complex features, and kernel types.
  327. <link linkend='kernel-types'>Kernel types</link> define general
  328. kernel features and policy to be reused in the BSPs.
  329. </para>
  330. <para>
  331. BSPs define hardware-specific features and aggregate them with kernel
  332. types to form the final description of what will be assembled and built.
  333. </para>
  334. <para>
  335. While the kernel Metadata syntax does not enforce any logical
  336. separation of configuration fragments, patches, features or kernel
  337. types, best practices dictate a logical separation of these types
  338. of Metadata.
  339. The following Metadata file hierarchy is recommended:
  340. <literallayout class='monospaced'>
  341. &lt;base&gt;/
  342. bsp/
  343. cfg/
  344. features/
  345. ktypes/
  346. patches/
  347. </literallayout>
  348. </para>
  349. <para>
  350. The <filename>bsp</filename> directory contains the
  351. <link linkend='bsp-descriptions'>BSP descriptions</link>.
  352. The remaining directories all contain "features".
  353. Separating <filename>bsp</filename> from the rest of the structure
  354. aids conceptualizing intended usage.
  355. </para>
  356. <para>
  357. Use these guidelines to help place your <filename>scc</filename>
  358. description files within the structure:
  359. <itemizedlist>
  360. <listitem><para>If your file contains
  361. only configuration fragments, place the file in the
  362. <filename>cfg</filename> directory.</para></listitem>
  363. <listitem><para>If your file contains
  364. only source-code fixes, place the file in the
  365. <filename>patches</filename> directory.</para></listitem>
  366. <listitem><para>If your file encapsulates
  367. a major feature, often combining sources and configurations,
  368. place the file in <filename>features</filename> directory.
  369. </para></listitem>
  370. <listitem><para>If your file aggregates
  371. non-hardware configuration and patches in order to define a
  372. base kernel policy or major kernel type to be reused across
  373. multiple BSPs, place the file in <filename>ktypes</filename>
  374. directory.
  375. </para></listitem>
  376. </itemizedlist>
  377. </para>
  378. <para>
  379. These distinctions can easily become blurred - especially as
  380. out-of-tree features slowly merge upstream over time.
  381. Also, remember that how the description files are placed is
  382. a purely logical organization and has no impact on the functionality
  383. of the kernel Metadata.
  384. There is no impact because all of <filename>cfg</filename>,
  385. <filename>features</filename>, <filename>patches</filename>, and
  386. <filename>ktypes</filename>, contain "features" as far as the kernel
  387. tools are concerned.
  388. </para>
  389. <para>
  390. Paths used in kernel Metadata files are relative to
  391. <filename>&lt;base&gt;</filename>, which is either
  392. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
  393. if you are creating Metadata in
  394. <link linkend='recipe-space-metadata'>recipe-space</link>,
  395. or <filename>meta/cfg/kernel-cache/</filename> if you are creating
  396. Metadata <link linkend='in-tree-metadata'>in-tree</link>.
  397. </para>
  398. <section id='configuration'>
  399. <title>Configuration</title>
  400. <para>
  401. The simplest unit of kernel Metadata is the configuration-only
  402. feature.
  403. This feature consists of one or more Linux kernel configuration
  404. parameters in a configuration fragment file
  405. (<filename>.cfg</filename>) and an <filename>.scc</filename> file
  406. that describes the fragment.
  407. </para>
  408. <para>
  409. The Symmetric Multi-Processing (SMP) fragment included in the
  410. <filename>linux-yocto-3.4</filename> Git repository
  411. consists of the following two files:
  412. <literallayout class='monospaced'>
  413. cfg/smp.scc:
  414. define KFEATURE_DESCRIPTION "Enable SMP"
  415. kconf hardware smp.cfg
  416. cfg/smp.cfg:
  417. CONFIG_SMP=y
  418. CONFIG_SCHED_SMT=y
  419. </literallayout>
  420. You can find information on configuration fragment files in the
  421. "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-config-fragments'>Creating Configuration Fragments</ulink>"
  422. section of the Yocto Project Development Manual and in
  423. the "<link linkend='generating-configuration-files'>Generating Configuration Files</link>"
  424. section earlier in this manual.
  425. </para>
  426. <para>
  427. <ulink url='&YOCTO_DOCS_REF_URL;#var-KFEATURE_DESCRIPTION'><filename>KFEATURE_DESCRIPTION</filename></ulink>
  428. provides a short description of the fragment.
  429. Higher level kernel tools use this description.
  430. </para>
  431. <para>
  432. The <filename>kconf</filename> command is used to include the
  433. actual configuration fragment in an <filename>.scc</filename>
  434. file, and the "hardware" keyword identifies the fragment as
  435. being hardware enabling, as opposed to general policy,
  436. which would use the "non-hardware" keyword.
  437. The distinction is made for the benefit of the configuration
  438. validation tools, which warn you if a hardware fragment
  439. overrides a policy set by a non-hardware fragment.
  440. <note>
  441. The description file can include multiple
  442. <filename>kconf</filename> statements, one per fragment.
  443. </note>
  444. </para>
  445. <para>
  446. As described in the
  447. "<link linkend='generating-configuration-files'>Generating Configuration Files</link>"
  448. section, you can use the following BitBake command to audit your
  449. configuration:
  450. <literallayout class='monospaced'>
  451. $ bitbake linux-yocto -c kernel_configcheck -f
  452. </literallayout>
  453. </para>
  454. </section>
  455. <section id='patches'>
  456. <title>Patches</title>
  457. <para>
  458. Patch descriptions are very similar to configuration fragment
  459. descriptions, which are described in the previous section.
  460. However, instead of a <filename>.cfg</filename> file, these
  461. descriptions work with source patches.
  462. </para>
  463. <para>
  464. A typical patch includes a description file and the patch itself:
  465. <literallayout class='monospaced'>
  466. patches/mypatch.scc:
  467. patch mypatch.patch
  468. patches/mypatch.patch:
  469. &lt;typical-patch&gt;
  470. </literallayout>
  471. You can create the typical <filename>.patch</filename>
  472. file using <filename>diff -Nurp</filename> or
  473. <filename>git format-patch</filename>.
  474. </para>
  475. <para>
  476. The description file can include multiple patch statements,
  477. one per patch.
  478. </para>
  479. </section>
  480. <section id='features'>
  481. <title>Features</title>
  482. <para>
  483. Features are complex kernel Metadata types that consist
  484. of configuration fragments (<filename>kconf</filename>), patches
  485. (<filename>patch</filename>), and possibly other feature
  486. description files (<filename>include</filename>).
  487. </para>
  488. <para>
  489. Here is an example that shows a feature description file:
  490. <literallayout class='monospaced'>
  491. features/myfeature.scc
  492. define KFEATURE_DESCRIPTION "Enable myfeature"
  493. patch 0001-myfeature-core.patch
  494. patch 0002-myfeature-interface.patch
  495. include cfg/myfeature_dependency.scc
  496. kconf non-hardware myfeature.cfg
  497. </literallayout>
  498. This example shows how the <filename>patch</filename> and
  499. <filename>kconf</filename> commands are used as well as
  500. how an additional feature description file is included.
  501. </para>
  502. <para>
  503. Typically, features are less granular than configuration
  504. fragments and are more likely than configuration fragments
  505. and patches to be the types of things you want to specify
  506. in the <filename>KERNEL_FEATURES</filename> variable of the
  507. Linux kernel recipe.
  508. See the "<link linkend='using-kernel-metadata-in-a-recipe'>Using Kernel Metadata in a Recipe</link>"
  509. section earlier in the manual.
  510. </para>
  511. </section>
  512. <section id='kernel-types'>
  513. <title>Kernel Types</title>
  514. <para>
  515. A kernel type defines a high-level kernel policy by
  516. aggregating non-hardware configuration fragments with
  517. patches you want to use when building a Linux kernels of a
  518. specific type.
  519. Syntactically, kernel types are no different than features
  520. as described in the "<link linkend='features'>Features</link>"
  521. section.
  522. The <filename>LINUX_KERNEL_TYPE</filename> variable in the kernel
  523. recipe selects the kernel type.
  524. See the "<link linkend='using-kernel-metadata-in-a-recipe'>Using Kernel Metadata in a Recipe</link>"
  525. section for more information.
  526. </para>
  527. <para>
  528. As an example, the <filename>linux-yocto-3.4</filename>
  529. tree defines three kernel types: "standard",
  530. "tiny", and "preempt-rt":
  531. <itemizedlist>
  532. <listitem><para>"standard":
  533. Includes the generic Linux kernel policy of the Yocto
  534. Project linux-yocto kernel recipes.
  535. This policy includes, among other things, which file
  536. systems, networking options, core kernel features, and
  537. debugging and tracing options are supported.
  538. </para></listitem>
  539. <listitem><para>"preempt-rt":
  540. Applies the <filename>PREEMPT_RT</filename>
  541. patches and the configuration options required to
  542. build a real-time Linux kernel.
  543. This kernel type inherits from the "standard" kernel type.
  544. </para></listitem>
  545. <listitem><para>"tiny":
  546. Defines a bare minimum configuration meant to serve as a
  547. base for very small Linux kernels.
  548. The "tiny" kernel type is independent from the "standard"
  549. configuration.
  550. Although the "tiny" kernel type does not currently include
  551. any source changes, it might in the future.
  552. </para></listitem>
  553. </itemizedlist>
  554. </para>
  555. <para>
  556. The "standard" kernel type is defined by
  557. <filename>standard.scc</filename>:
  558. <literallayout class='monospaced'>
  559. # Include this kernel type fragment to get the standard features and
  560. # configuration values.
  561. # Include all standard features
  562. include standard-nocfg.scc
  563. kconf non-hardware standard.cfg
  564. # individual cfg block section
  565. include cfg/fs/devtmpfs.scc
  566. include cfg/fs/debugfs.scc
  567. include cfg/fs/btrfs.scc
  568. include cfg/fs/ext2.scc
  569. include cfg/fs/ext3.scc
  570. include cfg/fs/ext4.scc
  571. include cfg/net/ipv6.scc
  572. include cfg/net/ip_nf.scc
  573. include cfg/net/ip6_nf.scc
  574. include cfg/net/bridge.scc
  575. </literallayout>
  576. </para>
  577. <para>
  578. As with any <filename>.scc</filename> file, a
  579. kernel type definition can aggregate other
  580. <filename>.scc</filename> files with
  581. <filename>include</filename> commands.
  582. These definitions can also directly pull in
  583. configuration fragments and patches with the
  584. <filename>kconf</filename> and <filename>patch</filename>
  585. commands, respectively.
  586. </para>
  587. <note>
  588. It is not strictly necessary to create a kernel type
  589. <filename>.scc</filename> file.
  590. The Board Support Package (BSP) file can implicitly define
  591. the kernel type using a <filename>define
  592. <ulink url='&YOCTO_DOCS_REF_URL;#var-KTYPE'>KTYPE</ulink> myktype</filename>
  593. line.
  594. See the "<link linkend='bsp-descriptions'>BSP Descriptions</link>"
  595. section for more information.
  596. </note>
  597. </section>
  598. <section id='bsp-descriptions'>
  599. <title>BSP Descriptions</title>
  600. <para>
  601. BSP descriptions combine kernel types with hardware-specific
  602. features.
  603. The hardware-specific portion is typically defined
  604. independently, and then aggregated with each supported kernel
  605. type.
  606. Consider this simple BSP description that supports the "mybsp"
  607. machine:
  608. <literallayout class='monospaced'>
  609. mybsp.scc:
  610. define KMACHINE mybsp
  611. define KTYPE standard
  612. define KARCH i386
  613. kconf mybsp.cfg
  614. </literallayout>
  615. Every BSP description should define the
  616. <ulink url='&YOCTO_DOCS_REF_URL;#var-KMACHINE'><filename>KMACHINE</filename></ulink>,
  617. <ulink url='&YOCTO_DOCS_REF_URL;#var-KTYPE'><filename>KTYPE</filename></ulink>,
  618. and <ulink url='&YOCTO_DOCS_REF_URL;#var-KARCH'><filename>KARCH</filename></ulink>
  619. variables.
  620. These variables allow the OpenEmbedded build system to identify
  621. the description as meeting the criteria set by the recipe being
  622. built.
  623. This simple example supports the "mybsp" machine for the "standard"
  624. kernel and the "i386" architecture.
  625. </para>
  626. <para>
  627. Be aware that a hard link between the
  628. <filename>KTYPE</filename> variable and a kernel type
  629. description file does not exist.
  630. Thus, if you do not have kernel types defined in your kernel
  631. Metadata, you only need to ensure that the kernel recipe's
  632. <ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_KERNEL_TYPE'><filename>LINUX_KERNEL_TYPE</filename></ulink>
  633. variable and the <filename>KTYPE</filename> variable in the
  634. BSP description file match.
  635. <note>
  636. Future versions of the tooling make the specification of
  637. <filename>KTYPE</filename> in the BSP optional.
  638. </note>
  639. </para>
  640. <para>
  641. If you did want to separate your kernel policy from your
  642. hardware configuration, you could do so by specifying a kernel
  643. type, such as "standard" and including that description file
  644. in the BSP description file.
  645. See the "<link linkend='kernel-types'>Kernel Types</link>" section
  646. for more information.
  647. </para>
  648. <para>
  649. You might also have multiple hardware configurations that you
  650. aggregate into a single hardware description file that you
  651. could include in the BSP description file, rather than referencing
  652. a single <filename>.cfg</filename> file.
  653. Consider the following:
  654. <literallayout class='monospaced'>
  655. mybsp.scc:
  656. define KMACHINE mybsp
  657. define KTYPE standard
  658. define KARCH i386
  659. include standard.scc
  660. include mybsp-hw.scc
  661. </literallayout>
  662. </para>
  663. <para>
  664. In the above example, <filename>standard.scc</filename>
  665. aggregates all the configuration fragments, patches, and
  666. features that make up your standard kernel policy whereas
  667. <filename>mybsp-hw.scc</filename> aggregates all those necessary
  668. to support the hardware available on the "mybsp" machine.
  669. For information on how to break a complete
  670. <filename>.config</filename> file into the various
  671. configuration fragments, see the
  672. "<link linkend='generating-configuration-files'>Generating Configuration Files</link>"
  673. section.
  674. </para>
  675. <para>
  676. Many real-world examples are more complex.
  677. Like any other <filename>.scc</filename> file, BSP
  678. descriptions can aggregate features.
  679. Consider the Fish River Island 2 (fri2)
  680. BSP definition from the <filename>linux-yocto-3.4</filename>
  681. Git repository:
  682. <literallayout class='monospaced'>
  683. fri2.scc:
  684. kconf hardware fri2.cfg
  685. include cfg/x86.scc
  686. include features/eg20t/eg20t.scc
  687. include cfg/dmaengine.scc
  688. include features/ericsson-3g/f5521gw.scc
  689. include features/power/intel.scc
  690. include cfg/efi.scc
  691. include features/usb/ehci-hcd.scc
  692. include features/usb/ohci-hcd.scc
  693. include features/iwlwifi/iwlwifi.scc
  694. </literallayout>
  695. </para>
  696. <para>
  697. The <filename>fri2.scc</filename> description file includes
  698. a hardware configuration fragment
  699. (<filename>fri2.cfg</filename>) specific to the Fish River
  700. Island 2 BSP as well as several more general configuration
  701. fragments and features enabling hardware found on the
  702. machine.
  703. This description file is then included in each of the three
  704. "fri2" description files for the supported kernel types
  705. (i.e. "standard", "preempt-rt", and "tiny").
  706. Consider the "fri2" description for the "standard" kernel
  707. type:
  708. <literallayout class='monospaced'>
  709. fri2-standard.scc:
  710. define KMACHINE fri2
  711. define KTYPE standard
  712. define KARCH i386
  713. include ktypes/standard/standard.scc
  714. branch fri2
  715. git merge emgd-1.14
  716. include fri2.scc
  717. # Extra fri2 configs above the minimal defined in fri2.scc
  718. include cfg/efi-ext.scc
  719. include features/drm-emgd/drm-emgd.scc
  720. include cfg/vesafb.scc
  721. # default policy for standard kernels
  722. include cfg/usb-mass-storage.scc
  723. </literallayout>
  724. The <filename>include</filename> command midway through the file
  725. includes the <filename>fri2.scc</filename> description that
  726. defines all hardware enablements for the BSP that is common to all
  727. kernel types.
  728. Using this command significantly reduces duplication.
  729. </para>
  730. <para>
  731. This "fri2" standard description introduces a few more variables
  732. and commands that are worth further discussion.
  733. Notice the <filename>branch fri2</filename> command, which creates
  734. a machine-specific branch into which source changes are applied.
  735. With this branch set up, the <filename>git merge</filename> command
  736. uses Git to merge in a feature branch named "emgd-1.14".
  737. You could also handle this with the <filename>patch</filename>
  738. command.
  739. However, for commonly used features such as this, feature branches
  740. are a convenient mechanism.
  741. See the "<link linkend='feature-branches'>Feature Branches</link>"
  742. section for more information.
  743. </para>
  744. <para>
  745. Now consider the "fri2" description for the "tiny" kernel type:
  746. <literallayout class='monospaced'>
  747. fri2-tiny.scc:
  748. define KMACHINE fri2
  749. define KTYPE tiny
  750. define KARCH i386
  751. include ktypes/tiny/tiny.scc
  752. branch fri2
  753. include fri2.scc
  754. </literallayout>
  755. As you might expect, the "tiny" description includes quite a
  756. bit less.
  757. In fact, it includes only the minimal policy defined by the
  758. "tiny" kernel type and the hardware-specific configuration required
  759. for booting the machine along with the most basic functionality of
  760. the system as defined in the base "fri2" description file.
  761. </para>
  762. <para>
  763. Notice again the three critical variables:
  764. <filename>KMACHINE</filename>, <filename>KTYPE</filename>,
  765. and <filename>KARCH</filename>.
  766. Of these variables, only the <filename>KTYPE</filename> has changed.
  767. It is now set to "tiny".
  768. </para>
  769. </section>
  770. </section>
  771. <section id='organizing-your-source'>
  772. <title>Organizing Your Source</title>
  773. <para>
  774. Many recipes based on the <filename>linux-yocto-custom.bb</filename>
  775. recipe use Linux kernel sources that have only a single
  776. branch - "master".
  777. This type of repository structure is fine for linear development
  778. supporting a single machine and architecture.
  779. However, if you work with multiple boards and architectures,
  780. a kernel source repository with multiple branches is more
  781. efficient.
  782. For example, suppose you need a series of patches for one board to boot.
  783. Sometimes, these patches are works-in-progress or fundamentally wrong,
  784. yet they are still necessary for specific boards.
  785. In these situations, you most likely do not want to include these
  786. patches in every kernel you build (i.e. have the patches as part of
  787. the lone "master" branch).
  788. It is situations like these that give rise to multiple branches used
  789. within a Linux kernel sources Git repository.
  790. </para>
  791. <para>
  792. Repository organization strategies exist that maximize source reuse,
  793. remove redundancy, and logically order your changes.
  794. This section presents strategies for the following cases:
  795. <itemizedlist>
  796. <listitem><para>Encapsulating patches in a feature description
  797. and only including the patches in the BSP descriptions of
  798. the applicable boards.</para></listitem>
  799. <listitem><para>Creating a machine branch in your
  800. kernel source repository and applying the patches on that
  801. branch only.</para></listitem>
  802. <listitem><para>Creating a feature branch in your
  803. kernel source repository and merging that branch into your
  804. BSP when needed.</para></listitem>
  805. </itemizedlist>
  806. </para>
  807. <para>
  808. The approach you take is entirely up to you
  809. and depends on what works best for your development model.
  810. </para>
  811. <section id='encapsulating-patches'>
  812. <title>Encapsulating Patches</title>
  813. <para>
  814. if you are reusing patches from an external tree and are not
  815. working on the patches, you might find the encapsulated feature
  816. to be appropriate.
  817. Given this scenario, you do not need to create any branches in the
  818. source repository.
  819. Rather, you just take the static patches you need and encapsulate
  820. them within a feature description.
  821. Once you have the feature description, you simply include that into
  822. the BSP description as described in the
  823. "<link linkend='bsp-descriptions'>BSP Descriptions</link>"
  824. section.
  825. </para>
  826. <para>
  827. You can find information on how to create patches and BSP
  828. descriptions in the "<link linkend='patches'>Patches</link>" and
  829. "<link linkend='bsp-descriptions'>BSP Descriptions</link>"
  830. sections.
  831. </para>
  832. </section>
  833. <section id='machine-branches'>
  834. <title>Machine Branches</title>
  835. <para>
  836. When you have multiple machines and architectures to support,
  837. or you are actively working on board support, it is more
  838. efficient to create branches in the repository based on
  839. individual machines.
  840. Having machine branches allows common source to remain in the
  841. "master" branch with any features specific to a machine stored
  842. in the appropriate machine branch.
  843. This organization method frees you from continually reintegrating
  844. your patches into a feature.
  845. </para>
  846. <para>
  847. Once you have a new branch, you can set up your kernel Metadata
  848. to use the branch a couple different ways.
  849. In the recipe, you can specify the new branch as the
  850. <filename>KBRANCH</filename> to use for the board as
  851. follows:
  852. <literallayout class='monospaced'>
  853. KBRANCH = "mynewbranch"
  854. </literallayout>
  855. Another method is to use the <filename>branch</filename> command
  856. in the BSP description:
  857. <literallayout class='monospaced'>
  858. mybsp.scc:
  859. define KMACHINE mybsp
  860. define KTYPE standard
  861. define KARCH i386
  862. include standard.scc
  863. branch mynewbranch
  864. include mybsp-hw.scc
  865. </literallayout>
  866. </para>
  867. <para>
  868. If you find
  869. yourself with numerous branches, you might consider using a
  870. hierarchical branching system similar to what the linux-yocto Linux
  871. kernel repositories use:
  872. <literallayout class='monospaced'>
  873. &lt;common&gt;/&lt;kernel_type&gt;/&lt;machine&gt;
  874. </literallayout>
  875. </para>
  876. <para>
  877. If you had two kernel types, "standard" and "small" for
  878. instance, and three machines, the branches in your
  879. Git repository might look like this:
  880. <literallayout class='monospaced'>
  881. common/base
  882. common/standard/base
  883. common/standard/machine_a
  884. common/standard/machine_b
  885. common/standard/machine_c
  886. common/small/base
  887. common/small/machine_a
  888. </literallayout>
  889. </para>
  890. <para>
  891. This organization can help clarify the branch relationships.
  892. In this case, <filename>common/standard/machine_a</filename>
  893. includes everything in <filename>common/base</filename> and
  894. <filename>common/standard/base</filename>.
  895. The "standard" and "small" branches add sources specific to those
  896. kernel types that for whatever reason are not appropriate for the
  897. other branches.
  898. <note>The "base" branches are an artifact of the way Git manages
  899. its data internally on the filesystem: Git will not allow you
  900. to use <filename>common/standard</filename> and
  901. <filename>common/standard/machine_a</filename> because it
  902. would have to create a file and a directory named "standard".
  903. </note>
  904. </para>
  905. </section>
  906. <section id='feature-branches'>
  907. <title>Feature Branches</title>
  908. <para>
  909. When you are actively developing new features, it can be more
  910. efficient to work with that feature as a branch, rather than
  911. as a set of patches that have to be regularly updated.
  912. The Yocto Project Linux kernel tools provide for this with
  913. the <filename>git merge</filename> command.
  914. </para>
  915. <para>
  916. To merge a feature branch into a BSP, insert the
  917. <filename>git merge</filename> command after any
  918. <filename>branch</filename> commands:
  919. <literallayout class='monospaced'>
  920. mybsp.scc:
  921. define KMACHINE mybsp
  922. define KTYPE standard
  923. define KARCH i386
  924. include standard.scc
  925. branch mynewbranch
  926. git merge myfeature
  927. include mybsp-hw.scc
  928. </literallayout>
  929. </para>
  930. </section>
  931. </section>
  932. <section id='scc-reference'>
  933. <title>SCC Description File Reference</title>
  934. <para>
  935. This section provides a brief reference for the commands you can use
  936. within an SCC description file (<filename>.scc</filename>):
  937. <itemizedlist>
  938. <listitem><para><filename>branch [ref]</filename>:
  939. Creates a new branch relative to the current branch
  940. (typically <filename>${KTYPE}</filename>) using
  941. the currently checked-out branch, or "ref" if specified.
  942. </para></listitem>
  943. <listitem><para><filename>define</filename>:
  944. Defines variables, such as <filename>KMACHINE</filename>,
  945. <filename>KTYPE</filename>, <filename>KARCH</filename>,
  946. and <filename>KFEATURE_DESCRIPTION</filename>.</para></listitem>
  947. <listitem><para><filename>include SCC_FILE</filename>:
  948. Includes an SCC file in the current file.
  949. The file is parsed as if you had inserted it inline.
  950. </para></listitem>
  951. <listitem><para><filename>kconf [hardware|non-hardware] CFG_FILE</filename>:
  952. Queues a configuration fragment for merging into the final
  953. Linux <filename>.config</filename> file.</para></listitem>
  954. <listitem><para><filename>git merge GIT_BRANCH</filename>:
  955. Merges the feature branch into the current branch.
  956. </para></listitem>
  957. <listitem><para><filename>patch PATCH_FILE</filename>:
  958. Applies the patch to the current Git branch.</para></listitem>
  959. </itemizedlist>
  960. </para>
  961. </section>
  962. </chapter>
  963. <!--
  964. vim: expandtab tw=80 ts=4
  965. -->