common.rst 74 KB

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