kernel-dev-common.xml 140 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730
  1. <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  2. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
  3. [<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
  4. <!--SPDX-License-Identifier: CC-BY-2.0-UK-->
  5. <chapter id='kernel-dev-common'>
  6. <title>Common Tasks</title>
  7. <para>
  8. This chapter presents several common tasks you perform when you
  9. work with the Yocto Project Linux kernel.
  10. These tasks include preparing your host development system for
  11. kernel development, preparing a layer, modifying an existing recipe,
  12. patching the kernel, configuring the kernel, iterative development,
  13. working with your own sources, and incorporating out-of-tree modules.
  14. <note>
  15. The examples presented in this chapter work with the Yocto Project
  16. 2.4 Release and forward.
  17. </note>
  18. </para>
  19. <section id='preparing-the-build-host-to-work-on-the-kernel'>
  20. <title>Preparing the Build Host to Work on the Kernel</title>
  21. <para>
  22. Before you can do any kernel development, you need to be
  23. sure your build host is set up to use the Yocto Project.
  24. For information on how to get set up, see the
  25. "<ulink url='&YOCTO_DOCS_DEV_URL;#dev-preparing-the-build-host'>Preparing the Build Host</ulink>"
  26. section in the Yocto Project Development Tasks Manual.
  27. Part of preparing the system is creating a local Git
  28. repository of the
  29. <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
  30. (<filename>poky</filename>) on your system.
  31. Follow the steps in the
  32. "<ulink url='&YOCTO_DOCS_DEV_URL;#cloning-the-poky-repository'>Cloning the <filename>poky</filename> Repository</ulink>"
  33. section in the Yocto Project Development Tasks Manual to set up your
  34. Source Directory.
  35. <note>
  36. Be sure you check out the appropriate development branch or
  37. you create your local branch by checking out a specific tag
  38. to get the desired version of Yocto Project.
  39. See the
  40. "<ulink url='&YOCTO_DOCS_DEV_URL;#checking-out-by-branch-in-poky'>Checking Out by Branch in Poky</ulink>"
  41. and
  42. "<ulink url='&YOCTO_DOCS_DEV_URL;#checkout-out-by-tag-in-poky'>Checking Out by Tag in Poky</ulink>"
  43. sections in the Yocto Project Development Tasks Manual for more
  44. information.
  45. </note>
  46. </para>
  47. <para>
  48. Kernel development is best accomplished using
  49. <ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'><filename>devtool</filename></ulink>
  50. and not through traditional kernel workflow methods.
  51. The remainder of this section provides information for both
  52. scenarios.
  53. </para>
  54. <section id='getting-ready-to-develop-using-devtool'>
  55. <title>Getting Ready to Develop Using <filename>devtool</filename></title>
  56. <para>
  57. Follow these steps to prepare to update the kernel image using
  58. <filename>devtool</filename>.
  59. Completing this procedure leaves you with a clean kernel image
  60. and ready to make modifications as described in the
  61. "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>"
  62. section:
  63. <orderedlist>
  64. <listitem><para>
  65. <emphasis>Initialize the BitBake Environment:</emphasis>
  66. Before building an extensible SDK, you need to
  67. initialize the BitBake build environment by sourcing the
  68. build environment script
  69. (i.e. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>):
  70. <literallayout class='monospaced'>
  71. $ cd ~/poky
  72. $ source oe-init-build-env
  73. </literallayout>
  74. <note>
  75. The previous commands assume the
  76. <ulink url='&YOCTO_DOCS_OM_URL;#source-repositories'>Source Repositories</ulink>
  77. (i.e. <filename>poky</filename>) have been cloned
  78. using Git and the local repository is named
  79. "poky".
  80. </note>
  81. </para></listitem>
  82. <listitem><para>
  83. <emphasis>Prepare Your <filename>local.conf</filename> File:</emphasis>
  84. By default, the
  85. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
  86. variable is set to "qemux86-64", which is fine if you are
  87. building for the QEMU emulator in 64-bit mode.
  88. However, if you are not, you need to set the
  89. <filename>MACHINE</filename> variable appropriately in
  90. your <filename>conf/local.conf</filename> file found in
  91. the
  92. <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
  93. (i.e. <filename>~/poky/build</filename> in this
  94. example).</para>
  95. <para>Also, since you are preparing to work on the
  96. kernel image, you need to set the
  97. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink>
  98. variable to include kernel modules.</para>
  99. <para>In this example we wish to build for qemux86 so
  100. we must set the <filename>MACHINE</filename> variable
  101. to "qemux86" and also add the "kernel-modules". As described
  102. we do this by appending to <filename>conf/local.conf</filename>:
  103. <literallayout class='monospaced'>
  104. MACHINE = "qemux86"
  105. MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules"
  106. </literallayout>
  107. </para></listitem>
  108. <listitem><para>
  109. <emphasis>Create a Layer for Patches:</emphasis>
  110. You need to create a layer to hold patches created
  111. for the kernel image.
  112. You can use the
  113. <filename>bitbake-layers create-layer</filename>
  114. command as follows:
  115. <literallayout class='monospaced'>
  116. $ cd ~/poky/build
  117. $ bitbake-layers create-layer ../../meta-mylayer
  118. NOTE: Starting bitbake server...
  119. Add your new layer with 'bitbake-layers add-layer ../../meta-mylayer'
  120. $
  121. </literallayout>
  122. <note>
  123. For background information on working with
  124. common and BSP layers, see the
  125. "<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>"
  126. section in the Yocto Project Development Tasks
  127. Manual and the
  128. "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
  129. section in the Yocto Project Board Support (BSP)
  130. Developer's Guide, respectively.
  131. For information on how to use the
  132. <filename>bitbake-layers create-layer</filename>
  133. command to quickly set up a layer, see the
  134. "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</ulink>"
  135. section in the Yocto Project Development Tasks
  136. Manual.
  137. </note>
  138. </para></listitem>
  139. <listitem><para>
  140. <emphasis>Inform the BitBake Build Environment About
  141. Your Layer:</emphasis>
  142. As directed when you created your layer, you need to
  143. add the layer to the
  144. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
  145. variable in the <filename>bblayers.conf</filename> file
  146. as follows:
  147. <literallayout class='monospaced'>
  148. $ cd ~/poky/build
  149. $ bitbake-layers add-layer ../../meta-mylayer
  150. NOTE: Starting bitbake server...
  151. $
  152. </literallayout>
  153. </para></listitem>
  154. <listitem><para>
  155. <emphasis>Build the Extensible SDK:</emphasis>
  156. Use BitBake to build the extensible SDK specifically
  157. for use with images to be run using QEMU:
  158. <literallayout class='monospaced'>
  159. $ cd ~/poky/build
  160. $ bitbake core-image-minimal -c populate_sdk_ext
  161. </literallayout>
  162. Once the build finishes, you can find the SDK installer
  163. file (i.e. <filename>*.sh</filename> file) in the
  164. following directory:
  165. <literallayout class='monospaced'>
  166. ~/poky/build/tmp/deploy/sdk
  167. </literallayout>
  168. For this example, the installer file is named
  169. <filename>poky-glibc-x86_64-core-image-minimal-i586-toolchain-ext-&DISTRO;.sh</filename>
  170. </para></listitem>
  171. <listitem><para>
  172. <emphasis>Install the Extensible SDK:</emphasis>
  173. Use the following command to install the SDK.
  174. For this example, install the SDK in the default
  175. <filename>~/poky_sdk</filename> directory:
  176. <literallayout class='monospaced'>
  177. $ cd ~/poky/build/tmp/deploy/sdk
  178. $ ./poky-glibc-x86_64-core-image-minimal-i586-toolchain-ext-&DISTRO;.sh
  179. Poky (Yocto Project Reference Distro) Extensible SDK installer version &DISTRO;
  180. ============================================================================
  181. Enter target directory for SDK (default: ~/poky_sdk):
  182. You are about to install the SDK to "/home/scottrif/poky_sdk". Proceed [Y/n]? Y
  183. Extracting SDK......................................done
  184. Setting it up...
  185. Extracting buildtools...
  186. Preparing build system...
  187. Parsing recipes: 100% |#################################################################| Time: 0:00:52
  188. Initializing tasks: 100% |############## ###############################################| Time: 0:00:04
  189. Checking sstate mirror object availability: 100% |######################################| Time: 0:00:00
  190. Parsing recipes: 100% |#################################################################| Time: 0:00:33
  191. Initializing tasks: 100% |##############################################################| Time: 0:00:00
  192. done
  193. SDK has been successfully set up and is ready to be used.
  194. Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
  195. $ . /home/scottrif/poky_sdk/environment-setup-i586-poky-linux
  196. </literallayout>
  197. </para></listitem>
  198. <listitem><para id='setting-up-the-esdk-terminal'>
  199. <emphasis>Set Up a New Terminal to Work With the
  200. Extensible SDK:</emphasis>
  201. You must set up a new terminal to work with the SDK.
  202. You cannot use the same BitBake shell used to build the
  203. installer.</para>
  204. <para>After opening a new shell, run the SDK environment
  205. setup script as directed by the output from installing
  206. the SDK:
  207. <literallayout class='monospaced'>
  208. $ source ~/poky_sdk/environment-setup-i586-poky-linux
  209. "SDK environment now set up; additionally you may now run devtool to perform development tasks.
  210. Run devtool --help for further details.
  211. </literallayout>
  212. <note>
  213. If you get a warning about attempting to use the
  214. extensible SDK in an environment set up to run
  215. BitBake, you did not use a new shell.
  216. </note>
  217. </para></listitem>
  218. <listitem><para>
  219. <emphasis>Build the Clean Image:</emphasis>
  220. The final step in preparing to work on the kernel is to
  221. build an initial image using
  222. <filename>devtool</filename> in the new terminal you
  223. just set up and initialized for SDK work:
  224. <literallayout class='monospaced'>
  225. $ devtool build-image
  226. Parsing recipes: 100% |##########################################| Time: 0:00:05
  227. Parsing of 830 .bb files complete (0 cached, 830 parsed). 1299 targets, 47 skipped, 0 masked, 0 errors.
  228. WARNING: No packages to add, building image core-image-minimal unmodified
  229. Loading cache: 100% |############################################| Time: 0:00:00
  230. Loaded 1299 entries from dependency cache.
  231. NOTE: Resolving any missing task queue dependencies
  232. Initializing tasks: 100% |#######################################| Time: 0:00:07
  233. Checking sstate mirror object availability: 100% |###############| Time: 0:00:00
  234. NOTE: Executing SetScene Tasks
  235. NOTE: Executing RunQueue Tasks
  236. NOTE: Tasks Summary: Attempted 2866 tasks of which 2604 didn't need to be rerun and all succeeded.
  237. NOTE: Successfully built core-image-minimal. You can find output files in /home/scottrif/poky_sdk/tmp/deploy/images/qemux86
  238. </literallayout>
  239. If you were building for actual hardware and not for
  240. emulation, you could flash the image to a USB stick
  241. on <filename>/dev/sdd</filename> and boot your device.
  242. For an example that uses a Minnowboard, see the
  243. <ulink url='https://wiki.yoctoproject.org/wiki/TipsAndTricks/KernelDevelopmentWithEsdk'>TipsAndTricks/KernelDevelopmentWithEsdk</ulink>
  244. Wiki page.
  245. </para></listitem>
  246. </orderedlist>
  247. </para>
  248. <para>
  249. At this point you have set up to start making modifications to
  250. the kernel by using the extensible SDK.
  251. For a continued example, see the
  252. "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>"
  253. section.
  254. </para>
  255. </section>
  256. <section id='getting-ready-for-traditional-kernel-development'>
  257. <title>Getting Ready for Traditional Kernel Development</title>
  258. <para>
  259. Getting ready for traditional kernel development using the Yocto
  260. Project involves many of the same steps as described in the
  261. previous section.
  262. However, you need to establish a local copy of the kernel source
  263. since you will be editing these files.
  264. </para>
  265. <para>
  266. Follow these steps to prepare to update the kernel image using
  267. traditional kernel development flow with the Yocto Project.
  268. Completing this procedure leaves you ready to make modifications
  269. to the kernel source as described in the
  270. "<link linkend='using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</link>"
  271. section:
  272. <orderedlist>
  273. <listitem><para>
  274. <emphasis>Initialize the BitBake Environment:</emphasis>
  275. Before you can do anything using BitBake, you need to
  276. initialize the BitBake build environment by sourcing the
  277. build environment script
  278. (i.e. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>).
  279. Also, for this example, be sure that the local branch
  280. you have checked out for <filename>poky</filename> is
  281. the Yocto Project &DISTRO_NAME; branch.
  282. If you need to checkout out the &DISTRO_NAME; branch,
  283. see the
  284. "<ulink url='&YOCTO_DOCS_DEV_URL;#checking-out-by-branch-in-poky'>Checking out by Branch in Poky</ulink>"
  285. section in the Yocto Project Development Tasks Manual.
  286. <literallayout class='monospaced'>
  287. $ cd ~/poky
  288. $ git branch
  289. master
  290. * &DISTRO_NAME;
  291. $ source oe-init-build-env
  292. </literallayout>
  293. <note>
  294. The previous commands assume the
  295. <ulink url='&YOCTO_DOCS_OM_URL;#source-repositories'>Source Repositories</ulink>
  296. (i.e. <filename>poky</filename>) have been cloned
  297. using Git and the local repository is named
  298. "poky".
  299. </note>
  300. </para></listitem>
  301. <listitem><para>
  302. <emphasis>Prepare Your <filename>local.conf</filename>
  303. File:</emphasis>
  304. By default, the
  305. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
  306. variable is set to "qemux86-64", which is fine if you are
  307. building for the QEMU emulator in 64-bit mode.
  308. However, if you are not, you need to set the
  309. <filename>MACHINE</filename> variable appropriately in
  310. your <filename>conf/local.conf</filename> file found
  311. in the
  312. <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
  313. (i.e. <filename>~/poky/build</filename> in this
  314. example).</para>
  315. <para>Also, since you are preparing to work on the
  316. kernel image, you need to set the
  317. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink>
  318. variable to include kernel modules.</para>
  319. <para>In this example we wish to build for qemux86 so
  320. we must set the <filename>MACHINE</filename> variable
  321. to "qemux86" and also add the "kernel-modules". As described
  322. we do this by appending to <filename>conf/local.conf</filename>:
  323. <literallayout class='monospaced'>
  324. MACHINE = "qemux86"
  325. MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules"
  326. </literallayout>
  327. </para></listitem>
  328. <listitem><para>
  329. <emphasis>Create a Layer for Patches:</emphasis>
  330. You need to create a layer to hold patches created
  331. for the kernel image.
  332. You can use the
  333. <filename>bitbake-layers create-layer</filename>
  334. command as follows:
  335. <literallayout class='monospaced'>
  336. $ cd ~/poky/build
  337. $ bitbake-layers create-layer ../../meta-mylayer
  338. NOTE: Starting bitbake server...
  339. Add your new layer with 'bitbake-layers add-layer ../../meta-mylayer'
  340. </literallayout>
  341. <note>
  342. For background information on working with
  343. common and BSP layers, see the
  344. "<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>"
  345. section in the Yocto Project Development Tasks
  346. Manual and the
  347. "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
  348. section in the Yocto Project Board Support (BSP)
  349. Developer's Guide, respectively.
  350. For information on how to use the
  351. <filename>bitbake-layers create-layer</filename>
  352. command to quickly set up a layer, see the
  353. "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</ulink>"
  354. section in the Yocto Project Development Tasks
  355. Manual.
  356. </note>
  357. </para></listitem>
  358. <listitem><para>
  359. <emphasis>Inform the BitBake Build Environment About
  360. Your Layer:</emphasis>
  361. As directed when you created your layer, you need to add
  362. the layer to the
  363. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
  364. variable in the <filename>bblayers.conf</filename> file
  365. as follows:
  366. <literallayout class='monospaced'>
  367. $ cd ~/poky/build
  368. $ bitbake-layers add-layer ../../meta-mylayer
  369. NOTE: Starting bitbake server ...
  370. $
  371. </literallayout>
  372. </para></listitem>
  373. <listitem><para>
  374. <emphasis>Create a Local Copy of the Kernel Git
  375. Repository:</emphasis>
  376. You can find Git repositories of supported Yocto Project
  377. kernels organized under "Yocto Linux Kernel" in the
  378. Yocto Project Source Repositories at
  379. <ulink url='&YOCTO_GIT_URL;'></ulink>.
  380. </para>
  381. <para>
  382. For simplicity, it is recommended that you create your
  383. copy of the kernel Git repository outside of the
  384. <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>,
  385. which is usually named <filename>poky</filename>.
  386. Also, be sure you are in the
  387. <filename>standard/base</filename> branch.
  388. </para>
  389. <para>
  390. The following commands show how to create a local copy
  391. of the <filename>linux-yocto-4.12</filename> kernel and
  392. be in the <filename>standard/base</filename> branch.
  393. <note>
  394. The <filename>linux-yocto-4.12</filename> kernel
  395. can be used with the Yocto Project 2.4 release
  396. and forward.
  397. You cannot use the
  398. <filename>linux-yocto-4.12</filename> kernel with
  399. releases prior to Yocto Project 2.4:
  400. </note>
  401. <literallayout class='monospaced'>
  402. $ cd ~
  403. $ git clone git://git.yoctoproject.org/linux-yocto-4.12 --branch standard/base
  404. Cloning into 'linux-yocto-4.12'...
  405. remote: Counting objects: 6097195, done.
  406. remote: Compressing objects: 100% (901026/901026), done.
  407. remote: Total 6097195 (delta 5152604), reused 6096847 (delta 5152256)
  408. Receiving objects: 100% (6097195/6097195), 1.24 GiB | 7.81 MiB/s, done.
  409. Resolving deltas: 100% (5152604/5152604), done.
  410. Checking connectivity... done.
  411. Checking out files: 100% (59846/59846), done.
  412. </literallayout>
  413. </para></listitem>
  414. <listitem><para>
  415. <emphasis>Create a Local Copy of the Kernel Cache Git
  416. Repository:</emphasis>
  417. For simplicity, it is recommended that you create your
  418. copy of the kernel cache Git repository outside of the
  419. <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>,
  420. which is usually named <filename>poky</filename>.
  421. Also, for this example, be sure you are in the
  422. <filename>yocto-4.12</filename> branch.
  423. </para>
  424. <para>
  425. The following commands show how to create a local copy
  426. of the <filename>yocto-kernel-cache</filename> and
  427. be in the <filename>yocto-4.12</filename> branch:
  428. <literallayout class='monospaced'>
  429. $ cd ~
  430. $ git clone git://git.yoctoproject.org/yocto-kernel-cache --branch yocto-4.12
  431. Cloning into 'yocto-kernel-cache'...
  432. remote: Counting objects: 22639, done.
  433. remote: Compressing objects: 100% (9761/9761), done.
  434. remote: Total 22639 (delta 12400), reused 22586 (delta 12347)
  435. Receiving objects: 100% (22639/22639), 22.34 MiB | 6.27 MiB/s, done.
  436. Resolving deltas: 100% (12400/12400), done.
  437. Checking connectivity... done.
  438. </literallayout>
  439. </para></listitem>
  440. </orderedlist>
  441. </para>
  442. <para>
  443. At this point, you are ready to start making modifications to
  444. the kernel using traditional kernel development steps.
  445. For a continued example, see the
  446. "<link linkend='using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</link>"
  447. section.
  448. </para>
  449. </section>
  450. </section>
  451. <section id='creating-and-preparing-a-layer'>
  452. <title>Creating and Preparing a Layer</title>
  453. <para>
  454. If you are going to be modifying kernel recipes, it is recommended
  455. that you create and prepare your own layer in which to do your
  456. work.
  457. Your layer contains its own
  458. <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
  459. append files (<filename>.bbappend</filename>) and provides a
  460. convenient mechanism to create your own recipe files
  461. (<filename>.bb</filename>) as well as store and use kernel
  462. patch files.
  463. For background information on working with layers, see the
  464. "<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>"
  465. section in the Yocto Project Development Tasks Manual.
  466. <note><title>Tip</title>
  467. The Yocto Project comes with many tools that simplify
  468. tasks you need to perform.
  469. One such tool is the
  470. <filename>bitbake-layers create-layer</filename>
  471. command, which simplifies creating a new layer.
  472. See the
  473. "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</ulink>"
  474. section in the Yocto Project Development Tasks Manual for
  475. information on how to use this script to quick set up a
  476. new layer.
  477. </note>
  478. </para>
  479. <para>
  480. To better understand the layer you create for kernel development,
  481. the following section describes how to create a layer
  482. without the aid of tools.
  483. These steps assume creation of a layer named
  484. <filename>mylayer</filename> in your home directory:
  485. <orderedlist>
  486. <listitem><para>
  487. <emphasis>Create Structure</emphasis>:
  488. Create the layer's structure:
  489. <literallayout class='monospaced'>
  490. $ cd $HOME
  491. $ mkdir meta-mylayer
  492. $ mkdir meta-mylayer/conf
  493. $ mkdir meta-mylayer/recipes-kernel
  494. $ mkdir meta-mylayer/recipes-kernel/linux
  495. $ mkdir meta-mylayer/recipes-kernel/linux/linux-yocto
  496. </literallayout>
  497. The <filename>conf</filename> directory holds your
  498. configuration files, while the
  499. <filename>recipes-kernel</filename> directory holds your
  500. append file and eventual patch files.
  501. </para></listitem>
  502. <listitem><para>
  503. <emphasis>Create the Layer Configuration File</emphasis>:
  504. Move to the <filename>meta-mylayer/conf</filename>
  505. directory and create the <filename>layer.conf</filename>
  506. file as follows:
  507. <literallayout class='monospaced'>
  508. # We have a conf and classes directory, add to BBPATH
  509. BBPATH .= ":${LAYERDIR}"
  510. # We have recipes-* directories, add to BBFILES
  511. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  512. ${LAYERDIR}/recipes-*/*/*.bbappend"
  513. BBFILE_COLLECTIONS += "mylayer"
  514. BBFILE_PATTERN_mylayer = "^${LAYERDIR}/"
  515. BBFILE_PRIORITY_mylayer = "5"
  516. </literallayout>
  517. Notice <filename>mylayer</filename> as part of the last
  518. three statements.
  519. </para></listitem>
  520. <listitem><para>
  521. <emphasis>Create the Kernel Recipe Append File</emphasis>:
  522. Move to the
  523. <filename>meta-mylayer/recipes-kernel/linux</filename>
  524. directory and create the kernel's append file.
  525. This example uses the
  526. <filename>linux-yocto-4.12</filename> kernel.
  527. Thus, the name of the append file is
  528. <filename>linux-yocto_4.12.bbappend</filename>:
  529. <literallayout class='monospaced'>
  530. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
  531. SRC_URI_append = " file://<replaceable>patch-file-one</replaceable>"
  532. SRC_URI_append = " file://<replaceable>patch-file-two</replaceable>"
  533. SRC_URI_append = " file://<replaceable>patch-file-three</replaceable>"
  534. </literallayout>
  535. The
  536. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
  537. and
  538. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  539. statements enable the OpenEmbedded build system to find
  540. patch files.
  541. For more information on using append files, see the
  542. "<ulink url='&YOCTO_DOCS_DEV_URL;#using-bbappend-files'>Using .bbappend Files in Your Layer</ulink>"
  543. section in the Yocto Project Development Tasks Manual.
  544. </para></listitem>
  545. </orderedlist>
  546. </para>
  547. </section>
  548. <section id='modifying-an-existing-recipe'>
  549. <title>Modifying an Existing Recipe</title>
  550. <para>
  551. In many cases, you can customize an existing linux-yocto recipe to
  552. meet the needs of your project.
  553. Each release of the Yocto Project provides a few Linux
  554. kernel recipes from which you can choose.
  555. These are located in the
  556. <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
  557. in <filename>meta/recipes-kernel/linux</filename>.
  558. </para>
  559. <para>
  560. Modifying an existing recipe can consist of the following:
  561. <itemizedlist>
  562. <listitem><para>Creating the append file</para></listitem>
  563. <listitem><para>Applying patches</para></listitem>
  564. <listitem><para>Changing the configuration</para></listitem>
  565. </itemizedlist>
  566. </para>
  567. <para>
  568. Before modifying an existing recipe, be sure that you have created
  569. a minimal, custom layer from which you can work.
  570. See the
  571. "<link linkend='creating-and-preparing-a-layer'>Creating and Preparing a Layer</link>"
  572. section for information.
  573. </para>
  574. <section id='creating-the-append-file'>
  575. <title>Creating the Append File</title>
  576. <para>
  577. You create this file in your custom layer.
  578. You also name it accordingly based on the linux-yocto recipe
  579. you are using.
  580. For example, if you are modifying the
  581. <filename>meta/recipes-kernel/linux/linux-yocto_4.12.bb</filename>
  582. recipe, the append file will typically be located as follows
  583. within your custom layer:
  584. <literallayout class='monospaced'>
  585. <replaceable>your-layer</replaceable>/recipes-kernel/linux/linux-yocto_4.12.bbappend
  586. </literallayout>
  587. The append file should initially extend the
  588. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
  589. search path by prepending the directory that contains your
  590. files to the
  591. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
  592. variable as follows:
  593. <literallayout class='monospaced'>
  594. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
  595. </literallayout>
  596. The path <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-THISDIR'><filename>THISDIR</filename></ulink><filename>}/${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
  597. expands to "linux-yocto" in the current directory for this
  598. example.
  599. If you add any new files that modify the kernel recipe and you
  600. have extended <filename>FILESPATH</filename> as
  601. described above, you must place the files in your layer in the
  602. following area:
  603. <literallayout class='monospaced'>
  604. <replaceable>your-layer</replaceable>/recipes-kernel/linux/linux-yocto/
  605. </literallayout>
  606. <note>If you are working on a new machine Board Support Package
  607. (BSP), be sure to refer to the
  608. <ulink url='&YOCTO_DOCS_BSP_URL;'>Yocto Project Board Support Package (BSP) Developer's Guide</ulink>.
  609. </note>
  610. </para>
  611. <para>
  612. As an example, consider the following append file
  613. used by the BSPs in <filename>meta-yocto-bsp</filename>:
  614. <literallayout class='monospaced'>
  615. meta-yocto-bsp/recipes-kernel/linux/linux-yocto_4.12.bbappend
  616. </literallayout>
  617. The following listing shows the file.
  618. Be aware that the actual commit ID strings in this
  619. example listing might be different than the actual strings
  620. in the file from the <filename>meta-yocto-bsp</filename>
  621. layer upstream.
  622. <literallayout class='monospaced'>
  623. KBRANCH_genericx86 = "standard/base"
  624. KBRANCH_genericx86-64 = "standard/base"
  625. KMACHINE_genericx86 ?= "common-pc"
  626. KMACHINE_genericx86-64 ?= "common-pc-64"
  627. KBRANCH_edgerouter = "standard/edgerouter"
  628. KBRANCH_beaglebone = "standard/beaglebone"
  629. SRCREV_machine_genericx86 ?= "d09f2ce584d60ecb7890550c22a80c48b83c2e19"
  630. SRCREV_machine_genericx86-64 ?= "d09f2ce584d60ecb7890550c22a80c48b83c2e19"
  631. SRCREV_machine_edgerouter ?= "b5c8cfda2dfe296410d51e131289fb09c69e1e7d"
  632. SRCREV_machine_beaglebone ?= "b5c8cfda2dfe296410d51e131289fb09c69e1e7d"
  633. COMPATIBLE_MACHINE_genericx86 = "genericx86"
  634. COMPATIBLE_MACHINE_genericx86-64 = "genericx86-64"
  635. COMPATIBLE_MACHINE_edgerouter = "edgerouter"
  636. COMPATIBLE_MACHINE_beaglebone = "beaglebone"
  637. LINUX_VERSION_genericx86 = "4.12.7"
  638. LINUX_VERSION_genericx86-64 = "4.12.7"
  639. LINUX_VERSION_edgerouter = "4.12.10"
  640. LINUX_VERSION_beaglebone = "4.12.10"
  641. </literallayout>
  642. This append file contains statements used to support
  643. several BSPs that ship with the Yocto Project.
  644. The file defines machines using the
  645. <ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'><filename>COMPATIBLE_MACHINE</filename></ulink>
  646. variable and uses the
  647. <ulink url='&YOCTO_DOCS_REF_URL;#var-KMACHINE'><filename>KMACHINE</filename></ulink>
  648. variable to ensure the machine name used by the OpenEmbedded
  649. build system maps to the machine name used by the Linux Yocto
  650. kernel.
  651. The file also uses the optional
  652. <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'><filename>KBRANCH</filename></ulink>
  653. variable to ensure the build process uses the
  654. appropriate kernel branch.
  655. </para>
  656. <para>
  657. Although this particular example does not use it, the
  658. <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_FEATURES'><filename>KERNEL_FEATURES</filename></ulink>
  659. variable could be used to enable features specific to
  660. the kernel.
  661. The append file points to specific commits in the
  662. <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
  663. Git repository and the <filename>meta</filename> Git repository
  664. branches to identify the exact kernel needed to build the
  665. BSP.
  666. </para>
  667. <para>
  668. One thing missing in this particular BSP, which you will
  669. typically need when developing a BSP, is the kernel
  670. configuration file (<filename>.config</filename>) for your BSP.
  671. When developing a BSP, you probably have a kernel configuration
  672. file or a set of kernel configuration files that, when taken
  673. together, define the kernel configuration for your BSP.
  674. You can accomplish this definition by putting the configurations
  675. in a file or a set of files inside a directory located at the
  676. same level as your kernel's append file and having the same
  677. name as the kernel's main recipe file.
  678. With all these conditions met, simply reference those files in
  679. the
  680. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  681. statement in the append file.
  682. </para>
  683. <para>
  684. For example, suppose you had some configuration options
  685. in a file called <filename>network_configs.cfg</filename>.
  686. You can place that file inside a directory named
  687. <filename>linux-yocto</filename> and then add
  688. a <filename>SRC_URI</filename> statement such as the
  689. following to the append file.
  690. When the OpenEmbedded build system builds the kernel, the
  691. configuration options are picked up and applied.
  692. <literallayout class='monospaced'>
  693. SRC_URI += "file://network_configs.cfg"
  694. </literallayout>
  695. </para>
  696. <para>
  697. To group related configurations into multiple files, you
  698. perform a similar procedure.
  699. Here is an example that groups separate configurations
  700. specifically for Ethernet and graphics into their own
  701. files and adds the configurations by using a
  702. <filename>SRC_URI</filename> statement like the following
  703. in your append file:
  704. <literallayout class='monospaced'>
  705. SRC_URI += "file://myconfig.cfg \
  706. file://eth.cfg \
  707. file://gfx.cfg"
  708. </literallayout>
  709. </para>
  710. <para>
  711. Another variable you can use in your kernel recipe append
  712. file is the
  713. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
  714. variable.
  715. When you use this statement, you are extending the locations
  716. used by the OpenEmbedded system to look for files and
  717. patches as the recipe is processed.
  718. </para>
  719. <note>
  720. <para>
  721. Other methods exist to accomplish grouping and defining
  722. configuration options.
  723. For example, if you are working with a local clone of the
  724. kernel repository, you could checkout the kernel's
  725. <filename>meta</filename> branch, make your changes, and
  726. then push the changes to the local bare clone of the
  727. kernel.
  728. The result is that you directly add configuration options
  729. to the <filename>meta</filename> branch for your BSP.
  730. The configuration options will likely end up in that
  731. location anyway if the BSP gets added to the Yocto Project.
  732. </para>
  733. <para>
  734. In general, however, the Yocto Project maintainers take
  735. care of moving the <filename>SRC_URI</filename>-specified
  736. configuration options to the kernel's
  737. <filename>meta</filename> branch.
  738. Not only is it easier for BSP developers to not have to
  739. worry about putting those configurations in the branch,
  740. but having the maintainers do it allows them to apply
  741. 'global' knowledge about the kinds of common configuration
  742. options multiple BSPs in the tree are typically using.
  743. This allows for promotion of common configurations into
  744. common features.
  745. </para>
  746. </note>
  747. </section>
  748. <section id='applying-patches'>
  749. <title>Applying Patches</title>
  750. <para>
  751. If you have a single patch or a small series of patches
  752. that you want to apply to the Linux kernel source, you
  753. can do so just as you would with any other recipe.
  754. You first copy the patches to the path added to
  755. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
  756. in your <filename>.bbappend</filename> file as described in
  757. the previous section, and then reference them in
  758. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  759. statements.
  760. </para>
  761. <para>
  762. For example, you can apply a three-patch series by adding the
  763. following lines to your linux-yocto
  764. <filename>.bbappend</filename> file in your layer:
  765. <literallayout class='monospaced'>
  766. SRC_URI += "file://0001-first-change.patch"
  767. SRC_URI += "file://0002-second-change.patch"
  768. SRC_URI += "file://0003-third-change.patch"
  769. </literallayout>
  770. The next time you run BitBake to build the Linux kernel,
  771. BitBake detects the change in the recipe and fetches and
  772. applies the patches before building the kernel.
  773. </para>
  774. <para>
  775. For a detailed example showing how to patch the kernel using
  776. <filename>devtool</filename>, see the
  777. "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>"
  778. and
  779. "<link linkend='using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</link>"
  780. sections.
  781. </para>
  782. </section>
  783. <section id='changing-the-configuration'>
  784. <title>Changing the Configuration</title>
  785. <para>
  786. You can make wholesale or incremental changes to the final
  787. <filename>.config</filename> file used for the eventual
  788. Linux kernel configuration by including a
  789. <filename>defconfig</filename> file and by specifying
  790. configuration fragments in the
  791. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  792. to be applied to that file.
  793. </para>
  794. <para>
  795. If you have a complete, working Linux kernel
  796. <filename>.config</filename>
  797. file you want to use for the configuration, as before, copy
  798. that file to the appropriate <filename>${PN}</filename>
  799. directory in your layer's
  800. <filename>recipes-kernel/linux</filename> directory,
  801. and rename the copied file to "defconfig".
  802. Then, add the following lines to the linux-yocto
  803. <filename>.bbappend</filename> file in your layer:
  804. <literallayout class='monospaced'>
  805. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
  806. SRC_URI += "file://defconfig"
  807. </literallayout>
  808. The <filename>SRC_URI</filename> tells the build system how to
  809. search for the file, while the
  810. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
  811. extends the
  812. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
  813. variable (search directories) to include the
  814. <filename>${PN}</filename> directory you created to hold the
  815. configuration changes.
  816. </para>
  817. <note>
  818. The build system applies the configurations from the
  819. <filename>defconfig</filename> file before applying any
  820. subsequent configuration fragments.
  821. The final kernel configuration is a combination of the
  822. configurations in the <filename>defconfig</filename> file and
  823. any configuration fragments you provide.
  824. You need to realize that if you have any configuration
  825. fragments, the build system applies these on top of and
  826. after applying the existing <filename>defconfig</filename>
  827. file configurations.
  828. </note>
  829. <para>
  830. Generally speaking, the preferred approach is to determine the
  831. incremental change you want to make and add that as a
  832. configuration fragment.
  833. For example, if you want to add support for a basic serial
  834. console, create a file named <filename>8250.cfg</filename> in
  835. the <filename>${PN}</filename> directory with the following
  836. content (without indentation):
  837. <literallayout class='monospaced'>
  838. CONFIG_SERIAL_8250=y
  839. CONFIG_SERIAL_8250_CONSOLE=y
  840. CONFIG_SERIAL_8250_PCI=y
  841. CONFIG_SERIAL_8250_NR_UARTS=4
  842. CONFIG_SERIAL_8250_RUNTIME_UARTS=4
  843. CONFIG_SERIAL_CORE=y
  844. CONFIG_SERIAL_CORE_CONSOLE=y
  845. </literallayout>
  846. Next, include this configuration fragment and extend the
  847. <filename>FILESPATH</filename> variable in your
  848. <filename>.bbappend</filename> file:
  849. <literallayout class='monospaced'>
  850. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
  851. SRC_URI += "file://8250.cfg"
  852. </literallayout>
  853. The next time you run BitBake to build the Linux kernel, BitBake
  854. detects the change in the recipe and fetches and applies the
  855. new configuration before building the kernel.
  856. </para>
  857. <para>
  858. For a detailed example showing how to configure the kernel,
  859. see the
  860. "<link linkend='configuring-the-kernel'>Configuring the Kernel</link>"
  861. section.
  862. </para>
  863. </section>
  864. <section id='using-an-in-tree-defconfig-file'>
  865. <title>Using an "In-Tree"&nbsp;&nbsp;<filename>defconfig</filename> File</title>
  866. <para>
  867. It might be desirable to have kernel configuration fragment
  868. support through a <filename>defconfig</filename> file that
  869. is pulled from the kernel source tree for the configured
  870. machine.
  871. By default, the OpenEmbedded build system looks for
  872. <filename>defconfig</filename> files in the layer used for
  873. Metadata, which is "out-of-tree", and then configures them
  874. using the following:
  875. <literallayout class='monospaced'>
  876. SRC_URI += "file://defconfig"
  877. </literallayout>
  878. If you do not want to maintain copies of
  879. <filename>defconfig</filename> files in your layer but would
  880. rather allow users to use the default configuration from the
  881. kernel tree and still be able to add configuration fragments
  882. to the
  883. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  884. through, for example, append files, you can direct the
  885. OpenEmbedded build system to use a
  886. <filename>defconfig</filename> file that is "in-tree".
  887. </para>
  888. <para>
  889. To specify an "in-tree" <filename>defconfig</filename> file,
  890. use the following statement form:
  891. <literallayout class='monospaced'>
  892. KBUILD_DEFCONFIG_<replaceable>KMACHINE</replaceable> ?= <replaceable>defconfig_file</replaceable>
  893. </literallayout>
  894. Here is an example that assigns the
  895. <filename>KBUILD_DEFCONFIG</filename> variable based on
  896. "raspberrypi2" and provides the path to the "in-tree"
  897. <filename>defconfig</filename> file
  898. to be used for a Raspberry Pi 2,
  899. which is based on the Broadcom 2708/2709 chipset:
  900. <literallayout class='monospaced'>
  901. KBUILD_DEFCONFIG_raspberrypi2 ?= "bcm2709_defconfig"
  902. </literallayout>
  903. </para>
  904. <para>
  905. Aside from modifying your kernel recipe and providing your own
  906. <filename>defconfig</filename> file, you need to be sure no
  907. files or statements set <filename>SRC_URI</filename> to use a
  908. <filename>defconfig</filename> other than your "in-tree"
  909. file (e.g. a kernel's
  910. <filename>linux-</filename><replaceable>machine</replaceable><filename>.inc</filename>
  911. file).
  912. In other words, if the build system detects a statement
  913. that identifies an "out-of-tree"
  914. <filename>defconfig</filename> file, that statement
  915. will override your
  916. <filename>KBUILD_DEFCONFIG</filename> variable.
  917. </para>
  918. <para>
  919. See the
  920. <ulink url='&YOCTO_DOCS_REF_URL;#var-KBUILD_DEFCONFIG'><filename>KBUILD_DEFCONFIG</filename></ulink>
  921. variable description for more information.
  922. </para>
  923. </section>
  924. </section>
  925. <section id="using-devtool-to-patch-the-kernel">
  926. <title>Using <filename>devtool</filename> to Patch the Kernel</title>
  927. <para>
  928. The steps in this procedure show you how you can patch the
  929. kernel using the extensible SDK and <filename>devtool</filename>.
  930. <note>
  931. Before attempting this procedure, be sure you have performed
  932. the steps to get ready for updating the kernel as described
  933. in the
  934. "<link linkend='getting-ready-to-develop-using-devtool'>Getting Ready to Develop Using <filename>devtool</filename></link>"
  935. section.
  936. </note>
  937. </para>
  938. <para>
  939. Patching the kernel involves changing or adding configurations
  940. to an existing kernel, changing or adding recipes to the kernel
  941. that are needed to support specific hardware features, or even
  942. altering the source code itself.
  943. </para>
  944. <para>
  945. This example creates a simple patch by adding some QEMU emulator
  946. console output at boot time through <filename>printk</filename>
  947. statements in the kernel's <filename>calibrate.c</filename> source
  948. code file.
  949. Applying the patch and booting the modified image causes the added
  950. messages to appear on the emulator's console.
  951. The example is a continuation of the setup procedure found in
  952. the
  953. "<link linkend='getting-ready-to-develop-using-devtool'>Getting Ready to Develop Using <filename>devtool</filename></link>"
  954. Section.
  955. <orderedlist>
  956. <listitem><para>
  957. <emphasis>Check Out the Kernel Source Files:</emphasis>
  958. First you must use <filename>devtool</filename> to checkout
  959. the kernel source code in its workspace.
  960. Be sure you are in the terminal set up to do work
  961. with the extensible SDK.
  962. <note>
  963. See this
  964. <link linkend='setting-up-the-esdk-terminal'>step</link>
  965. in the
  966. "<link linkend='getting-ready-to-develop-using-devtool'>Getting Ready to Develop Using <filename>devtool</filename></link>"
  967. section for more information.
  968. </note>
  969. Use the following <filename>devtool</filename> command
  970. to check out the code:
  971. <literallayout class='monospaced'>
  972. $ devtool modify linux-yocto
  973. </literallayout>
  974. <note>
  975. During the checkout operation, a bug exists that could
  976. cause errors such as the following to appear:
  977. <literallayout class='monospaced'>
  978. ERROR: Taskhash mismatch 2c793438c2d9f8c3681fd5f7bc819efa versus
  979. be3a89ce7c47178880ba7bf6293d7404 for
  980. /path/to/esdk/layers/poky/meta/recipes-kernel/linux/linux-yocto_4.10.bb.do_unpack
  981. </literallayout>
  982. You can safely ignore these messages.
  983. The source code is correctly checked out.
  984. </note>
  985. </para></listitem>
  986. <listitem><para>
  987. <emphasis>Edit the Source Files</emphasis>
  988. Follow these steps to make some simple changes to the source
  989. files:
  990. <orderedlist>
  991. <listitem><para>
  992. <emphasis>Change the working directory</emphasis>:
  993. In the previous step, the output noted where you can find
  994. the source files (e.g.
  995. <filename>~/poky_sdk/workspace/sources/linux-yocto</filename>).
  996. Change to where the kernel source code is before making
  997. your edits to the <filename>calibrate.c</filename> file:
  998. <literallayout class='monospaced'>
  999. $ cd ~/poky_sdk/workspace/sources/linux-yocto
  1000. </literallayout>
  1001. </para></listitem>
  1002. <listitem><para>
  1003. <emphasis>Edit the source file</emphasis>:
  1004. Edit the <filename>init/calibrate.c</filename> file to have
  1005. the following changes:
  1006. <literallayout class='monospaced'>
  1007. void calibrate_delay(void)
  1008. {
  1009. unsigned long lpj;
  1010. static bool printed;
  1011. int this_cpu = smp_processor_id();
  1012. printk("*************************************\n");
  1013. printk("* *\n");
  1014. printk("* HELLO YOCTO KERNEL *\n");
  1015. printk("* *\n");
  1016. printk("*************************************\n");
  1017. if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
  1018. .
  1019. .
  1020. .
  1021. </literallayout>
  1022. </para></listitem>
  1023. </orderedlist>
  1024. </para></listitem>
  1025. <listitem><para>
  1026. <emphasis>Build the Updated Kernel Source:</emphasis>
  1027. To build the updated kernel source, use
  1028. <filename>devtool</filename>:
  1029. <literallayout class='monospaced'>
  1030. $ devtool build linux-yocto
  1031. </literallayout>
  1032. </para></listitem>
  1033. <listitem><para>
  1034. <emphasis>Create the Image With the New Kernel:</emphasis>
  1035. Use the <filename>devtool build-image</filename> command
  1036. to create a new image that has the new kernel.
  1037. <note>
  1038. If the image you originally created resulted in a Wic
  1039. file, you can use an alternate method to create the new
  1040. image with the updated kernel.
  1041. For an example, see the steps in the
  1042. <ulink url='https://wiki.yoctoproject.org/wiki/TipsAndTricks/KernelDevelopmentWithEsdk'>TipsAndTricks/KernelDevelopmentWithEsdk</ulink>
  1043. Wiki Page.
  1044. </note>
  1045. <literallayout class='monospaced'>
  1046. $ cd ~
  1047. $ devtool build-image core-image-minimal
  1048. </literallayout>
  1049. </para></listitem>
  1050. <listitem><para>
  1051. <emphasis>Test the New Image:</emphasis>
  1052. For this example, you can run the new image using QEMU
  1053. to verify your changes:
  1054. <orderedlist>
  1055. <listitem><para>
  1056. <emphasis>Boot the image</emphasis>:
  1057. Boot the modified image in the QEMU emulator
  1058. using this command:
  1059. <literallayout class='monospaced'>
  1060. $ runqemu qemux86
  1061. </literallayout>
  1062. </para></listitem>
  1063. <listitem><para>
  1064. <emphasis>Verify the changes</emphasis>:
  1065. Log into the machine using <filename>root</filename>
  1066. with no password and then use the following shell
  1067. command to scroll through the console's boot output.
  1068. <literallayout class='monospaced'>
  1069. # dmesg | less
  1070. </literallayout>
  1071. You should see the results of your
  1072. <filename>printk</filename> statements
  1073. as part of the output when you scroll down the
  1074. console window.
  1075. </para></listitem>
  1076. </orderedlist>
  1077. </para></listitem>
  1078. <listitem><para>
  1079. <emphasis>Stage and commit your changes</emphasis>:
  1080. Within your eSDK terminal, change your working directory to
  1081. where you modified the <filename>calibrate.c</filename>
  1082. file and use these Git commands to stage and commit your
  1083. changes:
  1084. <literallayout class='monospaced'>
  1085. $ cd ~/poky_sdk/workspace/sources/linux-yocto
  1086. $ git status
  1087. $ git add init/calibrate.c
  1088. $ git commit -m "calibrate: Add printk example"
  1089. </literallayout>
  1090. </para></listitem>
  1091. <listitem><para>
  1092. <emphasis>Export the Patches and Create an Append File:</emphasis>
  1093. To export your commits as patches and create a
  1094. <filename>.bbappend</filename> file, use the following
  1095. command in the terminal used to work with the extensible
  1096. SDK.
  1097. This example uses the previously established layer named
  1098. <filename>meta-mylayer</filename>.
  1099. <note>
  1100. See Step 3 of the
  1101. "<link linkend='getting-ready-to-develop-using-devtool'>Getting Ready to Develop Using devtool</link>"
  1102. section for information on setting up this layer.
  1103. </note>
  1104. <literallayout class='monospaced'>
  1105. $ devtool finish linux-yocto ~/meta-mylayer
  1106. </literallayout>
  1107. Once the command finishes, the patches and the
  1108. <filename>.bbappend</filename> file are located in the
  1109. <filename>~/meta-mylayer/recipes-kernel/linux</filename>
  1110. directory.
  1111. </para></listitem>
  1112. <listitem><para>
  1113. <emphasis>Build the Image With Your Modified Kernel:</emphasis>
  1114. You can now build an image that includes your kernel
  1115. patches.
  1116. Execute the following command from your
  1117. <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
  1118. in the terminal set up to run BitBake:
  1119. <literallayout class='monospaced'>
  1120. $ cd ~/poky/build
  1121. $ bitbake core-image-minimal
  1122. </literallayout>
  1123. </para></listitem>
  1124. </orderedlist>
  1125. </para>
  1126. </section>
  1127. <section id="using-traditional-kernel-development-to-patch-the-kernel">
  1128. <title>Using Traditional Kernel Development to Patch the Kernel</title>
  1129. <para>
  1130. The steps in this procedure show you how you can patch the
  1131. kernel using traditional kernel development (i.e. not using
  1132. <filename>devtool</filename> and the extensible SDK as
  1133. described in the
  1134. "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>"
  1135. section).
  1136. <note>
  1137. Before attempting this procedure, be sure you have performed
  1138. the steps to get ready for updating the kernel as described
  1139. in the
  1140. "<link linkend='getting-ready-for-traditional-kernel-development'>Getting Ready for Traditional Kernel Development</link>"
  1141. section.
  1142. </note>
  1143. </para>
  1144. <para>
  1145. Patching the kernel involves changing or adding configurations
  1146. to an existing kernel, changing or adding recipes to the kernel
  1147. that are needed to support specific hardware features, or even
  1148. altering the source code itself.
  1149. </para>
  1150. <para>
  1151. The example in this section creates a simple patch by adding some
  1152. QEMU emulator console output at boot time through
  1153. <filename>printk</filename> statements in the kernel's
  1154. <filename>calibrate.c</filename> source code file.
  1155. Applying the patch and booting the modified image causes the added
  1156. messages to appear on the emulator's console.
  1157. The example is a continuation of the setup procedure found in
  1158. the
  1159. "<link linkend='getting-ready-for-traditional-kernel-development'>Getting Ready for Traditional Kernel Development</link>"
  1160. Section.
  1161. <orderedlist>
  1162. <listitem><para>
  1163. <emphasis>Edit the Source Files</emphasis>
  1164. Prior to this step, you should have used Git to create a
  1165. local copy of the repository for your kernel.
  1166. Assuming you created the repository as directed in the
  1167. "<link linkend='getting-ready-for-traditional-kernel-development'>Getting Ready for Traditional Kernel Development</link>"
  1168. section, use the following commands to edit the
  1169. <filename>calibrate.c</filename> file:
  1170. <orderedlist>
  1171. <listitem><para>
  1172. <emphasis>Change the working directory</emphasis>:
  1173. You need to locate the source files in the
  1174. local copy of the kernel Git repository:
  1175. Change to where the kernel source code is before making
  1176. your edits to the <filename>calibrate.c</filename> file:
  1177. <literallayout class='monospaced'>
  1178. $ cd ~/linux-yocto-4.12/init
  1179. </literallayout>
  1180. </para></listitem>
  1181. <listitem><para>
  1182. <emphasis>Edit the source file</emphasis>:
  1183. Edit the <filename>calibrate.c</filename> file to have
  1184. the following changes:
  1185. <literallayout class='monospaced'>
  1186. void calibrate_delay(void)
  1187. {
  1188. unsigned long lpj;
  1189. static bool printed;
  1190. int this_cpu = smp_processor_id();
  1191. printk("*************************************\n");
  1192. printk("* *\n");
  1193. printk("* HELLO YOCTO KERNEL *\n");
  1194. printk("* *\n");
  1195. printk("*************************************\n");
  1196. if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
  1197. .
  1198. .
  1199. .
  1200. </literallayout>
  1201. </para></listitem>
  1202. </orderedlist>
  1203. </para></listitem>
  1204. <listitem><para>
  1205. <emphasis>Stage and Commit Your Changes:</emphasis>
  1206. Use standard Git commands to stage and commit the changes
  1207. you just made:
  1208. <literallayout class='monospaced'>
  1209. $ git add calibrate.c
  1210. $ git commit -m "calibrate.c - Added some printk statements"
  1211. </literallayout>
  1212. If you do not stage and commit your changes, the OpenEmbedded
  1213. Build System will not pick up the changes.
  1214. </para></listitem>
  1215. <listitem><para>
  1216. <emphasis>Update Your <filename>local.conf</filename> File
  1217. to Point to Your Source Files:</emphasis>
  1218. In addition to your <filename>local.conf</filename> file
  1219. specifying to use "kernel-modules" and the "qemux86"
  1220. machine, it must also point to the updated kernel source
  1221. files.
  1222. Add
  1223. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  1224. and
  1225. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
  1226. statements similar to the following to your
  1227. <filename>local.conf</filename>:
  1228. <literallayout class='monospaced'>
  1229. $ cd ~/poky/build/conf
  1230. </literallayout>
  1231. Add the following to the <filename>local.conf</filename>:
  1232. <literallayout class='monospaced'>
  1233. SRC_URI_pn-linux-yocto = "git:///<replaceable>path-to</replaceable>/linux-yocto-4.12;protocol=file;name=machine;branch=standard/base; \
  1234. git:///<replaceable>path-to</replaceable>/yocto-kernel-cache;protocol=file;type=kmeta;name=meta;branch=yocto-4.12;destsuffix=${KMETA}"
  1235. SRCREV_meta_qemux86 = "${AUTOREV}"
  1236. SRCREV_machine_qemux86 = "${AUTOREV}"
  1237. </literallayout>
  1238. <note>
  1239. Be sure to replace
  1240. <replaceable>path-to</replaceable> with the pathname
  1241. to your local Git repositories.
  1242. Also, you must be sure to specify the correct branch
  1243. and machine types.
  1244. For this example, the branch is
  1245. <filename>standard/base</filename> and the machine is
  1246. "qemux86".
  1247. </note>
  1248. </para></listitem>
  1249. <listitem><para>
  1250. <emphasis>Build the Image:</emphasis>
  1251. With the source modified, your changes staged and
  1252. committed, and the <filename>local.conf</filename> file
  1253. pointing to the kernel files, you can now use BitBake to
  1254. build the image:
  1255. <literallayout class='monospaced'>
  1256. $ cd ~/poky/build
  1257. $ bitbake core-image-minimal
  1258. </literallayout>
  1259. </para></listitem>
  1260. <listitem><para>
  1261. <emphasis>Boot the image</emphasis>:
  1262. Boot the modified image in the QEMU emulator
  1263. using this command.
  1264. When prompted to login to the QEMU console, use "root"
  1265. with no password:
  1266. <literallayout class='monospaced'>
  1267. $ cd ~/poky/build
  1268. $ runqemu qemux86
  1269. </literallayout>
  1270. </para></listitem>
  1271. <listitem><para>
  1272. <emphasis>Look for Your Changes:</emphasis>
  1273. As QEMU booted, you might have seen your changes rapidly
  1274. scroll by.
  1275. If not, use these commands to see your changes:
  1276. <literallayout class='monospaced'>
  1277. # dmesg | less
  1278. </literallayout>
  1279. You should see the results of your
  1280. <filename>printk</filename> statements
  1281. as part of the output when you scroll down the
  1282. console window.
  1283. </para></listitem>
  1284. <listitem><para>
  1285. <emphasis>Generate the Patch File:</emphasis>
  1286. Once you are sure that your patch works correctly, you
  1287. can generate a <filename>*.patch</filename> file in the
  1288. kernel source repository:
  1289. <literallayout class='monospaced'>
  1290. $ cd ~/linux-yocto-4.12/init
  1291. $ git format-patch -1
  1292. 0001-calibrate.c-Added-some-printk-statements.patch
  1293. </literallayout>
  1294. </para></listitem>
  1295. <listitem><para>
  1296. <emphasis>Move the Patch File to Your Layer:</emphasis>
  1297. In order for subsequent builds to pick up patches, you
  1298. need to move the patch file you created in the previous
  1299. step to your layer <filename>meta-mylayer</filename>.
  1300. For this example, the layer created earlier is located
  1301. in your home directory as <filename>meta-mylayer</filename>.
  1302. When the layer was created using the
  1303. <filename>yocto-create</filename> script, no additional
  1304. hierarchy was created to support patches.
  1305. Before moving the patch file, you need to add additional
  1306. structure to your layer using the following commands:
  1307. <literallayout class='monospaced'>
  1308. $ cd ~/meta-mylayer
  1309. $ mkdir recipes-kernel
  1310. $ mkdir recipes-kernel/linux
  1311. $ mkdir recipes-kernel/linux/linux-yocto
  1312. </literallayout>
  1313. Once you have created this hierarchy in your layer, you can
  1314. move the patch file using the following command:
  1315. <literallayout class='monospaced'>
  1316. $ mv ~/linux-yocto-4.12/init/0001-calibrate.c-Added-some-printk-statements.patch ~/meta-mylayer/recipes-kernel/linux/linux-yocto
  1317. </literallayout>
  1318. </para></listitem>
  1319. <listitem><para>
  1320. <emphasis>Create the Append File:</emphasis>
  1321. Finally, you need to create the
  1322. <filename>linux-yocto_4.12.bbappend</filename> file and
  1323. insert statements that allow the OpenEmbedded build
  1324. system to find the patch.
  1325. The append file needs to be in your layer's
  1326. <filename>recipes-kernel/linux</filename>
  1327. directory and it must be named
  1328. <filename>linux-yocto_4.12.bbappend</filename> and have
  1329. the following contents:
  1330. <literallayout class='monospaced'>
  1331. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
  1332. SRC_URI_append = " file://0001-calibrate.c-Added-some-printk-statements.patch"
  1333. </literallayout>
  1334. The
  1335. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
  1336. and
  1337. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  1338. statements enable the OpenEmbedded build system to find
  1339. the patch file.</para>
  1340. <para>For more information on append files and patches,
  1341. see the
  1342. "<link linkend='creating-the-append-file'>Creating the Append File</link>"
  1343. and
  1344. "<link linkend='applying-patches'>Applying Patches</link>"
  1345. sections.
  1346. You can also see the
  1347. "<ulink url='&YOCTO_DOCS_DEV_URL;#using-bbappend-files'>Using .bbappend Files in Your Layer"</ulink>"
  1348. section in the Yocto Project Development Tasks Manual.
  1349. <note>
  1350. To build <filename>core-image-minimal</filename>
  1351. again and see the effects of your patch, you can
  1352. essentially eliminate the temporary source files
  1353. saved in <filename>poky/build/tmp/work/...</filename>
  1354. and residual effects of the build by entering the
  1355. following sequence of commands:
  1356. <literallayout class='monospaced'>
  1357. $ cd ~/poky/build
  1358. $ bitbake -c cleanall yocto-linux
  1359. $ bitbake core-image-minimal -c cleanall
  1360. $ bitbake core-image-minimal
  1361. $ runqemu qemux86
  1362. </literallayout>
  1363. </note>
  1364. </para></listitem>
  1365. </orderedlist>
  1366. </para>
  1367. </section>
  1368. <section id='configuring-the-kernel'>
  1369. <title>Configuring the Kernel</title>
  1370. <para>
  1371. Configuring the Yocto Project kernel consists of making sure the
  1372. <filename>.config</filename> file has all the right information
  1373. in it for the image you are building.
  1374. You can use the <filename>menuconfig</filename> tool and
  1375. configuration fragments to make sure your
  1376. <filename>.config</filename> file is just how you need it.
  1377. You can also save known configurations in a
  1378. <filename>defconfig</filename> file that the build system can use
  1379. for kernel configuration.
  1380. </para>
  1381. <para>
  1382. This section describes how to use <filename>menuconfig</filename>,
  1383. create and use configuration fragments, and how to interactively
  1384. modify your <filename>.config</filename> file to create the
  1385. leanest kernel configuration file possible.
  1386. </para>
  1387. <para>
  1388. For more information on kernel configuration, see the
  1389. "<link linkend='changing-the-configuration'>Changing the Configuration</link>"
  1390. section.
  1391. </para>
  1392. <section id='using-menuconfig'>
  1393. <title>Using&nbsp;&nbsp;<filename>menuconfig</filename></title>
  1394. <para>
  1395. The easiest way to define kernel configurations is to set
  1396. them through the <filename>menuconfig</filename> tool.
  1397. This tool provides an interactive method with which
  1398. to set kernel configurations.
  1399. For general information on <filename>menuconfig</filename>, see
  1400. <ulink url='http://en.wikipedia.org/wiki/Menuconfig'></ulink>.
  1401. </para>
  1402. <para>
  1403. To use the <filename>menuconfig</filename> tool in the Yocto
  1404. Project development environment, you must do the following:
  1405. <itemizedlist>
  1406. <listitem><para>
  1407. Because you launch <filename>menuconfig</filename>
  1408. using BitBake, you must be sure to set up your
  1409. environment by running the
  1410. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
  1411. script found in the
  1412. <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
  1413. </para></listitem>
  1414. <listitem><para>
  1415. You must be sure of the state of your build's
  1416. configuration in the
  1417. <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
  1418. </para></listitem>
  1419. <listitem><para>
  1420. Your build host must have the following two packages
  1421. installed:
  1422. <literallayout class='monospaced'>
  1423. libncurses5-dev
  1424. libtinfo-dev
  1425. </literallayout>
  1426. </para></listitem>
  1427. </itemizedlist>
  1428. </para>
  1429. <para>
  1430. The following commands initialize the BitBake environment,
  1431. run the
  1432. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configme'><filename>do_kernel_configme</filename></ulink>
  1433. task, and launch <filename>menuconfig</filename>.
  1434. These commands assume the Source Directory's top-level folder
  1435. is <filename>~/poky</filename>:
  1436. <literallayout class='monospaced'>
  1437. $ cd poky
  1438. $ source oe-init-build-env
  1439. $ bitbake linux-yocto -c kernel_configme -f
  1440. $ bitbake linux-yocto -c menuconfig
  1441. </literallayout>
  1442. Once <filename>menuconfig</filename> comes up, its standard
  1443. interface allows you to interactively examine and configure
  1444. all the kernel configuration parameters.
  1445. After making your changes, simply exit the tool and save your
  1446. changes to create an updated version of the
  1447. <filename>.config</filename> configuration file.
  1448. <note>
  1449. You can use the entire <filename>.config</filename> file
  1450. as the <filename>defconfig</filename> file.
  1451. For information on <filename>defconfig</filename> files,
  1452. see the
  1453. "<link linkend='changing-the-configuration'>Changing the Configuration</link>",
  1454. "<link linkend='using-an-in-tree-defconfig-file'>Using an In-Tree <filename>defconfig</filename> File</link>,
  1455. and
  1456. "<link linkend='creating-a-defconfig-file'>Creating a <filename>defconfig</filename> File</link>"
  1457. sections.
  1458. </note>
  1459. </para>
  1460. <para>
  1461. Consider an example that configures the "CONFIG_SMP" setting
  1462. for the <filename>linux-yocto-4.12</filename> kernel.
  1463. <note>
  1464. The OpenEmbedded build system recognizes this kernel as
  1465. <filename>linux-yocto</filename> through Metadata (e.g.
  1466. <ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_VERSION'><filename>PREFERRED_VERSION</filename></ulink><filename>_linux-yocto ?= "12.4%"</filename>).
  1467. </note>
  1468. Once <filename>menuconfig</filename> launches, use the
  1469. interface to navigate through the selections to find the
  1470. configuration settings in which you are interested.
  1471. For this example, you deselect "CONFIG_SMP" by clearing the
  1472. "Symmetric Multi-Processing Support" option.
  1473. Using the interface, you can find the option under
  1474. "Processor Type and Features".
  1475. To deselect "CONFIG_SMP", use the arrow keys to
  1476. highlight "Symmetric Multi-Processing Support" and enter "N"
  1477. to clear the asterisk.
  1478. When you are finished, exit out and save the change.
  1479. </para>
  1480. <para>
  1481. Saving the selections updates the <filename>.config</filename>
  1482. configuration file.
  1483. This is the file that the OpenEmbedded build system uses to
  1484. configure the kernel during the build.
  1485. You can find and examine this file in the Build Directory in
  1486. <filename>tmp/work/</filename>.
  1487. The actual <filename>.config</filename> is located in the
  1488. area where the specific kernel is built.
  1489. For example, if you were building a Linux Yocto kernel based
  1490. on the <filename>linux-yocto-4.12</filename> kernel and you
  1491. were building a QEMU image targeted for
  1492. <filename>x86</filename> architecture, the
  1493. <filename>.config</filename> file would be:
  1494. <literallayout class='monospaced'>
  1495. poky/build/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+gitAUTOINC+eda4d18...
  1496. ...967-r0/linux-qemux86-standard-build/.config
  1497. </literallayout>
  1498. <note>
  1499. The previous example directory is artificially split and
  1500. many of the characters in the actual filename are omitted
  1501. in order to make it more readable.
  1502. Also, depending on the kernel you are using, the exact
  1503. pathname might differ.
  1504. </note>
  1505. </para>
  1506. <para>
  1507. Within the <filename>.config</filename> file, you can see the
  1508. kernel settings.
  1509. For example, the following entry shows that symmetric
  1510. multi-processor support is not set:
  1511. <literallayout class='monospaced'>
  1512. # CONFIG_SMP is not set
  1513. </literallayout>
  1514. </para>
  1515. <para>
  1516. A good method to isolate changed configurations is to use a
  1517. combination of the <filename>menuconfig</filename> tool and
  1518. simple shell commands.
  1519. Before changing configurations with
  1520. <filename>menuconfig</filename>, copy the existing
  1521. <filename>.config</filename> and rename it to something else,
  1522. use <filename>menuconfig</filename> to make as many changes as
  1523. you want and save them, then compare the renamed configuration
  1524. file against the newly created file.
  1525. You can use the resulting differences as your base to create
  1526. configuration fragments to permanently save in your kernel
  1527. layer.
  1528. <note>
  1529. Be sure to make a copy of the <filename>.config</filename>
  1530. file and do not just rename it.
  1531. The build system needs an existing
  1532. <filename>.config</filename> file from which to work.
  1533. </note>
  1534. </para>
  1535. </section>
  1536. <section id='creating-a-defconfig-file'>
  1537. <title>Creating a&nbsp;&nbsp;<filename>defconfig</filename> File</title>
  1538. <para>
  1539. A <filename>defconfig</filename> file in the context of
  1540. the Yocto Project is often a <filename>.config</filename>
  1541. file that is copied from a build or a
  1542. <filename>defconfig</filename> taken from the kernel tree
  1543. and moved into recipe space.
  1544. You can use a <filename>defconfig</filename> file
  1545. to retain a known set of kernel configurations from which the
  1546. OpenEmbedded build system can draw to create the final
  1547. <filename>.config</filename> file.
  1548. <note>
  1549. Out-of-the-box, the Yocto Project never ships a
  1550. <filename>defconfig</filename> or
  1551. <filename>.config</filename> file.
  1552. The OpenEmbedded build system creates the final
  1553. <filename>.config</filename> file used to configure the
  1554. kernel.
  1555. </note>
  1556. </para>
  1557. <para>
  1558. To create a <filename>defconfig</filename>, start with a
  1559. complete, working Linux kernel <filename>.config</filename>
  1560. file.
  1561. Copy that file to the appropriate
  1562. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
  1563. directory in your layer's
  1564. <filename>recipes-kernel/linux</filename> directory, and rename
  1565. the copied file to "defconfig" (e.g.
  1566. <filename>~/meta-mylayer/recipes-kernel/linux/linux-yocto/defconfig</filename>).
  1567. Then, add the following lines to the linux-yocto
  1568. <filename>.bbappend</filename> file in your layer:
  1569. <literallayout class='monospaced'>
  1570. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
  1571. SRC_URI += "file://defconfig"
  1572. </literallayout>
  1573. The
  1574. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  1575. tells the build system how to search for the file, while the
  1576. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
  1577. extends the
  1578. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
  1579. variable (search directories) to include the
  1580. <filename>${PN}</filename> directory you created to hold the
  1581. configuration changes.
  1582. <note>
  1583. The build system applies the configurations from the
  1584. <filename>defconfig</filename> file before applying any
  1585. subsequent configuration fragments.
  1586. The final kernel configuration is a combination of the
  1587. configurations in the <filename>defconfig</filename>
  1588. file and any configuration fragments you provide.
  1589. You need to realize that if you have any configuration
  1590. fragments, the build system applies these on top of and
  1591. after applying the existing defconfig file configurations.
  1592. </note>
  1593. For more information on configuring the kernel, see the
  1594. "<link linkend='changing-the-configuration'>Changing the Configuration</link>"
  1595. section.
  1596. </para>
  1597. </section>
  1598. <section id='creating-config-fragments'>
  1599. <title>Creating Configuration Fragments</title>
  1600. <para>
  1601. Configuration fragments are simply kernel options that
  1602. appear in a file placed where the OpenEmbedded build system
  1603. can find and apply them.
  1604. The build system applies configuration fragments after
  1605. applying configurations from a <filename>defconfig</filename>
  1606. file.
  1607. Thus, the final kernel configuration is a combination of the
  1608. configurations in the <filename>defconfig</filename>
  1609. file and then any configuration fragments you provide.
  1610. The build system applies fragments on top of and
  1611. after applying the existing defconfig file configurations.
  1612. </para>
  1613. <para>
  1614. Syntactically, the configuration statement is identical to
  1615. what would appear in the <filename>.config</filename> file,
  1616. which is in the
  1617. <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
  1618. <note>
  1619. For more information about where the
  1620. <filename>.config</filename> file is located, see the
  1621. example in the
  1622. "<link linkend='using-menuconfig'>Using <filename>menuconfig</filename></link>"
  1623. section.
  1624. </note>
  1625. </para>
  1626. <para>
  1627. It is simple to create a configuration fragment.
  1628. One method is to use shell commands.
  1629. For example, issuing the following from the shell creates a
  1630. configuration fragment file named
  1631. <filename>my_smp.cfg</filename> that enables multi-processor
  1632. support within the kernel:
  1633. <literallayout class='monospaced'>
  1634. $ echo "CONFIG_SMP=y" >> my_smp.cfg
  1635. </literallayout>
  1636. <note>
  1637. All configuration fragment files must use the
  1638. <filename>.cfg</filename> extension in order for the
  1639. OpenEmbedded build system to recognize them as a
  1640. configuration fragment.
  1641. </note>
  1642. </para>
  1643. <para>
  1644. Another method is to create a configuration fragment using the
  1645. differences between two configuration files: one previously
  1646. created and saved, and one freshly created using the
  1647. <filename>menuconfig</filename> tool.
  1648. </para>
  1649. <para>
  1650. To create a configuration fragment using this method, follow
  1651. these steps:
  1652. <orderedlist>
  1653. <listitem><para>
  1654. <emphasis>Complete a Build Through Kernel Configuration:</emphasis>
  1655. Complete a build at least through the kernel
  1656. configuration task as follows:
  1657. <literallayout class='monospaced'>
  1658. $ bitbake linux-yocto -c kernel_configme -f
  1659. </literallayout>
  1660. This step ensures that you create a
  1661. <filename>.config</filename> file from a known state.
  1662. Because situations exist where your build state might
  1663. become unknown, it is best to run this task prior
  1664. to starting <filename>menuconfig</filename>.
  1665. </para></listitem>
  1666. <listitem><para>
  1667. <emphasis>Launch <filename>menuconfig</filename>:</emphasis>
  1668. Run the <filename>menuconfig</filename> command:
  1669. <literallayout class='monospaced'>
  1670. $ bitbake linux-yocto -c menuconfig
  1671. </literallayout>
  1672. </para></listitem>
  1673. <listitem><para>
  1674. <emphasis>Create the Configuration Fragment:</emphasis>
  1675. Run the <filename>diffconfig</filename>
  1676. command to prepare a configuration fragment.
  1677. The resulting file <filename>fragment.cfg</filename>
  1678. is placed in the
  1679. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename> directory:
  1680. <literallayout class='monospaced'>
  1681. $ bitbake linux-yocto -c diffconfig
  1682. </literallayout>
  1683. </para></listitem>
  1684. </orderedlist>
  1685. </para>
  1686. <para>
  1687. The <filename>diffconfig</filename> command creates a file
  1688. that is a list of Linux kernel <filename>CONFIG_</filename>
  1689. assignments.
  1690. See the "<link linkend='changing-the-configuration'>Changing the Configuration</link>"
  1691. section for additional information on how to use the output
  1692. as a configuration fragment.
  1693. <note>
  1694. You can also use this method to create configuration
  1695. fragments for a BSP.
  1696. See the "<link linkend='bsp-descriptions'>BSP Descriptions</link>"
  1697. section for more information.
  1698. </note>
  1699. </para>
  1700. <para>
  1701. Where do you put your configuration fragment files?
  1702. You can place these files in an area pointed to by
  1703. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  1704. as directed by your <filename>bblayers.conf</filename> file,
  1705. which is located in your layer.
  1706. The OpenEmbedded build system picks up the configuration and
  1707. adds it to the kernel's configuration.
  1708. For example, suppose you had a set of configuration options
  1709. in a file called <filename>myconfig.cfg</filename>.
  1710. If you put that file inside a directory named
  1711. <filename>linux-yocto</filename> that resides in the same
  1712. directory as the kernel's append file within your layer
  1713. and then add the following statements to the kernel's append
  1714. file, those configuration options will be picked up and applied
  1715. when the kernel is built:
  1716. <literallayout class='monospaced'>
  1717. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
  1718. SRC_URI += "file://myconfig.cfg"
  1719. </literallayout>
  1720. </para>
  1721. <para>
  1722. As mentioned earlier, you can group related configurations
  1723. into multiple files and name them all in the
  1724. <filename>SRC_URI</filename> statement as well.
  1725. For example, you could group separate configurations
  1726. specifically for Ethernet and graphics into their own files
  1727. and add those by using a <filename>SRC_URI</filename> statement
  1728. like the following in your append file:
  1729. <literallayout class='monospaced'>
  1730. SRC_URI += "file://myconfig.cfg \
  1731. file://eth.cfg \
  1732. file://gfx.cfg"
  1733. </literallayout>
  1734. </para>
  1735. </section>
  1736. <section id='validating-configuration'>
  1737. <title>Validating Configuration</title>
  1738. <para>
  1739. You can use the
  1740. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configcheck'><filename>do_kernel_configcheck</filename></ulink>
  1741. task to provide configuration validation:
  1742. <literallayout class='monospaced'>
  1743. $ bitbake linux-yocto -c kernel_configcheck -f
  1744. </literallayout>
  1745. Running this task produces warnings for when a
  1746. requested configuration does not appear in the final
  1747. <filename>.config</filename> file or when you override a
  1748. policy configuration in a hardware configuration fragment.
  1749. </para>
  1750. <para>
  1751. In order to run this task, you must have an existing
  1752. <filename>.config</filename> file.
  1753. See the
  1754. "<link linkend='using-menuconfig'>Using <filename>menuconfig</filename></link>"
  1755. section for information on how to create a configuration file.
  1756. </para>
  1757. <para>
  1758. Following is sample output from the
  1759. <filename>do_kernel_configcheck</filename> task:
  1760. <literallayout class='monospaced'>
  1761. Loading cache: 100% |########################################################| Time: 0:00:00
  1762. Loaded 1275 entries from dependency cache.
  1763. NOTE: Resolving any missing task queue dependencies
  1764. Build Configuration:
  1765. .
  1766. .
  1767. .
  1768. NOTE: Executing SetScene Tasks
  1769. NOTE: Executing RunQueue Tasks
  1770. WARNING: linux-yocto-4.12.12+gitAUTOINC+eda4d18ce4_16de014967-r0 do_kernel_configcheck:
  1771. [kernel config]: specified values did not make it into the kernel's final configuration:
  1772. ---------- CONFIG_X86_TSC -----------------
  1773. Config: CONFIG_X86_TSC
  1774. From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/bsp/common-pc/common-pc-cpu.cfg
  1775. Requested value: CONFIG_X86_TSC=y
  1776. Actual value:
  1777. ---------- CONFIG_X86_BIGSMP -----------------
  1778. Config: CONFIG_X86_BIGSMP
  1779. From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
  1780. /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
  1781. Requested value: # CONFIG_X86_BIGSMP is not set
  1782. Actual value:
  1783. ---------- CONFIG_NR_CPUS -----------------
  1784. Config: CONFIG_NR_CPUS
  1785. From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
  1786. /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/bsp/common-pc/common-pc.cfg
  1787. /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
  1788. Requested value: CONFIG_NR_CPUS=8
  1789. Actual value: CONFIG_NR_CPUS=1
  1790. ---------- CONFIG_SCHED_SMT -----------------
  1791. Config: CONFIG_SCHED_SMT
  1792. From: /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/cfg/smp.cfg
  1793. /home/scottrif/poky/build/tmp/work-shared/qemux86/kernel-source/.kernel-meta/configs/standard/defconfig
  1794. Requested value: CONFIG_SCHED_SMT=y
  1795. Actual value:
  1796. NOTE: Tasks Summary: Attempted 288 tasks of which 285 didn't need to be rerun and all succeeded.
  1797. Summary: There were 3 WARNING messages shown.
  1798. </literallayout>
  1799. <note>
  1800. The previous output example has artificial line breaks
  1801. to make it more readable.
  1802. </note>
  1803. </para>
  1804. <para>
  1805. The output describes the various problems that you can
  1806. encounter along with where to find the offending configuration
  1807. items.
  1808. You can use the information in the logs to adjust your
  1809. configuration files and then repeat the
  1810. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configme'><filename>do_kernel_configme</filename></ulink>
  1811. and
  1812. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-kernel_configcheck'><filename>do_kernel_configcheck</filename></ulink>
  1813. tasks until they produce no warnings.
  1814. </para>
  1815. <para>
  1816. For more information on how to use the
  1817. <filename>menuconfig</filename> tool, see the
  1818. "<link linkend='using-menuconfig'>Using <filename>menuconfig</filename></link>"
  1819. section.
  1820. </para>
  1821. </section>
  1822. <section id='fine-tuning-the-kernel-configuration-file'>
  1823. <title>Fine-Tuning the Kernel Configuration File</title>
  1824. <para>
  1825. You can make sure the <filename>.config</filename> file is as
  1826. lean or efficient as possible by reading the output of the
  1827. kernel configuration fragment audit, noting any issues, making
  1828. changes to correct the issues, and then repeating.
  1829. </para>
  1830. <para>
  1831. As part of the kernel build process, the
  1832. <filename>do_kernel_configcheck</filename> task runs.
  1833. This task validates the kernel configuration by checking the
  1834. final <filename>.config</filename> file against the input
  1835. files.
  1836. During the check, the task produces warning messages for the
  1837. following issues:
  1838. <itemizedlist>
  1839. <listitem><para>
  1840. Requested options that did not make the final
  1841. <filename>.config</filename> file.
  1842. </para></listitem>
  1843. <listitem><para>
  1844. Configuration items that appear twice in the same
  1845. configuration fragment.
  1846. </para></listitem>
  1847. <listitem><para>
  1848. Configuration items tagged as "required" that were
  1849. overridden.
  1850. </para></listitem>
  1851. <listitem><para>
  1852. A board overrides a non-board specific option.
  1853. </para></listitem>
  1854. <listitem><para>
  1855. Listed options not valid for the kernel being
  1856. processed.
  1857. In other words, the option does not appear anywhere.
  1858. </para></listitem>
  1859. </itemizedlist>
  1860. <note>
  1861. The <filename>do_kernel_configcheck</filename> task can
  1862. also optionally report if an option is overridden during
  1863. processing.
  1864. </note>
  1865. </para>
  1866. <para>
  1867. For each output warning, a message points to the file
  1868. that contains a list of the options and a pointer to the
  1869. configuration fragment that defines them.
  1870. Collectively, the files are the key to streamlining the
  1871. configuration.
  1872. </para>
  1873. <para>
  1874. To streamline the configuration, do the following:
  1875. <orderedlist>
  1876. <listitem><para>
  1877. <emphasis>Use a Working Configuration:</emphasis>
  1878. Start with a full configuration that you
  1879. know works.
  1880. Be sure the configuration builds and boots
  1881. successfully.
  1882. Use this configuration file as your baseline.
  1883. </para></listitem>
  1884. <listitem><para>
  1885. <emphasis>Run Configure and Check Tasks:</emphasis>
  1886. Separately run the
  1887. <filename>do_kernel_configme</filename> and
  1888. <filename>do_kernel_configcheck</filename> tasks:
  1889. <literallayout class='monospaced'>
  1890. $ bitbake linux-yocto -c kernel_configme -f
  1891. $ bitbake linux-yocto -c kernel_configcheck -f
  1892. </literallayout>
  1893. </para></listitem>
  1894. <listitem><para>
  1895. <emphasis>Process the Results:</emphasis>
  1896. Take the resulting list of files from the
  1897. <filename>do_kernel_configcheck</filename> task
  1898. warnings and do the following:
  1899. <itemizedlist>
  1900. <listitem><para>
  1901. Drop values that are redefined in the fragment
  1902. but do not change the final
  1903. <filename>.config</filename> file.
  1904. </para></listitem>
  1905. <listitem><para>
  1906. Analyze and potentially drop values from the
  1907. <filename>.config</filename> file that override
  1908. required configurations.
  1909. </para></listitem>
  1910. <listitem><para>
  1911. Analyze and potentially remove non-board
  1912. specific options.
  1913. </para></listitem>
  1914. <listitem><para>
  1915. Remove repeated and invalid options.
  1916. </para></listitem>
  1917. </itemizedlist>
  1918. </para></listitem>
  1919. <listitem><para>
  1920. <emphasis>Re-Run Configure and Check Tasks:</emphasis>
  1921. After you have worked through the output of the kernel
  1922. configuration audit, you can re-run the
  1923. <filename>do_kernel_configme</filename> and
  1924. <filename>do_kernel_configcheck</filename> tasks to
  1925. see the results of your changes.
  1926. If you have more issues, you can deal with them as
  1927. described in the previous step.
  1928. </para></listitem>
  1929. </orderedlist>
  1930. </para>
  1931. <para>
  1932. Iteratively working through steps two through four eventually
  1933. yields a minimal, streamlined configuration file.
  1934. Once you have the best <filename>.config</filename>, you can
  1935. build the Linux Yocto kernel.
  1936. </para>
  1937. </section>
  1938. </section>
  1939. <section id='expanding-variables'>
  1940. <title>Expanding Variables</title>
  1941. <para>
  1942. Sometimes it is helpful to determine what a variable expands
  1943. to during a build.
  1944. You can do examine the values of variables by examining the
  1945. output of the <filename>bitbake -e</filename> command.
  1946. The output is long and is more easily managed in a text file,
  1947. which allows for easy searches:
  1948. <literallayout class='monospaced'>
  1949. $ bitbake -e virtual/kernel > <replaceable>some_text_file</replaceable>
  1950. </literallayout>
  1951. Within the text file, you can see exactly how each variable is
  1952. expanded and used by the OpenEmbedded build system.
  1953. </para>
  1954. </section>
  1955. <section id='working-with-a-dirty-kernel-version-string'>
  1956. <title>Working with a "Dirty" Kernel Version String</title>
  1957. <para>
  1958. If you build a kernel image and the version string has a
  1959. "+" or a "-dirty" at the end, uncommitted modifications exist
  1960. in the kernel's source directory.
  1961. Follow these steps to clean up the version string:
  1962. <orderedlist>
  1963. <listitem><para>
  1964. <emphasis>Discover the Uncommitted Changes:</emphasis>
  1965. Go to the kernel's locally cloned Git repository
  1966. (source directory) and use the following Git command
  1967. to list the files that have been changed, added, or
  1968. removed:
  1969. <literallayout class='monospaced'>
  1970. $ git status
  1971. </literallayout>
  1972. </para></listitem>
  1973. <listitem><para>
  1974. <emphasis>Commit the Changes:</emphasis>
  1975. You should commit those changes to the kernel source
  1976. tree regardless of whether or not you will save,
  1977. export, or use the changes:
  1978. <literallayout class='monospaced'>
  1979. $ git add
  1980. $ git commit -s -a -m "getting rid of -dirty"
  1981. </literallayout>
  1982. </para></listitem>
  1983. <listitem><para>
  1984. <emphasis>Rebuild the Kernel Image:</emphasis>
  1985. Once you commit the changes, rebuild the kernel.</para>
  1986. <para>Depending on your particular kernel development
  1987. workflow, the commands you use to rebuild the
  1988. kernel might differ.
  1989. For information on building the kernel image when
  1990. using <filename>devtool</filename>, see the
  1991. "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>"
  1992. section.
  1993. For information on building the kernel image when
  1994. using Bitbake, see the
  1995. "<link linkend='using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</link>"
  1996. section.
  1997. </para></listitem>
  1998. </orderedlist>
  1999. </para>
  2000. </section>
  2001. <section id='working-with-your-own-sources'>
  2002. <title>Working With Your Own Sources</title>
  2003. <para>
  2004. If you cannot work with one of the Linux kernel
  2005. versions supported by existing linux-yocto recipes, you can
  2006. still make use of the Yocto Project Linux kernel tooling by
  2007. working with your own sources.
  2008. When you use your own sources, you will not be able to
  2009. leverage the existing kernel
  2010. <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink> and
  2011. stabilization work of the linux-yocto sources.
  2012. However, you will be able to manage your own Metadata in the same
  2013. format as the linux-yocto sources.
  2014. Maintaining format compatibility facilitates converging with
  2015. linux-yocto on a future, mutually-supported kernel version.
  2016. </para>
  2017. <para>
  2018. To help you use your own sources, the Yocto Project provides a
  2019. linux-yocto custom recipe
  2020. (<filename>linux-yocto-custom.bb</filename>) that uses
  2021. <filename>kernel.org</filename> sources
  2022. and the Yocto Project Linux kernel tools for managing
  2023. kernel Metadata.
  2024. You can find this recipe in the
  2025. <filename>poky</filename> Git repository of the
  2026. Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink>
  2027. at:
  2028. <literallayout class="monospaced">
  2029. poky/meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb
  2030. </literallayout>
  2031. </para>
  2032. <para>
  2033. Here are some basic steps you can use to work with your own
  2034. sources:
  2035. <orderedlist>
  2036. <listitem><para>
  2037. <emphasis>Create a Copy of the Kernel Recipe:</emphasis>
  2038. Copy the <filename>linux-yocto-custom.bb</filename>
  2039. recipe to your layer and give it a meaningful name.
  2040. The name should include the version of the Yocto Linux
  2041. kernel you are using (e.g.
  2042. <filename>linux-yocto-myproject_4.12.bb</filename>,
  2043. where "4.12" is the base version of the Linux kernel
  2044. with which you would be working).
  2045. </para></listitem>
  2046. <listitem><para>
  2047. <emphasis>Create a Directory for Your Patches:</emphasis>
  2048. In the same directory inside your layer, create a matching
  2049. directory to store your patches and configuration files
  2050. (e.g. <filename>linux-yocto-myproject</filename>).
  2051. </para></listitem>
  2052. <listitem><para>
  2053. <emphasis>Ensure You Have Configurations:</emphasis>
  2054. Make sure you have either a <filename>defconfig</filename>
  2055. file or configuration fragment files in your layer.
  2056. When you use the <filename>linux-yocto-custom.bb</filename>
  2057. recipe, you must specify a configuration.
  2058. If you do not have a <filename>defconfig</filename> file,
  2059. you can run the following:
  2060. <literallayout class='monospaced'>
  2061. $ make defconfig
  2062. </literallayout>
  2063. After running the command, copy the resulting
  2064. <filename>.config</filename> file to the
  2065. <filename>files</filename> directory in your layer
  2066. as "defconfig" and then add it to the
  2067. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  2068. variable in the recipe.</para>
  2069. <para>Running the <filename>make defconfig</filename>
  2070. command results in the default configuration for your
  2071. architecture as defined by your kernel.
  2072. However, no guarantee exists that this configuration is
  2073. valid for your use case, or that your board will even boot.
  2074. This is particularly true for non-x86 architectures.</para>
  2075. <para>To use non-x86 <filename>defconfig</filename> files,
  2076. you need to be more specific and find one that matches your
  2077. board (i.e. for arm, you look in
  2078. <filename>arch/arm/configs</filename> and use the one that
  2079. is the best starting point for your board).
  2080. </para></listitem>
  2081. <listitem><para>
  2082. <emphasis>Edit the Recipe:</emphasis>
  2083. Edit the following variables in your recipe as appropriate
  2084. for your project:
  2085. <itemizedlist>
  2086. <listitem><para>
  2087. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>:
  2088. The <filename>SRC_URI</filename> should specify
  2089. a Git repository that uses one of the supported Git
  2090. fetcher protocols (i.e. <filename>file</filename>,
  2091. <filename>git</filename>, <filename>http</filename>,
  2092. and so forth).
  2093. The <filename>SRC_URI</filename> variable should
  2094. also specify either a <filename>defconfig</filename>
  2095. file or some configuration fragment files.
  2096. The skeleton recipe provides an example
  2097. <filename>SRC_URI</filename> as a syntax reference.
  2098. </para></listitem>
  2099. <listitem><para>
  2100. <ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION'><filename>LINUX_VERSION</filename></ulink>:
  2101. The Linux kernel version you are using (e.g.
  2102. "4.12").
  2103. </para></listitem>
  2104. <listitem><para>
  2105. <ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION_EXTENSION'><filename>LINUX_VERSION_EXTENSION</filename></ulink>:
  2106. The Linux kernel
  2107. <filename>CONFIG_LOCALVERSION</filename> that is
  2108. compiled into the resulting kernel and visible
  2109. through the <filename>uname</filename> command.
  2110. </para></listitem>
  2111. <listitem><para>
  2112. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>:
  2113. The commit ID from which you want to build.
  2114. </para></listitem>
  2115. <listitem><para>
  2116. <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
  2117. Treat this variable the same as you would in any
  2118. other recipe.
  2119. Increment the variable to indicate to the
  2120. OpenEmbedded build system that the recipe has
  2121. changed.
  2122. </para></listitem>
  2123. <listitem><para>
  2124. <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
  2125. The default <filename>PV</filename> assignment is
  2126. typically adequate.
  2127. It combines the <filename>LINUX_VERSION</filename>
  2128. with the Source Control Manager (SCM) revision
  2129. as derived from the
  2130. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>
  2131. variable.
  2132. The combined results are a string with the
  2133. following form:
  2134. <literallayout class='monospaced'>
  2135. 3.19.11+git1+68a635bf8dfb64b02263c1ac80c948647cc76d5f_1+218bd8d2022b9852c60d32f0d770931e3cf343e2
  2136. </literallayout>
  2137. While lengthy, the extra verbosity in
  2138. <filename>PV</filename> helps ensure you are using
  2139. the exact sources from which you intend to build.
  2140. </para></listitem>
  2141. <listitem><para>
  2142. <ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'><filename>COMPATIBLE_MACHINE</filename></ulink>:
  2143. A list of the machines supported by your new recipe.
  2144. This variable in the example recipe is set
  2145. by default to a regular expression that matches
  2146. only the empty string, "(^$)".
  2147. This default setting triggers an explicit build
  2148. failure.
  2149. You must change it to match a list of the machines
  2150. that your new recipe supports.
  2151. For example, to support the
  2152. <filename>qemux86</filename> and
  2153. <filename>qemux86-64</filename> machines, use
  2154. the following form:
  2155. <literallayout class='monospaced'>
  2156. COMPATIBLE_MACHINE = "qemux86|qemux86-64"
  2157. </literallayout>
  2158. </para></listitem>
  2159. </itemizedlist>
  2160. </para></listitem>
  2161. <listitem><para>
  2162. <emphasis>Customize Your Recipe as Needed:</emphasis>
  2163. Provide further customizations to your recipe
  2164. as needed just as you would customize an existing
  2165. linux-yocto recipe.
  2166. See the
  2167. "<link linkend='modifying-an-existing-recipe'>Modifying an Existing Recipe</link>"
  2168. section for information.
  2169. </para></listitem>
  2170. </orderedlist>
  2171. </para>
  2172. </section>
  2173. <section id='working-with-out-of-tree-modules'>
  2174. <title>Working with Out-of-Tree Modules</title>
  2175. <para>
  2176. This section describes steps to build out-of-tree modules on
  2177. your target and describes how to incorporate out-of-tree modules
  2178. in the build.
  2179. </para>
  2180. <section id='building-out-of-tree-modules-on-the-target'>
  2181. <title>Building Out-of-Tree Modules on the Target</title>
  2182. <para>
  2183. While the traditional Yocto Project development model would be
  2184. to include kernel modules as part of the normal build
  2185. process, you might find it useful to build modules on the
  2186. target.
  2187. This could be the case if your target system is capable
  2188. and powerful enough to handle the necessary compilation.
  2189. Before deciding to build on your target, however, you should
  2190. consider the benefits of using a proper cross-development
  2191. environment from your build host.
  2192. </para>
  2193. <para>
  2194. If you want to be able to build out-of-tree modules on
  2195. the target, there are some steps you need to take
  2196. on the target that is running your SDK image.
  2197. Briefly, the <filename>kernel-dev</filename> package
  2198. is installed by default on all
  2199. <filename>*.sdk</filename> images and the
  2200. <filename>kernel-devsrc</filename> package is installed
  2201. on many of the <filename>*.sdk</filename> images.
  2202. However, you need to create some scripts prior to
  2203. attempting to build the out-of-tree modules on the target
  2204. that is running that image.
  2205. </para>
  2206. <para>
  2207. Prior to attempting to build the out-of-tree modules,
  2208. you need to be on the target as root and you need to
  2209. change to the <filename>/usr/src/kernel</filename> directory.
  2210. Next, <filename>make</filename> the scripts:
  2211. <literallayout class='monospaced'>
  2212. # cd /usr/src/kernel
  2213. # make scripts
  2214. </literallayout>
  2215. Because all SDK image recipes include
  2216. <filename>dev-pkgs</filename>, the
  2217. <filename>kernel-dev</filename> packages will be installed
  2218. as part of the SDK image and the
  2219. <filename>kernel-devsrc</filename> packages will be installed
  2220. as part of applicable SDK images.
  2221. The SDK uses the scripts when building out-of-tree
  2222. modules.
  2223. Once you have switched to that directory and created the
  2224. scripts, you should be able to build your out-of-tree modules
  2225. on the target.
  2226. </para>
  2227. </section>
  2228. <section id='incorporating-out-of-tree-modules'>
  2229. <title>Incorporating Out-of-Tree Modules</title>
  2230. <para>
  2231. While it is always preferable to work with sources integrated
  2232. into the Linux kernel sources, if you need an external kernel
  2233. module, the <filename>hello-mod.bb</filename> recipe is
  2234. available as a template from which you can create your
  2235. own out-of-tree Linux kernel module recipe.
  2236. </para>
  2237. <para>
  2238. This template recipe is located in the
  2239. <filename>poky</filename> Git repository of the
  2240. Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink>
  2241. at:
  2242. <literallayout class="monospaced">
  2243. poky/meta-skeleton/recipes-kernel/hello-mod/hello-mod_0.1.bb
  2244. </literallayout>
  2245. </para>
  2246. <para>
  2247. To get started, copy this recipe to your layer and give it a
  2248. meaningful name (e.g. <filename>mymodule_1.0.bb</filename>).
  2249. In the same directory, create a new directory named
  2250. <filename>files</filename> where you can store any source files,
  2251. patches, or other files necessary for building
  2252. the module that do not come with the sources.
  2253. Finally, update the recipe as needed for the module.
  2254. Typically, you will need to set the following variables:
  2255. <itemizedlist>
  2256. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
  2257. </para></listitem>
  2258. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE*</filename></ulink>
  2259. </para></listitem>
  2260. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  2261. </para></listitem>
  2262. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
  2263. </para></listitem>
  2264. </itemizedlist>
  2265. </para>
  2266. <para>
  2267. Depending on the build system used by the module sources,
  2268. you might need to make some adjustments.
  2269. For example, a typical module <filename>Makefile</filename>
  2270. looks much like the one provided with the
  2271. <filename>hello-mod</filename> template:
  2272. <literallayout class='monospaced'>
  2273. obj-m := hello.o
  2274. SRC := $(shell pwd)
  2275. all:
  2276. $(MAKE) -C $(KERNEL_SRC) M=$(SRC)
  2277. modules_install:
  2278. $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
  2279. ...
  2280. </literallayout>
  2281. </para>
  2282. <para>
  2283. The important point to note here is the
  2284. <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_SRC'><filename>KERNEL_SRC</filename></ulink>
  2285. variable.
  2286. The
  2287. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-module'><filename>module</filename></ulink>
  2288. class sets this variable and the
  2289. <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_PATH'><filename>KERNEL_PATH</filename></ulink>
  2290. variable to
  2291. <filename>${<ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_KERNEL_DIR'><filename>STAGING_KERNEL_DIR</filename></ulink>}</filename>
  2292. with the necessary Linux kernel build information to build
  2293. modules.
  2294. If your module <filename>Makefile</filename> uses a different
  2295. variable, you might want to override the
  2296. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
  2297. step, or create a patch to
  2298. the <filename>Makefile</filename> to work with the more typical
  2299. <filename>KERNEL_SRC</filename> or
  2300. <filename>KERNEL_PATH</filename> variables.
  2301. </para>
  2302. <para>
  2303. After you have prepared your recipe, you will likely want to
  2304. include the module in your images.
  2305. To do this, see the documentation for the following variables in
  2306. the Yocto Project Reference Manual and set one of them
  2307. appropriately for your machine configuration file:
  2308. <itemizedlist>
  2309. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RDEPENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RDEPENDS</filename></ulink>
  2310. </para></listitem>
  2311. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink>
  2312. </para></listitem>
  2313. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RDEPENDS'><filename>MACHINE_EXTRA_RDEPENDS</filename></ulink>
  2314. </para></listitem>
  2315. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RRECOMMENDS'><filename>MACHINE_EXTRA_RRECOMMENDS</filename></ulink>
  2316. </para></listitem>
  2317. </itemizedlist>
  2318. </para>
  2319. <para>
  2320. Modules are often not required for boot and can be excluded from
  2321. certain build configurations.
  2322. The following allows for the most flexibility:
  2323. <literallayout class='monospaced'>
  2324. MACHINE_EXTRA_RRECOMMENDS += "kernel-module-mymodule"
  2325. </literallayout>
  2326. The value is derived by appending the module filename without
  2327. the <filename>.ko</filename> extension to the string
  2328. "kernel-module-".
  2329. </para>
  2330. <para>
  2331. Because the variable is
  2332. <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
  2333. and not a
  2334. <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
  2335. variable, the build will not fail if this module is not
  2336. available to include in the image.
  2337. </para>
  2338. </section>
  2339. </section>
  2340. <section id='inspecting-changes-and-commits'>
  2341. <title>Inspecting Changes and Commits</title>
  2342. <para>
  2343. A common question when working with a kernel is:
  2344. "What changes have been applied to this tree?"
  2345. Rather than using "grep" across directories to see what has
  2346. changed, you can use Git to inspect or search the kernel tree.
  2347. Using Git is an efficient way to see what has changed in the tree.
  2348. </para>
  2349. <section id='what-changed-in-a-kernel'>
  2350. <title>What Changed in a Kernel?</title>
  2351. <para>
  2352. Following are a few examples that show how to use Git
  2353. commands to examine changes.
  2354. These examples are by no means the only way to see changes.
  2355. <note>
  2356. In the following examples, unless you provide a commit
  2357. range, <filename>kernel.org</filename> history is blended
  2358. with Yocto Project kernel changes.
  2359. You can form ranges by using branch names from the
  2360. kernel tree as the upper and lower commit markers with
  2361. the Git commands.
  2362. You can see the branch names through the web interface
  2363. to the Yocto Project source repositories at
  2364. <ulink url='&YOCTO_GIT_URL;'></ulink>.
  2365. </note>
  2366. To see a full range of the changes, use the
  2367. <filename>git whatchanged</filename> command and specify a
  2368. commit range for the branch
  2369. (<replaceable>commit</replaceable><filename>..</filename><replaceable>commit</replaceable>).
  2370. </para>
  2371. <para>
  2372. Here is an example that looks at what has changed in the
  2373. <filename>emenlow</filename> branch of the
  2374. <filename>linux-yocto-3.19</filename> kernel.
  2375. The lower commit range is the commit associated with the
  2376. <filename>standard/base</filename> branch, while
  2377. the upper commit range is the commit associated with the
  2378. <filename>standard/emenlow</filename> branch.
  2379. <literallayout class='monospaced'>
  2380. $ git whatchanged origin/standard/base..origin/standard/emenlow
  2381. </literallayout>
  2382. </para>
  2383. <para>
  2384. To see short, one line summaries of changes use the
  2385. <filename>git log</filename> command:
  2386. <literallayout class='monospaced'>
  2387. $ git log --oneline origin/standard/base..origin/standard/emenlow
  2388. </literallayout>
  2389. </para>
  2390. <para>
  2391. Use this command to see code differences for the changes:
  2392. <literallayout class='monospaced'>
  2393. $ git diff origin/standard/base..origin/standard/emenlow
  2394. </literallayout>
  2395. </para>
  2396. <para>
  2397. Use this command to see the commit log messages and the
  2398. text differences:
  2399. <literallayout class='monospaced'>
  2400. $ git show origin/standard/base..origin/standard/emenlow
  2401. </literallayout>
  2402. </para>
  2403. <para>
  2404. Use this command to create individual patches for
  2405. each change.
  2406. Here is an example that that creates patch files for each
  2407. commit and places them in your <filename>Documents</filename>
  2408. directory:
  2409. <literallayout class='monospaced'>
  2410. $ git format-patch -o $HOME/Documents origin/standard/base..origin/standard/emenlow
  2411. </literallayout>
  2412. </para>
  2413. </section>
  2414. <section id='showing-a-particular-feature-or-branch-change'>
  2415. <title>Showing a Particular Feature or Branch Change</title>
  2416. <para>
  2417. Tags in the Yocto Project kernel tree divide changes for
  2418. significant features or branches.
  2419. The <filename>git show</filename>&nbsp;<replaceable>tag</replaceable>
  2420. command shows changes based on a tag.
  2421. Here is an example that shows <filename>systemtap</filename>
  2422. changes:
  2423. <literallayout class='monospaced'>
  2424. $ git show systemtap
  2425. </literallayout>
  2426. You can use the
  2427. <filename>git branch --contains</filename>&nbsp;<replaceable>tag</replaceable>
  2428. command to show the branches that contain a particular feature.
  2429. This command shows the branches that contain the
  2430. <filename>systemtap</filename> feature:
  2431. <literallayout class='monospaced'>
  2432. $ git branch --contains systemtap
  2433. </literallayout>
  2434. </para>
  2435. </section>
  2436. </section>
  2437. <section id='adding-recipe-space-kernel-features'>
  2438. <title>Adding Recipe-Space Kernel Features</title>
  2439. <para>
  2440. You can add kernel features in the
  2441. <link linkend='recipe-space-metadata'>recipe-space</link> by
  2442. using the
  2443. <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_FEATURES'><filename>KERNEL_FEATURES</filename></ulink>
  2444. variable and by specifying the feature's <filename>.scc</filename>
  2445. file path in the
  2446. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  2447. statement.
  2448. When you add features using this method, the OpenEmbedded build
  2449. system checks to be sure the features are present.
  2450. If the features are not present, the build stops.
  2451. Kernel features are the last elements processed for configuring
  2452. and patching the kernel.
  2453. Therefore, adding features in this manner is a way
  2454. to enforce specific features are present and enabled
  2455. without needing to do a full audit of any other layer's additions
  2456. to the <filename>SRC_URI</filename> statement.
  2457. </para>
  2458. <para>
  2459. You add a kernel feature by providing the feature as part of the
  2460. <filename>KERNEL_FEATURES</filename> variable and by providing the
  2461. path to the feature's <filename>.scc</filename> file, which is
  2462. relative to the root of the kernel Metadata.
  2463. The OpenEmbedded build system searches all forms of kernel
  2464. Metadata on the <filename>SRC_URI</filename> statement regardless
  2465. of whether the Metadata is in the "kernel-cache", system kernel
  2466. Metadata, or a recipe-space Metadata (i.e. part of the kernel
  2467. recipe).
  2468. See the
  2469. "<link linkend='kernel-metadata-location'>Kernel Metadata Location</link>"
  2470. section for additional information.
  2471. </para>
  2472. <para>
  2473. When you specify the feature's <filename>.scc</filename> file
  2474. on the <filename>SRC_URI</filename> statement, the OpenEmbedded
  2475. build system adds the directory of that
  2476. <filename>.scc</filename> file along with all its subdirectories
  2477. to the kernel feature search path.
  2478. Because subdirectories are searched, you can reference a single
  2479. <filename>.scc</filename> file in the
  2480. <filename>SRC_URI</filename> statement to reference multiple kernel
  2481. features.
  2482. </para>
  2483. <para>
  2484. Consider the following example that adds the "test.scc" feature
  2485. to the build.
  2486. <orderedlist>
  2487. <listitem><para>
  2488. <emphasis>Create the Feature File:</emphasis>
  2489. Create a <filename>.scc</filename> file and locate it
  2490. just as you would any other patch file,
  2491. <filename>.cfg</filename> file, or fetcher item
  2492. you specify in the <filename>SRC_URI</filename>
  2493. statement.
  2494. <note><title>Notes</title>
  2495. <itemizedlist>
  2496. <listitem><para>
  2497. You must add the directory of the
  2498. <filename>.scc</filename> file to the fetcher's
  2499. search path in the same manner as you would
  2500. add a <filename>.patch</filename> file.
  2501. </para></listitem>
  2502. <listitem><para>
  2503. You can create additional
  2504. <filename>.scc</filename> files beneath the
  2505. directory that contains the file you are
  2506. adding.
  2507. All subdirectories are searched during the
  2508. build as potential feature directories.
  2509. </para></listitem>
  2510. </itemizedlist>
  2511. </note>
  2512. Continuing with the example, suppose the "test.scc"
  2513. feature you are adding has a
  2514. <filename>test.scc</filename> file in the following
  2515. directory:
  2516. <literallayout class='monospaced'>
  2517. <replaceable>my_recipe</replaceable>
  2518. |
  2519. +-linux-yocto
  2520. |
  2521. +-test.cfg
  2522. +-test.scc
  2523. </literallayout>
  2524. In this example, the <filename>linux-yocto</filename>
  2525. directory has both the feature
  2526. <filename>test.scc</filename> file and a similarly
  2527. named configuration fragment file
  2528. <filename>test.cfg</filename>.
  2529. </para></listitem>
  2530. <listitem><para>
  2531. <emphasis>Add the Feature File to <filename>SRC_URI</filename>:</emphasis>
  2532. Add the <filename>.scc</filename> file to the
  2533. recipe's <filename>SRC_URI</filename> statement:
  2534. <literallayout class='monospaced'>
  2535. SRC_URI_append = " file://test.scc"
  2536. </literallayout>
  2537. The leading space before the path is important as the
  2538. path is appended to the existing path.
  2539. </para></listitem>
  2540. <listitem><para>
  2541. <emphasis>Specify the Feature as a Kernel Feature:</emphasis>
  2542. Use the <filename>KERNEL_FEATURES</filename> statement
  2543. to specify the feature as a kernel feature:
  2544. <literallayout class='monospaced'>
  2545. KERNEL_FEATURES_append = " test.scc"
  2546. </literallayout>
  2547. The OpenEmbedded build system processes the kernel feature
  2548. when it builds the kernel.
  2549. <note>
  2550. If other features are contained below "test.scc",
  2551. then their directories are relative to the directory
  2552. containing the <filename>test.scc</filename> file.
  2553. </note>
  2554. </para></listitem>
  2555. </orderedlist>
  2556. </para>
  2557. </section>
  2558. </chapter>
  2559. <!--
  2560. vim: expandtab tw=80 ts=4
  2561. -->