common.rst 78 KB

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