kernel-dev-common.xml 120 KB

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