common.rst 74 KB

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