kernel-dev-common.xml 140 KB

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