kernel-dev-common.xml 42 KB

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