common.rst 77 KB

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