kernel-dev-common.rst 77 KB

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