kernel-dev-common.xml 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  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-common'>
  5. <title>Common Tasks</title>
  6. <para>
  7. This chapter presents several common tasks you perform when you
  8. work with the Yocto Project Linux kernel.
  9. These tasks include preparing a layer, modifying an existing recipe,
  10. iterative development, working with your own sources, and incorporating
  11. out-of-tree modules.
  12. <note>
  13. The examples presented in this chapter work with the Yocto Project
  14. 1.2.2 Release and forward.
  15. </note>
  16. </para>
  17. <section id='creating-and-preparing-a-layer'>
  18. <title>Creating and Preparing a Layer</title>
  19. <para>
  20. If you are going to be modifying kernel recipes, it is recommended
  21. that you create and prepare your own layer in which to do your
  22. work.
  23. Your layer contains its own BitBake append files
  24. (<filename>.bbappend</filename>) and provides a convenient
  25. mechanism to create your own recipe files
  26. (<filename>.bb</filename>).
  27. For details on how to create and work with layers, see the following
  28. sections in the Yocto Project Development Manual:
  29. <itemizedlist>
  30. <listitem><para>"<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>" for
  31. general information on layers and how to create layers.</para></listitem>
  32. <listitem><para>"<ulink url='&YOCTO_DOCS_DEV_URL;#get-your-layer-setup-for-the-build'>Get Your Layer Setup for the Build</ulink>" for
  33. specific instructions on setting up a layer for kernel
  34. development.</para></listitem>
  35. </itemizedlist>
  36. </para>
  37. </section>
  38. <section id='modifying-an-existing-recipe'>
  39. <title>Modifying an Existing Recipe</title>
  40. <para>
  41. In many cases, you can customize an existing linux-yocto recipe to
  42. meet the needs of your project.
  43. Each release of the Yocto Project provides a few Linux
  44. kernel recipes from which you can choose.
  45. These are located in the
  46. <ulink url='&YOCTO_DOCS_DEV_URL;#source-directory'>Source Directory</ulink>
  47. in <filename>meta/recipes-kernel/linux</filename>.
  48. </para>
  49. <para>
  50. Modifying an existing recipe can consist of the following:
  51. <itemizedlist>
  52. <listitem><para>Creating the append file</para></listitem>
  53. <listitem><para>Applying patches</para></listitem>
  54. <listitem><para>Changing the configuration</para></listitem>
  55. </itemizedlist>
  56. </para>
  57. <para>
  58. Before modifying an existing recipe, be sure that you have created
  59. a minimal, custom layer from which you can work.
  60. See the "<link linkend='creating-and-preparing-a-layer'>Creating and Preparing a Layer</link>"
  61. section for some general resources.
  62. You can also see the
  63. "<ulink url='&YOCTO_DOCS_DEV_URL;#get-your-layer-setup-for-the-build'>Get Your Layer Setup for the Build</ulink>" section
  64. of the Yocto Project Development Manual for a detailed
  65. example.
  66. </para>
  67. <section id='creating-the-append-file'>
  68. <title>Creating the Append File</title>
  69. <para>
  70. You create this file in your custom layer.
  71. You also name it accordingly based on the linux-yocto recipe
  72. you are using.
  73. For example, if you are modifying the
  74. <filename>meta/recipes-kernel/linux/linux-yocto_3.4.bb</filename>
  75. recipe, the append file will typical be located as follows
  76. within your custom layer:
  77. <literallayout class='monospaced'>
  78. &lt;your-layer&gt;/recipes-kernel/linux/linux-yocto_3.4.bbappend
  79. </literallayout>
  80. The append file should initially contain the following text:
  81. <literallayout class='monospaced'>
  82. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'>FILESEXTRAPATHS</ulink> := "${THISDIR}/${PN}"
  83. </literallayout>
  84. The path <filename>${THISDIR}/${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename> expands
  85. to "linux-yocto" in the current directory for this example.
  86. If you add any new files that modify the kernel recipe,
  87. you need to place them in your layer in the following area:
  88. <literallayout class='monospaced'>
  89. &lt;your-layer&gt;/recipes-kernel/linux/linux-yocto/
  90. </literallayout>
  91. <note>If you are working on a new machine Board Support Package
  92. (BSP), be sure to refer to the
  93. <ulink url='&YOCTO_DOCS_BSP_URL;'>Yocto Project Board Support Package (BSP) Developer's Guide</ulink>.
  94. </note>
  95. </para>
  96. </section>
  97. <section id='applying-patches'>
  98. <title>Applying Patches</title>
  99. <para>
  100. If you have a single patch or a small series of patches
  101. that you want to apply to the Linux kernel source, you
  102. can do so just as you would with any other recipe.
  103. You first copy the patches to the path added to
  104. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
  105. in your <filename>.bbappend</filename> file as described in
  106. the previous section, and then reference them in
  107. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  108. statements.
  109. </para>
  110. <para>
  111. For example, you can apply a three-patch series by adding the
  112. following lines to your linux-yocto <filename>.bbappend</filename>
  113. file in your layer:
  114. <literallayout class='monospaced'>
  115. SRC_URI += "file://0001-first-change.patch"
  116. SRC_URI += "file://0002-first-change.patch"
  117. SRC_URI += "file://0003-first-change.patch"
  118. </literallayout>
  119. The next time you run BitBake to build the Linux kernel, BitBake
  120. detects the change in the recipe and fetches and applies the patches
  121. before building the kernel.
  122. </para>
  123. <para>
  124. For a detailed example showing how to patch the kernel, see the
  125. "<ulink url='&YOCTO_DOCS_DEV_URL;#patching-the-kernel'>Patching the Kernel</ulink>"
  126. section in the Yocto Project Development Manual.
  127. </para>
  128. </section>
  129. <section id='changing-the-configuration'>
  130. <title>Changing the Configuration</title>
  131. <para>
  132. You can make wholesale or incremental changes to the Linux
  133. kernel <filename>.config</filename> file by including a
  134. <filename>defconfig</filename> or by specifying
  135. configuration fragments in the <filename>SRC_URI</filename>.
  136. </para>
  137. <para>
  138. If you have a complete Linux kernel <filename>.config</filename>
  139. file you want to use, copy it to the
  140. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink><filename>}</filename>
  141. directory within your layer and name it "defconfig".
  142. Then, add the following line to your linux-yocto
  143. <filename>.bbappend</filename> file in your layer:
  144. <literallayout class='monospaced'>
  145. SRC_URI += "file://defconfig"
  146. </literallayout>
  147. </para>
  148. <para>
  149. Generally speaking, the preferred approach is to determine the
  150. incremental change you want to make and add that as a
  151. configuration fragment.
  152. For example, if you want to add support for a basic serial
  153. console, create a file named <filename>8250.cfg</filename> in the
  154. <filename>${FILES}</filename> directory with the following
  155. content (without indentation):
  156. <literallayout class='monospaced'>
  157. CONFIG_SERIAL_8250=y
  158. CONFIG_SERIAL_8250_CONSOLE=y
  159. CONFIG_SERIAL_8250_PCI=y
  160. CONFIG_SERIAL_8250_NR_UARTS=4
  161. CONFIG_SERIAL_8250_RUNTIME_UARTS=4
  162. CONFIG_SERIAL_CORE=y
  163. CONFIG_SERIAL_CORE_CONSOLE=y
  164. </literallayout>
  165. Next, include this configuration fragment in a
  166. <filename>SRC_URI</filename> statement in your
  167. <filename>.bbappend</filename> file:
  168. <literallayout class='monospaced'>
  169. SRC_URI += "file://8250.cfg"
  170. </literallayout>
  171. The next time you run BitBake to build the Linux kernel, BitBake
  172. detects the change in the recipe and fetches and applies the
  173. new configuration before building the kernel.
  174. </para>
  175. <para>
  176. For a detailed example showing how to configure the kernel,
  177. see the
  178. "<ulink url='&YOCTO_DOCS_DEV_URL;#configuring-the-kernel'>Configuring the Kernel</ulink>"
  179. section in the Yocto Project Development Manual.
  180. </para>
  181. </section>
  182. </section>
  183. <section id='using-an-iterative-development-process'>
  184. <title>Using an Iterative Development Process</title>
  185. <para>
  186. If you do not have existing patches or configuration files,
  187. you can iteratively generate them from within the BitBake build
  188. environment as described within this section.
  189. During an iterative workflow, running a previously completed BitBake
  190. task causes BitBake to invalidate the tasks that follow the
  191. completed task in the build sequence.
  192. Invalidated tasks rebuild the next time you run the build using
  193. BitBake.
  194. </para>
  195. <para>
  196. As you read this section, be sure to substitute the name
  197. of your Linux kernel recipe for the term
  198. "linux-yocto".
  199. </para>
  200. <section id='tip-dirty-string'>
  201. <title>"-dirty" String</title>
  202. <!--
  203. <para>
  204. <emphasis>AR - Darrren Hart:</emphasis> This section
  205. originated from the old Yocto Project Kernel Architecture
  206. and Use Manual.
  207. It was decided we need to put it in this section here.
  208. Darren needs to figure out where we want it and what part
  209. of it we want (all, revision???)
  210. </para>
  211. -->
  212. <para>
  213. If kernel images are being built with "-dirty" on the
  214. end of the version string, this simply means that
  215. modifications in the source directory have not been committed.
  216. <literallayout class='monospaced'>
  217. $ git status
  218. </literallayout>
  219. </para>
  220. <para>
  221. You can use the above Git command to report modified,
  222. removed, or added files.
  223. You should commit those changes to the tree regardless of
  224. whether they will be saved, exported, or used.
  225. Once you commit the changes, you need to rebuild the kernel.
  226. </para>
  227. <para>
  228. To force a pickup and commit of all such pending changes,
  229. enter the following:
  230. <literallayout class='monospaced'>
  231. $ git add .
  232. $ git commit -s -a -m "getting rid of -dirty"
  233. </literallayout>
  234. </para>
  235. <para>
  236. Next, rebuild the kernel.
  237. </para>
  238. </section>
  239. <section id='generating-configuration-files'>
  240. <title>Generating Configuration Files</title>
  241. <para>
  242. You can manipulate the <filename>.config</filename> file
  243. used to build a linux-yocto recipe with the
  244. <filename>menuconfig</filename> command as follows:
  245. <literallayout class='monospaced'>
  246. $ bitbake linux-yocto -c menuconfig
  247. </literallayout>
  248. This command starts the Linux kernel configuration tool,
  249. which allows you to prepare a new
  250. <filename>.config</filename> file for the build.
  251. When you exit the tool, be sure to save your changes
  252. at the prompt.
  253. </para>
  254. <para>
  255. The resulting <filename>.config</filename> file is
  256. located in
  257. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename> under the
  258. <filename>linux-${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink><filename>}-${<ulink url='&YOCTO_DOCS_REF_URL;#var-KTYPE'><filename>KTYPE</filename></ulink>}-build</filename> directory.
  259. You can use the entire <filename>.config</filename> file as the
  260. <filename>defconfig</filename> file as described in the
  261. "<link linkend='changing-the-configuration'>Changing the Configuration</link>" section.
  262. </para>
  263. <para>
  264. A better method is to create a configuration fragment using the
  265. differences between two configuration files: one previously
  266. created and saved, and one freshly created using the
  267. <filename>menuconfig</filename> tool.
  268. </para>
  269. <para>
  270. To create a configuration fragment using this method, follow
  271. these steps:
  272. <orderedlist>
  273. <listitem><para>Complete a build at least through the kernel
  274. configuration task as follows:
  275. <literallayout class='monospaced'>
  276. $ bitbake linux-yocto -c kernel_configme -f
  277. </literallayout></para></listitem>
  278. <listitem><para>Copy and rename the resulting
  279. <filename>.config</filename> file (e.g.
  280. <filename>config.orig</filename>).
  281. </para></listitem>
  282. <listitem><para>Run the <filename>menuconfig</filename>
  283. command:
  284. <literallayout class='monospaced'>
  285. $ bitbake linux-yocto -c menuconfig
  286. </literallayout></para></listitem>
  287. <listitem><para>Prepare a configuration fragment based on
  288. the differences between the two files.
  289. </para></listitem>
  290. </orderedlist>
  291. </para>
  292. <para>
  293. Ultimately, the configuration fragment file needs to be a
  294. list of Linux kernel <filename>CONFIG_</filename> assignments.
  295. It cannot be in <filename>diff</filename> format.
  296. Here is an example of a command that creates your
  297. configuration fragment file.
  298. Regardless of the exact command you use, plan on reviewing
  299. the output as you can usually remove some of the defaults:
  300. <literallayout class='monospaced'>
  301. $ diff -Nurp config.orig .config | sed -n "s/^\+//p" > frag.cfg
  302. </literallayout>
  303. See the "<link linkend='changing-the-configuration'>Changing the Configuration</link>"
  304. section for information on how to use the output as a
  305. configuration fragment.
  306. <note>
  307. You can also use this method to create configuration
  308. fragments for a BSP.
  309. See the "<link linkend='bsp-descriptions'>BSP Descriptions</link>"
  310. section for more information.
  311. </note>
  312. </para>
  313. <para>
  314. The kernel tools also provide configuration validation.
  315. You can use these tools to produce warnings for when a
  316. requested configuration does not appear in the final
  317. <filename>.config</filename> file or when you override a
  318. policy configuration in a hardware configuration fragment.
  319. Here is an example with some sample output of the command
  320. that runs these tools:
  321. <literallayout class='monospaced'>
  322. $ bitbake linux-yocto -c kernel_configcheck -f
  323. ...
  324. NOTE: validating kernel configuration
  325. This BSP sets 3 invalid/obsolete kernel options.
  326. These config options are not offered anywhere within this kernel.
  327. The full list can be found in your kernel src dir at:
  328. meta/cfg/standard/mybsp/invalid.cfg
  329. This BSP sets 21 kernel options that are possibly non-hardware related.
  330. The full list can be found in your kernel src dir at:
  331. meta/cfg/standard/mybsp/specified_non_hdw.cfg
  332. WARNING: There were 2 hardware options requested that do not
  333. have a corresponding value present in the final ".config" file.
  334. This probably means you aren't getting the config you wanted.
  335. The full list can be found in your kernel src dir at:
  336. meta/cfg/standard/mybsp/mismatch.cfg
  337. </literallayout>
  338. </para>
  339. <para>
  340. The output describes the various problems that you can
  341. encounter along with where to find the offending configuration
  342. items.
  343. You can use the information in the logs to adjust your
  344. configuration files and then repeat the
  345. <filename>kernel_configme</filename> and
  346. <filename>kernel_configcheck</filename> commands until
  347. they produce no warnings.
  348. </para>
  349. <para>
  350. For more information on how to use the
  351. <filename>menuconfig</filename> tool, see the
  352. "<ulink url='&YOCTO_DOCS_DEV_URL;#using-menuconfig'>Using <filename>menuconfig</filename></ulink>"
  353. section in the Yocto Project Development Manual.
  354. </para>
  355. </section>
  356. <section id='modifying-source-code'>
  357. <title>Modifying Source Code</title>
  358. <para>
  359. You can experiment with source code changes and create a
  360. simple patch without leaving the BitBake environment.
  361. To get started, be sure to complete a build at
  362. least through the kernel configuration task:
  363. <literallayout class='monospaced'>
  364. $ bitbake linux-yocto -c kernel_configme -f
  365. </literallayout>
  366. Taking this step ensures you have the sources prepared
  367. and the configuration completed.
  368. You can find the sources in the
  369. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/linux</filename> directory.
  370. </para>
  371. <para>
  372. You can edit the sources as you would any other Linux source
  373. tree.
  374. However, keep in mind that you will lose changes if you
  375. trigger the <filename>fetch</filename> task for the recipe.
  376. You can avoid triggering this task by not issuing BitBake's
  377. <filename>cleanall</filename>, <filename>cleansstate</filename>,
  378. or forced <filename>fetch</filename> commands.
  379. Also, do not modify the recipe itself while working
  380. with temporary changes or BitBake might run the
  381. <filename>fetch</filename> command depending on the
  382. changes to the recipe.
  383. </para>
  384. <para>
  385. To test your temporary changes, instruct BitBake to run the
  386. <filename>compile</filename> again.
  387. The <filename>-f</filename> option forces the command to run
  388. even though BitBake might think it has already done so:
  389. <literallayout class='monospaced'>
  390. $ bitbake linux-yocto -c compile -f
  391. </literallayout>
  392. If the compile fails, you can update the sources and repeat
  393. the <filename>compile</filename>.
  394. Once compilation is successful, you can inspect and test
  395. the resulting build (i.e. kernel, modules, and so forth) from
  396. the <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>:
  397. <literallayout class='monospaced'>
  398. ${WORKDIR}/linux-${MACHINE}-${KTYPE}-build
  399. </literallayout>
  400. Alternatively, you can run the <filename>deploy</filename>
  401. command to place the kernel image in the
  402. <filename>tmp/deploy/images</filename> directory:
  403. <literallayout class='monospaced'>
  404. $ bitbake linux-yocto -c deploy
  405. </literallayout>
  406. And, of course, you can perform the remaining installation and
  407. packaging steps by issuing:
  408. <literallayout class='monospaced'>
  409. $ bitbake linux-yocto
  410. </literallayout>
  411. </para>
  412. <para>
  413. For rapid iterative development, the edit-compile-repeat loop
  414. described in this section is preferable to rebuilding the
  415. entire recipe because the installation and packaging tasks
  416. are very time consuming.
  417. </para>
  418. <para>
  419. Once you are satisfied with your source code modifications,
  420. you can make them permanent by generating patches and
  421. applying them to the
  422. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  423. statement as described in section
  424. "<link linkend='applying-patches'>Applying Patches</link>" section.
  425. If you are not familiar with generating patches, refer to the
  426. "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-the-patch'>Creating the Patch</ulink>"
  427. section in the Yocto Project Development Manual.
  428. </para>
  429. </section>
  430. </section>
  431. <section id='working-with-your-own-sources'>
  432. <title>Working With Your Own Sources</title>
  433. <para>
  434. If you cannot work with one of the Linux kernel
  435. versions supported by existing linux-yocto recipes, you can
  436. still make use of the Yocto Project Linux kernel tooling by
  437. working with your own sources.
  438. When you use your own sources, you will not be able to
  439. leverage the existing kernel
  440. <ulink url='&YOCTO_DOCS_DEV_URL;#metadata'>Metadata</ulink> and
  441. stabilization work of the linux-yocto sources.
  442. However, you will be able to manage your own Metadata in the same
  443. format as the linux-yocto sources.
  444. Maintaining format compatibility facilitates converging with
  445. linux-yocto on a future, mutually-supported kernel version.
  446. </para>
  447. <para>
  448. To help you use your own sources, the Yocto Project provides a
  449. linux-yocto custom recipe
  450. (<filename>linux-yocto-custom.bb</filename>) that uses
  451. <filename>kernel.org</filename> sources
  452. and the Yocto Project Linux kernel tools for managing
  453. kernel Metadata.
  454. You can find this recipe in the
  455. <filename>poky</filename> Git repository of the
  456. Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink>
  457. at:
  458. <literallayout class="monospaced">
  459. poky/meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb
  460. </literallayout>
  461. </para>
  462. <para>
  463. Here are some basic steps you can use to work with your own sources:
  464. <orderedlist>
  465. <listitem><para>Copy the <filename>linux-yocto-custom.bb</filename>
  466. recipe to your layer and give it a meaningful name.
  467. The name should include the version of the Linux kernel you
  468. are using (e.g. <filename>linux-yocto-myproject_3.5.bb</filename>,
  469. where "3.5" is the base version of the Linux kernel
  470. with which you would be working).</para></listitem>
  471. <listitem><para>In the same directory inside your layer,
  472. create a matching directory
  473. to store your patches and configuration files (e.g.
  474. <filename>linux-yocto-myproject</filename>).
  475. </para></listitem>
  476. <listitem><para>Edit the following variables in your recipe
  477. as appropriate for your project:
  478. <itemizedlist>
  479. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>:
  480. The <filename>SRC_URI</filename> should be a Git
  481. repository that uses one of the supported Git fetcher
  482. protocols (i.e. <filename>file</filename>,
  483. <filename>git</filename>, <filename>http</filename>,
  484. and so forth).
  485. The skeleton recipe provides an example
  486. <filename>SRC_URI</filename> as a syntax reference.
  487. </para></listitem>
  488. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION'><filename>LINUX_VERSION</filename></ulink>:
  489. The Linux kernel version you are using (e.g.
  490. "3.4").</para></listitem>
  491. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION_EXTENSION'><filename>LINUX_VERSION_EXTENSION</filename></ulink>:
  492. The Linux kernel <filename>CONFIG_LOCALVERSION</filename>
  493. that is compiled into the resulting kernel and visible
  494. through the <filename>uname</filename> command.
  495. </para></listitem>
  496. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>:
  497. The commit ID from which you want to build.
  498. </para></listitem>
  499. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
  500. Treat this variable the same as you would in any other
  501. recipe.
  502. Increment the variable to indicate to the OpenEmbedded
  503. build system that the recipe has changed.
  504. </para></listitem>
  505. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
  506. The default <filename>PV</filename> assignment is
  507. typically adequate.
  508. It combines the <filename>LINUX_VERSION</filename>
  509. with the Source Control Manager (SCM) revision
  510. as derived from the
  511. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>
  512. variable.
  513. The combined results are a string with
  514. the following form:
  515. <literallayout class='monospaced'>
  516. 3.4.11+git1+68a635bf8dfb64b02263c1ac80c948647cc76d5f_1+218bd8d2022b9852c60d32f0d770931e3cf343e2
  517. </literallayout>
  518. While lengthy, the extra verbosity in <filename>PV</filename>
  519. helps ensure you are using the exact
  520. sources from which you intend to build.
  521. </para></listitem>
  522. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'><filename>COMPATIBLE_MACHINE</filename></ulink>:
  523. A list of the machines supported by your new recipe.
  524. This variable in the example recipe is set
  525. by default to a regular expression that matches
  526. only the empty string, "(^$)".
  527. This default setting triggers an explicit build
  528. failure.
  529. You must change it to match a list of the machines
  530. that your new recipe supports.
  531. For example, to support the <filename>qemux86</filename>
  532. and <filename>qemux86-64</filename> machines, use
  533. the following form:
  534. <literallayout class='monospaced'>
  535. COMPATIBLE_MACHINE = "qemux86|qemux86-64"
  536. </literallayout></para></listitem>
  537. </itemizedlist></para></listitem>
  538. <listitem><para>Provide further customizations to your recipe
  539. as needed just as you would customize an existing
  540. linux-yocto recipe.
  541. See the "<link linkend='modifying-an-existing-recipe'>Modifying
  542. an Existing Recipe</link>" section for information.
  543. </para></listitem>
  544. </orderedlist>
  545. </para>
  546. </section>
  547. <section id='incorporating-out-of-tree-modules'>
  548. <title>Incorporating Out-of-Tree Modules</title>
  549. <para>
  550. While it is always preferable to work with sources integrated
  551. into the Linux kernel sources, if you need an external kernel
  552. module, the <filename>hello-mod.bb</filename> recipe is available
  553. as a template from which you can create your own out-of-tree
  554. Linux kernel module recipe.
  555. </para>
  556. <para>
  557. This template recipe is located in the
  558. <filename>poky</filename> Git repository of the
  559. Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink>
  560. at:
  561. <literallayout class="monospaced">
  562. poky/meta-skeleton/recipes-kernel/hello-mod/hello-mod_0.1.bb
  563. </literallayout>
  564. </para>
  565. <para>
  566. To get started, copy this recipe to your layer and give it a
  567. meaningful name (e.g. <filename>mymodule_1.0.bb</filename>).
  568. In the same directory, create a directory named
  569. <filename>files</filename> where you can store any source files,
  570. patches, or other files necessary for building
  571. the module that do not come with the sources.
  572. Finally, update the recipe as appropriate for the module.
  573. Typically you will need to set the following variables:
  574. <itemizedlist>
  575. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
  576. </para></listitem>
  577. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE*</filename></ulink>
  578. </para></listitem>
  579. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  580. </para></listitem>
  581. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
  582. </para></listitem>
  583. </itemizedlist>
  584. </para>
  585. <para>
  586. Depending on the build system used by the module sources, you might
  587. need to make some adjustments.
  588. For example, a typical module <filename>Makefile</filename> looks
  589. much like the one provided with the <filename>hello-mod</filename>
  590. template:
  591. <literallayout class='monospaced'>
  592. obj-m := hello.o
  593. SRC := $(shell pwd)
  594. all:
  595. $(MAKE) -C $(KERNEL_SRC) M=$(SRC)
  596. modules_install:
  597. $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
  598. ...
  599. </literallayout>
  600. </para>
  601. <para>
  602. The important point to note here is the
  603. <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_SRC'><filename>KERNEL_SRC</filename></ulink>
  604. variable.
  605. The class <filename>module.bbclass</filename> sets this variable,
  606. as well as the
  607. <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_PATH'><filename>KERNEL_PATH</filename></ulink>
  608. variable to
  609. <filename>${<ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_KERNEL_DIR'><filename>STAGING_KERNEL_DIR</filename></ulink>}</filename>
  610. with the necessary Linux kernel build information to build modules.
  611. If your module <filename>Makefile</filename> uses a different
  612. variable, you might want to override the
  613. <filename>do_compile()</filename> step, or create a patch to
  614. the <filename>Makefile</filename> to work with the more typical
  615. <filename>KERNEL_SRC</filename> or <filename>KERNEL_PATH</filename>
  616. variables.
  617. </para>
  618. <para>
  619. After you have prepared your recipe, you will likely want to
  620. include the module in your images.
  621. To do this, see the documentation for the following variables in
  622. the Yocto Project Reference Manual and set one of them as
  623. appropriate in your machine configuration file:
  624. <itemizedlist>
  625. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RDEPENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RDEPENDS</filename></ulink>
  626. </para></listitem>
  627. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink>
  628. </para></listitem>
  629. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RDEPENDS'><filename>MACHINE_EXTRA_RDEPENDS</filename></ulink>
  630. </para></listitem>
  631. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RRECOMMENDS'><filename>MACHINE_EXTRA_RRECOMMENDS</filename></ulink>
  632. </para></listitem>
  633. </itemizedlist>
  634. </para>
  635. <para>
  636. modules are often not required for boot and can be excluded from
  637. certain build configurations.
  638. The following allows for the most flexibility:
  639. <literallayout class='monospaced'>
  640. MACHINE_EXTRA_RRECOMMENDS += "kernel-module-mymodule"
  641. </literallayout>
  642. Where the value is derived by appending the module filename without
  643. the <filename>.ko</filename> extension to the string
  644. "kernel-module-".
  645. </para>
  646. <para>
  647. Because the variable is
  648. <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
  649. and not a
  650. <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
  651. variable, the build will not fail if this module is not available
  652. to include in the image.
  653. </para>
  654. </section>
  655. <section id='inspecting-changes-and-commits'>
  656. <title>Inspecting Changes and Commits</title>
  657. <para>
  658. A common question when working with a kernel is:
  659. "What changes have been applied to this tree?"
  660. Rather than using "grep" across directories to see what has
  661. changed, you can use Git to inspect or search the kernel tree.
  662. Using Git is an efficent way to see what has changed in the tree.
  663. </para>
  664. <section id='what-changed-in-a-kernel'>
  665. <title>What Changed in a Kernel?</title>
  666. <para>
  667. Following are a few examples that show how to use Git
  668. commands to examine changes.
  669. These examples are by no means the only way to see changes.
  670. <note>
  671. In the following examples, unless you provide a commit
  672. range, <filename>kernel.org</filename> history is blended
  673. with Yocto Project kernel changes.
  674. You can form ranges by using branch names from the
  675. kernel tree as the upper and lower commit markers with
  676. the Git commands.
  677. You can see the branch names through the web interface
  678. to the Yocto Project source repositories at
  679. <ulink url='http://git.yoctoproject.org/cgit.cgi'></ulink>.
  680. </note>
  681. To see a full range of the changes, use the
  682. <filename>git whatchanged</filename> command and specify a
  683. commit range for the branch
  684. (<filename>&lt;commit&gt;..&lt;commit&gt;</filename>).
  685. </para>
  686. <para>
  687. Here is an example that looks at what has changed in the
  688. <filename>emenlow</filename> branch of the
  689. <filename>linux-yocto-3.4</filename> kernel.
  690. The lower commit range is the commit associated with the
  691. <filename>standard/base</filename> branch, while
  692. the upper commit range is the commit associated with the
  693. <filename>standard/emenlow</filename> branch.
  694. <literallayout class='monospaced'>
  695. $ git whatchanged origin/standard/base..origin/standard/emenlow
  696. </literallayout>
  697. </para>
  698. <para>
  699. To see short, oneline summaries of changes use the
  700. <filename>git log</filename> command:
  701. <literallayout class='monospaced'>
  702. $ git log --oneline origin/standard/base..origin/standard/emenlow
  703. </literallayout>
  704. </para>
  705. <para>
  706. Use this command to see code differences for the changes:
  707. <literallayout class='monospaced'>
  708. $ git diff origin/standard/base..origin/standard/emenlow
  709. </literallayout>
  710. </para>
  711. <para>
  712. Use this command to see the commit log messages and the
  713. text differences:
  714. <literallayout class='monospaced'>
  715. $ git show origin/standard/base..origin/standard/emenlow
  716. </literallayout>
  717. </para>
  718. <para>
  719. Use this command to create individual patches for
  720. each change.
  721. Here is an example that that creates patch files for each
  722. commit and places them in your <filename>Documents</filename>
  723. directory:
  724. <literallayout class='monospaced'>
  725. $ git format-patch -o $HOME/Documents origin/standard/base..origin/standard/emenlow
  726. </literallayout>
  727. </para>
  728. </section>
  729. <section id='showing-a-particular-feature-or-branch-change'>
  730. <title>Showing a Particular Feature or Branch Change</title>
  731. <para>
  732. Tags in the Yocto Project kernel tree divide changes for
  733. significant features or branches.
  734. The <filename>git show &lt;tag&gt;</filename> command shows
  735. changes based on a tag.
  736. Here is an example that shows <filename>systemtap</filename>
  737. changes:
  738. <literallayout class='monospaced'>
  739. $ git show systemtap
  740. </literallayout>
  741. You can use the
  742. <filename>git branch --contains &lt;tag&gt;</filename> command
  743. to show the branches that contain a particular feature.
  744. This command shows the branches that contain the
  745. <filename>systemtap</filename> feature:
  746. <literallayout class='monospaced'>
  747. $ git branch --contains systemtap
  748. </literallayout>
  749. </para>
  750. </section>
  751. </section>
  752. </chapter>
  753. <!--
  754. vim: expandtab tw=80 ts=4
  755. -->