common.rst 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. ************
  3. Common Tasks
  4. ************
  5. This chapter presents several common tasks you perform when you work
  6. with the Yocto Project Linux kernel. These tasks include preparing your
  7. host development system for kernel development, preparing a layer,
  8. modifying an existing recipe, patching the kernel, configuring the
  9. kernel, iterative development, working with your own sources, and
  10. incorporating out-of-tree modules.
  11. .. note::
  12. The examples presented in this chapter work with the Yocto Project
  13. 2.4 Release and forward.
  14. Preparing the Build Host to Work on the Kernel
  15. ==============================================
  16. Before you can do any kernel development, you need to be sure your build
  17. host is set up to use the Yocto Project. For information on how to get
  18. set up, see the ":doc:`/dev-manual/start`" section in
  19. the Yocto Project Development Tasks Manual. Part of preparing the system
  20. is creating a local Git repository of the
  21. :term:`Source Directory` (``poky``) on your system. Follow the steps in the
  22. ":ref:`dev-manual/start:cloning the \`\`poky\`\` repository`"
  23. section in the Yocto Project Development Tasks Manual to set up your
  24. Source Directory.
  25. .. note::
  26. Be sure you check out the appropriate development branch or you
  27. create your local branch by checking out a specific tag to get the
  28. desired version of Yocto Project. See the
  29. ":ref:`dev-manual/start:checking out by branch in poky`" and
  30. ":ref:`dev-manual/start:checking out by tag in poky`"
  31. sections in the Yocto Project Development Tasks Manual for more information.
  32. Kernel development is best accomplished using
  33. :ref:`devtool <sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow>`
  34. and not through traditional kernel workflow methods. The remainder of
  35. this section provides information for both scenarios.
  36. Getting Ready to Develop Using ``devtool``
  37. ------------------------------------------
  38. Follow these steps to prepare to update the kernel image using
  39. ``devtool``. Completing this procedure leaves you with a clean kernel
  40. image and ready to make modifications as described in the
  41. ":ref:`kernel-dev/common:using \`\`devtool\`\` to patch the kernel`"
  42. section:
  43. 1. *Initialize the BitBake Environment:*
  44. you need to initialize the BitBake build environment by sourcing
  45. the build environment script (i.e. :ref:`structure-core-script`)::
  46. $ cd poky
  47. $ source oe-init-build-env
  48. .. note::
  49. The previous commands assume the
  50. :ref:`overview-manual/development-environment:yocto project source repositories`
  51. (i.e. ``poky``) have been cloned using Git and the local repository is named
  52. "poky".
  53. 2. *Prepare Your local.conf File:* By default, the :term:`MACHINE` variable
  54. is set to "qemux86-64", which is fine if you are building for the QEMU
  55. emulator in 64-bit mode. However, if you are not, you need to set the
  56. :term:`MACHINE` variable appropriately in your ``conf/local.conf`` file
  57. found in the :term:`Build Directory` (i.e. ``poky/build`` in this example).
  58. Also, since you are preparing to work on the kernel image, you need
  59. to set the :term:`MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS` variable to include
  60. kernel modules.
  61. In this example we wish to build for qemux86 so we must set the
  62. :term:`MACHINE` variable to "qemux86" and also add the "kernel-modules".
  63. As described we do this by appending to ``conf/local.conf``::
  64. MACHINE = "qemux86"
  65. MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules"
  66. 3. *Create a Layer for Patches:* You need to create a layer to hold
  67. patches created for the kernel image. You can use the
  68. ``bitbake-layers create-layer`` command as follows::
  69. $ cd poky/build
  70. $ bitbake-layers create-layer ../../meta-mylayer
  71. NOTE: Starting bitbake server...
  72. Add your new layer with 'bitbake-layers add-layer ../../meta-mylayer'
  73. $
  74. .. note::
  75. For background information on working with common and BSP layers,
  76. see the
  77. ":ref:`dev-manual/layers:understanding and creating layers`"
  78. section in the Yocto Project Development Tasks Manual and the
  79. ":ref:`bsp-guide/bsp:bsp layers`" section in the Yocto Project Board
  80. Support (BSP) Developer's Guide, respectively. For information on how to
  81. use the ``bitbake-layers create-layer`` command to quickly set up a layer,
  82. see the
  83. ":ref:`dev-manual/layers:creating a general layer using the \`\`bitbake-layers\`\` script`"
  84. section in the Yocto Project Development Tasks Manual.
  85. 4. *Inform the BitBake Build Environment About Your Layer:* As directed
  86. when you created your layer, you need to add the layer to the
  87. :term:`BBLAYERS` variable in the
  88. ``bblayers.conf`` file as follows::
  89. $ cd poky/build
  90. $ bitbake-layers add-layer ../../meta-mylayer
  91. NOTE: Starting bitbake server...
  92. $
  93. 5. *Build the Clean Image:* The final step in preparing to work on the
  94. kernel is to build an initial image using ``bitbake``::
  95. $ bitbake core-image-minimal
  96. Parsing recipes: 100% |##########################################| Time: 0:00:05
  97. Parsing of 830 .bb files complete (0 cached, 830 parsed). 1299 targets, 47 skipped, 0 masked, 0 errors.
  98. WARNING: No packages to add, building image core-image-minimal unmodified
  99. Loading cache: 100% |############################################| Time: 0:00:00
  100. Loaded 1299 entries from dependency cache.
  101. NOTE: Resolving any missing task queue dependencies
  102. Initializing tasks: 100% |#######################################| Time: 0:00:07
  103. Checking sstate mirror object availability: 100% |###############| Time: 0:00:00
  104. NOTE: Executing SetScene Tasks
  105. NOTE: Executing RunQueue Tasks
  106. NOTE: Tasks Summary: Attempted 2866 tasks of which 2604 didn't need to be rerun and all succeeded.
  107. If you were
  108. building for actual hardware and not for emulation, you could flash
  109. the image to a USB stick on ``/dev/sdd`` and boot your device. For an
  110. example that uses a Minnowboard, see the
  111. :yocto_wiki:`TipsAndTricks/KernelDevelopmentWithEsdk </TipsAndTricks/KernelDevelopmentWithEsdk>`
  112. Wiki page.
  113. At this point you have set up to start making modifications to the
  114. kernel. For a continued example, see the
  115. ":ref:`kernel-dev/common:using \`\`devtool\`\` to patch the kernel`"
  116. section.
  117. Getting Ready for Traditional Kernel Development
  118. ------------------------------------------------
  119. Getting ready for traditional kernel development using the Yocto Project
  120. involves many of the same steps as described in the previous section.
  121. However, you need to establish a local copy of the kernel source since
  122. you will be editing these files.
  123. Follow these steps to prepare to update the kernel image using
  124. traditional kernel development flow with the Yocto Project. Completing
  125. this procedure leaves you ready to make modifications to the kernel
  126. source as described in the ":ref:`kernel-dev/common:using traditional kernel development to patch the kernel`"
  127. section:
  128. 1. *Initialize the BitBake Environment:* Before you can do anything
  129. using BitBake, you need to initialize the BitBake build environment
  130. by sourcing the build environment script (i.e.
  131. :ref:`structure-core-script`).
  132. Also, for this example, be sure that the local branch you have
  133. checked out for ``poky`` is the Yocto Project &DISTRO_NAME; branch. If
  134. you need to checkout out the &DISTRO_NAME; branch, see the
  135. ":ref:`dev-manual/start:checking out by branch in poky`"
  136. section in the Yocto Project Development Tasks Manual.
  137. ::
  138. $ cd poky
  139. $ git branch
  140. master
  141. * &DISTRO_NAME_NO_CAP;
  142. $ source oe-init-build-env
  143. .. note::
  144. The previous commands assume the
  145. :ref:`overview-manual/development-environment:yocto project source repositories`
  146. (i.e. ``poky``) have been cloned using Git and the local repository is named
  147. "poky".
  148. 2. *Prepare Your local.conf File:* By default, the :term:`MACHINE` variable is
  149. set to "qemux86-64", which is fine if you are building for the QEMU emulator
  150. in 64-bit mode. However, if you are not, you need to set the :term:`MACHINE`
  151. variable appropriately in your ``conf/local.conf`` file found in the
  152. :term:`Build Directory` (i.e. ``poky/build`` in this example).
  153. Also, since you are preparing to work on the kernel image, you need
  154. to set the
  155. :term:`MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS`
  156. variable to include kernel modules.
  157. In this example we wish to build for qemux86 so we must set the
  158. :term:`MACHINE` variable to "qemux86" and also add the "kernel-modules".
  159. As described we do this by appending to ``conf/local.conf``::
  160. MACHINE = "qemux86"
  161. MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules"
  162. 3. *Create a Layer for Patches:* You need to create a layer to hold
  163. patches created for the kernel image. You can use the
  164. ``bitbake-layers create-layer`` command as follows::
  165. $ cd poky/build
  166. $ bitbake-layers create-layer ../../meta-mylayer
  167. NOTE: Starting bitbake server...
  168. Add your new layer with 'bitbake-layers add-layer ../../meta-mylayer'
  169. .. note::
  170. For background information on working with common and BSP layers,
  171. see the
  172. ":ref:`dev-manual/layers:understanding and creating layers`"
  173. section in the Yocto Project Development Tasks Manual and the
  174. ":ref:`bsp-guide/bsp:bsp layers`" section in the Yocto Project Board
  175. Support (BSP) Developer's Guide, respectively. For information on how to
  176. use the ``bitbake-layers create-layer`` command to quickly set up a layer,
  177. see the
  178. ":ref:`dev-manual/layers:creating a general layer using the \`\`bitbake-layers\`\` script`"
  179. section in the Yocto Project Development Tasks Manual.
  180. 4. *Inform the BitBake Build Environment About Your Layer:* As directed
  181. when you created your layer, you need to add the layer to the
  182. :term:`BBLAYERS` variable in the
  183. ``bblayers.conf`` file as follows::
  184. $ cd poky/build
  185. $ bitbake-layers add-layer ../../meta-mylayer
  186. NOTE: Starting bitbake server ...
  187. $
  188. 5. *Create a Local Copy of the Kernel Git Repository:* You can find Git
  189. repositories of supported Yocto Project kernels organized under
  190. "Yocto Linux Kernel" in the Yocto Project Source Repositories at
  191. :yocto_git:`/`.
  192. For simplicity, it is recommended that you create your copy of the
  193. kernel Git repository outside of the
  194. :term:`Source Directory`, which is
  195. usually named ``poky``. Also, be sure you are in the
  196. ``standard/base`` branch.
  197. The following commands show how to create a local copy of the
  198. ``linux-yocto-4.12`` kernel and be in the ``standard/base`` branch.
  199. .. note::
  200. The ``linux-yocto-4.12`` kernel can be used with the Yocto Project 2.4
  201. release and forward.
  202. You cannot use the ``linux-yocto-4.12`` kernel with releases prior to
  203. Yocto Project 2.4.
  204. ::
  205. $ cd ~
  206. $ git clone git://git.yoctoproject.org/linux-yocto-4.12 --branch standard/base
  207. Cloning into 'linux-yocto-4.12'...
  208. remote: Counting objects: 6097195, done.
  209. remote: Compressing objects: 100% (901026/901026), done.
  210. remote: Total 6097195 (delta 5152604), reused 6096847 (delta 5152256)
  211. Receiving objects: 100% (6097195/6097195), 1.24 GiB | 7.81 MiB/s, done.
  212. Resolving deltas: 100% (5152604/5152604), done. Checking connectivity... done.
  213. Checking out files: 100% (59846/59846), done.
  214. 6. *Create a Local Copy of the Kernel Cache Git Repository:* For
  215. simplicity, it is recommended that you create your copy of the kernel
  216. cache Git repository outside of the
  217. :term:`Source Directory`, which is
  218. usually named ``poky``. Also, for this example, be sure you are in
  219. the ``yocto-4.12`` branch.
  220. The following commands show how to create a local copy of the
  221. ``yocto-kernel-cache`` and switch to the ``yocto-4.12`` branch::
  222. $ cd ~
  223. $ git clone git://git.yoctoproject.org/yocto-kernel-cache --branch yocto-4.12
  224. Cloning into 'yocto-kernel-cache'...
  225. remote: Counting objects: 22639, done.
  226. remote: Compressing objects: 100% (9761/9761), done.
  227. remote: Total 22639 (delta 12400), reused 22586 (delta 12347)
  228. Receiving objects: 100% (22639/22639), 22.34 MiB | 6.27 MiB/s, done.
  229. Resolving deltas: 100% (12400/12400), done.
  230. Checking connectivity... done.
  231. At this point, you are ready to start making modifications to the kernel
  232. using traditional kernel development steps. For a continued example, see
  233. the ":ref:`kernel-dev/common:using traditional kernel development to patch the kernel`"
  234. section.
  235. Creating and Preparing a Layer
  236. ==============================
  237. If you are going to be modifying kernel recipes, it is recommended that
  238. you create and prepare your own layer in which to do your work. Your
  239. layer contains its own :term:`BitBake`
  240. append files (``.bbappend``) and provides a convenient mechanism to
  241. create your own recipe files (``.bb``) as well as store and use kernel
  242. patch files. For background information on working with layers, see the
  243. ":ref:`dev-manual/layers:understanding and creating layers`"
  244. section in the Yocto Project Development Tasks Manual.
  245. .. note::
  246. The Yocto Project comes with many tools that simplify tasks you need
  247. to perform. One such tool is the ``bitbake-layers create-layer``
  248. command, which simplifies creating a new layer. See the
  249. ":ref:`dev-manual/layers:creating a general layer using the \`\`bitbake-layers\`\` script`"
  250. section in the Yocto Project Development Tasks Manual for
  251. information on how to use this script to quick set up a new layer.
  252. To better understand the layer you create for kernel development, the
  253. following section describes how to create a layer without the aid of
  254. tools. These steps assume creation of a layer named ``mylayer`` in your
  255. home directory:
  256. 1. *Create Structure*: Create the layer's structure::
  257. $ mkdir meta-mylayer
  258. $ mkdir meta-mylayer/conf
  259. $ mkdir meta-mylayer/recipes-kernel
  260. $ mkdir meta-mylayer/recipes-kernel/linux
  261. $ mkdir meta-mylayer/recipes-kernel/linux/linux-yocto
  262. The ``conf`` directory holds your configuration files, while the
  263. ``recipes-kernel`` directory holds your append file and eventual
  264. patch files.
  265. 2. *Create the Layer Configuration File*: Move to the
  266. ``meta-mylayer/conf`` directory and create the ``layer.conf`` file as
  267. follows::
  268. # We have a conf and classes directory, add to BBPATH
  269. BBPATH .= ":${LAYERDIR}"
  270. # We have recipes-* directories, add to BBFILES
  271. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  272. ${LAYERDIR}/recipes-*/*/*.bbappend"
  273. BBFILE_COLLECTIONS += "mylayer"
  274. BBFILE_PATTERN_mylayer = "^${LAYERDIR}/"
  275. BBFILE_PRIORITY_mylayer = "5"
  276. Notice ``mylayer`` as part of the last three statements.
  277. 3. *Create the Kernel Recipe Append File*: Move to the
  278. ``meta-mylayer/recipes-kernel/linux`` directory and create the
  279. kernel's append file. This example uses the ``linux-yocto-4.12``
  280. kernel. Thus, the name of the append file is
  281. ``linux-yocto_4.12.bbappend``::
  282. FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
  283. SRC_URI += "file://patch-file-one.patch"
  284. SRC_URI += "file://patch-file-two.patch"
  285. SRC_URI += "file://patch-file-three.patch"
  286. The :term:`FILESEXTRAPATHS` and :term:`SRC_URI` statements
  287. enable the OpenEmbedded build system to find patch files. For more
  288. information on using append files, see the
  289. ":ref:`dev-manual/layers:appending other layers metadata with your layer`"
  290. section in the Yocto Project Development Tasks Manual.
  291. Modifying an Existing Recipe
  292. ============================
  293. In many cases, you can customize an existing linux-yocto recipe to meet
  294. the needs of your project. Each release of the Yocto Project provides a
  295. few Linux kernel recipes from which you can choose. These are located in
  296. the :term:`Source Directory` in
  297. ``meta/recipes-kernel/linux``.
  298. Modifying an existing recipe can consist of the following:
  299. - :ref:`kernel-dev/common:creating the append file`
  300. - :ref:`kernel-dev/common:applying patches`
  301. - :ref:`kernel-dev/common:changing the configuration`
  302. Before modifying an existing recipe, be sure that you have created a
  303. minimal, custom layer from which you can work. See the
  304. ":ref:`kernel-dev/common:creating and preparing a layer`" section for
  305. information.
  306. Creating the Append File
  307. ------------------------
  308. You create this file in your custom layer. You also name it accordingly
  309. based on the linux-yocto recipe you are using. For example, if you are
  310. modifying the ``meta/recipes-kernel/linux/linux-yocto_4.12.bb`` recipe,
  311. the append file will typically be located as follows within your custom
  312. layer:
  313. .. code-block:: none
  314. your-layer/recipes-kernel/linux/linux-yocto_4.12.bbappend
  315. The append file should initially extend the
  316. :term:`FILESPATH` search path by
  317. prepending the directory that contains your files to the
  318. :term:`FILESEXTRAPATHS`
  319. variable as follows::
  320. FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
  321. The path ``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``
  322. expands to "linux-yocto" in the current directory for this example. If
  323. you add any new files that modify the kernel recipe and you have
  324. extended :term:`FILESPATH` as described above, you must place the files in
  325. your layer in the following area::
  326. your-layer/recipes-kernel/linux/linux-yocto/
  327. .. note::
  328. If you are working on a new machine Board Support Package (BSP), be
  329. sure to refer to the :doc:`/bsp-guide/index`.
  330. As an example, consider the following append file used by the BSPs in
  331. ``meta-yocto-bsp``:
  332. .. code-block:: none
  333. meta-yocto-bsp/recipes-kernel/linux/linux-yocto_4.12.bbappend
  334. Here are the contents of this file. Be aware that the actual commit ID
  335. strings in this example listing might be different than the actual
  336. strings in the file from the ``meta-yocto-bsp`` layer upstream.
  337. ::
  338. KBRANCH:genericx86 = "standard/base"
  339. KBRANCH:genericx86-64 = "standard/base"
  340. KMACHINE:genericx86 ?= "common-pc"
  341. KMACHINE:genericx86-64 ?= "common-pc-64"
  342. KBRANCH:edgerouter = "standard/edgerouter"
  343. KBRANCH:beaglebone = "standard/beaglebone"
  344. SRCREV_machine:genericx86 ?= "d09f2ce584d60ecb7890550c22a80c48b83c2e19"
  345. SRCREV_machine:genericx86-64 ?= "d09f2ce584d60ecb7890550c22a80c48b83c2e19"
  346. SRCREV_machine:edgerouter ?= "b5c8cfda2dfe296410d51e131289fb09c69e1e7d"
  347. SRCREV_machine:beaglebone ?= "b5c8cfda2dfe296410d51e131289fb09c69e1e7d"
  348. COMPATIBLE_MACHINE:genericx86 = "genericx86"
  349. COMPATIBLE_MACHINE:genericx86-64 = "genericx86-64"
  350. COMPATIBLE_MACHINE:edgerouter = "edgerouter"
  351. COMPATIBLE_MACHINE:beaglebone = "beaglebone"
  352. LINUX_VERSION:genericx86 = "4.12.7"
  353. LINUX_VERSION:genericx86-64 = "4.12.7"
  354. LINUX_VERSION:edgerouter = "4.12.10"
  355. LINUX_VERSION:beaglebone = "4.12.10"
  356. This append file
  357. contains statements used to support several BSPs that ship with the
  358. Yocto Project. The file defines machines using the
  359. :term:`COMPATIBLE_MACHINE`
  360. variable and uses the
  361. :term:`KMACHINE` variable to ensure
  362. the machine name used by the OpenEmbedded build system maps to the
  363. machine name used by the Linux Yocto kernel. The file also uses the
  364. optional :term:`KBRANCH` variable to
  365. ensure the build process uses the appropriate kernel branch.
  366. Although this particular example does not use it, the
  367. :term:`KERNEL_FEATURES`
  368. variable could be used to enable features specific to the kernel. The
  369. append file points to specific commits in the
  370. :term:`Source Directory` Git repository and
  371. the ``meta`` Git repository branches to identify the exact kernel needed
  372. to build the BSP.
  373. One thing missing in this particular BSP, which you will typically need
  374. when developing a BSP, is the kernel configuration file (``.config``)
  375. for your BSP. When developing a BSP, you probably have a kernel
  376. configuration file or a set of kernel configuration files that, when
  377. taken together, define the kernel configuration for your BSP. You can
  378. accomplish this definition by putting the configurations in a file or a
  379. set of files inside a directory located at the same level as your
  380. kernel's append file and having the same name as the kernel's main
  381. recipe file. With all these conditions met, simply reference those files
  382. in the :term:`SRC_URI` statement in
  383. the append file.
  384. For example, suppose you had some configuration options in a file called
  385. ``network_configs.cfg``. You can place that file inside a directory
  386. named ``linux-yocto`` and then add a :term:`SRC_URI` statement such as the
  387. following to the append file. When the OpenEmbedded build system builds
  388. the kernel, the configuration options are picked up and applied.
  389. ::
  390. SRC_URI += "file://network_configs.cfg"
  391. To group related configurations into multiple files, you perform a
  392. similar procedure. Here is an example that groups separate
  393. configurations specifically for Ethernet and graphics into their own
  394. files and adds the configurations by using a :term:`SRC_URI` statement like
  395. the following in your append file::
  396. SRC_URI += "file://myconfig.cfg \
  397. file://eth.cfg \
  398. file://gfx.cfg"
  399. Another variable you can use in your kernel recipe append file is the
  400. :term:`FILESEXTRAPATHS`
  401. variable. When you use this statement, you are extending the locations
  402. used by the OpenEmbedded system to look for files and patches as the
  403. recipe is processed.
  404. .. note::
  405. There are other ways of grouping and defining configuration
  406. options. For example, if you are working with a local clone of the
  407. kernel repository, you could checkout the kernel's ``meta`` branch,
  408. make your changes, and then push the changes to the local bare clone
  409. of the kernel. The result is that you directly add configuration
  410. options to the ``meta`` branch for your BSP. The configuration
  411. options will likely end up in that location anyway if the BSP gets
  412. added to the Yocto Project.
  413. In general, however, the Yocto Project maintainers take care of
  414. moving the :term:`SRC_URI`-specified configuration options to the
  415. kernel's ``meta`` branch. Not only is it easier for BSP developers
  416. not to have to put those configurations in the branch,
  417. but having the maintainers do it allows them to apply 'global'
  418. knowledge about the kinds of common configuration options multiple
  419. BSPs in the tree are typically using. This allows for promotion of
  420. common configurations into common features.
  421. Applying Patches
  422. ----------------
  423. If you have a single patch or a small series of patches that you want to
  424. apply to the Linux kernel source, you can do so just as you would with
  425. any other recipe. You first copy the patches to the path added to
  426. :term:`FILESEXTRAPATHS` in
  427. your ``.bbappend`` file as described in the previous section, and then
  428. reference them in :term:`SRC_URI`
  429. statements.
  430. For example, you can apply a three-patch series by adding the following
  431. lines to your linux-yocto ``.bbappend`` file in your layer::
  432. SRC_URI += "file://0001-first-change.patch"
  433. SRC_URI += "file://0002-second-change.patch"
  434. SRC_URI += "file://0003-third-change.patch"
  435. The next time you run BitBake to build
  436. the Linux kernel, BitBake detects the change in the recipe and fetches
  437. and applies the patches before building the kernel.
  438. For a detailed example showing how to patch the kernel using
  439. ``devtool``, see the
  440. ":ref:`kernel-dev/common:using \`\`devtool\`\` to patch the kernel`"
  441. and
  442. ":ref:`kernel-dev/common:using traditional kernel development to patch the kernel`"
  443. sections.
  444. Changing the Configuration
  445. --------------------------
  446. You can make wholesale or incremental changes to the final ``.config``
  447. file used for the eventual Linux kernel configuration by including a
  448. ``defconfig`` file and by specifying configuration fragments in the
  449. :term:`SRC_URI` to be applied to that
  450. file.
  451. If you have a complete, working Linux kernel ``.config`` file you want
  452. to use for the configuration, as before, copy that file to the
  453. appropriate ``${PN}`` directory in your layer's ``recipes-kernel/linux``
  454. directory, and rename the copied file to "defconfig". Then, add the
  455. following lines to the linux-yocto ``.bbappend`` file in your layer::
  456. FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
  457. SRC_URI += "file://defconfig"
  458. The :term:`SRC_URI` tells the build system how to search
  459. for the file, while the
  460. :term:`FILESEXTRAPATHS`
  461. extends the :term:`FILESPATH`
  462. variable (search directories) to include the ``${PN}`` directory you
  463. created to hold the configuration changes.
  464. You can also use a regular ``defconfig`` file, as generated by the
  465. :ref:`ref-tasks-savedefconfig`
  466. task instead of a complete ``.config`` file. This only specifies the
  467. non-default configuration values. You need to additionally set
  468. :term:`KCONFIG_MODE`
  469. in the linux-yocto ``.bbappend`` file in your layer::
  470. KCONFIG_MODE = "alldefconfig"
  471. .. note::
  472. The build system applies the configurations from the ``defconfig``
  473. file before applying any subsequent configuration fragments. The
  474. final kernel configuration is a combination of the configurations in
  475. the ``defconfig`` file and any configuration fragments you provide. You need
  476. to realize that if you have any configuration fragments, the build system
  477. applies these on top of and after applying the existing ``defconfig`` file
  478. configurations.
  479. Generally speaking, the preferred approach is to determine the
  480. incremental change you want to make and add that as a configuration
  481. fragment. For example, if you want to add support for a basic serial
  482. console, create a file named ``8250.cfg`` in the ``${PN}`` directory
  483. with the following content (without indentation)::
  484. CONFIG_SERIAL_8250=y
  485. CONFIG_SERIAL_8250_CONSOLE=y
  486. CONFIG_SERIAL_8250_PCI=y
  487. CONFIG_SERIAL_8250_NR_UARTS=4
  488. CONFIG_SERIAL_8250_RUNTIME_UARTS=4
  489. CONFIG_SERIAL_CORE=y
  490. CONFIG_SERIAL_CORE_CONSOLE=y
  491. Next, include this
  492. configuration fragment and extend the :term:`FILESPATH` variable in your
  493. ``.bbappend`` file::
  494. FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
  495. SRC_URI += "file://8250.cfg"
  496. The next time you run BitBake to build the
  497. Linux kernel, BitBake detects the change in the recipe and fetches and
  498. applies the new configuration before building the kernel.
  499. For a detailed example showing how to configure the kernel, see the
  500. ":ref:`kernel-dev/common:configuring the kernel`" section.
  501. Using an "In-Tree"  ``defconfig`` File
  502. --------------------------------------
  503. It might be desirable to have kernel configuration fragment support
  504. through a ``defconfig`` file that is pulled from the kernel source tree
  505. for the configured machine. By default, the OpenEmbedded build system
  506. looks for ``defconfig`` files in the layer used for Metadata, which is
  507. "out-of-tree", and then configures them using the following::
  508. SRC_URI += "file://defconfig"
  509. If you do not want to maintain copies of
  510. ``defconfig`` files in your layer but would rather allow users to use
  511. the default configuration from the kernel tree and still be able to add
  512. configuration fragments to the
  513. :term:`SRC_URI` through, for example,
  514. append files, you can direct the OpenEmbedded build system to use a
  515. ``defconfig`` file that is "in-tree".
  516. To specify an "in-tree" ``defconfig`` file, use the following statement
  517. form::
  518. KBUILD_DEFCONFIG_KMACHINE ?= "defconfig_file"
  519. Here is an example
  520. that assigns the :term:`KBUILD_DEFCONFIG` variable based on "raspberrypi2"
  521. and provides the path to the "in-tree" ``defconfig`` file to be used for
  522. a Raspberry Pi 2, which is based on the Broadcom 2708/2709 chipset::
  523. KBUILD_DEFCONFIG:raspberrypi2 ?= "bcm2709_defconfig"
  524. Aside from modifying your kernel recipe and providing your own
  525. ``defconfig`` file, you need to be sure no files or statements set
  526. :term:`SRC_URI` to use a ``defconfig`` other than your "in-tree" file (e.g.
  527. a kernel's ``linux-``\ `machine`\ ``.inc`` file). In other words, if the
  528. build system detects a statement that identifies an "out-of-tree"
  529. ``defconfig`` file, that statement will override your
  530. :term:`KBUILD_DEFCONFIG` variable.
  531. See the
  532. :term:`KBUILD_DEFCONFIG`
  533. variable description for more information.
  534. Using ``devtool`` to Patch the Kernel
  535. =====================================
  536. The steps in this procedure show you how you can patch the kernel using
  537. ``devtool``.
  538. .. note::
  539. Before attempting this procedure, be sure you have performed the
  540. steps to get ready for updating the kernel as described in the
  541. ":ref:`kernel-dev/common:getting ready to develop using \`\`devtool\`\``"
  542. section.
  543. Patching the kernel involves changing or adding configurations to an
  544. existing kernel, changing or adding recipes to the kernel that are
  545. needed to support specific hardware features, or even altering the
  546. source code itself.
  547. This example creates a simple patch by adding some QEMU emulator console
  548. output at boot time through ``printk`` statements in the kernel's
  549. ``calibrate.c`` source code file. Applying the patch and booting the
  550. modified image causes the added messages to appear on the emulator's
  551. console. The example is a continuation of the setup procedure found in
  552. the ":ref:`kernel-dev/common:getting ready to develop using \`\`devtool\`\``" Section.
  553. 1. *Check Out the Kernel Source Files:* First you must use ``devtool``
  554. to checkout the kernel source code in its workspace.
  555. .. note::
  556. See this step in the
  557. ":ref:`kernel-dev/common:getting ready to develop using \`\`devtool\`\``"
  558. section for more information.
  559. Use the following ``devtool`` command to check out the code::
  560. $ devtool modify linux-yocto
  561. .. note::
  562. During the checkout operation, there is a bug that could cause
  563. errors such as the following:
  564. .. code-block:: none
  565. ERROR: Taskhash mismatch 2c793438c2d9f8c3681fd5f7bc819efa versus
  566. be3a89ce7c47178880ba7bf6293d7404 for
  567. /path/to/esdk/layers/poky/meta/recipes-kernel/linux/linux-yocto_4.10.bb.do_unpack
  568. You can safely ignore these messages. The source code is correctly
  569. checked out.
  570. 2. *Edit the Source Files* Follow these steps to make some simple
  571. changes to the source files:
  572. 1. *Change the working directory*: In the previous step, the output
  573. noted where you can find the source files (e.g.
  574. ``poky_sdk/workspace/sources/linux-yocto``). Change to where the
  575. kernel source code is before making your edits to the
  576. ``calibrate.c`` file::
  577. $ cd poky_sdk/workspace/sources/linux-yocto
  578. 2. *Edit the source file*: Edit the ``init/calibrate.c`` file to have
  579. the following changes::
  580. void calibrate_delay(void)
  581. {
  582. unsigned long lpj;
  583. static bool printed;
  584. int this_cpu = smp_processor_id();
  585. printk("*************************************\n");
  586. printk("* *\n");
  587. printk("* HELLO YOCTO KERNEL *\n");
  588. printk("* *\n");
  589. printk("*************************************\n");
  590. if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
  591. .
  592. .
  593. .
  594. 3. *Build the Updated Kernel Source:* To build the updated kernel
  595. source, use ``devtool``::
  596. $ devtool build linux-yocto
  597. 4. *Create the Image With the New Kernel:* Use the
  598. ``devtool build-image`` command to create a new image that has the
  599. new kernel.
  600. .. note::
  601. If the image you originally created resulted in a Wic file, you
  602. can use an alternate method to create the new image with the
  603. updated kernel. For an example, see the steps in the
  604. :yocto_wiki:`TipsAndTricks/KernelDevelopmentWithEsdk </TipsAndTricks/KernelDevelopmentWithEsdk>`
  605. Wiki Page.
  606. ::
  607. $ cd ~
  608. $ devtool build-image core-image-minimal
  609. 5. *Test the New Image:* For this example, you can run the new image
  610. using QEMU to verify your changes:
  611. 1. *Boot the image*: Boot the modified image in the QEMU emulator
  612. using this command::
  613. $ runqemu qemux86
  614. 2. *Verify the changes*: Log into the machine using ``root`` with no
  615. password and then use the following shell command to scroll
  616. through the console's boot output.
  617. .. code-block:: none
  618. # dmesg | less
  619. You should see
  620. the results of your ``printk`` statements as part of the output
  621. when you scroll down the console window.
  622. 6. *Stage and commit your changes*: Change
  623. your working directory to where you modified the ``calibrate.c`` file
  624. and use these Git commands to stage and commit your changes::
  625. $ cd poky_sdk/workspace/sources/linux-yocto
  626. $ git status
  627. $ git add init/calibrate.c
  628. $ git commit -m "calibrate: Add printk example"
  629. 7. *Export the Patches and Create an Append File:* To export your
  630. commits as patches and create a ``.bbappend`` file, use the following
  631. command. This example uses the previously established layer named ``meta-mylayer``.
  632. ::
  633. $ devtool finish linux-yocto ~/meta-mylayer
  634. .. note::
  635. See Step 3 of the
  636. ":ref:`kernel-dev/common:getting ready to develop using \`\`devtool\`\``"
  637. section for information on setting up this layer.
  638. Once the command
  639. finishes, the patches and the ``.bbappend`` file are located in the
  640. ``~/meta-mylayer/recipes-kernel/linux`` directory.
  641. 8. *Build the Image With Your Modified Kernel:* You can now build an
  642. image that includes your kernel patches. Execute the following
  643. command from your :term:`Build Directory` in the terminal
  644. set up to run BitBake::
  645. $ cd poky/build
  646. $ bitbake core-image-minimal
  647. Using Traditional Kernel Development to Patch the Kernel
  648. ========================================================
  649. The steps in this procedure show you how you can patch the kernel using
  650. traditional kernel development (i.e. not using ``devtool``
  651. as described in the
  652. ":ref:`kernel-dev/common:using \`\`devtool\`\` to patch the kernel`"
  653. section).
  654. .. note::
  655. Before attempting this procedure, be sure you have performed the
  656. steps to get ready for updating the kernel as described in the
  657. ":ref:`kernel-dev/common:getting ready for traditional kernel development`"
  658. section.
  659. Patching the kernel involves changing or adding configurations to an
  660. existing kernel, changing or adding recipes to the kernel that are
  661. needed to support specific hardware features, or even altering the
  662. source code itself.
  663. The example in this section creates a simple patch by adding some QEMU
  664. emulator console output at boot time through ``printk`` statements in
  665. the kernel's ``calibrate.c`` source code file. Applying the patch and
  666. booting the modified image causes the added messages to appear on the
  667. emulator's console. The example is a continuation of the setup procedure
  668. found in the
  669. ":ref:`kernel-dev/common:getting ready for traditional kernel development`"
  670. Section.
  671. 1. *Edit the Source Files* Prior to this step, you should have used Git
  672. to create a local copy of the repository for your kernel. Assuming
  673. you created the repository as directed in the
  674. ":ref:`kernel-dev/common:getting ready for traditional kernel development`"
  675. section, use the following commands to edit the ``calibrate.c`` file:
  676. 1. *Change the working directory*: You need to locate the source
  677. files in the local copy of the kernel Git repository. Change to
  678. where the kernel source code is before making your edits to the
  679. ``calibrate.c`` file::
  680. $ cd ~/linux-yocto-4.12/init
  681. 2. *Edit the source file*: Edit the ``calibrate.c`` file to have the
  682. following changes::
  683. void calibrate_delay(void)
  684. {
  685. unsigned long lpj;
  686. static bool printed;
  687. int this_cpu = smp_processor_id();
  688. printk("*************************************\n");
  689. printk("* *\n");
  690. printk("* HELLO YOCTO KERNEL *\n");
  691. printk("* *\n");
  692. printk("*************************************\n");
  693. if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
  694. .
  695. .
  696. .
  697. 2. *Stage and Commit Your Changes:* Use standard Git commands to stage
  698. and commit the changes you just made::
  699. $ git add calibrate.c
  700. $ git commit -m "calibrate.c - Added some printk statements"
  701. If you do not
  702. stage and commit your changes, the OpenEmbedded Build System will not
  703. pick up the changes.
  704. 3. *Update Your local.conf File to Point to Your Source Files:* In
  705. addition to your ``local.conf`` file specifying to use
  706. "kernel-modules" and the "qemux86" machine, it must also point to the
  707. updated kernel source files. Add
  708. :term:`SRC_URI` and
  709. :term:`SRCREV` statements similar
  710. to the following to your ``local.conf``::
  711. $ cd poky/build/conf
  712. Add the following to the ``local.conf``::
  713. SRC_URI:pn-linux-yocto = "git:///path-to/linux-yocto-4.12;protocol=file;name=machine;branch=standard/base; \
  714. git:///path-to/yocto-kernel-cache;protocol=file;type=kmeta;name=meta;branch=yocto-4.12;destsuffix=${KMETA}"
  715. SRCREV_meta:qemux86 = "${AUTOREV}"
  716. SRCREV_machine:qemux86 = "${AUTOREV}"
  717. .. note::
  718. Be sure to replace `path-to`
  719. with the pathname to your local Git repositories. Also, you must
  720. be sure to specify the correct branch and machine types. For this
  721. example, the branch is ``standard/base`` and the machine is ``qemux86``.
  722. 4. *Build the Image:* With the source modified, your changes staged and
  723. committed, and the ``local.conf`` file pointing to the kernel files,
  724. you can now use BitBake to build the image::
  725. $ cd poky/build
  726. $ bitbake core-image-minimal
  727. 5. *Boot the image*: Boot the modified image in the QEMU emulator using
  728. this command. When prompted to login to the QEMU console, use "root"
  729. with no password::
  730. $ cd poky/build
  731. $ runqemu qemux86
  732. 6. *Look for Your Changes:* As QEMU booted, you might have seen your
  733. changes rapidly scroll by. If not, use these commands to see your
  734. changes:
  735. .. code-block:: none
  736. # dmesg | less
  737. You should see the results of your
  738. ``printk`` statements as part of the output when you scroll down the
  739. console window.
  740. 7. *Generate the Patch File:* Once you are sure that your patch works
  741. correctly, you can generate a ``*.patch`` file in the kernel source
  742. repository::
  743. $ cd ~/linux-yocto-4.12/init
  744. $ git format-patch -1
  745. 0001-calibrate.c-Added-some-printk-statements.patch
  746. 8. *Move the Patch File to Your Layer:* In order for subsequent builds
  747. to pick up patches, you need to move the patch file you created in
  748. the previous step to your layer ``meta-mylayer``. For this example,
  749. the layer created earlier is located in your home directory as
  750. ``meta-mylayer``. When the layer was created using the
  751. ``yocto-create`` script, no additional hierarchy was created to
  752. support patches. Before moving the patch file, you need to add
  753. additional structure to your layer using the following commands::
  754. $ cd ~/meta-mylayer
  755. $ mkdir recipes-kernel
  756. $ mkdir recipes-kernel/linux
  757. $ mkdir recipes-kernel/linux/linux-yocto
  758. Once you have created this
  759. hierarchy in your layer, you can move the patch file using the
  760. following command::
  761. $ mv ~/linux-yocto-4.12/init/0001-calibrate.c-Added-some-printk-statements.patch ~/meta-mylayer/recipes-kernel/linux/linux-yocto
  762. 9. *Create the Append File:* Finally, you need to create the
  763. ``linux-yocto_4.12.bbappend`` file and insert statements that allow
  764. the OpenEmbedded build system to find the patch. The append file
  765. needs to be in your layer's ``recipes-kernel/linux`` directory and it
  766. must be named ``linux-yocto_4.12.bbappend`` and have the following
  767. contents::
  768. FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
  769. SRC_URI += "file://0001-calibrate.c-Added-some-printk-statements.patch"
  770. The :term:`FILESEXTRAPATHS` and :term:`SRC_URI` statements
  771. enable the OpenEmbedded build system to find the patch file.
  772. For more information on append files and patches, see the
  773. ":ref:`kernel-dev/common:creating the append file`" and
  774. ":ref:`kernel-dev/common:applying patches`" sections. You can also see the
  775. ":ref:`dev-manual/layers:appending other layers metadata with your layer`"
  776. section in the Yocto Project Development Tasks Manual.
  777. .. note::
  778. To build ``core-image-minimal`` again and see the effects of your patch,
  779. you can essentially eliminate the temporary source files saved in
  780. ``poky/build/tmp/work/...`` and residual effects of the build by entering
  781. the following sequence of commands::
  782. $ cd poky/build
  783. $ bitbake -c cleanall yocto-linux
  784. $ bitbake core-image-minimal -c cleanall
  785. $ bitbake core-image-minimal
  786. $ runqemu qemux86
  787. Configuring the Kernel
  788. ======================
  789. Configuring the Yocto Project kernel consists of making sure the
  790. ``.config`` file has all the right information in it for the image you
  791. are building. You can use the ``menuconfig`` tool and configuration
  792. fragments to make sure your ``.config`` file is just how you need it.
  793. You can also save known configurations in a ``defconfig`` file that the
  794. build system can use for kernel configuration.
  795. This section describes how to use ``menuconfig``, create and use
  796. configuration fragments, and how to interactively modify your
  797. ``.config`` file to create the leanest kernel configuration file
  798. possible.
  799. For more information on kernel configuration, see the
  800. ":ref:`kernel-dev/common:changing the configuration`" section.
  801. Using  ``menuconfig``
  802. ---------------------
  803. The easiest way to define kernel configurations is to set them through
  804. the ``menuconfig`` tool. This tool provides an interactive method with
  805. which to set kernel configurations. For general information on
  806. ``menuconfig``, see :wikipedia:`Menuconfig`.
  807. To use the ``menuconfig`` tool in the Yocto Project development
  808. environment, you must do the following:
  809. - Because you launch ``menuconfig`` using BitBake, you must be sure to
  810. set up your environment by running the :ref:`structure-core-script` script
  811. found in the :term:`Build Directory`.
  812. - You must be sure of the state of your build's configuration in the
  813. :term:`Source Directory`.
  814. - Your build host must have the following two packages installed::
  815. libncurses5-dev
  816. libtinfo-dev
  817. The following commands initialize the BitBake environment, run the
  818. :ref:`ref-tasks-kernel_configme`
  819. task, and launch ``menuconfig``. These commands assume the Source
  820. Directory's top-level folder is ``poky``::
  821. $ cd poky
  822. $ source oe-init-build-env
  823. $ bitbake linux-yocto -c kernel_configme -f
  824. $ bitbake linux-yocto -c menuconfig
  825. Once ``menuconfig`` comes up, its standard
  826. interface allows you to interactively examine and configure all the
  827. kernel configuration parameters. After making your changes, simply exit
  828. the tool and save your changes to create an updated version of the
  829. ``.config`` configuration file.
  830. .. note::
  831. You can use the entire ``.config`` file as the ``defconfig`` file. For
  832. information on ``defconfig`` files, see the
  833. ":ref:`kernel-dev/common:changing the configuration`",
  834. ":ref:`kernel-dev/common:using an "in-tree" \`\`defconfig\`\` file`",
  835. and ":ref:`kernel-dev/common:creating a \`\`defconfig\`\` file`"
  836. sections.
  837. Consider an example that configures the "CONFIG_SMP" setting for the
  838. ``linux-yocto-4.12`` kernel.
  839. .. note::
  840. The OpenEmbedded build system recognizes this kernel as ``linux-yocto``
  841. through Metadata (e.g. :term:`PREFERRED_VERSION`\ ``_linux-yocto ?= "12.4%"``).
  842. Once ``menuconfig`` launches, use the interface to navigate through the
  843. selections to find the configuration settings in which you are
  844. interested. For this example, you deselect "CONFIG_SMP" by clearing the
  845. "Symmetric Multi-Processing Support" option. Using the interface, you
  846. can find the option under "Processor Type and Features". To deselect
  847. "CONFIG_SMP", use the arrow keys to highlight "Symmetric
  848. Multi-Processing Support" and enter "N" to clear the asterisk. When you
  849. are finished, exit out and save the change.
  850. Saving the selections updates the ``.config`` configuration file. This is the
  851. file that the OpenEmbedded build system uses to configure the kernel during
  852. the build. You can find and examine this file in the :term:`Build Directory`
  853. in ``tmp/work/``. The actual ``.config`` is located in the
  854. area where the specific kernel is built. For example, if you were
  855. building a Linux Yocto kernel based on the ``linux-yocto-4.12`` kernel
  856. and you were building a QEMU image targeted for ``x86`` architecture,
  857. the ``.config`` file would be:
  858. .. code-block:: none
  859. poky/build/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+gitAUTOINC+eda4d18...
  860. ...967-r0/linux-qemux86-standard-build/.config
  861. .. note::
  862. The previous example directory is artificially split and many of the
  863. characters in the actual filename are omitted in order to make it
  864. more readable. Also, depending on the kernel you are using, the exact
  865. pathname might differ.
  866. Within the ``.config`` file, you can see the kernel settings. For
  867. example, the following entry shows that symmetric multi-processor
  868. support is not set::
  869. # CONFIG_SMP is not set
  870. A good method to isolate changed configurations is to use a combination
  871. of the ``menuconfig`` tool and simple shell commands. Before changing
  872. configurations with ``menuconfig``, copy the existing ``.config`` and
  873. rename it to something else, use ``menuconfig`` to make as many changes
  874. as you want and save them, then compare the renamed configuration file
  875. against the newly created file. You can use the resulting differences as
  876. your base to create configuration fragments to permanently save in your
  877. kernel layer.
  878. .. note::
  879. Be sure to make a copy of the ``.config`` file and do not just rename it.
  880. The build system needs an existing ``.config`` file from which to work.
  881. Creating a  ``defconfig`` File
  882. ------------------------------
  883. A ``defconfig`` file in the context of the Yocto Project is often a
  884. ``.config`` file that is copied from a build or a ``defconfig`` taken
  885. from the kernel tree and moved into recipe space. You can use a
  886. ``defconfig`` file to retain a known set of kernel configurations from
  887. which the OpenEmbedded build system can draw to create the final
  888. ``.config`` file.
  889. .. note::
  890. Out-of-the-box, the Yocto Project never ships a ``defconfig`` or ``.config``
  891. file. The OpenEmbedded build system creates the final ``.config`` file used
  892. to configure the kernel.
  893. To create a ``defconfig``, start with a complete, working Linux kernel
  894. ``.config`` file. Copy that file to the appropriate
  895. ``${``\ :term:`PN`\ ``}`` directory in
  896. your layer's ``recipes-kernel/linux`` directory, and rename the copied
  897. file to "defconfig" (e.g.
  898. ``~/meta-mylayer/recipes-kernel/linux/linux-yocto/defconfig``). Then,
  899. add the following lines to the linux-yocto ``.bbappend`` file in your
  900. layer::
  901. FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
  902. SRC_URI += "file://defconfig"
  903. The :term:`SRC_URI` tells the build system how to search for the file, while the
  904. :term:`FILESEXTRAPATHS` extends the :term:`FILESPATH`
  905. variable (search directories) to include the ``${PN}`` directory you
  906. created to hold the configuration changes.
  907. .. note::
  908. The build system applies the configurations from the ``defconfig``
  909. file before applying any subsequent configuration fragments. The
  910. final kernel configuration is a combination of the configurations in
  911. the ``defconfig`` file and any configuration fragments you provide. You need
  912. to realize that if you have any configuration fragments, the build system
  913. applies these on top of and after applying the existing ``defconfig`` file
  914. configurations.
  915. For more information on configuring the kernel, see the
  916. ":ref:`kernel-dev/common:changing the configuration`" section.
  917. Creating Configuration Fragments
  918. --------------------------------
  919. Configuration fragments are simply kernel options that appear in a file
  920. placed where the OpenEmbedded build system can find and apply them. The
  921. build system applies configuration fragments after applying
  922. configurations from a ``defconfig`` file. Thus, the final kernel
  923. configuration is a combination of the configurations in the
  924. ``defconfig`` file and then any configuration fragments you provide. The
  925. build system applies fragments on top of and after applying the existing
  926. defconfig file configurations.
  927. Syntactically, the configuration statement is identical to what would
  928. appear in the ``.config`` file, which is in the :term:`Build Directory`.
  929. .. note::
  930. For more information about where the ``.config`` file is located, see the
  931. example in the
  932. ":ref:`kernel-dev/common:using \`\`menuconfig\`\``"
  933. section.
  934. It is simple to create a configuration fragment. One method is to use
  935. shell commands. For example, issuing the following from the shell
  936. creates a configuration fragment file named ``my_smp.cfg`` that enables
  937. multi-processor support within the kernel::
  938. $ echo "CONFIG_SMP=y" >> my_smp.cfg
  939. .. note::
  940. All configuration fragment files must use the ``.cfg`` extension in order
  941. for the OpenEmbedded build system to recognize them as a configuration
  942. fragment.
  943. Another method is to create a configuration fragment using the
  944. differences between two configuration files: one previously created and
  945. saved, and one freshly created using the ``menuconfig`` tool.
  946. To create a configuration fragment using this method, follow these
  947. steps:
  948. 1. *Complete a Build Through Kernel Configuration:* Complete a build at
  949. least through the kernel configuration task as follows::
  950. $ bitbake linux-yocto -c kernel_configme -f
  951. This step ensures that you create a
  952. ``.config`` file from a known state. Because there are situations where
  953. your build state might become unknown, it is best to run this task
  954. prior to starting ``menuconfig``.
  955. 2. *Launch menuconfig:* Run the ``menuconfig`` command::
  956. $ bitbake linux-yocto -c menuconfig
  957. 3. *Create the Configuration Fragment:* Run the ``diffconfig`` command
  958. to prepare a configuration fragment. The resulting file
  959. ``fragment.cfg`` is placed in the
  960. ``${``\ :term:`WORKDIR`\ ``}``
  961. directory::
  962. $ bitbake linux-yocto -c diffconfig
  963. The ``diffconfig`` command creates a file that is a list of Linux kernel
  964. ``CONFIG_`` assignments. See the
  965. ":ref:`kernel-dev/common:changing the configuration`" section for additional
  966. information on how to use the output as a configuration fragment.
  967. .. note::
  968. You can also use this method to create configuration fragments for a
  969. BSP. See the ":ref:`kernel-dev/advanced:bsp descriptions`"
  970. section for more information.
  971. Where do you put your configuration fragment files? You can place these
  972. files in an area pointed to by
  973. :term:`SRC_URI` as directed by your
  974. ``bblayers.conf`` file, which is located in your layer. The OpenEmbedded
  975. build system picks up the configuration and adds it to the kernel's
  976. configuration. For example, suppose you had a set of configuration
  977. options in a file called ``myconfig.cfg``. If you put that file inside a
  978. directory named ``linux-yocto`` that resides in the same directory as
  979. the kernel's append file within your layer and then add the following
  980. statements to the kernel's append file, those configuration options will
  981. be picked up and applied when the kernel is built::
  982. FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
  983. SRC_URI += "file://myconfig.cfg"
  984. As mentioned earlier, you can group related configurations into multiple
  985. files and name them all in the :term:`SRC_URI` statement as well. For
  986. example, you could group separate configurations specifically for
  987. Ethernet and graphics into their own files and add those by using a
  988. :term:`SRC_URI` statement like the following in your append file::
  989. SRC_URI += "file://myconfig.cfg \
  990. file://eth.cfg \
  991. file://gfx.cfg"
  992. Validating Configuration
  993. ------------------------
  994. You can use the
  995. :ref:`ref-tasks-kernel_configcheck`
  996. task to provide configuration validation::
  997. $ bitbake linux-yocto -c kernel_configcheck -f
  998. Running this task produces warnings for when a
  999. requested configuration does not appear in the final ``.config`` file or
  1000. when you override a policy configuration in a hardware configuration
  1001. fragment.
  1002. In order to run this task, you must have an existing ``.config`` file.
  1003. See the ":ref:`kernel-dev/common:using \`\`menuconfig\`\``" section for
  1004. information on how to create a configuration file.
  1005. Following is sample output from the :ref:`ref-tasks-kernel_configcheck` task:
  1006. .. code-block:: none
  1007. Loading cache: 100% |########################################################| Time: 0:00:00
  1008. Loaded 1275 entries from dependency cache.
  1009. NOTE: Resolving any missing task queue dependencies
  1010. Build Configuration:
  1011. .
  1012. .
  1013. .
  1014. NOTE: Executing SetScene Tasks
  1015. NOTE: Executing RunQueue Tasks
  1016. WARNING: linux-yocto-4.12.12+gitAUTOINC+eda4d18ce4_16de014967-r0 do_kernel_configcheck:
  1017. [kernel config]: specified values did not make it into the kernel's final configuration:
  1018. ---------- CONFIG_X86_TSC -----------------
  1019. Config: CONFIG_X86_TSC
  1020. From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/bsp/common-pc/common-pc-cpu.cfg
  1021. Requested value: CONFIG_X86_TSC=y
  1022. Actual value:
  1023. ---------- CONFIG_X86_BIGSMP -----------------
  1024. Config: CONFIG_X86_BIGSMP
  1025. From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
  1026. /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
  1027. Requested value: # CONFIG_X86_BIGSMP is not set
  1028. Actual value:
  1029. ---------- CONFIG_NR_CPUS -----------------
  1030. Config: CONFIG_NR_CPUS
  1031. From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
  1032. /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/bsp/common-pc/common-pc.cfg
  1033. /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
  1034. Requested value: CONFIG_NR_CPUS=8
  1035. Actual value: CONFIG_NR_CPUS=1
  1036. ---------- CONFIG_SCHED_SMT -----------------
  1037. Config: CONFIG_SCHED_SMT
  1038. From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
  1039. /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
  1040. Requested value: CONFIG_SCHED_SMT=y
  1041. Actual value:
  1042. NOTE: Tasks Summary: Attempted 288 tasks of which 285 didn't need to be rerun and all succeeded.
  1043. Summary: There were 3 WARNING messages shown.
  1044. .. note::
  1045. The previous output example has artificial line breaks to make it
  1046. more readable.
  1047. The output describes the various problems that you can encounter along
  1048. with where to find the offending configuration items. You can use the
  1049. information in the logs to adjust your configuration files and then
  1050. repeat the
  1051. :ref:`ref-tasks-kernel_configme`
  1052. and
  1053. :ref:`ref-tasks-kernel_configcheck`
  1054. tasks until they produce no warnings.
  1055. For more information on how to use the ``menuconfig`` tool, see the
  1056. :ref:`kernel-dev/common:using \`\`menuconfig\`\`` section.
  1057. Fine-Tuning the Kernel Configuration File
  1058. -----------------------------------------
  1059. You can make sure the ``.config`` file is as lean or efficient as
  1060. possible by reading the output of the kernel configuration fragment
  1061. audit, noting any issues, making changes to correct the issues, and then
  1062. repeating.
  1063. As part of the kernel build process, the :ref:`ref-tasks-kernel_configcheck` task
  1064. runs. This task validates the kernel configuration by checking the final
  1065. ``.config`` file against the input files. During the check, the task
  1066. produces warning messages for the following issues:
  1067. - Requested options that did not make the final ``.config`` file.
  1068. - Configuration items that appear twice in the same configuration
  1069. fragment.
  1070. - Configuration items tagged as "required" that were overridden.
  1071. - A board overrides a non-board specific option.
  1072. - Listed options not valid for the kernel being processed. In other
  1073. words, the option does not appear anywhere.
  1074. .. note::
  1075. The :ref:`ref-tasks-kernel_configcheck` task can also optionally report if
  1076. an option is overridden during processing.
  1077. For each output warning, a message points to the file that contains a
  1078. list of the options and a pointer to the configuration fragment that
  1079. defines them. Collectively, the files are the key to streamlining the
  1080. configuration.
  1081. To streamline the configuration, do the following:
  1082. 1. *Use a Working Configuration:* Start with a full configuration that
  1083. you know works. Be sure the configuration builds and boots
  1084. successfully. Use this configuration file as your baseline.
  1085. 2. *Run Configure and Check Tasks:* Separately run the
  1086. :ref:`ref-tasks-kernel_configme` and :ref:`ref-tasks-kernel_configcheck` tasks::
  1087. $ bitbake linux-yocto -c kernel_configme -f
  1088. $ bitbake linux-yocto -c kernel_configcheck -f
  1089. 3. *Process the Results:* Take the resulting list of files from the
  1090. :ref:`ref-tasks-kernel_configcheck` task warnings and do the following:
  1091. - Drop values that are redefined in the fragment but do not change
  1092. the final ``.config`` file.
  1093. - Analyze and potentially drop values from the ``.config`` file that
  1094. override required configurations.
  1095. - Analyze and potentially remove non-board specific options.
  1096. - Remove repeated and invalid options.
  1097. 4. *Re-Run Configure and Check Tasks:* After you have worked through the
  1098. output of the kernel configuration audit, you can re-run the
  1099. :ref:`ref-tasks-kernel_configme` and :ref:`ref-tasks-kernel_configcheck` tasks to see the
  1100. results of your changes. If you have more issues, you can deal with
  1101. them as described in the previous step.
  1102. Iteratively working through steps two through four eventually yields a
  1103. minimal, streamlined configuration file. Once you have the best
  1104. ``.config``, you can build the Linux Yocto kernel.
  1105. Expanding Variables
  1106. ===================
  1107. Sometimes it is helpful to determine what a variable expands to during a
  1108. build. You can examine the values of variables by examining the
  1109. output of the ``bitbake -e`` command. The output is long and is more
  1110. easily managed in a text file, which allows for easy searches::
  1111. $ bitbake -e virtual/kernel > some_text_file
  1112. Within the text file, you can see
  1113. exactly how each variable is expanded and used by the OpenEmbedded build
  1114. system.
  1115. Working with a "Dirty" Kernel Version String
  1116. ============================================
  1117. If you build a kernel image and the version string has a "+" or a
  1118. "-dirty" at the end, it means there are uncommitted modifications in the kernel's
  1119. source directory. Follow these steps to clean up the version string:
  1120. 1. *Discover the Uncommitted Changes:* Go to the kernel's locally cloned
  1121. Git repository (source directory) and use the following Git command
  1122. to list the files that have been changed, added, or removed::
  1123. $ git status
  1124. 2. *Commit the Changes:* You should commit those changes to the kernel
  1125. source tree regardless of whether or not you will save, export, or
  1126. use the changes::
  1127. $ git add
  1128. $ git commit -s -a -m "getting rid of -dirty"
  1129. 3. *Rebuild the Kernel Image:* Once you commit the changes, rebuild the
  1130. kernel.
  1131. Depending on your particular kernel development workflow, the
  1132. commands you use to rebuild the kernel might differ. For information
  1133. on building the kernel image when using ``devtool``, see the
  1134. ":ref:`kernel-dev/common:using \`\`devtool\`\` to patch the kernel`"
  1135. section. For
  1136. information on building the kernel image when using BitBake, see the
  1137. ":ref:`kernel-dev/common:using traditional kernel development to patch the kernel`"
  1138. section.
  1139. Working With Your Own Sources
  1140. =============================
  1141. If you cannot work with one of the Linux kernel versions supported by
  1142. existing linux-yocto recipes, you can still make use of the Yocto
  1143. Project Linux kernel tooling by working with your own sources. When you
  1144. use your own sources, you will not be able to leverage the existing
  1145. kernel :term:`Metadata` and stabilization
  1146. work of the linux-yocto sources. However, you will be able to manage
  1147. your own Metadata in the same format as the linux-yocto sources.
  1148. Maintaining format compatibility facilitates converging with linux-yocto
  1149. on a future, mutually-supported kernel version.
  1150. To help you use your own sources, the Yocto Project provides a
  1151. linux-yocto custom recipe that uses ``kernel.org`` sources and
  1152. the Yocto Project Linux kernel tools for managing kernel Metadata.
  1153. You can find this recipe in the ``poky`` Git repository:
  1154. :yocto_git:`meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb
  1155. </poky/tree/meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb>`.
  1156. Here are some basic steps you can use to work with your own sources:
  1157. 1. *Create a Copy of the Kernel Recipe:* Copy the
  1158. ``linux-yocto-custom.bb`` recipe to your layer and give it a
  1159. meaningful name. The name should include the version of the Yocto
  1160. Linux kernel you are using (e.g. ``linux-yocto-myproject_4.12.bb``,
  1161. where "4.12" is the base version of the Linux kernel with which you
  1162. would be working).
  1163. 2. *Create a Directory for Your Patches:* In the same directory inside
  1164. your layer, create a matching directory to store your patches and
  1165. configuration files (e.g. ``linux-yocto-myproject``).
  1166. 3. *Ensure You Have Configurations:* Make sure you have either a
  1167. ``defconfig`` file or configuration fragment files in your layer.
  1168. When you use the ``linux-yocto-custom.bb`` recipe, you must specify a
  1169. configuration. If you do not have a ``defconfig`` file, you can run
  1170. the following::
  1171. $ make defconfig
  1172. After running the command, copy the
  1173. resulting ``.config`` file to the ``files`` directory in your layer
  1174. as "defconfig" and then add it to the
  1175. :term:`SRC_URI` variable in the
  1176. recipe.
  1177. Running the ``make defconfig`` command results in the default
  1178. configuration for your architecture as defined by your kernel.
  1179. However, there is no guarantee that this configuration is valid for
  1180. your use case, or that your board will even boot. This is
  1181. particularly true for non-x86 architectures.
  1182. To use non-x86 ``defconfig`` files, you need to be more specific and
  1183. find one that matches your board (i.e. for arm, you look in
  1184. ``arch/arm/configs`` and use the one that is the best starting point
  1185. for your board).
  1186. 4. *Edit the Recipe:* Edit the following variables in your recipe as
  1187. appropriate for your project:
  1188. - :term:`SRC_URI`: The
  1189. :term:`SRC_URI` should specify a Git repository that uses one of the
  1190. supported Git fetcher protocols (i.e. ``file``, ``git``, ``http``,
  1191. and so forth). The :term:`SRC_URI` variable should also specify either
  1192. a ``defconfig`` file or some configuration fragment files. The
  1193. skeleton recipe provides an example :term:`SRC_URI` as a syntax
  1194. reference.
  1195. - :term:`LINUX_VERSION`:
  1196. The Linux kernel version you are using (e.g. "4.12").
  1197. - :term:`LINUX_VERSION_EXTENSION`:
  1198. The Linux kernel ``CONFIG_LOCALVERSION`` that is compiled into the
  1199. resulting kernel and visible through the ``uname`` command.
  1200. - :term:`SRCREV`: The commit ID
  1201. from which you want to build.
  1202. - :term:`PR`: Treat this variable the
  1203. same as you would in any other recipe. Increment the variable to
  1204. indicate to the OpenEmbedded build system that the recipe has
  1205. changed.
  1206. - :term:`PV`: The default :term:`PV`
  1207. assignment is typically adequate. It combines the
  1208. :term:`LINUX_VERSION` with the Source Control Manager (SCM) revision
  1209. as derived from the :term:`SRCPV`
  1210. variable. The combined results are a string with the following
  1211. form::
  1212. 3.19.11+git1+68a635bf8dfb64b02263c1ac80c948647cc76d5f_1+218bd8d2022b9852c60d32f0d770931e3cf343e2
  1213. While lengthy, the extra verbosity in :term:`PV` helps ensure you are
  1214. using the exact sources from which you intend to build.
  1215. - :term:`COMPATIBLE_MACHINE`:
  1216. A list of the machines supported by your new recipe. This variable
  1217. in the example recipe is set by default to a regular expression
  1218. that matches only the empty string, "(^$)". This default setting
  1219. triggers an explicit build failure. You must change it to match a
  1220. list of the machines that your new recipe supports. For example,
  1221. to support the ``qemux86`` and ``qemux86-64`` machines, use the
  1222. following form::
  1223. COMPATIBLE_MACHINE = "qemux86|qemux86-64"
  1224. 5. *Customize Your Recipe as Needed:* Provide further customizations to
  1225. your recipe as needed just as you would customize an existing
  1226. linux-yocto recipe. See the
  1227. ":ref:`ref-manual/devtool-reference:modifying an existing recipe`" section
  1228. for information.
  1229. Working with Out-of-Tree Modules
  1230. ================================
  1231. This section describes steps to build out-of-tree modules on your target
  1232. and describes how to incorporate out-of-tree modules in the build.
  1233. Building Out-of-Tree Modules on the Target
  1234. ------------------------------------------
  1235. While the traditional Yocto Project development model would be to
  1236. include kernel modules as part of the normal build process, you might
  1237. find it useful to build modules on the target. This could be the case if
  1238. your target system is capable and powerful enough to handle the
  1239. necessary compilation. Before deciding to build on your target, however,
  1240. you should consider the benefits of using a proper cross-development
  1241. environment from your build host.
  1242. If you want to be able to build out-of-tree modules on the target, there
  1243. are some steps you need to take on the target that is running your SDK
  1244. image. Briefly, the ``kernel-dev`` package is installed by default on
  1245. all ``*.sdk`` images and the ``kernel-devsrc`` package is installed on
  1246. many of the ``*.sdk`` images. However, you need to create some scripts
  1247. prior to attempting to build the out-of-tree modules on the target that
  1248. is running that image.
  1249. Prior to attempting to build the out-of-tree modules, you need to be on
  1250. the target as root and you need to change to the ``/usr/src/kernel``
  1251. directory. Next, ``make`` the scripts:
  1252. .. code-block:: none
  1253. # cd /usr/src/kernel
  1254. # make scripts
  1255. Because all SDK image recipes include ``dev-pkgs``, the
  1256. ``kernel-dev`` packages will be installed as part of the SDK image and
  1257. the ``kernel-devsrc`` packages will be installed as part of applicable
  1258. SDK images. The SDK uses the scripts when building out-of-tree modules.
  1259. Once you have switched to that directory and created the scripts, you
  1260. should be able to build your out-of-tree modules on the target.
  1261. Incorporating Out-of-Tree Modules
  1262. ---------------------------------
  1263. While it is always preferable to work with sources integrated into the
  1264. Linux kernel sources, if you need an external kernel module, the
  1265. ``hello-mod.bb`` recipe is available as a template from which you can
  1266. create your own out-of-tree Linux kernel module recipe.
  1267. This template recipe is located in the ``poky`` Git repository of the
  1268. Yocto Project:
  1269. :yocto_git:`meta-skeleton/recipes-kernel/hello-mod/hello-mod_0.1.bb
  1270. </poky/tree/meta-skeleton/recipes-kernel/hello-mod/hello-mod_0.1.bb>`.
  1271. To get started, copy this recipe to your layer and give it a meaningful
  1272. name (e.g. ``mymodule_1.0.bb``). In the same directory, create a new
  1273. directory named ``files`` where you can store any source files, patches,
  1274. or other files necessary for building the module that do not come with
  1275. the sources. Finally, update the recipe as needed for the module.
  1276. Typically, you will need to set the following variables:
  1277. - :term:`DESCRIPTION`
  1278. - :term:`LICENSE* <LICENSE>`
  1279. - :term:`SRC_URI`
  1280. - :term:`PV`
  1281. Depending on the build system used by the module sources, you might need
  1282. to make some adjustments. For example, a typical module ``Makefile``
  1283. looks much like the one provided with the ``hello-mod`` template::
  1284. obj-m := hello.o
  1285. SRC := $(shell pwd)
  1286. all:
  1287. $(MAKE) -C $(KERNEL_SRC) M=$(SRC)
  1288. modules_install:
  1289. $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
  1290. ...
  1291. The important point to note here is the :term:`KERNEL_SRC` variable. The
  1292. :ref:`module <ref-classes-module>` class sets this variable and the
  1293. :term:`KERNEL_PATH` variable to
  1294. ``${STAGING_KERNEL_DIR}`` with the necessary Linux kernel build
  1295. information to build modules. If your module ``Makefile`` uses a
  1296. different variable, you might want to override the
  1297. :ref:`ref-tasks-compile` step, or
  1298. create a patch to the ``Makefile`` to work with the more typical
  1299. :term:`KERNEL_SRC` or :term:`KERNEL_PATH` variables.
  1300. After you have prepared your recipe, you will likely want to include the
  1301. module in your images. To do this, see the documentation for the
  1302. following variables in the Yocto Project Reference Manual and set one of
  1303. them appropriately for your machine configuration file:
  1304. - :term:`MACHINE_ESSENTIAL_EXTRA_RDEPENDS`
  1305. - :term:`MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS`
  1306. - :term:`MACHINE_EXTRA_RDEPENDS`
  1307. - :term:`MACHINE_EXTRA_RRECOMMENDS`
  1308. Modules are often not required for boot and can be excluded from certain
  1309. build configurations. The following allows for the most flexibility::
  1310. MACHINE_EXTRA_RRECOMMENDS += "kernel-module-mymodule"
  1311. The value is
  1312. derived by appending the module filename without the ``.ko`` extension
  1313. to the string "kernel-module-".
  1314. Because the variable is
  1315. :term:`RRECOMMENDS` and not a
  1316. :term:`RDEPENDS` variable, the build
  1317. will not fail if this module is not available to include in the image.
  1318. Inspecting Changes and Commits
  1319. ==============================
  1320. A common question when working with a kernel is: "What changes have been
  1321. applied to this tree?" Rather than using "grep" across directories to
  1322. see what has changed, you can use Git to inspect or search the kernel
  1323. tree. Using Git is an efficient way to see what has changed in the tree.
  1324. What Changed in a Kernel?
  1325. -------------------------
  1326. Following are a few examples that show how to use Git commands to
  1327. examine changes. These examples are by no means the only way to see
  1328. changes.
  1329. .. note::
  1330. In the following examples, unless you provide a commit range, ``kernel.org``
  1331. history is blended with Yocto Project kernel changes. You can form
  1332. ranges by using branch names from the kernel tree as the upper and
  1333. lower commit markers with the Git commands. You can see the branch
  1334. names through the web interface to the Yocto Project source
  1335. repositories at :yocto_git:`/`.
  1336. To see a full range of the changes, use the ``git whatchanged`` command
  1337. and specify a commit range for the branch (`commit`\ ``..``\ `commit`).
  1338. Here is an example that looks at what has changed in the ``emenlow``
  1339. branch of the ``linux-yocto-3.19`` kernel. The lower commit range is the
  1340. commit associated with the ``standard/base`` branch, while the upper
  1341. commit range is the commit associated with the ``standard/emenlow``
  1342. branch.
  1343. ::
  1344. $ git whatchanged origin/standard/base..origin/standard/emenlow
  1345. To see short, one line summaries of changes use the ``git log`` command::
  1346. $ git log --oneline origin/standard/base..origin/standard/emenlow
  1347. Use this command to see code differences for the changes::
  1348. $ git diff origin/standard/base..origin/standard/emenlow
  1349. Use this command to see the commit log messages and the text
  1350. differences::
  1351. $ git show origin/standard/base..origin/standard/emenlow
  1352. Use this command to create individual patches for each change. Here is
  1353. an example that creates patch files for each commit and places them
  1354. in your ``Documents`` directory::
  1355. $ git format-patch -o $HOME/Documents origin/standard/base..origin/standard/emenlow
  1356. Showing a Particular Feature or Branch Change
  1357. ---------------------------------------------
  1358. Tags in the Yocto Project kernel tree divide changes for significant
  1359. features or branches. The ``git show`` tag command shows changes based
  1360. on a tag. Here is an example that shows ``systemtap`` changes::
  1361. $ git show systemtap
  1362. You can use the ``git branch --contains`` tag command to
  1363. show the branches that contain a particular feature. This command shows
  1364. the branches that contain the ``systemtap`` feature::
  1365. $ git branch --contains systemtap
  1366. Adding Recipe-Space Kernel Features
  1367. ===================================
  1368. You can add kernel features in the
  1369. :ref:`recipe-space <kernel-dev/advanced:recipe-space metadata>`
  1370. by using the :term:`KERNEL_FEATURES`
  1371. variable and by specifying the feature's ``.scc`` file path in the
  1372. :term:`SRC_URI` statement. When you
  1373. add features using this method, the OpenEmbedded build system checks to
  1374. be sure the features are present. If the features are not present, the
  1375. build stops. Kernel features are the last elements processed for
  1376. configuring and patching the kernel. Therefore, adding features in this
  1377. manner is a way to enforce specific features are present and enabled
  1378. without needing to do a full audit of any other layer's additions to the
  1379. :term:`SRC_URI` statement.
  1380. You add a kernel feature by providing the feature as part of the
  1381. :term:`KERNEL_FEATURES` variable and by providing the path to the feature's
  1382. ``.scc`` file, which is relative to the root of the kernel Metadata. The
  1383. OpenEmbedded build system searches all forms of kernel Metadata on the
  1384. :term:`SRC_URI` statement regardless of whether the Metadata is in the
  1385. "kernel-cache", system kernel Metadata, or a recipe-space Metadata (i.e.
  1386. part of the kernel recipe). See the
  1387. ":ref:`kernel-dev/advanced:kernel metadata location`" section for
  1388. additional information.
  1389. When you specify the feature's ``.scc`` file on the :term:`SRC_URI`
  1390. statement, the OpenEmbedded build system adds the directory of that
  1391. ``.scc`` file along with all its subdirectories to the kernel feature
  1392. search path. Because subdirectories are searched, you can reference a
  1393. single ``.scc`` file in the :term:`SRC_URI` statement to reference multiple
  1394. kernel features.
  1395. Consider the following example that adds the "test.scc" feature to the
  1396. build.
  1397. 1. *Create the Feature File:* Create a ``.scc`` file and locate it just
  1398. as you would any other patch file, ``.cfg`` file, or fetcher item you
  1399. specify in the :term:`SRC_URI` statement.
  1400. .. note::
  1401. - You must add the directory of the ``.scc`` file to the
  1402. fetcher's search path in the same manner as you would add a
  1403. ``.patch`` file.
  1404. - You can create additional ``.scc`` files beneath the directory
  1405. that contains the file you are adding. All subdirectories are
  1406. searched during the build as potential feature directories.
  1407. Continuing with the example, suppose the "test.scc" feature you are
  1408. adding has a ``test.scc`` file in the following directory::
  1409. my_recipe
  1410. |
  1411. +-linux-yocto
  1412. |
  1413. +-test.cfg
  1414. +-test.scc
  1415. In this example, the
  1416. ``linux-yocto`` directory has both the feature ``test.scc`` file and
  1417. a similarly named configuration fragment file ``test.cfg``.
  1418. 2. *Add the Feature File to SRC_URI:* Add the ``.scc`` file to the
  1419. recipe's :term:`SRC_URI` statement::
  1420. SRC_URI += "file://test.scc"
  1421. The leading space before the path is important as the path is
  1422. appended to the existing path.
  1423. 3. *Specify the Feature as a Kernel Feature:* Use the
  1424. :term:`KERNEL_FEATURES` statement to specify the feature as a kernel
  1425. feature::
  1426. KERNEL_FEATURES += "test.scc"
  1427. The OpenEmbedded build
  1428. system processes the kernel feature when it builds the kernel.
  1429. .. note::
  1430. If other features are contained below "test.scc", then their
  1431. directories are relative to the directory containing the ``test.scc``
  1432. file.