dev-manual-common-tasks.xml 241 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768
  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='extendpoky'>
  5. <title>Common Tasks</title>
  6. <para>
  7. This chapter describes fundamental procedures such as creating layers,
  8. adding new software packages, extending or customizing images,
  9. porting work to new hardware (adding a new machine), and so forth.
  10. You will find the procedures documented here occur often in the
  11. develop cycle using the Yocto Project.
  12. </para>
  13. <section id="understanding-and-creating-layers">
  14. <title>Understanding and Creating Layers</title>
  15. <para>
  16. The OpenEmbedded build system supports organizing
  17. <link linkend='metadata'>Metadata</link> into multiple layers.
  18. Layers allow you to isolate different types of customizations from
  19. each other.
  20. You might find it tempting to keep everything in one layer when
  21. working on a single project.
  22. However, the more modular you organize your Metadata, the easier
  23. it is to cope with future changes.
  24. </para>
  25. <para>
  26. To illustrate how layers are used to keep things modular, consider
  27. machine customizations.
  28. These types of customizations typically reside in a special layer,
  29. rather than a general layer, called a Board Specific Package (BSP)
  30. Layer.
  31. Furthermore, the machine customizations should be isolated from
  32. recipes and Metadata that support a new GUI environment,
  33. for example.
  34. This situation gives you a couple of layers: one for the machine
  35. configurations, and one for the GUI environment.
  36. It is important to understand, however, that the BSP layer can
  37. still make machine-specific additions to recipes within the GUI
  38. environment layer without polluting the GUI layer itself
  39. with those machine-specific changes.
  40. You can accomplish this through a recipe that is a BitBake append
  41. (<filename>.bbappend</filename>) file, which is described later
  42. in this section.
  43. </para>
  44. <para>
  45. </para>
  46. <section id='yocto-project-layers'>
  47. <title>Layers</title>
  48. <para>
  49. The <link linkend='source-directory'>Source Directory</link>
  50. contains both general layers and BSP
  51. layers right out of the box.
  52. You can easily identify layers that ship with a
  53. Yocto Project release in the Source Directory by their
  54. folder names.
  55. Folders that are layers begin with the string
  56. <filename>meta</filename>.
  57. <note>
  58. It is not a requirement that a layer begins with the
  59. string <filename>meta</filename>.
  60. </note>
  61. For example, when you set up the Source Directory structure,
  62. you will see several layers:
  63. <filename>meta</filename>, <filename>meta-hob</filename>,
  64. <filename>meta-skeleton</filename>,
  65. <filename>meta-yocto</filename>, and
  66. <filename>meta-yocto-bsp</filename>.
  67. Each of these folders is a layer.
  68. </para>
  69. <para>
  70. Furthermore, if you set up a local copy of the
  71. <filename>meta-intel</filename> Git repository
  72. and then explore the folder of that general layer,
  73. you will discover many BSP layers inside.
  74. For more information on BSP layers, see the
  75. "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
  76. section in the Yocto Project Board Support Package (BSP)
  77. Developer's Guide.
  78. </para>
  79. </section>
  80. <section id='creating-your-own-layer'>
  81. <title>Creating Your Own Layer</title>
  82. <para>
  83. It is very easy to create your own layers to use with the
  84. OpenEmbedded build system.
  85. The Yocto Project ships with scripts that speed up creating
  86. general layers and BSP layers.
  87. This section describes the steps you perform by hand to create
  88. a layer so that you can better understand them.
  89. For information about the layer-creation scripts, see the
  90. "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-yocto-bsp-script'>Creating a New BSP Layer Using the yocto-bsp Script</ulink>"
  91. section in the Yocto Project Board Support Package (BSP)
  92. Developer's Guide and the
  93. "<link linkend='creating-a-general-layer-using-the-yocto-layer-script'>Creating a General Layer Using the yocto-layer Script</link>"
  94. section further down in this manual.
  95. </para>
  96. <para>
  97. Follow these general steps to create your layer:
  98. <orderedlist>
  99. <listitem><para><emphasis>Check Existing Layers:</emphasis>
  100. Before creating a new layer, you should be sure someone
  101. has not already created a layer containing the Metadata
  102. you need.
  103. You can see the
  104. <ulink url='http://layers.openembedded.org/layerindex/layers/'><filename>OpenEmbedded Metadata Index</filename></ulink>
  105. for a list of layers from the OpenEmbedded community
  106. that can be used in the Yocto Project.
  107. </para></listitem>
  108. <listitem><para><emphasis>Create a Directory:</emphasis>
  109. Create the directory for your layer.
  110. While not strictly required, prepend the name of the
  111. folder with the string <filename>meta-</filename>.
  112. For example:
  113. <literallayout class='monospaced'>
  114. meta-mylayer
  115. meta-GUI_xyz
  116. meta-mymachine
  117. </literallayout>
  118. </para></listitem>
  119. <listitem><para><emphasis>Create a Layer Configuration
  120. File:</emphasis>
  121. Inside your new layer folder, you need to create a
  122. <filename>conf/layer.conf</filename> file.
  123. It is easiest to take an existing layer configuration
  124. file and copy that to your layer's
  125. <filename>conf</filename> directory and then modify the
  126. file as needed.</para>
  127. <para>The
  128. <filename>meta-yocto-bsp/conf/layer.conf</filename> file
  129. demonstrates the required syntax:
  130. <literallayout class='monospaced'>
  131. # We have a conf and classes directory, add to BBPATH
  132. BBPATH .= ":${LAYERDIR}"
  133. # We have recipes-* directories, add to BBFILES
  134. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  135. ${LAYERDIR}/recipes-*/*/*.bbappend"
  136. BBFILE_COLLECTIONS += "yoctobsp"
  137. BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
  138. BBFILE_PRIORITY_yoctobsp = "5"
  139. </literallayout></para>
  140. <para>Here is an explanation of the example:
  141. <itemizedlist>
  142. <listitem><para>The configuration and
  143. classes directory is appended to
  144. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>.
  145. <note>
  146. All non-distro layers, which include all BSP
  147. layers, are expected to append the layer
  148. directory to the
  149. <filename>BBPATH</filename>.
  150. On the other hand, distro layers, such as
  151. <filename>meta-yocto</filename>, can choose
  152. to enforce their own precedence over
  153. <filename>BBPATH</filename>.
  154. For an example of that syntax, see the
  155. <filename>layer.conf</filename> file for
  156. the <filename>meta-yocto</filename> layer.
  157. </note></para></listitem>
  158. <listitem><para>The recipes for the layers are
  159. appended to
  160. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'>BBFILES</ulink></filename>.
  161. </para></listitem>
  162. <listitem><para>The
  163. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_COLLECTIONS'>BBFILE_COLLECTIONS</ulink></filename>
  164. variable is then appended with the layer name.
  165. </para></listitem>
  166. <listitem><para>The
  167. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PATTERN'>BBFILE_PATTERN</ulink></filename>
  168. variable is set to a regular expression and is
  169. used to match files from
  170. <filename>BBFILES</filename> into a particular
  171. layer.
  172. In this case,
  173. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDIR'>LAYERDIR</ulink></filename>
  174. is used to make <filename>BBFILE_PATTERN</filename> match within the
  175. layer's path.</para></listitem>
  176. <listitem><para>The
  177. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'>BBFILE_PRIORITY</ulink></filename>
  178. variable then assigns a priority to the layer.
  179. Applying priorities is useful in situations
  180. where the same package might appear in multiple
  181. layers and allows you to choose what layer
  182. should take precedence.</para></listitem>
  183. </itemizedlist></para>
  184. <para>Note the use of the
  185. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDIR'>LAYERDIR</ulink></filename>
  186. variable, which expands to the directory of the current
  187. layer.</para>
  188. <para>Through the use of the <filename>BBPATH</filename>
  189. variable, BitBake locates <filename>.bbclass</filename>
  190. files, configuration files, and files that are included
  191. with <filename>include</filename> and
  192. <filename>require</filename> statements.
  193. For these cases, BitBake uses the first file that
  194. matches the name found in <filename>BBPATH</filename>.
  195. This is similar to the way the <filename>PATH</filename>
  196. variable is used for binaries.
  197. We recommend, therefore, that you use unique
  198. <filename>.bbclass</filename> and configuration
  199. filenames in your custom layer.</para></listitem>
  200. <listitem><para><emphasis>Add Content:</emphasis> Depending
  201. on the type of layer, add the content.
  202. If the layer adds support for a machine, add the machine
  203. configuration in a <filename>conf/machine/</filename>
  204. file within the layer.
  205. If the layer adds distro policy, add the distro
  206. configuration in a <filename>conf/distro/</filename>
  207. file with the layer.
  208. If the layer introduces new recipes, put the recipes
  209. you need in <filename>recipes-*</filename>
  210. subdirectories within the layer.
  211. <note>In order to be compliant with the Yocto Project,
  212. a layer must contain a
  213. <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-filelayout-readme'>README file.</ulink>
  214. </note></para></listitem>
  215. </orderedlist>
  216. </para>
  217. <para>
  218. To create layers that are easier to maintain, you should
  219. consider the following:
  220. <itemizedlist>
  221. <listitem><para>Avoid "overlaying" entire recipes from
  222. other layers in your configuration.
  223. In other words, do not copy an entire recipe into your
  224. layer and then modify it.
  225. Use <filename>.bbappend</filename> files to override the
  226. parts of the recipe you need to modify.
  227. </para></listitem>
  228. <listitem><para>Avoid duplicating include files.
  229. Use <filename>.bbappend</filename> files for each recipe
  230. that uses an include file.
  231. Or, if you are introducing a new recipe that requires
  232. the included file, use the path relative to the original
  233. layer directory to refer to the file.
  234. For example, use
  235. <filename>require recipes-core/somepackage/somefile.inc</filename>
  236. instead of <filename>require somefile.inc</filename>.
  237. If you're finding you have to overlay the include file,
  238. it could indicate a deficiency in the include file in
  239. the layer to which it originally belongs.
  240. If this is the case, you need to address that deficiency
  241. instead of overlaying the include file.
  242. For example, consider how Qt 4 database support plug-ins
  243. are configured.
  244. The Source Directory does not have MySQL or PostgreSQL,
  245. however OpenEmbedded's layer
  246. <filename>meta-oe</filename> does.
  247. Consequently, <filename>meta-oe</filename> uses
  248. <filename>.bbappend</filename> files to modify the
  249. <filename>QT_SQL_DRIVER_FLAGS</filename> variable to
  250. enable the appropriate plugins.
  251. This variable was added to the
  252. <filename>qt4.inc</filename> include file in the Source
  253. Directory specifically to allow the
  254. <filename>meta-oe</filename> layer to be able to control
  255. which plugins are built.</para></listitem>
  256. </itemizedlist>
  257. </para>
  258. <para>
  259. We also recommend the following:
  260. <itemizedlist>
  261. <listitem><para>Store custom layers in a Git repository
  262. that uses the
  263. <filename>meta-&lt;layer_name&gt;</filename> format.
  264. </para></listitem>
  265. <listitem><para>Clone the repository alongside other
  266. <filename>meta</filename> directories in the
  267. <link linkend='source-directory'>Source Directory</link>.
  268. </para></listitem>
  269. </itemizedlist>
  270. Following these recommendations keeps your Source Directory and
  271. its configuration entirely inside the Yocto Project's core
  272. base.
  273. </para>
  274. </section>
  275. <section id='enabling-your-layer'>
  276. <title>Enabling Your Layer</title>
  277. <para>
  278. Before the OpenEmbedded build system can use your new layer,
  279. you need to enable it.
  280. To enable your layer, simply add your layer's path to the
  281. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'>BBLAYERS</ulink></filename>
  282. variable in your <filename>conf/bblayers.conf</filename> file,
  283. which is found in the
  284. <link linkend='build-directory'>Build Directory</link>.
  285. The following example shows how to enable a layer named
  286. <filename>meta-mylayer</filename>:
  287. <literallayout class='monospaced'>
  288. LCONF_VERSION = "6"
  289. BBPATH = "${TOPDIR}"
  290. BBFILES ?= ""
  291. BBLAYERS ?= " \
  292. $HOME/poky/meta \
  293. $HOME/poky/meta-yocto \
  294. $HOME/poky/meta-yocto-bsp \
  295. $HOME/poky/meta-mylayer \
  296. "
  297. BBLAYERS_NON_REMOVABLE ?= " \
  298. $HOME/poky/meta \
  299. $HOME/poky/meta-yocto \
  300. "
  301. </literallayout>
  302. </para>
  303. <para>
  304. BitBake parses each <filename>conf/layer.conf</filename> file
  305. as specified in the <filename>BBLAYERS</filename> variable
  306. within the <filename>conf/bblayers.conf</filename> file.
  307. During the processing of each
  308. <filename>conf/layer.conf</filename> file, BitBake adds the
  309. recipes, classes and configurations contained within the
  310. particular layer to the source directory.
  311. </para>
  312. </section>
  313. <section id='using-bbappend-files'>
  314. <title>Using .bbappend Files</title>
  315. <para>
  316. Recipes used to append Metadata to other recipes are called
  317. BitBake append files.
  318. BitBake append files use the <filename>.bbappend</filename> file
  319. type suffix, while the corresponding recipes to which Metadata
  320. is being appended use the <filename>.bb</filename> file type
  321. suffix.
  322. </para>
  323. <para>
  324. A <filename>.bbappend</filename> file allows your layer to make
  325. additions or changes to the content of another layer's recipe
  326. without having to copy the other recipe into your layer.
  327. Your <filename>.bbappend</filename> file resides in your layer,
  328. while the main <filename>.bb</filename> recipe file to
  329. which you are appending Metadata resides in a different layer.
  330. </para>
  331. <para>
  332. Append files must have the same root names as their corresponding
  333. recipes.
  334. For example, the append file
  335. <filename>someapp_&DISTRO;.bbappend</filename> must apply to
  336. <filename>someapp_&DISTRO;.bb</filename>.
  337. This means the original recipe and append file names are version
  338. number-specific.
  339. If the corresponding recipe is renamed to update to a newer
  340. version, the corresponding <filename>.bbappend</filename> file must
  341. be renamed as well.
  342. During the build process, BitBake displays an error on starting
  343. if it detects a <filename>.bbappend</filename> file that does
  344. not have a corresponding recipe with a matching name.
  345. See the
  346. <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_DANGLINGAPPENDS_WARNONLY'><filename>BB_DANGLINGAPPENDS_WARNONLY</filename></ulink>
  347. variable for information on how to handle this error.
  348. </para>
  349. <para>
  350. Being able to append information to an existing recipe not only
  351. avoids duplication, but also automatically applies recipe
  352. changes in a different layer to your layer.
  353. If you were copying recipes, you would have to manually merge
  354. changes as they occur.
  355. </para>
  356. <para>
  357. As an example, consider the main formfactor recipe and a
  358. corresponding formfactor append file both from the
  359. <link linkend='source-directory'>Source Directory</link>.
  360. Here is the main formfactor recipe, which is named
  361. <filename>formfactor_0.0.bb</filename> and located in the
  362. "meta" layer at
  363. <filename>meta/recipes-bsp/formfactor</filename>:
  364. <literallayout class='monospaced'>
  365. DESCRIPTION = "Device formfactor information"
  366. SECTION = "base"
  367. LICENSE = "MIT"
  368. LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58 \
  369. file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
  370. PR = "r21"
  371. SRC_URI = "file://config file://machconfig"
  372. S = "${WORKDIR}"
  373. PACKAGE_ARCH = "${MACHINE_ARCH}"
  374. INHIBIT_DEFAULT_DEPS = "1"
  375. do_install() {
  376. # Only install file if it has a contents
  377. install -d ${D}${sysconfdir}/formfactor/
  378. install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
  379. if [ -s "${S}/machconfig" ]; then
  380. install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
  381. fi
  382. } </literallayout>
  383. In the main recipe, note the
  384. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  385. variable, which tells the OpenEmbedded build system where to
  386. find files during the build.
  387. </para>
  388. <para>
  389. Following is the append file, which is named
  390. <filename>formfactor_0.0.bbappend</filename> and is from the
  391. Crown Bay BSP Layer named
  392. <filename>meta-intel/meta-crownbay</filename>.
  393. The file is in <filename>recipes-bsp/formfactor</filename>:
  394. <literallayout class='monospaced'>
  395. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
  396. PRINC := "${@int(PRINC) + 2}"
  397. </literallayout>
  398. </para>
  399. <para>
  400. By default, the build system uses the
  401. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
  402. variable to locate files.
  403. This append file extends the locations by setting the
  404. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
  405. variable.
  406. Setting this variable in the <filename>.bbappend</filename>
  407. file is the most reliable and recommended method for adding
  408. directories to the search path used by the build system
  409. to find files.
  410. </para>
  411. <para>
  412. The statement in this example extends the directories to include
  413. <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>,
  414. which resolves to a directory named
  415. <filename>formfactor</filename> in the same directory
  416. in which the append file resides (i.e.
  417. <filename>meta-intel/meta-crownbay/recipes-bsp/formfactor/formfactor</filename>.
  418. This implies that you must have the supporting directory
  419. structure set up that will contain any files or patches you
  420. will be including from the layer.
  421. </para>
  422. <para>
  423. Using the immediate expansion assignment operator
  424. <filename>:=</filename> is important because of the reference to
  425. <filename>THISDIR</filename>.
  426. The trailing colon character is important as it ensures that
  427. items in the list remain colon-separated.
  428. <note><para>BitBake automatically defines the
  429. <filename>THISDIR</filename> variable.
  430. You should never set this variable yourself.
  431. Using <filename>_prepend</filename> ensures your path will
  432. be searched prior to other paths in the final list.</para>
  433. <para>Also, not all append files add extra files.
  434. Many append files simply exist to add build options
  435. (e.g. <filename>systemd</filename>).
  436. For these cases, it is not necessary to use the
  437. "_prepend" part of the statement.</para>
  438. </note>
  439. </para>
  440. </section>
  441. <section id='prioritizing-your-layer'>
  442. <title>Prioritizing Your Layer</title>
  443. <para>
  444. Each layer is assigned a priority value.
  445. Priority values control which layer takes precedence if there
  446. are recipe files with the same name in multiple layers.
  447. For these cases, the recipe file from the layer with a higher
  448. priority number takes precedence.
  449. Priority values also affect the order in which multiple
  450. <filename>.bbappend</filename> files for the same recipe are
  451. applied.
  452. You can either specify the priority manually, or allow the
  453. build system to calculate it based on the layer's dependencies.
  454. </para>
  455. <para>
  456. To specify the layer's priority manually, use the
  457. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>
  458. variable.
  459. For example:
  460. <literallayout class='monospaced'>
  461. BBFILE_PRIORITY_mylayer = "1"
  462. </literallayout>
  463. </para>
  464. <note>
  465. <para>It is possible for a recipe with a lower version number
  466. <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
  467. in a layer that has a higher priority to take precedence.</para>
  468. <para>Also, the layer priority does not currently affect the
  469. precedence order of <filename>.conf</filename>
  470. or <filename>.bbclass</filename> files.
  471. Future versions of BitBake might address this.</para>
  472. </note>
  473. </section>
  474. <section id='managing-layers'>
  475. <title>Managing Layers</title>
  476. <para>
  477. You can use the BitBake layer management tool to provide a view
  478. into the structure of recipes across a multi-layer project.
  479. Being able to generate output that reports on configured layers
  480. with their paths and priorities and on
  481. <filename>.bbappend</filename> files and their applicable
  482. recipes can help to reveal potential problems.
  483. </para>
  484. <para>
  485. Use the following form when running the layer management tool.
  486. <literallayout class='monospaced'>
  487. $ bitbake-layers &lt;command&gt; [arguments]
  488. </literallayout>
  489. The following list describes the available commands:
  490. <itemizedlist>
  491. <listitem><para><filename><emphasis>help:</emphasis></filename>
  492. Displays general help or help on a specified command.
  493. </para></listitem>
  494. <listitem><para><filename><emphasis>show-layers:</emphasis></filename>
  495. Shows the current configured layers.
  496. </para></listitem>
  497. <listitem><para><filename><emphasis>show-recipes:</emphasis></filename>
  498. Lists available recipes and the layers that provide them.
  499. </para></listitem>
  500. <listitem><para><filename><emphasis>show-overlayed:</emphasis></filename>
  501. Lists overlayed recipes.
  502. A recipe is overlayed when a recipe with the same name
  503. exists in another layer that has a higher layer
  504. priority.
  505. </para></listitem>
  506. <listitem><para><filename><emphasis>show-appends:</emphasis></filename>
  507. Lists <filename>.bbappend</filename> files and the
  508. recipe files to which they apply.
  509. </para></listitem>
  510. <listitem><para><filename><emphasis>show-cross-depends:</emphasis></filename>
  511. Lists dependency relationships between recipes that
  512. cross layer boundaries.
  513. </para></listitem>
  514. <listitem><para><filename><emphasis>flatten:</emphasis></filename>
  515. Flattens the layer configuration into a separate output
  516. directory.
  517. Flattening your layer configuration builds a "flattened"
  518. directory that contains the contents of all layers,
  519. with any overlayed recipes removed and any
  520. <filename>.bbappend</filename> files appended to the
  521. corresponding recipes.
  522. You might have to perform some manual cleanup of the
  523. flattened layer as follows:
  524. <itemizedlist>
  525. <listitem><para>Non-recipe files (such as patches)
  526. are overwritten.
  527. The flatten command shows a warning for these
  528. files.
  529. </para></listitem>
  530. <listitem><para>Anything beyond the normal layer
  531. setup has been added to the
  532. <filename>layer.conf</filename> file.
  533. Only the lowest priority layer's
  534. <filename>layer.conf</filename> is used.
  535. </para></listitem>
  536. <listitem><para>Overridden and appended items from
  537. <filename>.bbappend</filename> files need to be
  538. cleaned up.
  539. The contents of each
  540. <filename>.bbappend</filename> end up in the
  541. flattened recipe.
  542. However, if there are appended or changed
  543. variable values, you need to tidy these up
  544. yourself.
  545. Consider the following example.
  546. Here, the <filename>bitbake-layers</filename>
  547. command adds the line
  548. <filename>#### bbappended ...</filename> so that
  549. you know where the following lines originate:
  550. <literallayout class='monospaced'>
  551. ...
  552. DESCRIPTION = "A useful utility"
  553. ...
  554. EXTRA_OECONF = "--enable-something"
  555. ...
  556. #### bbappended from meta-anotherlayer ####
  557. DESCRIPTION = "Customized utility"
  558. EXTRA_OECONF += "--enable-somethingelse"
  559. </literallayout>
  560. Ideally, you would tidy up these utilities as
  561. follows:
  562. <literallayout class='monospaced'>
  563. ...
  564. DESCRIPTION = "Customized utility"
  565. ...
  566. EXTRA_OECONF = "--enable-something --enable-somethingelse"
  567. ...
  568. </literallayout></para></listitem>
  569. </itemizedlist></para></listitem>
  570. </itemizedlist>
  571. </para>
  572. </section>
  573. <section id='creating-a-general-layer-using-the-yocto-layer-script'>
  574. <title>Creating a General Layer Using the yocto-layer Script</title>
  575. <para>
  576. The <filename>yocto-layer</filename> script simplifies
  577. creating a new general layer.
  578. <note>
  579. For information on BSP layers, see the
  580. "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
  581. section in the Yocto Project Board Specific (BSP)
  582. Developer's Guide.
  583. </note>
  584. The default mode of the script's operation is to prompt you for
  585. information needed to generate the layer:
  586. <itemizedlist>
  587. <listitem><para>The layer priority
  588. </para></listitem>
  589. <listitem><para>Whether or not to create a sample recipe.
  590. </para></listitem>
  591. <listitem><para>Whether or not to create a sample
  592. append file.
  593. </para></listitem>
  594. </itemizedlist>
  595. </para>
  596. <para>
  597. Use the <filename>yocto-layer create</filename> sub-command
  598. to create a new general layer.
  599. In its simplest form, you can create a layer as follows:
  600. <literallayout class='monospaced'>
  601. $ yocto-layer create mylayer
  602. </literallayout>
  603. The previous example creates a layer named
  604. <filename>meta-mylayer</filename> in the current directory.
  605. </para>
  606. <para>
  607. As the <filename>yocto-layer create</filename> command runs,
  608. default values for the prompts appear in brackets.
  609. Pressing enter without supplying anything for the prompts
  610. or pressing enter and providing an invalid response causes the
  611. script to accept the default value.
  612. Once the script completes, the new layer
  613. is created in the current working directory.
  614. The script names the layer by prepending
  615. <filename>meta-</filename> to the name you provide.
  616. </para>
  617. <para>
  618. Minimally, the script creates the following within the layer:
  619. <itemizedlist>
  620. <listitem><para><emphasis>The <filename>conf</filename>
  621. directory:</emphasis>
  622. This directory contains the layers
  623. <filename>.conf</filename>.
  624. The root name for the file is the same as the root name
  625. your provided for the layer.
  626. </para></listitem>
  627. <listitem><para><emphasis>The
  628. <filename>COPYING.MIT</filename>:</emphasis>
  629. The copyright and use notice for the software.
  630. </para></listitem>
  631. <listitem><para><emphasis>The <filename>README</filename>
  632. file:</emphasis>
  633. A file describing the contents of your new layer.
  634. </para></listitem>
  635. </itemizedlist>
  636. </para>
  637. <para>
  638. If you choose to generate a sample recipe file, the script
  639. prompts you for the name for the recipe and then creates it
  640. in <filename>&lt;layer&gt;/recipes-example/example/</filename>.
  641. in a directory named <filename>recipes-example</filename>.
  642. The script creates a <filename>.bb</filename> file and a
  643. directory, which contains a sample
  644. <filename>helloworld.c</filename> source file and along with
  645. a sample patch file.
  646. If you do not provide a recipe name, the script uses
  647. "example".
  648. </para>
  649. <para>
  650. If you choose to generate a sample append file, the script
  651. prompts you for the name for the file and then creates it
  652. in <filename>&lt;layer&gt;/recipes-example-bbappend/example-bbappend/</filename>.
  653. The script creates a <filename>.bbappend</filename> file and a
  654. directory, which contains a sample patch file.
  655. If you do not provide a recipe name, the script uses
  656. "example".
  657. The script also prompts you for the version of the append file.
  658. The version should match the recipe to which the append file
  659. is associated.
  660. </para>
  661. <para>
  662. The easiest way to see how the <filename>yocto-layer</filename>
  663. script works is to experiment with the script.
  664. You can also read the usage information by entering the
  665. following:
  666. <literallayout class='monospaced'>
  667. $ yocto-layer help
  668. </literallayout>
  669. </para>
  670. <para>
  671. Once you create your general layer, you must add it to your
  672. <filename>bblayers.conf</filename> file.
  673. Here is an example:
  674. <literallayout class='monospaced'>
  675. BBLAYERS = ?" \
  676. /usr/local/src/yocto/meta \
  677. /usr/local/src/yocto/meta-yocto \
  678. /usr/local/src/yocto/meta-yocto-bsp \
  679. /usr/local/src/yocto/meta-mylayer \
  680. "
  681. BBLAYERS_NON_REMOVABLE ?= " \
  682. /usr/local/src/yocto/meta \
  683. /usr/local/src/yocto/meta-yocto \
  684. "
  685. </literallayout>
  686. Adding the layer to this file enables the build system to
  687. locate the layer during the build.
  688. </para>
  689. </section>
  690. </section>
  691. <section id='usingpoky-extend-customimage'>
  692. <title>Customizing Images</title>
  693. <para>
  694. You can customize images to satisfy particular requirements.
  695. This section describes several methods and provides guidelines for each.
  696. </para>
  697. <section id='usingpoky-extend-customimage-custombb'>
  698. <title>Customizing Images Using Custom .bb Files</title>
  699. <para>
  700. One way to get additional software into an image is to create a custom image.
  701. The following example shows the form for the two lines you need:
  702. <literallayout class='monospaced'>
  703. IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
  704. inherit core-image
  705. </literallayout>
  706. </para>
  707. <para>
  708. By creating a custom image, a developer has total control
  709. over the contents of the image.
  710. It is important to use the correct names of packages in the
  711. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
  712. variable.
  713. You must use the OpenEmbedded notation and not the Debian notation for the names
  714. (e.g. <filename>eglibc-dev</filename> instead of <filename>libc6-dev</filename>).
  715. </para>
  716. <para>
  717. The other method for creating a custom image is to base it on an existing image.
  718. For example, if you want to create an image based on <filename>core-image-sato</filename>
  719. but add the additional package <filename>strace</filename> to the image,
  720. copy the <filename>meta/recipes-sato/images/core-image-sato.bb</filename> to a
  721. new <filename>.bb</filename> and add the following line to the end of the copy:
  722. <literallayout class='monospaced'>
  723. IMAGE_INSTALL += "strace"
  724. </literallayout>
  725. </para>
  726. </section>
  727. <section id='usingpoky-extend-customimage-customtasks'>
  728. <title>Customizing Images Using Custom Package Groups</title>
  729. <para>
  730. For complex custom images, the best approach is to create a custom package group recipe
  731. that is used to build the image or images.
  732. A good example of a package group recipe is
  733. <filename>meta/recipes-core/packagegroups/packagegroup-core-boot.bb</filename>.
  734. The
  735. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename>
  736. variable lists the package group packages you wish to produce. <filename>inherit packagegroup</filename>
  737. sets appropriate default values and automatically adds <filename>-dev</filename>
  738. and <filename>-dbg</filename> complementary
  739. packages for every package specified in <filename>PACKAGES</filename>.
  740. Note that the inherit line should be towards
  741. the top of the recipe, certainly before you set <filename>PACKAGES</filename>.
  742. For each package you specify in <filename>PACKAGES</filename>, you can use
  743. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'>RDEPENDS</ulink></filename>
  744. and
  745. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'>RRECOMMENDS</ulink></filename>
  746. entries to provide a list of packages the parent task package should contain.
  747. Following is an example:
  748. <literallayout class='monospaced'>
  749. DESCRIPTION = "My Custom Package Groups"
  750. inherit packagegroup
  751. PACKAGES = "\
  752. packagegroup-custom-apps \
  753. packagegroup-custom-tools \
  754. "
  755. RDEPENDS_packagegroup-custom-apps = "\
  756. dropbear \
  757. portmap \
  758. psplash"
  759. RDEPENDS_packagegroup-custom-tools = "\
  760. oprofile \
  761. oprofileui-server \
  762. lttng-control \
  763. lttng-viewer"
  764. RRECOMMENDS_packagegroup-custom-tools = "\
  765. kernel-module-oprofile"
  766. </literallayout>
  767. </para>
  768. <para>
  769. In the previous example, two package group packages are created with their dependencies and their
  770. recommended package dependencies listed: <filename>packagegroup-custom-apps</filename>, and
  771. <filename>packagegroup-custom-tools</filename>.
  772. To build an image using these package group packages, you need to add
  773. <filename>packagegroup-custom-apps</filename> and/or
  774. <filename>packagegroup-custom-tools</filename> to
  775. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>.
  776. For other forms of image dependencies see the other areas of this section.
  777. </para>
  778. </section>
  779. <section id='usingpoky-extend-customimage-imagefeatures'>
  780. <title>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and
  781. <filename>EXTRA_IMAGE_FEATURES</filename></title>
  782. <para>
  783. You might want to customize your image by enabling or
  784. disabling high-level image features by using the
  785. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
  786. and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
  787. variables.
  788. Although the functions for both variables are nearly equivalent,
  789. best practices dictate using <filename>IMAGE_FEATURES</filename>
  790. from within a recipe and using
  791. <filename>EXTRA_IMAGE_FEATURES</filename> from within
  792. your <filename>local.conf</filename> file, which is found in the
  793. <link linkend='build-directory'>Build Directory</link>.
  794. </para>
  795. <para>
  796. To understand how these features work, the best reference is
  797. <filename>meta/classes/core-image.bbclass</filename>.
  798. In summary, the file looks at the contents of the
  799. <filename>IMAGE_FEATURES</filename> variable and then maps
  800. those contents into a set of package groups.
  801. Based on this information, the build system automatically
  802. adds the appropriate packages to the
  803. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
  804. variable.
  805. Effectively, you are enabling extra features by extending the
  806. class or creating a custom class for use with specialized image
  807. <filename>.bb</filename> files.
  808. </para>
  809. <para>
  810. Use the <filename>EXTRA_IMAGE_FEATURES</filename> variable
  811. from within your local configuration file.
  812. Using a separate area from which to enable features with
  813. this variable helps you avoid overwriting the features in the
  814. image recipe that are enabled with
  815. <filename>IMAGE_FEATURES</filename>.
  816. The value of <filename>EXTRA_IMAGE_FEATURES</filename> is added
  817. to <filename>IMAGE_FEATURES</filename> within
  818. <filename>meta/conf/bitbake.conf</filename>.
  819. </para>
  820. <para>
  821. To illustrate how you can use these variables to modify your
  822. image, consider an example that selects the SSH server.
  823. The Yocto Project ships with two SSH servers you can use
  824. with your images: Dropbear and OpenSSH.
  825. Dropbear is a minimal SSH server appropriate for
  826. resource-constrained environments, while OpenSSH is a
  827. well-known standard SSH server implementation.
  828. By default, the <filename>core-image-sato</filename> image
  829. is configured to use Dropbear.
  830. The <filename>core-image-basic</filename> and
  831. <filename>core-image-lsb</filename> images both
  832. include OpenSSH.
  833. The <filename>core-image-minimal</filename> image does not
  834. contain an SSH server.
  835. </para>
  836. <para>
  837. You can customize your image and change these defaults.
  838. Edit the <filename>IMAGE_FEATURES</filename> variable
  839. in your recipe or use the
  840. <filename>EXTRA_IMAGE_FEATURES</filename> in your
  841. <filename>local.conf</filename> file so that it configures the
  842. image you are working with to include
  843. <filename>ssh-server-dropbear</filename> or
  844. <filename>ssh-server-openssh</filename>.
  845. </para>
  846. <note>
  847. See the
  848. "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
  849. section in the Yocto Project Reference Manual for a complete
  850. list of image features that ship with the Yocto Project.
  851. </note>
  852. </section>
  853. <section id='usingpoky-extend-customimage-localconf'>
  854. <title>Customizing Images Using <filename>local.conf</filename></title>
  855. <para>
  856. It is possible to customize image contents by using variables from your
  857. local configuration in your <filename>conf/local.conf</filename> file.
  858. Because it is limited to local use, this method generally only allows you to
  859. add packages and is not as flexible as creating your own customized image.
  860. When you add packages using local variables this way, you need to realize that
  861. these variable changes affect all images at the same time and might not be
  862. what you require.
  863. </para>
  864. <para>
  865. The simplest way to add extra packages to all images is by using the
  866. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
  867. variable with the <filename>_append</filename> operator:
  868. <literallayout class='monospaced'>
  869. IMAGE_INSTALL_append = " strace"
  870. </literallayout>
  871. Use of the syntax is important.
  872. Specifically, the space between the quote and the package name, which is
  873. <filename>strace</filename> in this example.
  874. This space is required since the <filename>_append</filename>
  875. operator does not add the space.
  876. </para>
  877. <para>
  878. Furthermore, you must use <filename>_append</filename> instead of the <filename>+=</filename>
  879. operator if you want to avoid ordering issues.
  880. The reason for this is because doing so unconditionally appends to the variable and
  881. avoids ordering problems due to the variable being set in image recipes and
  882. <filename>.bbclass</filename> files with operators like <filename>?=</filename>.
  883. Using <filename>_append</filename> ensures the operation takes affect.
  884. </para>
  885. <para>
  886. As shown in its simplest use, <filename>IMAGE_INSTALL_append</filename> affects
  887. all images.
  888. It is possible to extend the syntax so that the variable applies to a specific image only.
  889. Here is an example:
  890. <literallayout class='monospaced'>
  891. IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
  892. </literallayout>
  893. This example adds <filename>strace</filename> to <filename>core-image-minimal</filename>
  894. only.
  895. </para>
  896. <para>
  897. You can add packages using a similar approach through the
  898. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'>CORE_IMAGE_EXTRA_INSTALL</ulink></filename>
  899. variable.
  900. If you use this variable, only <filename>core-image-*</filename> images are affected.
  901. </para>
  902. </section>
  903. </section>
  904. <section id='usingpoky-extend-addpkg'>
  905. <title>Writing a Recipe to Add a Package to Your Image</title>
  906. <para>
  907. Recipes add packages to your image.
  908. Writing a recipe means creating a <filename>.bb</filename> file that sets some
  909. variables.
  910. For information on variables that are useful for recipes and for information about recipe naming
  911. issues, see the
  912. "<ulink url='&YOCTO_DOCS_REF_URL;#ref-varlocality-recipe-required'>Required</ulink>"
  913. section of the Yocto Project Reference Manual.
  914. </para>
  915. <para>
  916. Before writing a recipe from scratch, it is often useful to check
  917. whether someone else has written one already.
  918. OpenEmbedded is a good place to look as it has a wider scope and range of packages.
  919. Because the Yocto Project aims to be compatible with OpenEmbedded, most recipes
  920. you find there should work for you.
  921. </para>
  922. <para>
  923. For new packages, the simplest way to add a recipe is to base it on a similar
  924. pre-existing recipe.
  925. The sections that follow provide some examples that show how to add standard
  926. types of packages.
  927. </para>
  928. <note>
  929. <para>When writing shell functions, you need to be aware of BitBake's
  930. curly brace parsing.
  931. If a recipe uses a closing curly brace within the function and
  932. the character has no leading spaces, BitBake produces a parsing
  933. error.
  934. If you use a pair of curly brace in a shell function, the
  935. closing curly brace must not be located at the start of the line
  936. without leading spaces.</para>
  937. <para>Here is an example that causes BitBake to produce a parsing
  938. error:
  939. <literallayout class='monospaced'>
  940. fakeroot create_shar() {
  941. cat &lt;&lt; "EOF" &gt; ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh
  942. usage()
  943. {
  944. echo "test"
  945. ###### The following "}" at the start of the line causes a parsing error ######
  946. }
  947. EOF
  948. }
  949. </literallayout>
  950. Writing the recipe this way avoids the error:
  951. <literallayout class='monospaced'>
  952. fakeroot create_shar() {
  953. cat &lt;&lt; "EOF" &gt; ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh
  954. usage()
  955. {
  956. echo "test"
  957. ######The following "}" with a leading space at the start of the line avoids the error ######
  958. }
  959. EOF
  960. }
  961. </literallayout></para>
  962. </note>
  963. <section id='usingpoky-extend-addpkg-singlec'>
  964. <title>Single .c File Package (Hello World!)</title>
  965. <para>
  966. Building an application from a single file that is stored locally (e.g. under
  967. <filename>files/</filename>) requires a recipe that has the file listed in
  968. the
  969. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
  970. variable.
  971. Additionally, you need to manually write the <filename>do_compile</filename> and
  972. <filename>do_install</filename> tasks.
  973. The <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
  974. variable defines the
  975. directory containing the source code, which is set to
  976. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'>
  977. WORKDIR</ulink></filename> in this case - the directory BitBake uses for the build.
  978. <literallayout class='monospaced'>
  979. DESCRIPTION = "Simple helloworld application"
  980. SECTION = "examples"
  981. LICENSE = "MIT"
  982. LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
  983. PR = "r0"
  984. SRC_URI = "file://helloworld.c"
  985. S = "${WORKDIR}"
  986. do_compile() {
  987. ${CC} helloworld.c -o helloworld
  988. }
  989. do_install() {
  990. install -d ${D}${bindir}
  991. install -m 0755 helloworld ${D}${bindir}
  992. }
  993. </literallayout>
  994. </para>
  995. <para>
  996. By default, the <filename>helloworld</filename>, <filename>helloworld-dbg</filename>,
  997. and <filename>helloworld-dev</filename> packages are built.
  998. For information on how to customize the packaging process, see the
  999. "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application
  1000. into Multiple Packages</link>" section.
  1001. </para>
  1002. </section>
  1003. <section id='usingpoky-extend-addpkg-autotools'>
  1004. <title>Autotooled Package</title>
  1005. <para>
  1006. Applications that use Autotools such as <filename>autoconf</filename> and
  1007. <filename>automake</filename> require a recipe that has a source archive listed in
  1008. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> and
  1009. also inherits Autotools, which instructs BitBake to use the
  1010. <filename>autotools.bbclass</filename> file, which contains the definitions of all the steps
  1011. needed to build an Autotool-based application.
  1012. The result of the build is automatically packaged.
  1013. And, if the application uses NLS for localization, packages with local information are
  1014. generated (one package per language).
  1015. Following is one example: (<filename>hello_2.3.bb</filename>)
  1016. <literallayout class='monospaced'>
  1017. DESCRIPTION = "GNU Helloworld application"
  1018. SECTION = "examples"
  1019. LICENSE = "GPLv2+"
  1020. LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
  1021. PR = "r0"
  1022. SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
  1023. inherit autotools gettext
  1024. </literallayout>
  1025. </para>
  1026. <para>
  1027. The variable
  1028. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</ulink></filename>
  1029. is used to track source license changes as described in the
  1030. "<ulink url='&YOCTO_DOCS_REF_URL;#usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</ulink>" section.
  1031. You can quickly create Autotool-based recipes in a manner similar to the previous example.
  1032. </para>
  1033. </section>
  1034. <section id='usingpoky-extend-addpkg-makefile'>
  1035. <title>Makefile-Based Package</title>
  1036. <para>
  1037. Applications that use GNU <filename>make</filename> also require a recipe that has
  1038. the source archive listed in
  1039. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
  1040. You do not need to add a <filename>do_compile</filename> step since by default BitBake
  1041. starts the <filename>make</filename> command to compile the application.
  1042. If you need additional <filename>make</filename> options, you should store them in the
  1043. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OEMAKE'>EXTRA_OEMAKE</ulink></filename>
  1044. variable.
  1045. BitBake passes these options into the <filename>make</filename> GNU invocation.
  1046. Note that a <filename>do_install</filename> task is still required.
  1047. Otherwise, BitBake runs an empty <filename>do_install</filename> task by default.
  1048. </para>
  1049. <para>
  1050. Some applications might require extra parameters to be passed to the compiler.
  1051. For example, the application might need an additional header path.
  1052. You can accomplish this by adding to the
  1053. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CFLAGS'>CFLAGS</ulink></filename> variable.
  1054. The following example shows this:
  1055. <literallayout class='monospaced'>
  1056. CFLAGS_prepend = "-I ${S}/include "
  1057. </literallayout>
  1058. </para>
  1059. <para>
  1060. In the following example, <filename>mtd-utils</filename> is a makefile-based package:
  1061. <literallayout class='monospaced'>
  1062. DESCRIPTION = "Tools for managing memory technology devices."
  1063. SECTION = "base"
  1064. DEPENDS = "zlib lzo e2fsprogs util-linux"
  1065. HOMEPAGE = "http://www.linux-mtd.infradead.org/"
  1066. LICENSE = "GPLv2+"
  1067. LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
  1068. file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
  1069. SRC_URI = "git://git.infradead.org/mtd-utils.git;protocol=git;tag=995cfe51b0a3cf32f381c140bf72b21bf91cef1b \
  1070. file://add-exclusion-to-mkfs-jffs2-git-2.patch"
  1071. S = "${WORKDIR}/git/"
  1072. PR = "r1"
  1073. EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' \
  1074. 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
  1075. do_install () {
  1076. oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} \
  1077. INCLUDEDIR=${includedir}
  1078. install -d ${D}${includedir}/mtd/
  1079. for f in ${S}/include/mtd/*.h; do
  1080. install -m 0644 $f ${D}${includedir}/mtd/
  1081. done
  1082. }
  1083. PARALLEL_MAKE = ""
  1084. BBCLASSEXTEND = "native"
  1085. </literallayout>
  1086. </para>
  1087. <para>
  1088. If your sources are available as a tarball instead of a Git repository, you
  1089. will need to provide the URL to the tarball as well as an
  1090. <filename>md5</filename> or <filename>sha256</filename> sum of
  1091. the download.
  1092. Here is an example:
  1093. <literallayout class='monospaced'>
  1094. SRC_URI="ftp://ftp.infradead.org/pub/mtd-utils/mtd-utils-1.4.9.tar.bz2"
  1095. SRC_URI[md5sum]="82b8e714b90674896570968f70ca778b"
  1096. </literallayout>
  1097. You can generate the <filename>md5</filename> or <filename>sha256</filename> sums
  1098. by using the <filename>md5sum</filename> or <filename>sha256sum</filename> commands
  1099. with the target file as the only argument.
  1100. Here is an example:
  1101. <literallayout class='monospaced'>
  1102. $ md5sum mtd-utils-1.4.9.tar.bz2
  1103. 82b8e714b90674896570968f70ca778b mtd-utils-1.4.9.tar.bz2
  1104. </literallayout>
  1105. </para>
  1106. </section>
  1107. <section id='splitting-an-application-into-multiple-packages'>
  1108. <title>Splitting an Application into Multiple Packages</title>
  1109. <para>
  1110. You can use the variables
  1111. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> and
  1112. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'>FILES</ulink></filename>
  1113. to split an application into multiple packages.
  1114. </para>
  1115. <para>
  1116. Following is an example that uses the <filename>libXpm</filename> recipe.
  1117. By default, this recipe generates a single package that contains the library along
  1118. with a few binaries.
  1119. You can modify the recipe to split the binaries into separate packages:
  1120. <literallayout class='monospaced'>
  1121. require xorg-lib-common.inc
  1122. DESCRIPTION = "X11 Pixmap library"
  1123. LICENSE = "X-BSD"
  1124. LIC_FILES_CHKSUM = "file://COPYING;md5=3e07763d16963c3af12db271a31abaa5"
  1125. DEPENDS += "libxext libsm libxt"
  1126. PR = "r3"
  1127. PE = "1"
  1128. XORG_PN = "libXpm"
  1129. PACKAGES =+ "sxpm cxpm"
  1130. FILES_cxpm = "${bindir}/cxpm"
  1131. FILES_sxpm = "${bindir}/sxpm"
  1132. </literallayout>
  1133. </para>
  1134. <para>
  1135. In the previous example, we want to ship the <filename>sxpm</filename>
  1136. and <filename>cxpm</filename> binaries in separate packages.
  1137. Since <filename>bindir</filename> would be packaged into the main
  1138. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'>PN</ulink></filename>
  1139. package by default, we prepend the <filename>PACKAGES</filename>
  1140. variable so additional package names are added to the start of list.
  1141. This results in the extra <filename>FILES_*</filename>
  1142. variables then containing information that define which files and
  1143. directories go into which packages.
  1144. Files included by earlier packages are skipped by latter packages.
  1145. Thus, the main <filename>PN</filename> package
  1146. does not include the above listed files.
  1147. </para>
  1148. </section>
  1149. <section id='usingpoky-extend-addpkg-postinstalls'>
  1150. <title>Post-Installation Scripts</title>
  1151. <para>
  1152. To add a post-installation script to a package, add a
  1153. <filename>pkg_postinst_PACKAGENAME()</filename> function to the
  1154. <filename>.bb</filename> file and use
  1155. <filename>PACKAGENAME</filename> as the name of the package you want to attach to the
  1156. <filename>postinst</filename> script.
  1157. Normally,
  1158. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'>PN</ulink></filename>
  1159. can be used, which automatically expands to <filename>PACKAGENAME</filename>.
  1160. A post-installation function has the following structure:
  1161. <literallayout class='monospaced'>
  1162. pkg_postinst_PACKAGENAME () {
  1163. #!/bin/sh -e
  1164. # Commands to carry out
  1165. }
  1166. </literallayout>
  1167. </para>
  1168. <para>
  1169. The script defined in the post-installation function is called when the
  1170. root filesystem is created.
  1171. If the script succeeds, the package is marked as installed.
  1172. If the script fails, the package is marked as unpacked and the script is
  1173. executed when the image boots again.
  1174. </para>
  1175. <para>
  1176. Sometimes it is necessary for the execution of a post-installation
  1177. script to be delayed until the first boot.
  1178. For example, the script might need to be executed on the device itself.
  1179. To delay script execution until boot time, use the following structure in the
  1180. post-installation script:
  1181. <literallayout class='monospaced'>
  1182. pkg_postinst_PACKAGENAME () {
  1183. #!/bin/sh -e
  1184. if [ x"$D" = "x" ]; then
  1185. # Actions to carry out on the device go here
  1186. else
  1187. exit 1
  1188. fi
  1189. }
  1190. </literallayout>
  1191. </para>
  1192. <para>
  1193. The previous example delays execution until the image boots again because the
  1194. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'>D</ulink></filename>
  1195. variable points
  1196. to the directory containing the image when the root filesystem is created at build time but
  1197. is unset when executed on the first boot.
  1198. </para>
  1199. </section>
  1200. </section>
  1201. <section id="platdev-newmachine">
  1202. <title>Adding a New Machine</title>
  1203. <para>
  1204. Adding a new machine to the Yocto Project is a straightforward process.
  1205. This section provides information that gives you an idea of the changes you must make.
  1206. The information covers adding machines similar to those the Yocto Project already supports.
  1207. Although well within the capabilities of the Yocto Project, adding a totally new architecture
  1208. might require
  1209. changes to <filename>gcc/eglibc</filename> and to the site information, which is
  1210. beyond the scope of this manual.
  1211. </para>
  1212. <para>
  1213. For a complete example that shows how to add a new machine,
  1214. see the
  1215. "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-yocto-bsp-script'>Creating a New BSP Layer Using the yocto-bsp Script</ulink>"
  1216. in the Yocto Project Board Support Package (BSP) Developer's Guide.
  1217. </para>
  1218. <section id="platdev-newmachine-conffile">
  1219. <title>Adding the Machine Configuration File</title>
  1220. <para>
  1221. To add a machine configuration, you need to add a <filename>.conf</filename> file
  1222. with details of the device being added to the <filename>conf/machine/</filename> file.
  1223. The name of the file determines the name the OpenEmbedded build system
  1224. uses to reference the new machine.
  1225. </para>
  1226. <para>
  1227. The most important variables to set in this file are as follows:
  1228. <itemizedlist>
  1229. <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_ARCH'>
  1230. TARGET_ARCH</ulink></filename> (e.g. "arm")</para></listitem>
  1231. <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'>
  1232. PREFERRED_PROVIDER</ulink></filename>_virtual/kernel (see below)</para></listitem>
  1233. <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'>
  1234. MACHINE_FEATURES</ulink></filename> (e.g. "apm screen wifi")</para></listitem>
  1235. </itemizedlist>
  1236. </para>
  1237. <para>
  1238. You might also need these variables:
  1239. <itemizedlist>
  1240. <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLE'>
  1241. SERIAL_CONSOLE</ulink></filename> (e.g. "115200 ttyS0")</para></listitem>
  1242. <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_IMAGETYPE'>
  1243. KERNEL_IMAGETYPE</ulink></filename> (e.g. "zImage")</para></listitem>
  1244. <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'>
  1245. IMAGE_FSTYPES</ulink></filename> (e.g. "tar.gz jffs2")</para></listitem>
  1246. </itemizedlist>
  1247. </para>
  1248. <para>
  1249. You can find full details on these variables in the reference section.
  1250. You can leverage many existing machine <filename>.conf</filename> files from
  1251. <filename>meta/conf/machine/</filename>.
  1252. </para>
  1253. </section>
  1254. <section id="platdev-newmachine-kernel">
  1255. <title>Adding a Kernel for the Machine</title>
  1256. <para>
  1257. The OpenEmbedded build system needs to be able to build a kernel for the machine.
  1258. You need to either create a new kernel recipe for this machine, or extend an
  1259. existing recipe.
  1260. You can find several kernel examples in the
  1261. Source Directory at <filename>meta/recipes-kernel/linux</filename>
  1262. that you can use as references.
  1263. </para>
  1264. <para>
  1265. If you are creating a new recipe, normal recipe-writing rules apply for setting
  1266. up a
  1267. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
  1268. Thus, you need to specify any necessary patches and set
  1269. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename> to point at the source code.
  1270. You need to create a <filename>configure</filename> task that configures the
  1271. unpacked kernel with a defconfig.
  1272. You can do this by using a <filename>make defconfig</filename> command or,
  1273. more commonly, by copying in a suitable <filename>defconfig</filename> file and and then running
  1274. <filename>make oldconfig</filename>.
  1275. By making use of <filename>inherit kernel</filename> and potentially some of the
  1276. <filename>linux-*.inc</filename> files, most other functionality is
  1277. centralized and the the defaults of the class normally work well.
  1278. </para>
  1279. <para>
  1280. If you are extending an existing kernel, it is usually a matter of adding a
  1281. suitable defconfig file.
  1282. The file needs to be added into a location similar to defconfig files
  1283. used for other machines in a given kernel.
  1284. A possible way to do this is by listing the file in the
  1285. <filename>SRC_URI</filename> and adding the machine to the expression in
  1286. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'>COMPATIBLE_MACHINE</ulink></filename>:
  1287. <literallayout class='monospaced'>
  1288. COMPATIBLE_MACHINE = '(qemux86|qemumips)'
  1289. </literallayout>
  1290. </para>
  1291. </section>
  1292. <section id="platdev-newmachine-formfactor">
  1293. <title>Adding a Formfactor Configuration File</title>
  1294. <para>
  1295. A formfactor configuration file provides information about the
  1296. target hardware for which the image is being built and information that
  1297. the build system cannot obtain from other sources such as the kernel.
  1298. Some examples of information contained in a formfactor configuration file include
  1299. framebuffer orientation, whether or not the system has a keyboard,
  1300. the positioning of the keyboard in relation to the screen, and
  1301. the screen resolution.
  1302. </para>
  1303. <para>
  1304. The build system uses reasonable defaults in most cases.
  1305. However, if customization is
  1306. necessary, you need to create a <filename>machconfig</filename> file
  1307. in the <filename>meta/recipes-bsp/formfactor/files</filename>
  1308. directory.
  1309. This directory contains directories for specific machines such as
  1310. <filename>qemuarm</filename> and <filename>qemux86</filename>.
  1311. For information about the settings available and the defaults, see the
  1312. <filename>meta/recipes-bsp/formfactor/files/config</filename> file found in the
  1313. same area.
  1314. </para>
  1315. <para>
  1316. Following is an example for qemuarm:
  1317. <literallayout class='monospaced'>
  1318. HAVE_TOUCHSCREEN=1
  1319. HAVE_KEYBOARD=1
  1320. DISPLAY_CAN_ROTATE=0
  1321. DISPLAY_ORIENTATION=0
  1322. #DISPLAY_WIDTH_PIXELS=640
  1323. #DISPLAY_HEIGHT_PIXELS=480
  1324. #DISPLAY_BPP=16
  1325. DISPLAY_DPI=150
  1326. DISPLAY_SUBPIXEL_ORDER=vrgb
  1327. </literallayout>
  1328. </para>
  1329. </section>
  1330. </section>
  1331. <section id="platdev-working-with-libraries">
  1332. <title>Working With Libraries</title>
  1333. <para>
  1334. Libraries are an integral part of your system.
  1335. This section describes some common practices you might find
  1336. helpful when working with libraries to build your system:
  1337. <itemizedlist>
  1338. <listitem><para><link linkend='including-static-library-files'>How to include static library files</link>
  1339. </para></listitem>
  1340. <listitem><para><link linkend='combining-multiple-versions-library-files-into-one-image'>How to use the Multilib feature to combine multiple versions of library files into a single image</link>
  1341. </para></listitem>
  1342. <listitem><para><link linkend='installing-multiple-versions-of-the-same-library'>How to install multiple versions of the same library in parallel on the same system</link>
  1343. </para></listitem>
  1344. </itemizedlist>
  1345. </para>
  1346. <section id='including-static-library-files'>
  1347. <title>Including Static Library Files</title>
  1348. <para>
  1349. If you are building a library and the library offers static linking, you can control
  1350. which static library files (<filename>*.a</filename> files) get included in the
  1351. built library.
  1352. </para>
  1353. <para>
  1354. The <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
  1355. and <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES_*</filename></ulink>
  1356. variables in the
  1357. <filename>meta/conf/bitbake.conf</filename> configuration file define how files installed
  1358. by the <filename>do_install</filename> task are packaged.
  1359. By default, the <filename>PACKAGES</filename> variable contains
  1360. <filename>${PN}-staticdev</filename>, which includes all static library files.
  1361. <note>
  1362. Some previously released versions of the Yocto Project
  1363. defined the static library files through
  1364. <filename>${PN}-dev</filename>.
  1365. </note>
  1366. Following, is part of the BitBake configuration file.
  1367. You can see where the static library files are defined:
  1368. <literallayout class='monospaced'>
  1369. PACKAGES = "${PN}-dbg ${PN} ${PN}-doc ${PN}-dev ${PN}-staticdev ${PN}-locale"
  1370. PACKAGES_DYNAMIC = "${PN}-locale-*"
  1371. FILES = ""
  1372. FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
  1373. ${sysconfdir} ${sharedstatedir} ${localstatedir} \
  1374. ${base_bindir}/* ${base_sbindir}/* \
  1375. ${base_libdir}/*${SOLIBS} \
  1376. ${datadir}/${BPN} ${libdir}/${BPN}/* \
  1377. ${datadir}/pixmaps ${datadir}/applications \
  1378. ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
  1379. ${libdir}/bonobo/servers"
  1380. FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
  1381. ${datadir}/gnome/help"
  1382. SECTION_${PN}-doc = "doc"
  1383. FILES_${PN}-dev = "${includedir} ${libdir}/lib*${SOLIBSDEV} ${libdir}/*.la \
  1384. ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
  1385. ${datadir}/aclocal ${base_libdir}/*.o"
  1386. SECTION_${PN}-dev = "devel"
  1387. ALLOW_EMPTY_${PN}-dev = "1"
  1388. RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
  1389. FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a"
  1390. SECTION_${PN}-staticdev = "devel"
  1391. RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
  1392. </literallayout>
  1393. </para>
  1394. </section>
  1395. <section id="combining-multiple-versions-library-files-into-one-image">
  1396. <title>Combining Multiple Versions of Library Files into One Image</title>
  1397. <para>
  1398. The build system offers the ability to build libraries with different
  1399. target optimizations or architecture formats and combine these together
  1400. into one system image.
  1401. You can link different binaries in the image
  1402. against the different libraries as needed for specific use cases.
  1403. This feature is called "Multilib."
  1404. </para>
  1405. <para>
  1406. An example would be where you have most of a system compiled in 32-bit
  1407. mode using 32-bit libraries, but you have something large, like a database
  1408. engine, that needs to be a 64-bit application and uses 64-bit libraries.
  1409. Multilib allows you to get the best of both 32-bit and 64-bit libraries.
  1410. </para>
  1411. <para>
  1412. While the Multilib feature is most commonly used for 32 and 64-bit differences,
  1413. the approach the build system uses facilitates different target optimizations.
  1414. You could compile some binaries to use one set of libraries and other binaries
  1415. to use other different sets of libraries.
  1416. The libraries could differ in architecture, compiler options, or other
  1417. optimizations.
  1418. </para>
  1419. <para>
  1420. This section overviews the Multilib process only.
  1421. For more details on how to implement Multilib, see the
  1422. <ulink url='&YOCTO_WIKI_URL;/wiki/Multilib'>Multilib</ulink> wiki
  1423. page.
  1424. </para>
  1425. <para>
  1426. Aside from this wiki page, several examples exist in the
  1427. <ulink url='&YOCTO_GIT_URL;/cgit.cgi/poky/tree/meta-skeleton'><filename>meta-skeleton</filename></ulink>
  1428. layer found in the
  1429. <link linkend='source-directory'>Source Directory</link>:
  1430. <itemizedlist>
  1431. <listitem><para><filename>conf/multilib-example.conf</filename>
  1432. configuration file</para></listitem>
  1433. <listitem><para><filename>conf/multilib-example2.conf</filename>
  1434. configuration file</para></listitem>
  1435. <listitem><para><filename>recipes-multilib/images/core-image-multilib-example.bb</filename>
  1436. recipe</para></listitem>
  1437. </itemizedlist>
  1438. </para>
  1439. <section id='preparing-to-use-multilib'>
  1440. <title>Preparing to Use Multilib</title>
  1441. <para>
  1442. User-specific requirements drive the Multilib feature.
  1443. Consequently, there is no one "out-of-the-box" configuration that likely
  1444. exists to meet your needs.
  1445. </para>
  1446. <para>
  1447. In order to enable Multilib, you first need to ensure your recipe is
  1448. extended to support multiple libraries.
  1449. Many standard recipes are already extended and support multiple libraries.
  1450. You can check in the <filename>meta/conf/multilib.conf</filename>
  1451. configuration file in the
  1452. <link linkend='source-directory'>Source Directory</link> to see how this is
  1453. done using the
  1454. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></ulink>
  1455. variable.
  1456. Eventually, all recipes will be covered and this list will be unneeded.
  1457. </para>
  1458. <para>
  1459. For the most part, the Multilib class extension works automatically to
  1460. extend the package name from <filename>${PN}</filename> to
  1461. <filename>${MLPREFIX}${PN}</filename>, where <filename>MLPREFIX</filename>
  1462. is the particular multilib (e.g. "lib32-" or "lib64-").
  1463. Standard variables such as
  1464. <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
  1465. <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
  1466. <ulink url='&YOCTO_DOCS_REF_URL;#var-RPROVIDES'><filename>RPROVIDES</filename></ulink>,
  1467. <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
  1468. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>,
  1469. and <filename>PACKAGES_DYNAMIC</filename> are automatically extended by the system.
  1470. If you are extending any manual code in the recipe, you can use the
  1471. <filename>${MLPREFIX}</filename> variable to ensure those names are extended
  1472. correctly.
  1473. This automatic extension code resides in <filename>multilib.bbclass</filename>.
  1474. </para>
  1475. </section>
  1476. <section id='using-multilib'>
  1477. <title>Using Multilib</title>
  1478. <para>
  1479. After you have set up the recipes, you need to define the actual
  1480. combination of multiple libraries you want to build.
  1481. You accomplish this through your <filename>local.conf</filename>
  1482. configuration file in the
  1483. <link linkend='build-directory'>Build Directory</link>.
  1484. An example configuration would be as follows:
  1485. <literallayout class='monospaced'>
  1486. MACHINE = "qemux86-64"
  1487. require conf/multilib.conf
  1488. MULTILIBS = "multilib:lib32"
  1489. DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
  1490. IMAGE_INSTALL = "lib32-connman"
  1491. </literallayout>
  1492. This example enables an
  1493. additional library named <filename>lib32</filename> alongside the
  1494. normal target packages.
  1495. When combining these "lib32" alternatives, the example uses "x86" for tuning.
  1496. For information on this particular tuning, see
  1497. <filename>meta/conf/machine/include/ia32/arch-ia32.inc</filename>.
  1498. </para>
  1499. <para>
  1500. The example then includes <filename>lib32-connman</filename>
  1501. in all the images, which illustrates one method of including a
  1502. multiple library dependency.
  1503. You can use a normal image build to include this dependency,
  1504. for example:
  1505. <literallayout class='monospaced'>
  1506. $ bitbake core-image-sato
  1507. </literallayout>
  1508. You can also build Multilib packages specifically with a command like this:
  1509. <literallayout class='monospaced'>
  1510. $ bitbake lib32-connman
  1511. </literallayout>
  1512. </para>
  1513. </section>
  1514. <section id='additional-implementation-details'>
  1515. <title>Additional Implementation Details</title>
  1516. <para>
  1517. Different packaging systems have different levels of native Multilib
  1518. support.
  1519. For the RPM Package Management System, the following implementation details
  1520. exist:
  1521. <itemizedlist>
  1522. <listitem><para>A unique architecture is defined for the Multilib packages,
  1523. along with creating a unique deploy folder under
  1524. <filename>tmp/deploy/rpm</filename> in the
  1525. <link linkend='build-directory'>Build Directory</link>.
  1526. For example, consider <filename>lib32</filename> in a
  1527. <filename>qemux86-64</filename> image.
  1528. The possible architectures in the system are "all", "qemux86_64",
  1529. "lib32_qemux86_64", and "lib32_x86".</para></listitem>
  1530. <listitem><para>The <filename>${MLPREFIX}</filename> variable is stripped from
  1531. <filename>${PN}</filename> during RPM packaging.
  1532. The naming for a normal RPM package and a Multilib RPM package in a
  1533. <filename>qemux86-64</filename> system resolves to something similar to
  1534. <filename>bash-4.1-r2.x86_64.rpm</filename> and
  1535. <filename>bash-4.1.r2.lib32_x86.rpm</filename>, respectively.
  1536. </para></listitem>
  1537. <listitem><para>When installing a Multilib image, the RPM backend first
  1538. installs the base image and then installs the Multilib libraries.
  1539. </para></listitem>
  1540. <listitem><para>The build system relies on RPM to resolve the identical files in the
  1541. two (or more) Multilib packages.</para></listitem>
  1542. </itemizedlist>
  1543. </para>
  1544. <para>
  1545. For the IPK Package Management System, the following implementation details exist:
  1546. <itemizedlist>
  1547. <listitem><para>The <filename>${MLPREFIX}</filename> is not stripped from
  1548. <filename>${PN}</filename> during IPK packaging.
  1549. The naming for a normal RPM package and a Multilib IPK package in a
  1550. <filename>qemux86-64</filename> system resolves to something like
  1551. <filename>bash_4.1-r2.x86_64.ipk</filename> and
  1552. <filename>lib32-bash_4.1-rw_x86.ipk</filename>, respectively.
  1553. </para></listitem>
  1554. <listitem><para>The IPK deploy folder is not modified with
  1555. <filename>${MLPREFIX}</filename> because packages with and without
  1556. the Multilib feature can exist in the same folder due to the
  1557. <filename>${PN}</filename> differences.</para></listitem>
  1558. <listitem><para>IPK defines a sanity check for Multilib installation
  1559. using certain rules for file comparison, overridden, etc.
  1560. </para></listitem>
  1561. </itemizedlist>
  1562. </para>
  1563. </section>
  1564. </section>
  1565. <section id='installing-multiple-versions-of-the-same-library'>
  1566. <title>Installing Multiple Versions of the Same Library</title>
  1567. <para>
  1568. Situations can exist where you need to install and use
  1569. multiple versions of the same library on the same system
  1570. at the same time.
  1571. These situations almost always exist when a library API
  1572. changes and you have multiple pieces of software that
  1573. depend on the separate versions of the library.
  1574. To accommodate these situations, you can install multiple
  1575. versions of the same library in parallel on the same system.
  1576. </para>
  1577. <para>
  1578. The process is straight forward as long as the libraries use
  1579. proper versioning.
  1580. With properly versioned libraries, all you need to do to
  1581. individually specify the libraries is create separate,
  1582. appropriately named recipes where the
  1583. <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> part of the
  1584. name includes a portion that differentiates each library version
  1585. (e.g.the major part of the version number).
  1586. Thus, instead of having a single recipe that loads one version
  1587. of a library (e.g. <filename>clutter</filename>), you provide
  1588. multiple recipes that result in different versions
  1589. of the libraries you want.
  1590. As an example, the following two recipes would allow the
  1591. two separate versions of the <filename>clutter</filename>
  1592. library to co-exist on the same system:
  1593. <literallayout class='monospaced'>
  1594. clutter-1.6_1.6.20.bb
  1595. clutter-1.8_1.8.4.bb
  1596. </literallayout>
  1597. Additionally, if you have other recipes that depend on a given
  1598. library, you need to use the
  1599. <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
  1600. variable to create the dependency.
  1601. Continuing with the same example, if you want to have a recipe
  1602. depend on the 1.8 version of the <filename>clutter</filename>
  1603. library, use the following in your recipe:
  1604. <literallayout class='monospaced'>
  1605. DEPENDS = "clutter-1.8"
  1606. </literallayout>
  1607. </para>
  1608. </section>
  1609. </section>
  1610. <section id='configuring-the-kernel'>
  1611. <title>Configuring the Kernel</title>
  1612. <para>
  1613. Configuring the Yocto Project kernel consists of making sure the <filename>.config</filename>
  1614. file has all the right information in it for the image you are building.
  1615. You can use the <filename>menuconfig</filename> tool and configuration fragments to
  1616. make sure your <filename>.config</filename> file is just how you need it.
  1617. This section describes how to use <filename>menuconfig</filename>, create and use
  1618. configuration fragments, and how to interactively tweak your <filename>.config</filename>
  1619. file to create the leanest kernel configuration file possible.
  1620. </para>
  1621. <para>
  1622. For more information on kernel configuration, see the
  1623. "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>"
  1624. section in the Yocto Project Linux Kernel Development Manual.
  1625. </para>
  1626. <section id='using-menuconfig'>
  1627. <title>Using&nbsp;&nbsp;<filename>menuconfig</filename></title>
  1628. <para>
  1629. The easiest way to define kernel configurations is to set them through the
  1630. <filename>menuconfig</filename> tool.
  1631. This tool provides an interactive method with which
  1632. to set kernel configurations.
  1633. For general information on <filename>menuconfig</filename>, see
  1634. <ulink url='http://en.wikipedia.org/wiki/Menuconfig'></ulink>.
  1635. </para>
  1636. <para>
  1637. To use the <filename>menuconfig</filename> tool in the Yocto Project development
  1638. environment, you must build the tool using BitBake.
  1639. Thus, the environment must be set up using the
  1640. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
  1641. script found in the
  1642. <link linkend='build-directory'>Build Directory</link>.
  1643. The following commands build and invoke <filename>menuconfig</filename> assuming the
  1644. <link linkend='source-directory'>Source Directory</link>
  1645. top-level folder is <filename>~/poky</filename>:
  1646. <literallayout class='monospaced'>
  1647. $ cd ~/poky
  1648. $ source oe-init-build-env
  1649. $ bitbake linux-yocto -c menuconfig
  1650. </literallayout>
  1651. Once <filename>menuconfig</filename> comes up, its standard interface allows you to
  1652. interactively examine and configure all the kernel configuration parameters.
  1653. After making your changes, simply exit the tool and save your changes to
  1654. create an updated version of the <filename>.config</filename> configuration file.
  1655. </para>
  1656. <para>
  1657. Consider an example that configures the <filename>linux-yocto-3.4</filename>
  1658. kernel.
  1659. The OpenEmbedded build system recognizes this kernel as
  1660. <filename>linux-yocto</filename>.
  1661. Thus, the following commands from the shell in which you previously sourced the
  1662. environment initialization script cleans the shared state cache and the
  1663. <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
  1664. directory and then builds and launches <filename>menuconfig</filename>:
  1665. <literallayout class='monospaced'>
  1666. $ bitbake linux-yocto -c menuconfig
  1667. </literallayout>
  1668. </para>
  1669. <para>
  1670. Once <filename>menuconfig</filename> launches, use the interface
  1671. to navigate through the selections to find the configuration settings in
  1672. which you are interested.
  1673. For example, consider the <filename>CONFIG_SMP</filename> configuration setting.
  1674. You can find it at <filename>Processor Type and Features</filename> under
  1675. the configuration selection <filename>Symmetric Multi-processing Support</filename>.
  1676. After highlighting the selection, use the arrow keys to select or deselect
  1677. the setting.
  1678. When you are finished with all your selections, exit out and save them.
  1679. </para>
  1680. <para>
  1681. Saving the selections updates the <filename>.config</filename> configuration file.
  1682. This is the file that the OpenEmbedded build system uses to configure the
  1683. kernel during the build.
  1684. You can find and examine this file in the Build Directory in
  1685. <filename>tmp/work/</filename>.
  1686. The actual <filename>.config</filename> is located in the area where the
  1687. specific kernel is built.
  1688. For example, if you were building a Linux Yocto kernel based on the
  1689. Linux 3.4 kernel and you were building a QEMU image targeted for
  1690. <filename>x86</filename> architecture, the
  1691. <filename>.config</filename> file would be located here:
  1692. <literallayout class='monospaced'>
  1693. ~/poky/build/tmp/work/qemux86-poky-linux/linux-yocto-3.4.11+git1+84f...
  1694. ...656ed30-r1/linux-qemux86-standard-build
  1695. </literallayout>
  1696. <note>
  1697. The previous example directory is artificially split and many of the characters
  1698. in the actual filename are omitted in order to make it more readable.
  1699. Also, depending on the kernel you are using, the exact pathname
  1700. for <filename>linux-yocto-3.4...</filename> might differ.
  1701. </note>
  1702. </para>
  1703. <para>
  1704. Within the <filename>.config</filename> file, you can see the kernel settings.
  1705. For example, the following entry shows that symmetric multi-processor support
  1706. is not set:
  1707. <literallayout class='monospaced'>
  1708. # CONFIG_SMP is not set
  1709. </literallayout>
  1710. </para>
  1711. <para>
  1712. A good method to isolate changed configurations is to use a combination of the
  1713. <filename>menuconfig</filename> tool and simple shell commands.
  1714. Before changing configurations with <filename>menuconfig</filename>, copy the
  1715. existing <filename>.config</filename> and rename it to something else,
  1716. use <filename>menuconfig</filename> to make
  1717. as many changes an you want and save them, then compare the renamed configuration
  1718. file against the newly created file.
  1719. You can use the resulting differences as your base to create configuration fragments
  1720. to permanently save in your kernel layer.
  1721. <note>
  1722. Be sure to make a copy of the <filename>.config</filename> and don't just
  1723. rename it.
  1724. The build system needs an existing <filename>.config</filename>
  1725. from which to work.
  1726. </note>
  1727. </para>
  1728. </section>
  1729. <section id='creating-config-fragments'>
  1730. <title>Creating Configuration Fragments</title>
  1731. <para>
  1732. Configuration fragments are simply kernel options that appear in a file
  1733. placed where the OpenEmbedded build system can find and apply them.
  1734. Syntactically, the configuration statement is identical to what would appear
  1735. in the <filename>.config</filename> file, which is in the
  1736. <link linkend='build-directory'>Build Directory</link> in
  1737. <filename>tmp/work/&lt;arch&gt;-poky-linux/linux-yocto-&lt;release-specific-string&gt;/linux-&lt;arch&gt;-&lt;build-type&gt;</filename>.
  1738. </para>
  1739. <para>
  1740. It is simple to create a configuration fragment.
  1741. For example, issuing the following from the shell creates a configuration fragment
  1742. file named <filename>my_smp.cfg</filename> that enables multi-processor support
  1743. within the kernel:
  1744. <literallayout class='monospaced'>
  1745. $ echo "CONFIG_SMP=y" >> my_smp.cfg
  1746. </literallayout>
  1747. <note>
  1748. All configuration files must use the <filename>.cfg</filename> extension in order
  1749. for the OpenEmbedded build system to recognize them as a configuration fragment.
  1750. </note>
  1751. </para>
  1752. <para>
  1753. Where do you put your configuration files?
  1754. You can place these configuration files in the same area pointed to by
  1755. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
  1756. The OpenEmbedded build system will pick up the configuration and add it to the
  1757. kernel's configuration.
  1758. For example, suppose you had a set of configuration options in a file called
  1759. <filename>myconfig.cfg</filename>.
  1760. If you put that file inside a directory named <filename>/linux-yocto</filename>
  1761. that resides in the same directory as the kernel's append file and then add
  1762. a <filename>SRC_URI</filename> statement such as the following to the kernel's append file,
  1763. those configuration options will be picked up and applied when the kernel is built.
  1764. <literallayout class='monospaced'>
  1765. SRC_URI += "file://myconfig.cfg"
  1766. </literallayout>
  1767. </para>
  1768. <para>
  1769. As mentioned earlier, you can group related configurations into multiple files and
  1770. name them all in the <filename>SRC_URI</filename> statement as well.
  1771. For example, you could group separate configurations specifically for Ethernet and graphics
  1772. into their own files and add those by using a <filename>SRC_URI</filename> statement like the
  1773. following in your append file:
  1774. <literallayout class='monospaced'>
  1775. SRC_URI += "file://myconfig.cfg \
  1776. file://eth.cfg \
  1777. file://gfx.cfg"
  1778. </literallayout>
  1779. </para>
  1780. </section>
  1781. <section id='fine-tuning-the-kernel-configuration-file'>
  1782. <title>Fine-Tuning the Kernel Configuration File</title>
  1783. <para>
  1784. You can make sure the <filename>.config</filename> file is as lean or efficient as
  1785. possible by reading the output of the kernel configuration fragment audit,
  1786. noting any issues, making changes to correct the issues, and then repeating.
  1787. </para>
  1788. <para>
  1789. As part of the kernel build process, the
  1790. <filename>kernel_configcheck</filename> task runs.
  1791. This task validates the kernel configuration by checking the final
  1792. <filename>.config</filename> file against the input files.
  1793. During the check, the task produces warning messages for the following
  1794. issues:
  1795. <itemizedlist>
  1796. <listitem><para>Requested options that did not make the final
  1797. <filename>.config</filename> file.</para></listitem>
  1798. <listitem><para>Configuration items that appear twice in the same
  1799. configuration fragment.</para></listitem>
  1800. <listitem><para>Configuration items tagged as "required" were overridden.
  1801. </para></listitem>
  1802. <listitem><para>A board overrides a non-board specific option.</para></listitem>
  1803. <listitem><para>Listed options not valid for the kernel being processed.
  1804. In other words, the option does not appear anywhere.</para></listitem>
  1805. </itemizedlist>
  1806. <note>
  1807. The <filename>kernel_configcheck</filename> task can also optionally report
  1808. if an option is overridden during processing.
  1809. </note>
  1810. </para>
  1811. <para>
  1812. For each output warning, a message points to the file
  1813. that contains a list of the options and a pointer to the config
  1814. fragment that defines them.
  1815. Collectively, the files are the key to streamlining the configuration.
  1816. </para>
  1817. <para>
  1818. To streamline the configuration, do the following:
  1819. <orderedlist>
  1820. <listitem><para>Start with a full configuration that you know
  1821. works - it builds and boots successfully.
  1822. This configuration file will be your baseline.</para></listitem>
  1823. <listitem><para>Separately run the <filename>configme</filename> and
  1824. <filename>kernel_configcheck</filename> tasks.</para></listitem>
  1825. <listitem><para>Take the resulting list of files from the
  1826. <filename>kernel_configcheck</filename> task warnings and do the following:
  1827. <itemizedlist>
  1828. <listitem><para>Drop values that are redefined in the fragment but do not
  1829. change the final <filename>.config</filename> file.</para></listitem>
  1830. <listitem><para>Analyze and potentially drop values from the
  1831. <filename>.config</filename> file that override required
  1832. configurations.</para></listitem>
  1833. <listitem><para>Analyze and potentially remove non-board specific options.
  1834. </para></listitem>
  1835. <listitem><para>Remove repeated and invalid options.</para></listitem>
  1836. </itemizedlist></para></listitem>
  1837. <listitem><para>After you have worked through the output of the kernel configuration
  1838. audit, you can re-run the <filename>configme</filename>
  1839. and <filename>kernel_configcheck</filename> tasks to see the results of your
  1840. changes.
  1841. If you have more issues, you can deal with them as described in the
  1842. previous step.</para></listitem>
  1843. </orderedlist>
  1844. </para>
  1845. <para>
  1846. Iteratively working through steps two through four eventually yields
  1847. a minimal, streamlined configuration file.
  1848. Once you have the best <filename>.config</filename>, you can build the Linux
  1849. Yocto kernel.
  1850. </para>
  1851. </section>
  1852. </section>
  1853. <section id="patching-the-kernel">
  1854. <title>Patching the Kernel</title>
  1855. <para>
  1856. Patching the kernel involves changing or adding configurations to an existing kernel,
  1857. changing or adding recipes to the kernel that are needed to support specific hardware features,
  1858. or even altering the source code itself.
  1859. <note>
  1860. You can use the <filename>yocto-kernel</filename> script
  1861. found in the <link linkend='source-directory'>Source Directory</link>
  1862. under <filename>scripts</filename> to manage kernel patches and configuration.
  1863. 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>"
  1864. section in the Yocto Project Board Support Packages (BSP) Developer's Guide for
  1865. more information.</note>
  1866. </para>
  1867. <para>
  1868. This example creates a simple patch by adding some QEMU emulator console
  1869. output at boot time through <filename>printk</filename> statements in the kernel's
  1870. <filename>calibrate.c</filename> source code file.
  1871. Applying the patch and booting the modified image causes the added
  1872. messages to appear on the emulator's console.
  1873. </para>
  1874. <para>
  1875. The example assumes a clean build exists for the <filename>qemux86</filename>
  1876. machine in a Source Directory named <filename>poky</filename>.
  1877. Furthermore, the <link linkend='build-directory'>Build Directory</link> is
  1878. <filename>build</filename> and is located in <filename>poky</filename> and
  1879. the kernel is based on the Linux 3.4 kernel.
  1880. For general information on how to configure the most efficient build, see the
  1881. "<ulink url='&YOCTO_DOCS_QS_URL;#building-image'>Building an Image</ulink>" section
  1882. in the Yocto Project Quick Start.
  1883. </para>
  1884. <para>
  1885. Also, for more information on patching the kernel, see the
  1886. "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#applying-patches'>Applying Patches</ulink>"
  1887. section in the Yocto Project Linux Kernel Development Manual.
  1888. </para>
  1889. <section id='create-a-layer-for-your-changes'>
  1890. <title>Create a Layer for your Changes</title>
  1891. <para>
  1892. The first step is to create a layer so you can isolate your changes:
  1893. <literallayout class='monospaced'>
  1894. $cd ~/poky
  1895. $mkdir meta-mylayer
  1896. </literallayout>
  1897. Creating a directory that follows the Yocto Project layer naming
  1898. conventions sets up the layer for your changes.
  1899. The layer is where you place your configuration files, append
  1900. files, and patch files.
  1901. To learn more about creating a layer and filling it with the
  1902. files you need, see the "<link linkend='understanding-and-creating-layers'>Understanding
  1903. and Creating Layers</link>" section.
  1904. </para>
  1905. </section>
  1906. <section id='finding-the-kernel-source-code'>
  1907. <title>Finding the Kernel Source Code</title>
  1908. <para>
  1909. Each time you build a kernel image, the kernel source code is fetched
  1910. and unpacked into the following directory:
  1911. <literallayout class='monospaced'>
  1912. ${S}/linux
  1913. </literallayout>
  1914. See the "<link linkend='finding-the-temporary-source-code'>Finding the Temporary Source Code</link>"
  1915. section and the
  1916. <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink> variable
  1917. for more information about where source is kept during a build.
  1918. </para>
  1919. <para>
  1920. For this example, we are going to patch the
  1921. <filename>init/calibrate.c</filename> file
  1922. by adding some simple console <filename>printk</filename> statements that we can
  1923. see when we boot the image using QEMU.
  1924. </para>
  1925. </section>
  1926. <section id='creating-the-patch'>
  1927. <title>Creating the Patch</title>
  1928. <para>
  1929. Two methods exist by which you can create the patch:
  1930. <link linkend='using-a-git-workflow'>Git workflow</link> and
  1931. <link linkend='using-a-quilt-workflow'>Quilt workflow</link>.
  1932. For kernel patches, the Git workflow is more appropriate.
  1933. This section assumes the Git workflow and shows the steps specific to
  1934. this example.
  1935. <orderedlist>
  1936. <listitem><para><emphasis>Change the working directory</emphasis>:
  1937. Change to where the kernel source code is before making
  1938. your edits to the <filename>calibrate.c</filename> file:
  1939. <literallayout class='monospaced'>
  1940. $ cd ~/poky/build/tmp/work/qemux86-poky-linux/linux-yocto-${PV}-${PR}/linux
  1941. </literallayout>
  1942. Because you are working in an established Git repository,
  1943. you must be in this directory in order to commit your changes
  1944. and create the patch file.
  1945. <note>The <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> and
  1946. <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink> variables
  1947. represent the version and revision for the
  1948. <filename>linux-yocto</filename> recipe.
  1949. The <filename>PV</filename> variable includes the Git meta and machine
  1950. hashes, which make the directory name longer than you might
  1951. expect.
  1952. </note></para></listitem>
  1953. <listitem><para><emphasis>Edit the source file</emphasis>:
  1954. Edit the <filename>init/calibrate.c</filename> file to have the
  1955. following changes:
  1956. <literallayout class='monospaced'>
  1957. void __cpuinit calibrate_delay(void)
  1958. {
  1959. unsigned long lpj;
  1960. static bool printed;
  1961. int this_cpu = smp_processor_id();
  1962. printk("*************************************\n");
  1963. printk("* *\n");
  1964. printk("* HELLO YOCTO KERNEL *\n");
  1965. printk("* *\n");
  1966. printk("*************************************\n");
  1967. if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
  1968. .
  1969. .
  1970. .
  1971. </literallayout></para></listitem>
  1972. <listitem><para><emphasis>Stage and commit your changes</emphasis>:
  1973. These Git commands display the modified file, stage it, and then
  1974. commit the file:
  1975. <literallayout class='monospaced'>
  1976. $ git status
  1977. $ git add init/calibrate.c
  1978. $ git commit -m "calibrate: Add printk example"
  1979. </literallayout></para></listitem>
  1980. <listitem><para><emphasis>Generate the patch file</emphasis>:
  1981. This Git command creates the a patch file named
  1982. <filename>0001-calibrate-Add-printk-example.patch</filename>
  1983. in the current directory.
  1984. <literallayout class='monospaced'>
  1985. $ git format-patch -1
  1986. </literallayout>
  1987. </para></listitem>
  1988. </orderedlist>
  1989. </para>
  1990. </section>
  1991. <section id='set-up-your-layer-for-the-build'>
  1992. <title>Set Up Your Layer for the Build</title>
  1993. <para>These steps get your layer set up for the build:
  1994. <orderedlist>
  1995. <listitem><para><emphasis>Create additional structure</emphasis>:
  1996. Create the additional layer structure:
  1997. <literallayout class='monospaced'>
  1998. $ cd ~/poky/meta-mylayer
  1999. $ mkdir conf
  2000. $ mkdir recipes-kernel
  2001. $ mkdir recipes-kernel/linux
  2002. $ mkdir recipes-kernel/linux/linux-yocto
  2003. </literallayout>
  2004. The <filename>conf</filename> directory holds your configuration files, while the
  2005. <filename>recipes-kernel</filename> directory holds your append file and
  2006. your patch file.</para></listitem>
  2007. <listitem><para><emphasis>Create the layer configuration file</emphasis>:
  2008. Move to the <filename>meta-mylayer/conf</filename> directory and create
  2009. the <filename>layer.conf</filename> file as follows:
  2010. <literallayout class='monospaced'>
  2011. # We have a conf and classes directory, add to BBPATH
  2012. BBPATH .= ":${LAYERDIR}"
  2013. # We have recipes-* directories, add to BBFILES
  2014. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  2015. ${LAYERDIR}/recipes-*/*/*.bbappend"
  2016. BBFILE_COLLECTIONS += "mylayer"
  2017. BBFILE_PATTERN_mylayer = "^${LAYERDIR}/"
  2018. BBFILE_PRIORITY_mylayer = "5"
  2019. </literallayout>
  2020. Notice <filename>mylayer</filename> as part of the last three
  2021. statements.</para></listitem>
  2022. <listitem><para><emphasis>Create the kernel recipe append file</emphasis>:
  2023. Move to the <filename>meta-mylayer/recipes-kernel/linux</filename> directory and create
  2024. the <filename>linux-yocto_3.4.bbappend</filename> file as follows:
  2025. <literallayout class='monospaced'>
  2026. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
  2027. SRC_URI += "file://0001-calibrate-Add-printk-example.patch"
  2028. PRINC := "${@int(PRINC) + 1}"
  2029. </literallayout>
  2030. The <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
  2031. and <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  2032. statements enable the OpenEmbedded build system to find the patch file.
  2033. For more information on using append files, see the
  2034. "<link linkend='using-bbappend-files'>Using .bbappend Files</link>"
  2035. section.
  2036. </para></listitem>
  2037. <listitem><para><emphasis>Put the patch file in your layer</emphasis>:
  2038. Move the <filename>0001-calibrate-Add-printk-example.patch</filename> file to
  2039. the <filename>meta-mylayer/recipes-kernel/linux/linux-yocto</filename>
  2040. directory.</para></listitem>
  2041. </orderedlist>
  2042. </para>
  2043. </section>
  2044. <section id='set-up-for-the-build'>
  2045. <title>Set Up for the Build</title>
  2046. <para>
  2047. Do the following to make sure the build parameters are set up for the example.
  2048. Once you set up these build parameters, they do not have to change unless you
  2049. change the target architecture of the machine you are building:
  2050. <itemizedlist>
  2051. <listitem><para><emphasis>Build for the correct target architecture:</emphasis> Your
  2052. selected <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
  2053. definition within the <filename>local.conf</filename> file in the
  2054. <link linkend='build-directory'>Build Directory</link>
  2055. specifies the target architecture used when building the Linux kernel.
  2056. By default, <filename>MACHINE</filename> is set to
  2057. <filename>qemux86</filename>, which specifies a 32-bit
  2058. <trademark class='registered'>Intel</trademark> Architecture
  2059. target machine suitable for the QEMU emulator.</para></listitem>
  2060. <listitem><para><emphasis>Identify your <filename>meta-mylayer</filename>
  2061. layer:</emphasis> The
  2062. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
  2063. variable in the
  2064. <filename>bblayers.conf</filename> file found in the
  2065. <filename>poky/build/conf</filename> directory needs to have the path to your local
  2066. <filename>meta-mylayer</filename> layer.
  2067. By default, the <filename>BBLAYERS</filename> variable contains paths to
  2068. <filename>meta</filename>, <filename>meta-yocto</filename>, and
  2069. <filename>meta-yocto-bsp</filename> in the
  2070. <filename>poky</filename> Git repository.
  2071. Add the path to your <filename>meta-mylayer</filename> location:
  2072. <literallayout class='monospaced'>
  2073. BBLAYERS ?= " \
  2074. $HOME/poky/meta \
  2075. $HOME/poky/meta-yocto \
  2076. $HOME/poky/meta-yocto-bsp \
  2077. $HOME/poky/meta-mylayer \
  2078. "
  2079. BBLAYERS_NON_REMOVABLE ?= " \
  2080. $HOME/poky/meta \
  2081. $HOME/poky/meta-yocto \
  2082. "
  2083. </literallayout></para></listitem>
  2084. </itemizedlist>
  2085. </para>
  2086. </section>
  2087. <section id='build-the-modified-qemu-kernel-image'>
  2088. <title>Build the Modified QEMU Kernel Image</title>
  2089. <para>
  2090. The following steps build your modified kernel image:
  2091. <orderedlist>
  2092. <listitem><para><emphasis>Be sure your build environment is initialized</emphasis>:
  2093. Your environment should be set up since you previously sourced
  2094. the
  2095. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
  2096. script.
  2097. If it is not, source the script again from <filename>poky</filename>.
  2098. <literallayout class='monospaced'>
  2099. $ cd ~/poky
  2100. $ source &OE_INIT_FILE;
  2101. </literallayout>
  2102. </para></listitem>
  2103. <listitem><para><emphasis>Clean up</emphasis>:
  2104. Be sure to clean the shared state out by running the
  2105. <filename>cleansstate</filename> BitBake task as follows from your Build Directory:
  2106. <literallayout class='monospaced'>
  2107. $ bitbake -c cleansstate linux-yocto
  2108. </literallayout></para>
  2109. <para><note>Never remove any files by hand from the <filename>tmp/deploy</filename>
  2110. directory inside the
  2111. <link linkend='build-directory'>Build Directory</link>.
  2112. Always use the various BitBake clean tasks to clear out previous
  2113. build artifacts.
  2114. </note></para></listitem>
  2115. <listitem><para><emphasis>Build the image</emphasis>:
  2116. Next, build the kernel image using this command:
  2117. <literallayout class='monospaced'>
  2118. $ bitbake -k linux-yocto
  2119. </literallayout></para></listitem>
  2120. </orderedlist>
  2121. </para>
  2122. </section>
  2123. <section id='boot-the-image-and-verify-your-changes'>
  2124. <title>Boot the Image and Verify Your Changes</title>
  2125. <para>
  2126. These steps boot the image and allow you to see the changes
  2127. <orderedlist>
  2128. <listitem><para><emphasis>Boot the image</emphasis>:
  2129. Boot the modified image in the QEMU emulator
  2130. using this command:
  2131. <literallayout class='monospaced'>
  2132. $ runqemu qemux86
  2133. </literallayout></para></listitem>
  2134. <listitem><para><emphasis>Verify the changes</emphasis>:
  2135. Log into the machine using <filename>root</filename> with no password and then
  2136. use the following shell command to scroll through the console's boot output.
  2137. <literallayout class='monospaced'>
  2138. # dmesg | less
  2139. </literallayout>
  2140. You should see the results of your <filename>printk</filename> statements
  2141. as part of the output.</para></listitem>
  2142. </orderedlist>
  2143. </para>
  2144. </section>
  2145. </section>
  2146. <section id='creating-your-own-distribution'>
  2147. <title>Creating Your Own Distribution</title>
  2148. <para>
  2149. When you build an image using the Yocto Project and
  2150. do not alter any distribution
  2151. <link linkend='metadata'>Metadata</link>, you are creating a
  2152. Poky distribution.
  2153. If you wish to gain more control over package alternative
  2154. selections, compile-time options, and other low-level
  2155. configurations, you can create your own distribution.
  2156. </para>
  2157. <para>
  2158. To create your own distribution, the basic steps consist of
  2159. creating your own distribution layer, creating your own
  2160. distribution configuration file, and then adding any needed
  2161. code and Metadata to the layer.
  2162. The following steps provide some more detail:
  2163. <itemizedlist>
  2164. <listitem><para><emphasis>Create a layer for your new distro:</emphasis>
  2165. Create your distribution layer so that you can keep your
  2166. Metadata and code for the distribution separate.
  2167. It is strongly recommended that you create and use your own
  2168. layer for configuration and code.
  2169. Using your own layer as compared to just placing
  2170. configurations in a <filename>local.conf</filename>
  2171. configuration file makes it easier to reproduce the same
  2172. build configuration when using multiple build machines.
  2173. See the
  2174. "<link linkend='creating-a-general-layer-using-the-yocto-layer-script'>Creating a General Layer Using the yocto-layer Script</link>"
  2175. section for information on how to quickly set up a layer.
  2176. </para></listitem>
  2177. <listitem><para><emphasis>Create the distribution configuration file:</emphasis>
  2178. The distribution configuration file needs to be created in
  2179. the <filename>conf/distro</filename> directory of your
  2180. layer.
  2181. You need to name it using your distribution name
  2182. (e.g. <filename>mydistro.conf</filename>).</para>
  2183. <para>You can split out parts of your configuration file
  2184. into include files and then "require" them from within
  2185. your distribution configuration file.
  2186. Be sure to place the include files in the
  2187. <filename>conf/distro/include</filename> directory of
  2188. your layer.
  2189. A common example usage of include files would be to
  2190. separate out the selection of desired version and revisions
  2191. for individual recipes.
  2192. </para>
  2193. <para>Your configuration file needs to set the following
  2194. required variables:
  2195. <literallayout class='monospaced'>
  2196. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_NAME'><filename>DISTRO_NAME</filename></ulink> [required]
  2197. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_VERSION'><filename>DISTRO_VERSION</filename></ulink> [required]
  2198. </literallayout>
  2199. These following variables are optional and you typically
  2200. set them from the distribution configuration file:
  2201. <literallayout class='monospaced'>
  2202. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink> [optional]
  2203. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RDEPENDS'><filename>DISTRO_EXTRA_RDEPENDS</filename></ulink> [optional]
  2204. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RRECOMMENDS'><filename>DISTRO_EXTRA_RRECOMMENDS</filename></ulink> [optional]
  2205. <ulink url='&YOCTO_DOCS_REF_URL;#var-TCLIBC'><filename>TCLIBC</filename></ulink> [optional]
  2206. </literallayout>
  2207. <tip>
  2208. If you want to base your distribution configuration file
  2209. on the very basic configuration from OE-Core, you
  2210. can use
  2211. <filename>conf/distro/defaultsetup.conf</filename> as
  2212. a reference and just include variables that differ
  2213. as compared to <filename>defaultsetup.conf</filename>.
  2214. Alternatively, you can create a distribution
  2215. configuration file from scratch using the
  2216. <filename>defaultsetup.conf</filename> file
  2217. or configuration files from other distributions
  2218. such as Poky or Angstrom as references.
  2219. </tip></para></listitem>
  2220. <listitem><para><emphasis>Provide miscellaneous variables:</emphasis>
  2221. Be sure to define any other variables for which you want to
  2222. create a default or enforce as part of the distribution
  2223. configuration.
  2224. You can include nearly any variable from the
  2225. <filename>local.conf</filename> file.
  2226. The variables you use are not limited to the list in the
  2227. previous bulleted item.</para></listitem>
  2228. <listitem><para><emphasis>Point to Your distribution configuration file:</emphasis>
  2229. In your <filename>local.conf</filename> file in the
  2230. <link linkend='build-directory'>Build Directory</link>,
  2231. set your
  2232. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
  2233. variable to point to your distribution's configuration file.
  2234. For example, if your distribution's configuration file is
  2235. named <filename>mydistro.conf</filename>, then you point
  2236. to it as follows:
  2237. <literallayout class='monospaced'>
  2238. DISTRO = "mydistro"
  2239. </literallayout></para></listitem>
  2240. <listitem><para><emphasis>Add more to the layer if necessary:</emphasis>
  2241. Use your layer to hold other information needed for the
  2242. distribution:
  2243. <itemizedlist>
  2244. <listitem><para>Add recipes for installing
  2245. distro-specific configuration files that are not
  2246. already installed by another recipe.
  2247. If you have distro-specific configuration files
  2248. that are included by an existing recipe, you should
  2249. add a <filename>.bbappend</filename> for those.
  2250. For general information on how to add recipes to
  2251. your layer, see the "<link linkend='creating-your-own-layer'>Creating Your Own Layer</link>"
  2252. section.</para></listitem>
  2253. <listitem><para>Add any image recipes that are specific
  2254. to your distribution.</para></listitem>
  2255. <listitem><para>Add a <filename>psplash</filename>
  2256. append file for a branded splash screen.
  2257. For information on append files, see the
  2258. "<link linkend='using-bbappend-files'>Using .bbappend Files</link>"
  2259. section.</para></listitem>
  2260. <listitem><para>Add any other append files to make
  2261. custom changes that are specific to individual
  2262. recipes.</para></listitem>
  2263. </itemizedlist></para></listitem>
  2264. </itemizedlist>
  2265. </para>
  2266. </section>
  2267. <section id='building-a-tiny-system'>
  2268. <title>Building a Tiny System</title>
  2269. <para>
  2270. Very small distributions have some significant advantages such
  2271. as requiring less on-die or in-package memory (cheaper), better
  2272. performance through efficient cache usage, lower power requirements
  2273. due to less memory, faster boot times, and reduced development
  2274. overhead.
  2275. Some real-world examples where a very small distribution gives
  2276. you distinct advantages are digital cameras, medical devices,
  2277. and small headless systems.
  2278. </para>
  2279. <para>
  2280. This section presents information that shows you how you can
  2281. trim your distribution to even smaller sizes than the
  2282. <filename>poky-tiny</filename> distribution, which is around
  2283. 5 Mbytes, that can be built out-of-the-box using the Yocto Project.
  2284. </para>
  2285. <section id='tiny-system-overview'>
  2286. <title>Overview</title>
  2287. <para>
  2288. The following list presents the overall steps you need to
  2289. consider and perform to create distributions with smaller
  2290. root filesystems, faster boot times, maintain your critical
  2291. functionality, and avoid initial RAM disks:
  2292. <itemizedlist>
  2293. <listitem><para>Determine your goals and guiding
  2294. principles.</para></listitem>
  2295. <listitem><para>Understand what gives your image size.
  2296. </para></listitem>
  2297. <listitem><para>Reduce the size of the root filesystem.
  2298. </para></listitem>
  2299. <listitem><para>Reduce the size of the kernel.
  2300. </para></listitem>
  2301. <listitem><para>Look for other ways to minimize size.
  2302. </para></listitem>
  2303. <listitem><para>Iterate on the process.</para></listitem>
  2304. </itemizedlist>
  2305. </para>
  2306. </section>
  2307. <section id='goals-and-guiding-principles'>
  2308. <title>Goals and Guiding Principles</title>
  2309. <para>
  2310. Before you can reach your destination, you need to know
  2311. where you are going.
  2312. Here is an example list that you can use as a guide when
  2313. creating very small distributions:
  2314. <itemizedlist>
  2315. <listitem><para>Determine how much space you need
  2316. (e.g. a kernel that is 1 Mbyte or less and
  2317. a root filesystem that is 3 Mbytes or less).
  2318. </para></listitem>
  2319. <listitem><para>Find the areas that are currently
  2320. taking 90% of the space and concentrate on reducing
  2321. those areas.
  2322. </para></listitem>
  2323. <listitem><para>Do not create any difficult "hacks"
  2324. to achieve your goals.</para></listitem>
  2325. <listitem><para>Leverage the device-specific
  2326. options.</para></listitem>
  2327. <listitem><para>Work in a separate layer so that you
  2328. keep changes isolated.
  2329. For information on how to create layers, see
  2330. the "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" section.
  2331. </para></listitem>
  2332. </itemizedlist>
  2333. </para>
  2334. </section>
  2335. <section id='understand-what-gives-your-image-size'>
  2336. <title>Understand What Gives Your Image Size</title>
  2337. <para>
  2338. It is easiest to have something to start with when creating
  2339. your own distribution.
  2340. You can use the Yocto Project out-of-the-box to create the
  2341. <filename>poky-tiny</filename> distribution.
  2342. Ultimately, you will want to make changes in your own
  2343. distribution that are likely modeled after
  2344. <filename>poky-tiny</filename>.
  2345. <note>
  2346. To use <filename>poky-tiny</filename> in your build,
  2347. set the
  2348. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
  2349. variable in your
  2350. <filename>local.conf</filename> file to "poky-tiny"
  2351. as described in the
  2352. "<link linkend='creating-your-own-distribution'>Creating Your Own Distribution</link>"
  2353. section.
  2354. </note>
  2355. </para>
  2356. <para>
  2357. Understanding some memory concepts will help you reduce the
  2358. system size.
  2359. Memory consists of static, dynamic, and temporary memory.
  2360. Static memory is the TEXT (code), DATA (initialized data
  2361. in the code), and BSS (uninitialized data) sections.
  2362. Dynamic memory contains memory that is allocated at runtime,
  2363. stacks, hash tables, and so forth.
  2364. Temporary memory is recovered after the boot process.
  2365. This memory consists of memory used for decompressing
  2366. the kernel and for the <filename>__init__</filename>
  2367. functions.
  2368. </para>
  2369. <para>
  2370. To help you see where you currently are with kernel and root
  2371. filesystem sizes, you can use two tools found in the
  2372. <link linkend='source-directory'>Source Directory</link> in
  2373. the <filename>scripts</filename> directory:
  2374. <itemizedlist>
  2375. <listitem><para><filename>ksize.py</filename>: Reports
  2376. component sizes for the kernel build objects.
  2377. </para></listitem>
  2378. <listitem><para><filename>dirsize.py</filename>: Reports
  2379. component sizes for the root filesystem.</para></listitem>
  2380. </itemizedlist>
  2381. This next tool and command helps you organize configuration
  2382. fragments and view file dependencies in a human-readable form:
  2383. <itemizedlist>
  2384. <listitem><para><filename>merge_config.sh</filename>:
  2385. Helps you manage configuration files and fragments
  2386. within the kernel.
  2387. With this tool, you can merge individual configuration
  2388. fragments together.
  2389. The tool allows you to make overrides and warns you
  2390. of any missing configuration options.
  2391. The tool is ideal for allowing you to iterate on
  2392. configurations, create minimal configurations, and
  2393. create configuration files for different machines
  2394. without having to duplicate your process.</para>
  2395. <para>The <filename>merge_config.sh</filename> script is
  2396. part of the Linux Yocto kernel Git repository in the
  2397. <filename>scripts/kconfig</filename> directory.</para>
  2398. <para>For more information on configuration fragments,
  2399. see the
  2400. "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#generating-configuration-files'>Generating Configuration Files</ulink>"
  2401. section of the Yocto Project Linux Kernel Development
  2402. Manual and the "<link linkend='creating-config-fragments'>Creating Configuration Fragments</link>"
  2403. section, which is in this manual.</para></listitem>
  2404. <listitem><para><filename>bitbake -u depexp -g &lt;bitbake_target&gt;</filename>:
  2405. Using the BitBake command with these options brings up
  2406. a Dependency Explorer from which you can view file
  2407. dependencies.
  2408. Understanding these dependencies allows you to make
  2409. informed decisions when cutting out various pieces of the
  2410. kernel and root filesystem.</para></listitem>
  2411. </itemizedlist>
  2412. </para>
  2413. </section>
  2414. <section id='trim-the-root-filesystem'>
  2415. <title>Trim the Root Filesystem</title>
  2416. <para>
  2417. The root filesystem is made up of packages for booting,
  2418. libraries, and applications.
  2419. To change things, you can configure how the packaging happens,
  2420. which changes the way you build them.
  2421. You can also tweak the filesystem itself or select a different
  2422. filesystem.
  2423. </para>
  2424. <para>
  2425. First, find out what is hogging your root filesystem by running the
  2426. <filename>dirsize.py</filename> script from your root directory:
  2427. <literallayout class='monospaced'>
  2428. $ cd &lt;root-directory-of-image&gt;
  2429. $ dirsize.py 100000 > dirsize-100k.log
  2430. $ cat dirsize-100k.log
  2431. </literallayout>
  2432. You can apply a filter to the script to ignore files under
  2433. a certain size.
  2434. This example filters out anything below 100 Kbytes.
  2435. The sizes reported by the tool are uncompressed and thus,
  2436. will be smaller by a relatively constant factor in a
  2437. compressed root filesystem.
  2438. When you examine your log file, you can focus on areas of the
  2439. root filesystem that take up large amounts of memory.
  2440. </para>
  2441. <para>
  2442. You need to be sure that what you eliminate does not cripple
  2443. the functionality you need.
  2444. One way to see how packages relate to each other is by using
  2445. the Dependency Explorer UI with the BitBake command:
  2446. <literallayout class='monospaced'>
  2447. $ cd &lt;image-directory&gt;
  2448. $ bitbake -u depexp -g &lt;image&gt;
  2449. </literallayout>
  2450. Use the interface to select potential packages you wish to
  2451. eliminate and see their dependency relationships.
  2452. </para>
  2453. <para>
  2454. When deciding how to reduce the size, get rid of packages that
  2455. result in minimal impact on the feature set.
  2456. For example, you might not need a VGA display.
  2457. Or, you might be able to get by with <filename>devtmpfs</filename>
  2458. and <filename>mdev</filename> instead of
  2459. <filename>udev</filename>.
  2460. </para>
  2461. <para>
  2462. Use the <filename>local.conf</filename> file to make changes.
  2463. For example, to eliminate <filename>udev</filename> and
  2464. <filename>glib</filename>, set the following in the
  2465. local configuration file:
  2466. <literallayout class='monospaced'>
  2467. VIRTUAL-RUNTIME_dev_manager = ""
  2468. </literallayout>
  2469. </para>
  2470. <para>
  2471. Finally, you should consider exactly the type of root
  2472. filesystem you need to meet your needs while also reducing
  2473. its size.
  2474. For example, consider <filename>cramfs</filename>,
  2475. <filename>squashfs</filename>, <filename>ubifs</filename>,
  2476. <filename>ext2</filename>, or an <filename>initramfs</filename>
  2477. using <filename>initramfs</filename>.
  2478. Be aware that <filename>ext3</filename> requires a 1 Mbyte
  2479. journal.
  2480. If you are okay with running read-only you do not need this
  2481. journal.
  2482. </para>
  2483. <note>
  2484. After each round of elimination, you need to rebuild your
  2485. system and then use the tools to see the effects of your
  2486. reductions.
  2487. </note>
  2488. </section>
  2489. <section id='trim-the-kernel'>
  2490. <title>Trim the Kernel</title>
  2491. <para>
  2492. The kernel is built by including policies for hardware-independent
  2493. aspects.
  2494. What subsystems do you enable?
  2495. For what architecture are you building?
  2496. Which drivers do you build by default.
  2497. <note>You can modify the kernel source if you want to help
  2498. with boot time.
  2499. </note>
  2500. </para>
  2501. <para>
  2502. Run the <filename>ksize.py</filename> script from the top-level
  2503. Linux build directory to get an idea of what is making up
  2504. the kernel:
  2505. <literallayout class='monospaced'>
  2506. $ cd &lt;top-level-linux-build-directory&gt;
  2507. $ ksize.py > ksize.log
  2508. $ cat ksize.log
  2509. </literallayout>
  2510. When you examine the log, you will see how much space is
  2511. taken up with the built-in <filename>.o</filename> files for
  2512. drivers, networking, core kernel files, filesystem, sound,
  2513. and so forth.
  2514. The sizes reported by the tool are uncompressed and thus,
  2515. will be smaller by a relatively constant factor in a compressed
  2516. kernel image.
  2517. Look to reduce the areas that are large and taking up around
  2518. the "90% rule."
  2519. </para>
  2520. <para>
  2521. To examine, or drill down, into any particular area, use the
  2522. <filename>-d</filename> option with the script:
  2523. <literallayout class='monospaced'>
  2524. $ ksize.py -d > ksize.log
  2525. </literallayout>
  2526. Using this option breaks out the individual file information
  2527. for each area of the kernel (e.g. drivers, networking, and
  2528. so forth).
  2529. </para>
  2530. <para>
  2531. Use your log file to see what you can eliminate from the kernel
  2532. based on features you can let go.
  2533. For example, if you are not going to need sound, you do not
  2534. need any drivers that support sound.
  2535. </para>
  2536. <para>
  2537. After figuring out what to eliminate, you need to reconfigure
  2538. the kernel to reflect those changes during the next build.
  2539. You could run <filename>menuconfig</filename> and make all your
  2540. changes at once.
  2541. However, that makes it difficult to see the effects of your
  2542. individual eliminations and also makes it difficult to replicate
  2543. the changes for perhaps another target device.
  2544. A better method is to start with no configurations using
  2545. <filename>allnoconfig</filename>, create configuration
  2546. fragments for individual changes, and then manage the
  2547. fragments into a single configuration file using
  2548. <filename>merge_config.sh</filename>.
  2549. The tool makes it easy for you to iterate using the
  2550. configuration change and build cycle.
  2551. </para>
  2552. <para>
  2553. Each time you make configuration changes, you need to rebuild
  2554. the kernel and check to see what impact your changes had on
  2555. the overall size.
  2556. </para>
  2557. </section>
  2558. <section id='look-for-other-ways-to-minimize-size'>
  2559. <title>Look for Other Ways to Minimize Size</title>
  2560. <para>
  2561. Depending on your particular circumstances, other areas that you
  2562. can trim likely exist.
  2563. The key to finding these areas is through tools and methods
  2564. described here combined with experimentation and iteration.
  2565. Here are a couple of areas to experiment with:
  2566. <itemizedlist>
  2567. <listitem><para><filename>eglibc</filename>:
  2568. In general, follow this process:
  2569. <orderedlist>
  2570. <listitem><para>Remove <filename>eglibc</filename>
  2571. features from
  2572. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
  2573. that you think you do not need.</para></listitem>
  2574. <listitem><para>Build your distribution.
  2575. </para></listitem>
  2576. <listitem><para>If the build fails due to missing
  2577. symbols in a package, determine if you can
  2578. reconfigure the package to not need those
  2579. features.
  2580. For example, change the configuration to not
  2581. support wide character support as is done for
  2582. <filename>ncurses</filename>.
  2583. Or, if support for those characters is needed,
  2584. determine what <filename>eglibc</filename>
  2585. features provide the support and restore the
  2586. configuration.
  2587. </para></listitem>
  2588. <listitem><para>Rebuild and repeat the process.
  2589. </para></listitem>
  2590. </orderedlist></para></listitem>
  2591. <listitem><para><filename>busybox</filename>:
  2592. For BusyBox, use a process similar as described for
  2593. <filename>eglibc</filename>.
  2594. A difference is you will need to boot the resulting
  2595. system to see if you are able to do everything you
  2596. expect from the running system.
  2597. You need to be sure to integrate configuration fragments
  2598. into Busybox because BusyBox handles its own core
  2599. features and then allows you to add configuration
  2600. fragments on top.
  2601. </para></listitem>
  2602. </itemizedlist>
  2603. </para>
  2604. </section>
  2605. <section id='iterate-on-the-process'>
  2606. <title>Iterate on the Process</title>
  2607. <para>
  2608. If you have not reached your goals on system size, you need
  2609. to iterate on the process.
  2610. The process is the same.
  2611. Use the tools and see just what is taking up 90% of the root
  2612. filesystem and the kernel.
  2613. Decide what you can eliminate without limiting your device
  2614. beyond what you need.
  2615. </para>
  2616. <para>
  2617. Depending on your system, a good place to look might be
  2618. Busybox, which provides a stripped down
  2619. version of Unix tools in a single, executable file.
  2620. You might be able to drop virtual terminal services or perhaps
  2621. ipv6.
  2622. </para>
  2623. </section>
  2624. </section>
  2625. <section id='working-with-packages'>
  2626. <title>Working with Packages</title>
  2627. <para>
  2628. This section describes a few tasks that involve packages:
  2629. <itemizedlist>
  2630. <listitem><para>Incrementing a package revision number
  2631. </para></listitem>
  2632. <listitem><para>Handling a package name alias
  2633. </para></listitem>
  2634. <listitem><para>Handling optional module packaging
  2635. </para></listitem>
  2636. <listitem><para>Setting up Runtime Package Management
  2637. </para></listitem>
  2638. <listitem><para>Setting up and running package test
  2639. (ptest)
  2640. </para></listitem>
  2641. </itemizedlist>
  2642. </para>
  2643. <section id='incrementing-a-package-revision-number'>
  2644. <title>Incrementing a Package Revision Number</title>
  2645. <para>
  2646. If a committed change results in changing the package output,
  2647. then the value of the
  2648. <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
  2649. variable needs to be increased (or "bumped").
  2650. Increasing <filename>PR</filename> occurs one of two ways:
  2651. <itemizedlist>
  2652. <listitem><para>Automatically using a Package Revision
  2653. Service (PR Service).</para></listitem>
  2654. <listitem><para>Manually incrementing the
  2655. <filename>PR</filename> variable.</para></listitem>
  2656. </itemizedlist>
  2657. </para>
  2658. <para>
  2659. Given that one of the challenges any build system and its
  2660. users face is how to maintain a package feed that is compatible
  2661. with existing package manager applications such as
  2662. RPM, APT, and OPKG, using an automated system is much
  2663. preferred over a manual system.
  2664. In either system, the main requirement is that version
  2665. numbering increases in a linear fashion and that a number of
  2666. version components exist that support that linear progression.
  2667. </para>
  2668. <para>
  2669. The following two sections provide information on the PR Service
  2670. and on manual <filename>PR</filename> bumping.
  2671. </para>
  2672. <section id='working-with-a-pr-service'>
  2673. <title>Working With a PR Service</title>
  2674. <para>
  2675. As mentioned, attempting to maintain revision numbers in the
  2676. <ulink url='&YOCTO_DOCS_DEV_URL;#metadata'>Metadata</ulink>
  2677. is error prone, inaccurate and causes problems for people
  2678. submitting recipes.
  2679. Conversely, the PR Service automatically generates
  2680. increasing numbers, particularly the revision field,
  2681. which removes the human element.
  2682. <note>
  2683. For additional information on using a PR Service, you
  2684. can see the
  2685. <ulink url='&YOCTO_WIKI_URL;/wiki/PR_Service'>PR Service</ulink>
  2686. wiki page.
  2687. </note>
  2688. </para>
  2689. <para>
  2690. The Yocto Project uses variables in order of
  2691. decreasing priority to facilitate revision numbering (i.e.
  2692. <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>,
  2693. <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>, and
  2694. <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
  2695. for epoch, version and revision, respectively).
  2696. The values are highly dependent on the policies and
  2697. procedures of a given distribution and package feed.
  2698. </para>
  2699. <para>
  2700. Because the OpenEmbedded build system uses
  2701. "<ulink url='&YOCTO_DOCS_REF_URL;#checksums'>signatures</ulink>",
  2702. which are unique to a given build, the build system
  2703. knows when to rebuild packages.
  2704. All the inputs into a given task are represented by a
  2705. signature, which can trigger a rebuild when different.
  2706. Thus, the build system itself does not rely on the
  2707. <filename>PR</filename> numbers to trigger a rebuild.
  2708. The signatures, however, can be used to generate
  2709. <filename>PR</filename> values.
  2710. </para>
  2711. <para>
  2712. The PR Service works with both
  2713. <filename>OEBasic</filename> and
  2714. <filename>OEBasicHash</filename> generators.
  2715. The value of <filename>PR</filename> bumps when the
  2716. checksum changes and the different generator mechanisms
  2717. change signatures under different circumstances.
  2718. </para>
  2719. <para>
  2720. As implemented, the build system includes values from
  2721. the PR Service into the <filename>PR</filename> field as
  2722. an addition using the form "<filename>.x</filename>" so
  2723. <filename>r0</filename> becomes <filename>r0.1</filename>,
  2724. <filename>r0.2</filename> and so forth.
  2725. This scheme allows existing <filename>PR</filename> values
  2726. to be used for whatever reasons, which include manual
  2727. <filename>PR</filename> bumps should it be necessary.
  2728. </para>
  2729. <para>
  2730. By default, the PR Service is not enabled or running.
  2731. Thus, the packages generated are just "self consistent".
  2732. The build system adds and removes packages and
  2733. there are no guarantees about upgrade paths but images
  2734. will be consistent and correct with the latest changes.
  2735. </para>
  2736. <para>
  2737. The simplest form for a PR Service is for it to exist
  2738. for a single host development system that builds the
  2739. package feed (building system).
  2740. For this scenario, you can enable the PR Service by adding
  2741. the following to your <filename>local.conf</filename>
  2742. file in the
  2743. <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>:
  2744. <literallayout class='monospaced'>
  2745. PRSERV_HOST = "localhost:0"
  2746. </literallayout>
  2747. Once the service is started, packages will automatically
  2748. get increasing <filename>PR</filename> values and
  2749. BitBake will take care of starting and stopping the server.
  2750. </para>
  2751. <para>
  2752. If you have a more complex setup where multiple host
  2753. development systems work against a common, shared package
  2754. feed, you have a single PR Service running and it is
  2755. connected to each building system.
  2756. For this scenario, you need to start the PR Service using
  2757. the <filename>bitbake-prserv</filename> command:
  2758. <literallayout class='monospaced'>
  2759. bitbake-prserv &dash;&dash;host &lt;ip&gt; &dash;&dash;port &lt;port&gt; &dash;&dash;start
  2760. </literallayout>
  2761. In addition to hand-starting the service, you need to
  2762. update the <filename>local.conf</filename> file of each
  2763. building system as described earlier so each system
  2764. points to the server and port.
  2765. </para>
  2766. <para>
  2767. It is also recommended you use Build History, which adds
  2768. some sanity checks to package versions, in conjunction with
  2769. the server that is running the PR Service.
  2770. To enable build history, add the following to each building
  2771. system's <filename>local.conf</filename> file:
  2772. <literallayout class='monospaced'>
  2773. # It is recommended to activate "buildhistory" for testing the PR service
  2774. INHERIT += "buildhistory"
  2775. BUILDHISTORY_COMMIT = "1"
  2776. </literallayout>
  2777. For information on Build History, see the
  2778. "<ulink url='&YOCTO_DOCS_REF_URL;#maintaining-build-output-quality'>Maintaining Build Output Quality</ulink>"
  2779. section in the Yocto Project Reference Manual.
  2780. </para>
  2781. <note>
  2782. <para>The OpenEmbedded build system does not maintain
  2783. <filename>PR</filename> information as part of the
  2784. shared state (sstate) packages.
  2785. If you maintain an sstate feed, its expected that either
  2786. all your building systems that contribute to the sstate
  2787. feed use a shared PR Service, or you do not run a PR
  2788. Service on any of your building systems.
  2789. Having some systems use a PR Service while others do
  2790. not leads to obvious problems.</para>
  2791. <para>For more information on shared state, see the
  2792. "<ulink url='&YOCTO_DOCS_REF_URL;#shared-state-cache'>Shared State Cache</ulink>"
  2793. section in the Yocto Project Reference Manual.</para>
  2794. </note>
  2795. </section>
  2796. <section id='manually-bumping-pr'>
  2797. <title>Manually Bumping PR</title>
  2798. <para>
  2799. The alternative to setting up a PR Service is to manually
  2800. bump the
  2801. <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
  2802. variable.
  2803. </para>
  2804. <para>
  2805. If a committed change results in changing the package output,
  2806. then the value of the PR variable needs to be increased
  2807. (or "bumped") as part of that commit.
  2808. For new recipes you should add the <filename>PR</filename>
  2809. variable and set its initial value equal to "r0", which is the default.
  2810. Even though the default value is "r0", the practice of adding it to a new recipe makes
  2811. it harder to forget to bump the variable when you make changes
  2812. to the recipe in future.
  2813. </para>
  2814. <para>
  2815. If you are sharing a common <filename>.inc</filename> file with multiple recipes,
  2816. you can also use the
  2817. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-INC_PR'>INC_PR</ulink></filename>
  2818. variable to ensure that
  2819. the recipes sharing the <filename>.inc</filename> file are rebuilt when the
  2820. <filename>.inc</filename> file itself is changed.
  2821. The <filename>.inc</filename> file must set <filename>INC_PR</filename>
  2822. (initially to "r0"), and all recipes referring to it should set <filename>PR</filename>
  2823. to "$(INC_PR).0" initially, incrementing the last number when the recipe is changed.
  2824. If the <filename>.inc</filename> file is changed then its
  2825. <filename>INC_PR</filename> should be incremented.
  2826. </para>
  2827. <para>
  2828. When upgrading the version of a package, assuming the
  2829. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'>PV</ulink></filename>
  2830. changes, the <filename>PR</filename> variable should be
  2831. reset to "r0" (or "$(INC_PR).0" if you are using
  2832. <filename>INC_PR</filename>).
  2833. </para>
  2834. <para>
  2835. Usually, version increases occur only to packages.
  2836. However, if for some reason <filename>PV</filename> changes but does not
  2837. increase, you can increase the
  2838. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PE'>PE</ulink></filename>
  2839. variable (Package Epoch).
  2840. The <filename>PE</filename> variable defaults to "0".
  2841. </para>
  2842. <para>
  2843. Version numbering strives to follow the
  2844. <ulink url='http://www.debian.org/doc/debian-policy/ch-controlfields.html'>
  2845. Debian Version Field Policy Guidelines</ulink>.
  2846. These guidelines define how versions are compared and what "increasing" a version means.
  2847. </para>
  2848. </section>
  2849. </section>
  2850. <section id="usingpoky-configuring-DISTRO_PN_ALIAS">
  2851. <title>Handling a Package Name Alias</title>
  2852. <para>
  2853. Sometimes a package name you are using might exist under an alias or as a similarly named
  2854. package in a different distribution.
  2855. The OpenEmbedded build system implements a <filename>distro_check</filename>
  2856. task that automatically connects to major distributions
  2857. and checks for these situations.
  2858. If the package exists under a different name in a different distribution, you get a
  2859. <filename>distro_check</filename> mismatch.
  2860. You can resolve this problem by defining a per-distro recipe name alias using the
  2861. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_PN_ALIAS'>DISTRO_PN_ALIAS</ulink></filename>
  2862. variable.
  2863. </para>
  2864. <para>
  2865. Following is an example that shows how you specify the <filename>DISTRO_PN_ALIAS</filename>
  2866. variable:
  2867. <literallayout class='monospaced'>
  2868. DISTRO_PN_ALIAS_pn-PACKAGENAME = "distro1=package_name_alias1 \
  2869. distro2=package_name_alias2 \
  2870. distro3=package_name_alias3 \
  2871. ..."
  2872. </literallayout>
  2873. </para>
  2874. <para>
  2875. If you have more than one distribution alias, separate them with a space.
  2876. Note that the build system currently automatically checks the
  2877. Fedora, OpenSUSE, Debian, Ubuntu,
  2878. and Mandriva distributions for source package recipes without having to specify them
  2879. using the <filename>DISTRO_PN_ALIAS</filename> variable.
  2880. For example, the following command generates a report that lists the Linux distributions
  2881. that include the sources for each of the recipes.
  2882. <literallayout class='monospaced'>
  2883. $ bitbake world -f -c distro_check
  2884. </literallayout>
  2885. The results are stored in the <filename>build/tmp/log/distro_check-${DATETIME}.results</filename>
  2886. file found in the
  2887. <link linkend='source-directory'>Source Directory</link>.
  2888. </para>
  2889. </section>
  2890. <section id='handling-optional-module-packaging'>
  2891. <title>Handling Optional Module Packaging</title>
  2892. <para>
  2893. Many pieces of software split functionality into optional
  2894. modules (or plugins) and the plugins that are built
  2895. might depend on configuration options.
  2896. To avoid having to duplicate the logic that determines what
  2897. modules are available in your recipe or to avoid having
  2898. to package each module by hand, the OpenEmbedded build system
  2899. provides functionality to handle module packaging dynamically.
  2900. </para>
  2901. <para>
  2902. To handle optional module packaging, you need to do two things:
  2903. <itemizedlist>
  2904. <listitem><para>Ensure the module packaging is actually
  2905. done</para></listitem>
  2906. <listitem><para>Ensure that any dependencies on optional
  2907. modules from other recipes are satisfied by your recipe
  2908. </para></listitem>
  2909. </itemizedlist>
  2910. </para>
  2911. <section id='making-sure-the-packaging-is-done'>
  2912. <title>Making Sure the Packaging is Done</title>
  2913. <para>
  2914. To ensure the module packaging actually gets done, you use
  2915. the <filename>do_split_packages</filename> function within
  2916. the <filename>populate_packages</filename> Python function
  2917. in your recipe.
  2918. The <filename>do_split_packages</filename> function
  2919. searches for a pattern of files or directories under a
  2920. specified path and creates a package for each one it finds
  2921. by appending to the
  2922. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
  2923. variable and setting the appropriate values for
  2924. <filename>FILES_packagename</filename>,
  2925. <filename>RDEPENDS_packagename</filename>,
  2926. <filename>DESCRIPTION_packagename</filename>, and so forth.
  2927. Here is an example from the <filename>lighttpd</filename>
  2928. recipe:
  2929. <literallayout class='monospaced'>
  2930. python populate_packages_prepend () {
  2931. lighttpd_libdir = d.expand('${libdir}')
  2932. do_split_packages(d, lighttpd_libdir, '^mod_(.*)\.so$',
  2933. 'lighttpd-module-%s', 'Lighttpd module for %s',
  2934. extra_depends='')
  2935. }
  2936. </literallayout>
  2937. The previous example specifies a number of things in the
  2938. call to <filename>do_split_packages</filename>.
  2939. <itemizedlist>
  2940. <listitem><para>A directory within the files installed
  2941. by your recipe through <filename>do_install</filename>
  2942. in which to search.</para></listitem>
  2943. <listitem><para>A regular expression to match module
  2944. files in that directory.
  2945. In the example, note the parentheses () that mark
  2946. the part of the expression from which the module
  2947. name should be derived.</para></listitem>
  2948. <listitem><para>A pattern to use for the package names.
  2949. </para></listitem>
  2950. <listitem><para>A description for each package.
  2951. </para></listitem>
  2952. <listitem><para>An empty string for
  2953. <filename>extra_depends</filename>, which disables
  2954. the default dependency on the main
  2955. <filename>lighttpd</filename> package.
  2956. Thus, if a file in <filename>${libdir}</filename>
  2957. called <filename>mod_alias.so</filename> is found,
  2958. a package called <filename>lighttpd-module-alias</filename>
  2959. is created for it and the
  2960. <ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
  2961. is set to "Lighttpd module for alias".</para></listitem>
  2962. </itemizedlist>
  2963. </para>
  2964. <para>
  2965. Often, packaging modules is as simple as the previous
  2966. example.
  2967. However, more advanced options exist that you can use
  2968. within <filename>do_split_packages</filename> to modify its
  2969. behavior.
  2970. And, if you need to, you can add more logic by specifying
  2971. a hook function that is called for each package.
  2972. It is also perfectly acceptable to call
  2973. <filename>do_split_packages</filename> multiple times if
  2974. you have more than one set of modules to package.
  2975. </para>
  2976. <para>
  2977. For more examples that show how to use
  2978. <filename>do_split_packages</filename>, see the
  2979. <filename>connman.inc</filename> file in the
  2980. <filename>meta/recipes-connectivity/connman/</filename>
  2981. directory of the <filename>poky</filename>
  2982. <link linkend='yocto-project-repositories'>source repository</link>.
  2983. You can also find examples in
  2984. <filename>meta/classes/kernel.bbclass</filename>.
  2985. </para>
  2986. <para>
  2987. Following is a reference that shows
  2988. <filename>do_split_packages</filename> mandatory and
  2989. optional arguments:
  2990. <literallayout class='monospaced'>
  2991. Mandatory arguments
  2992. root
  2993. The path in which to search
  2994. file_regex
  2995. Regular expression to match searched files.
  2996. Use parentheses () to mark the part of this
  2997. expression that should be used to derive the
  2998. module name (to be substituted where %s is
  2999. used in other function arguments as noted below)
  3000. output_pattern
  3001. Pattern to use for the package names. Must
  3002. include %s.
  3003. description
  3004. Description to set for each package. Must
  3005. include %s.
  3006. Optional arguments
  3007. postinst
  3008. Postinstall script to use for all packages
  3009. (as a string)
  3010. recursive
  3011. True to perform a recursive search - default
  3012. False
  3013. hook
  3014. A hook function to be called for every match.
  3015. The function will be called with the following
  3016. arguments (in the order listed):
  3017. f
  3018. Full path to the file/directory match
  3019. pkg
  3020. The package name
  3021. file_regex
  3022. As above
  3023. output_pattern
  3024. As above
  3025. modulename
  3026. The module name derived using file_regex
  3027. extra_depends
  3028. Extra runtime dependencies (RDEPENDS) to be
  3029. set for all packages. The default value of None
  3030. causes a dependency on the main package
  3031. (${PN}) - if you do not want this, pass empty
  3032. string '' for this parameter.
  3033. aux_files_pattern
  3034. Extra item(s) to be added to FILES for each
  3035. package. Can be a single string item or a list
  3036. of strings for multiple items. Must include %s.
  3037. postrm
  3038. postrm script to use for all packages (as a
  3039. string)
  3040. allow_dirs
  3041. True to allow directories to be matched -
  3042. default False
  3043. prepend
  3044. If True, prepend created packages to PACKAGES
  3045. instead of the default False which appends them
  3046. match_path
  3047. match file_regex on the whole relative path to
  3048. the root rather than just the file name
  3049. aux_files_pattern_verbatim
  3050. Extra item(s) to be added to FILES for each
  3051. package, using the actual derived module name
  3052. rather than converting it to something legal
  3053. for a package name. Can be a single string item
  3054. or a list of strings for multiple items. Must
  3055. include %s.
  3056. allow_links
  3057. True to allow symlinks to be matched - default
  3058. False
  3059. </literallayout>
  3060. </para>
  3061. </section>
  3062. <section id='satisfying-dependencies'>
  3063. <title>Satisfying Dependencies</title>
  3064. <para>
  3065. The second part for handling optional module packaging
  3066. is to ensure that any dependencies on optional modules
  3067. from other recipes are satisfied by your recipe.
  3068. You can be sure these dependencies are satisfied by
  3069. using the
  3070. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> variable.
  3071. Here is an example that continues with the
  3072. <filename>lighttpd</filename> recipe shown earlier:
  3073. <literallayout class='monospaced'>
  3074. PACKAGES_DYNAMIC = "lighttpd-module-.*"
  3075. </literallayout>
  3076. The name specified in the regular expression can of
  3077. course be anything.
  3078. In this example, it is <filename>lighttpd-module-</filename>
  3079. and is specified as the prefix to ensure that any
  3080. <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
  3081. and <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
  3082. on a package name starting with the prefix are satisfied
  3083. during build time.
  3084. If you are using <filename>do_split_packages</filename>
  3085. as described in the previous section, the value you put in
  3086. <filename>PACKAGES_DYNAMIC</filename> should correspond to
  3087. the name pattern specified in the call to
  3088. <filename>do_split_packages</filename>.
  3089. </para>
  3090. </section>
  3091. </section>
  3092. <section id='setting-up-runtime-package-management'>
  3093. <title>Setting Up Runtime Package Management</title>
  3094. <para>
  3095. For RPM, IPK, and DEB package formats, it is possible to set
  3096. up a repository that is a host-based
  3097. package feed from which you can install packages on the
  3098. target system during runtime.
  3099. Doing so is optional and depends on the following:
  3100. <itemizedlist>
  3101. <listitem><para>
  3102. You take specific steps to set up the feed.
  3103. </para></listitem>
  3104. <listitem><para>
  3105. When you build your image, you select to use the
  3106. appropriate package manager by setting the
  3107. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
  3108. variable.
  3109. </para></listitem>
  3110. <listitem><para>
  3111. You have a web server, such as Apache 2,
  3112. installed and configured on the development host.
  3113. </para></listitem>
  3114. <listitem><para>
  3115. You have <filename>createrepo</filename> installed on
  3116. the development host.
  3117. </para></listitem>
  3118. <listitem><para>
  3119. You enable package management on the target by
  3120. listing "package-management" in the
  3121. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
  3122. variable.
  3123. </para></listitem>
  3124. </itemizedlist>
  3125. </para>
  3126. <para>
  3127. Following are the steps to set up the optional repository.
  3128. This examples assumes you are using RPM and the Apache 2
  3129. server:
  3130. <orderedlist>
  3131. <listitem><para>
  3132. Add the directory to your Apache configuration, which
  3133. you can find at
  3134. <filename>/etc/httpd/conf/httpd.conf</filename>.
  3135. Use commands similar to these on the development system.
  3136. These example commands assume a top-level
  3137. <link linkend='source-directory'>Source Directory</link>
  3138. named <filename>poky</filename> in your home directory:
  3139. <literallayout class='monospaced'>
  3140. &lt;VirtualHost *:80&gt;
  3141. ....
  3142. Alias /rpm ~/poky/build/tmp/deploy/rpm
  3143. &lt;Directory "~/poky/build/tmp/deploy/rpm"&gt;
  3144. Options +Indexes
  3145. &lt;/Directory&gt;
  3146. &lt;/VirtualHost&gt;
  3147. </literallayout>
  3148. </para></listitem>
  3149. <listitem><para>
  3150. Reload the Apache configuration as follows.
  3151. For all commands, be sure you have root privileges.
  3152. </para>
  3153. <para>
  3154. If your development system is using Fedora or
  3155. CentOS, use the following:
  3156. <literallayout class='monospaced'>
  3157. service httpd reload
  3158. </literallayout>
  3159. For Ubuntu, use the following:
  3160. <literallayout class='monospaced'>
  3161. /etc/init.d/apache2 reload
  3162. </literallayout>
  3163. For OpenSUSE, use the following:
  3164. <literallayout class='monospaced'>
  3165. /etc/init.d/apache2 reload
  3166. </literallayout>
  3167. </para></listitem>
  3168. <listitem><para>
  3169. Change your working directory to
  3170. <filename>tmp/deploy/rpm</filename> in the
  3171. <link linkend='build-directory'>Build Directory</link>.
  3172. </para></listitem>
  3173. <listitem><para>
  3174. Create the repository data on the host using
  3175. this command:
  3176. <literallayout class='monospaced'>
  3177. createrepo .
  3178. </literallayout>
  3179. </para>
  3180. <para>
  3181. <note>
  3182. If you're updating, add
  3183. <filename>&dash;&dash;update</filename> to save some time.
  3184. </note>
  3185. </para></listitem>
  3186. <listitem><para>
  3187. If you are using Security-Enhanced Linux (SELinux),
  3188. you need to label the files as being accessible
  3189. through Apache.
  3190. Use the following command from the development host:
  3191. <literallayout class='monospaced'>
  3192. chcon -R -h -t httpd_sys_content_t .
  3193. </literallayout>
  3194. </para></listitem>
  3195. <listitem><para>
  3196. On the target machine, add the repository to Smart.
  3197. For <filename>somealias</filename>, provide a local
  3198. alias for the repository:
  3199. <literallayout class='monospaced'>
  3200. smart channel &dash;&dash;add &lt;somealias&gt; type=rpm-md baseurl=http://server.name/rpm
  3201. </literallayout>
  3202. </para></listitem>
  3203. <listitem><para>
  3204. Also from the target machine, fetch the repository
  3205. information using this command:
  3206. <literallayout class='monospaced'>
  3207. smart update
  3208. </literallayout>
  3209. </para></listitem>
  3210. </orderedlist>
  3211. </para>
  3212. <para>
  3213. After taking these steps and making sure that the other
  3214. requirements mentioned at the beginning of the section are met,
  3215. reboot the target device to take advantage of runtime package
  3216. installations.
  3217. </para>
  3218. <para>
  3219. If your packages are IPK, you can install packages onto an
  3220. existing running system by first sharing the
  3221. <filename>tmp/deploy/ipk/</filename> directory
  3222. through a web server and then by changing
  3223. <filename>/etc/opkg/base-feeds.conf</filename>
  3224. to point at the shared server.
  3225. Following is an example:
  3226. <literallayout class='monospaced'>
  3227. $ src/gz all http://www.mysite.com/somedir/deploy/ipk/all
  3228. $ src/gz armv7a http://www.mysite.com/somedir/deploy/ipk/armv7a
  3229. $ src/gz beagleboard http://www.mysite.com/somedir/deploy/ipk/beagleboard
  3230. </literallayout>
  3231. </para>
  3232. </section>
  3233. <section id='testing-packages-with-ptest'>
  3234. <title>Testing Packages With ptest</title>
  3235. <para>
  3236. A Package Test (ptest) runs tests against packages built
  3237. by the OpenEmbedded build system on the target machine.
  3238. A ptest contains at least two items: the actual test, and
  3239. a shell script (<filename>run-ptest</filename>) that starts
  3240. the test.
  3241. The shell script that starts the test must not contain
  3242. the actual test, the script only starts it.
  3243. On the other hand, the test can be anything from a simple
  3244. shell script that runs a binary and checks the output to
  3245. an elaborate system of test binaries and data files.
  3246. </para>
  3247. <para>
  3248. The test generates output in the format used by
  3249. Automake:
  3250. <literallayout class='monospaced'>
  3251. &lt;result&gt;: &lt;testname&gt;
  3252. </literallayout>
  3253. where the result can be <filename>PASS</filename>,
  3254. <filename>FAIL</filename>, or <filename>SKIP</filename>,
  3255. and the testname can be any identifying string.
  3256. </para>
  3257. <note>
  3258. With this release of the Yocto Project, three recipes exist
  3259. that are "ptest-enabled": <filename>bash</filename>,
  3260. <filename>glib-2.0</filename>, and
  3261. <filename>dbus</filename>.
  3262. These three recipes are Autotool-enabled.
  3263. </note>
  3264. <section id='adding-ptest-to-your-build'>
  3265. <title>Adding ptest to Your Build</title>
  3266. <para>
  3267. To add package testing to your build, add the
  3268. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
  3269. and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
  3270. variables to your <filename>local.conf</filename> file,
  3271. which is found in the
  3272. <link linkend='build-directory'>Build Directory</link>:
  3273. <literallayout class='monospaced'>
  3274. DISTRO_FEATURES_append = " ptest"
  3275. EXTRA_IMAGE_FEATURES += "ptest-pkgs"
  3276. </literallayout>
  3277. Once your build is complete, the ptest files are installed
  3278. into the <filename>/usr/lib/&lt;package&gt;/ptest</filename>
  3279. directory within the image, where
  3280. <filename>&lt;package&gt;</filename> is the name of the
  3281. package.
  3282. </para>
  3283. </section>
  3284. <section id='running-ptest'>
  3285. <title>Running ptest</title>
  3286. <para>
  3287. The <filename>ptest-runner</filename> package installs a
  3288. shell script that loops through all installed ptest test
  3289. suites and runs them in sequence.
  3290. Consequently, you might want to add this package to
  3291. your image.
  3292. </para>
  3293. </section>
  3294. <section id='getting-your-package-ready'>
  3295. <title>Getting Your Package Ready</title>
  3296. <para>
  3297. In order to enable a recipe to run installed ptests
  3298. on target hardware,
  3299. you need to prepare the recipes that build the packages
  3300. you want to test.
  3301. Here is what you have to do for each recipe:
  3302. <itemizedlist>
  3303. <listitem><para><emphasis>Be sure the recipe
  3304. inherits ptest:</emphasis>
  3305. Include the following line in each recipe:
  3306. <literallayout class='monospaced'>
  3307. inherit ptest
  3308. </literallayout>
  3309. </para></listitem>
  3310. <listitem><para><emphasis>Create <filename>run-ptest</filename>:</emphasis>
  3311. This script starts your test.
  3312. Locate the script where you will refer to it
  3313. using
  3314. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
  3315. Here is an example that starts a test for
  3316. <filename>dbus</filename>:
  3317. <literallayout class='monospaced'>
  3318. #!/bin/sh
  3319. cd test
  3320. make -k runtest-TESTS
  3321. </literallayout>
  3322. </para></listitem>
  3323. <listitem><para><emphasis>Ensure dependencies are
  3324. met:</emphasis>
  3325. If the test adds build or runtime dependencies
  3326. that normally do not exist for the package
  3327. (such as requiring "make" to run the test suite),
  3328. use the
  3329. <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
  3330. and
  3331. <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
  3332. variables in your recipe in order for the package
  3333. to meet the dependencies.
  3334. Here is an example where the package has a runtime
  3335. dependency on "make":
  3336. <literallayout class='monospaced'>
  3337. RDEPENDS_${PN}-ptest += "make"
  3338. </literallayout>
  3339. </para></listitem>
  3340. <listitem><para><emphasis>Add a function to build the
  3341. test suite:</emphasis>
  3342. Not many packages support cross-compilation of
  3343. their test suites.
  3344. Consequently, you usually need to add a
  3345. cross-compilation function to the package.
  3346. </para>
  3347. <para>Many packages based on Automake compile and
  3348. run the test suite by using a single command
  3349. such as <filename>make check</filename>.
  3350. However, the native <filename>make check</filename>
  3351. builds and runs on the same computer, while
  3352. cross-compiling requires that the package is built
  3353. on the host but executed on the target.
  3354. The built version of Automake that ships with the
  3355. Yocto Project includes a patch that separates
  3356. building and execution.
  3357. Consequently, packages that use the unaltered,
  3358. patched version of <filename>make check</filename>
  3359. automatically cross-compiles.</para>
  3360. <para>However, you still must add a
  3361. <filename>do_compile_ptest</filename> function to
  3362. build the test suite.
  3363. Add a function similar to the following to your
  3364. recipe:
  3365. <literallayout class='monospaced'>
  3366. do_compile_ptest() {
  3367. oe_runmake buildtest-TESTS
  3368. }
  3369. </literallayout>
  3370. </para></listitem>
  3371. <listitem><para><emphasis>Ensure special configurations
  3372. are set:</emphasis>
  3373. If the package requires special configurations
  3374. prior to compiling the test code, you must
  3375. insert a <filename>do_configure_ptest</filename>
  3376. function into the recipe.
  3377. </para></listitem>
  3378. <listitem><para><emphasis>Install the test
  3379. suite:</emphasis>
  3380. The <filename>ptest.bbclass</filename> class
  3381. automatically copies the file
  3382. <filename>run-ptest</filename> to the target and
  3383. then runs make <filename>install-ptest</filename>
  3384. to run the tests.
  3385. If this is not enough, you need to create a
  3386. <filename>do_install_ptest</filename> function and
  3387. make sure it gets called after the
  3388. "make install-ptest" completes.
  3389. </para></listitem>
  3390. </itemizedlist>
  3391. </para>
  3392. </section>
  3393. </section>
  3394. </section>
  3395. <section id="building-software-from-an-external-source">
  3396. <title>Building Software from an External Source</title>
  3397. <para>
  3398. By default, the OpenEmbedded build system does its work from within the
  3399. <link linkend='build-directory'>Build Directory</link>.
  3400. The build process involves fetching the source files, unpacking them, and then patching them
  3401. if necessary before the build takes place.
  3402. </para>
  3403. <para>
  3404. Situations exist where you might want to build software from source files that are external to
  3405. and thus outside of the <link linkend='source-directory'>Source Directory</link>.
  3406. For example, suppose you have a project that includes a new BSP with a heavily customized
  3407. kernel, a very minimal image, and some new user-space recipes.
  3408. And, you want to minimize exposing the build system to the
  3409. development team so that they can focus on their project and maintain everyone's workflow
  3410. as much as possible.
  3411. In this case, you want a kernel source directory on the development machine where the
  3412. development occurs.
  3413. You want the recipe's
  3414. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  3415. variable to point to the external directory and use it as is, not copy it.
  3416. </para>
  3417. <para>
  3418. To build from software that comes from an external source, all you need to do is
  3419. change your recipe so that it inherits the
  3420. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc.bbclass</filename></ulink>
  3421. class and then sets the
  3422. <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
  3423. variable to point to your external source code.
  3424. Here are the statements to put in your recipe:
  3425. <literallayout class='monospaced'>
  3426. inherit externalsrc
  3427. S = "/some/path/to/your/package/source"
  3428. </literallayout>
  3429. </para>
  3430. <para>
  3431. It is important to know that the <filename>externalsrc.bbclass</filename> assumes that the
  3432. source directory <filename>S</filename> and the Build Directory
  3433. <ulink url='&YOCTO_DOCS_REF_URL;#var-B'><filename>B</filename></ulink>
  3434. are different even though these directories are the same by default.
  3435. This assumption is important because it supports building different variants of the recipe
  3436. by using the
  3437. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></ulink>
  3438. variable.
  3439. You could allow the Build Directory to be the same as the source directory but you would
  3440. not be able to build more than one variant of the recipe.
  3441. Consequently, if you are building multiple variants of the recipe, you need to establish a
  3442. Build Directory that is different than the Source Directory.
  3443. </para>
  3444. </section>
  3445. <section id="selecting-an-initialization-manager">
  3446. <title>Selecting an Initialization Manager</title>
  3447. <para>
  3448. By default, the Yocto Project uses
  3449. <filename>SysVinit</filename> as the initialization manager.
  3450. However, support also exists for <filename>systemd</filename>,
  3451. which is a full replacement for <filename>init</filename> with
  3452. parallel starting of services, reduced shell overhead and other
  3453. features that are used by many distributions.
  3454. </para>
  3455. <para>
  3456. If you want to use <filename>SysVinit</filename>, you do
  3457. not have to do anything.
  3458. But, if you want to use <filename>systemd</filename>, you must
  3459. take some steps as described in the following sections.
  3460. </para>
  3461. <note>
  3462. It is recommended that you create your own distribution configuration
  3463. file to hold these settings instead of using your
  3464. <filename>local.conf</filename> file.
  3465. For information on creating your own distribution, see the
  3466. "<link linkend='creating-your-own-distribution'>Creating Your Own Distribution</link>"
  3467. section.
  3468. </note>
  3469. <section id='using-systemd-exclusively'>
  3470. <title>Using systemd Exclusively</title>
  3471. <para>
  3472. Set the following variables in your distribution configuration
  3473. file as follows:
  3474. <literallayout class='monospaced'>
  3475. DISTRO_FEATURES_append = " systemd"
  3476. VIRTUAL-RUNTIME_init_manager = "systemd"
  3477. </literallayout>
  3478. You can also prevent the <filename>sysvinit</filename>
  3479. distribution feature from
  3480. being automatically enabled as follows:
  3481. <literallayout class='monospaced'>
  3482. DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
  3483. </literallayout>
  3484. Doing so removes any redundant <filename>sysvinit</filename>
  3485. scripts.
  3486. </para>
  3487. </section>
  3488. <section id='using-systemd-for-the-main-image-and-using-sysvinit-for-the-rescue-image'>
  3489. <title>Using systemd for the Main Image and Using SysVinit for the Rescue Image</title>
  3490. <para>
  3491. Set the following variables in your distribution configuration
  3492. file as follows:
  3493. <literallayout class='monospaced'>
  3494. DISTRO_FEATURES_append = " systemd"
  3495. VIRTUAL-RUNTIME_init_manager = "systemd"
  3496. </literallayout>
  3497. Doing so causes your main image to use the
  3498. <filename>packagegroup-core-boot.bb</filename> recipe and
  3499. <filename>systemd</filename>.
  3500. The rescue/minimal image cannot use this package group.
  3501. However, it can install <filename>sysvinit</filename>
  3502. and the appropriate packages will have support for both
  3503. <filename>systemd</filename> and <filename>sysvinit</filename>.
  3504. </para>
  3505. </section>
  3506. </section>
  3507. <section id='excluding-recipes-from-the-build'>
  3508. <title>Excluding Recipes From the Build</title>
  3509. <para>
  3510. You might find that there are groups of recipes or append files
  3511. that you want to filter out of the build process.
  3512. Usually, this is not necessary.
  3513. However, on rare occasions where you might want to use a
  3514. layer but exclude parts that are causing problems, such
  3515. as introducing a different version of a recipe, you can
  3516. use
  3517. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBMASK'><filename>BBMASK</filename></ulink>
  3518. to exclude the recipe.
  3519. </para>
  3520. <para>
  3521. It is possible to filter or mask out <filename>.bb</filename> and
  3522. <filename>.bbappend</filename> files.
  3523. You can do this by providing an expression with the
  3524. <filename>BBMASK</filename> variable.
  3525. Here is an example:
  3526. <literallayout class='monospaced'>
  3527. BBMASK = "/meta-mymachine/recipes-maybe/"
  3528. </literallayout>
  3529. Here, all <filename>.bb</filename> and
  3530. <filename>.bbappend</filename> files in the directory that match
  3531. the expression are ignored during the build process.
  3532. </para>
  3533. <note>
  3534. The value you provide is passed to Python's regular expression
  3535. compiler.
  3536. The expression is compared against the full paths to the files.
  3537. For complete syntax information, see Python's documentation at
  3538. <ulink url='http://docs.python.org/release/2.3/lib/re-syntax.html'></ulink>.
  3539. </note>
  3540. </section>
  3541. <section id="platdev-appdev-srcrev">
  3542. <title>Using an External SCM</title>
  3543. <para>
  3544. If you're working on a recipe that pulls from an external Source Code Manager (SCM), it
  3545. is possible to have the OpenEmbedded build system notice new recipe changes added to the
  3546. SCM and then build the resulting package that depends on the new recipes by using the latest
  3547. versions.
  3548. This only works for SCMs from which it is possible to get a sensible revision number for changes.
  3549. Currently, you can do this with Apache Subversion (SVN), Git, and Bazaar (BZR) repositories.
  3550. </para>
  3551. <para>
  3552. To enable this behavior, simply add the following to the <filename>local.conf</filename>
  3553. configuration file found in the
  3554. <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>:
  3555. <literallayout class='monospaced'>
  3556. SRCREV_pn-&lt;PN&gt; = "${AUTOREV}"
  3557. </literallayout>
  3558. where <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
  3559. is the name of the recipe for which you want to enable automatic source
  3560. revision updating.
  3561. </para>
  3562. </section>
  3563. <section id='creating-a-read-only-root-filesystem'>
  3564. <title>Creating a Read-Only Root Filesystem</title>
  3565. <para>
  3566. Suppose, for security reasons, you need to disable
  3567. your target device's root filesystem's write permissions
  3568. (i.e. you need a read-only root filesystem).
  3569. Or, perhaps you are running the device's operating system
  3570. from a read-only storage device.
  3571. For either case, you can customize your image for
  3572. that behavior.
  3573. </para>
  3574. <note>
  3575. Supporting a read-only root filesystem requires that the system and
  3576. applications do not try to write to the root filesystem.
  3577. You must configure all parts of the target system to write
  3578. elsewhere, or to gracefully fail in the event of failing to
  3579. write to the root filesystem.
  3580. </note>
  3581. <section id='creating-the-root-filesystem'>
  3582. <title>Creating the Root Filesystem</title>
  3583. <para>
  3584. To create the read-only root filesystem, simply add the
  3585. <filename>read-only-rootfs</filename> feature to your image.
  3586. Using either of the following statements in your
  3587. image recipe or from within the
  3588. <filename>local.conf</filename> file found in the
  3589. <link linkend='build-directory'>Build Directory</link>
  3590. causes the build system to create a read-only root filesystem:
  3591. <literallayout class='monospaced'>
  3592. IMAGE_FEATURES = "read-only-rootfs"
  3593. </literallayout>
  3594. or
  3595. <literallayout class='monospaced'>
  3596. EXTRA_IMAGE_FEATURES = "read-only-rootfs"
  3597. </literallayout>
  3598. </para>
  3599. <para>
  3600. For more information on how to use these variables, see the
  3601. "<link linkend='usingpoky-extend-customimage-imagefeatures'>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and <filename>EXTRA_IMAGE_FEATURES</filename></link>"
  3602. section.
  3603. For information on the variables, see
  3604. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
  3605. and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>.
  3606. </para>
  3607. </section>
  3608. <section id='post-installation-scripts'>
  3609. <title>Post-Installation Scripts</title>
  3610. <para>
  3611. It is very important that you make sure all
  3612. post-Installation (<filename>pkg_postinst</filename>) scripts
  3613. for packages that are installed into the image can be run
  3614. at the time when the root filesystem is created during the
  3615. build on the host system.
  3616. These scripts cannot attempt to run during first-boot on the
  3617. target device.
  3618. With the <filename>read-only-rootfs</filename> feature enabled,
  3619. the build system checks during root filesystem creation to make
  3620. sure all post-installation scripts succeed.
  3621. If any of these scripts still need to be run after the root
  3622. filesystem is created, the build immediately fails.
  3623. These checks during build time ensure that the build fails
  3624. rather than the target device fails later during its
  3625. initial boot operation.
  3626. </para>
  3627. <para>
  3628. Most of the common post-installation scripts generated by the
  3629. build system for the out-of-the-box Yocto Project are engineered
  3630. so that they can run during root filesystem creation
  3631. (e.g. post-installation scripts for caching fonts).
  3632. However, if you create and add custom scripts, you need
  3633. to be sure they can be run during file system creation.
  3634. </para>
  3635. <para>
  3636. Here are some common problems that prevent
  3637. post-installation scripts from running during root filesystem
  3638. creation:
  3639. <itemizedlist>
  3640. <listitem><para><emphasis>Not using $D in front of absolute paths:</emphasis>
  3641. The build system defines
  3642. <filename>$</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
  3643. at root filesystem creation time, and
  3644. it is blank when run on the target device.
  3645. This implies two purposes for <filename>$D</filename>:
  3646. ensuring paths are valid in both the host and target
  3647. environments, and checking to determine which
  3648. environment is being used as a method for taking
  3649. appropriate actions.
  3650. </para></listitem>
  3651. <listitem><para><emphasis>Attempting to run processes that are
  3652. specific to or dependent on the target
  3653. architecture:</emphasis>
  3654. You can work around these attempts by using native
  3655. tools to accomplish the same tasks, or
  3656. by alternatively running the processes under QEMU,
  3657. which has the <filename>qemu_run_binary</filename>
  3658. function.
  3659. For more information, see the
  3660. <filename>meta/classes/qemu.bbclass</filename>
  3661. class in the
  3662. <link linkend='source-directory'>Source Directory</link>.
  3663. </para></listitem>
  3664. </itemizedlist>
  3665. </para>
  3666. </section>
  3667. <section id='areas-with-write-access'>
  3668. <title>Areas With Write Access</title>
  3669. <para>
  3670. With the <filename>read-only-rootfs</filename> feature enabled,
  3671. any attempt by the target to write to the root filesystem at
  3672. runtime fails.
  3673. Consequently, you must make sure that you configure processes
  3674. and applications that attempt these types of writes do so
  3675. to directories with write access (e.g.
  3676. <filename>/tmp</filename> or <filename>/var/run</filename>).
  3677. </para>
  3678. </section>
  3679. </section>
  3680. <section id="platdev-gdb-remotedebug">
  3681. <title>Debugging With the GNU Project Debugger (GDB) Remotely</title>
  3682. <para>
  3683. GDB allows you to examine running programs, which in turn helps you to understand and fix problems.
  3684. It also allows you to perform post-mortem style analysis of program crashes.
  3685. GDB is available as a package within the Yocto Project and is
  3686. installed in SDK images by default.
  3687. See the "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>" chapter
  3688. in the Yocto Project Reference Manual for a description of these images.
  3689. You can find information on GDB at <ulink url="http://sourceware.org/gdb/"/>.
  3690. </para>
  3691. <tip>
  3692. For best results, install <filename>-dbg</filename> packages for
  3693. the applications you are going to debug.
  3694. Doing so makes extra debug symbols available that give you more
  3695. meaningful output.
  3696. </tip>
  3697. <para>
  3698. Sometimes, due to memory or disk space constraints, it is not possible
  3699. to use GDB directly on the remote target to debug applications.
  3700. These constraints arise because GDB needs to load the debugging information and the
  3701. binaries of the process being debugged.
  3702. Additionally, GDB needs to perform many computations to locate information such as function
  3703. names, variable names and values, stack traces and so forth - even before starting the
  3704. debugging process.
  3705. These extra computations place more load on the target system and can alter the
  3706. characteristics of the program being debugged.
  3707. </para>
  3708. <para>
  3709. To help get past the previously mentioned constraints, you can use Gdbserver.
  3710. Gdbserver runs on the remote target and does not load any debugging information
  3711. from the debugged process.
  3712. Instead, a GDB instance processes the debugging information that is run on a
  3713. remote computer - the host GDB.
  3714. The host GDB then sends control commands to Gdbserver to make it stop or start the debugged
  3715. program, as well as read or write memory regions of that debugged program.
  3716. All the debugging information loaded and processed as well
  3717. as all the heavy debugging is done by the host GDB.
  3718. Offloading these processes gives the Gdbserver running on the target a chance to remain
  3719. small and fast.
  3720. </para>
  3721. <para>
  3722. Because the host GDB is responsible for loading the debugging information and
  3723. for doing the necessary processing to make actual debugging happen, the
  3724. user has to make sure the host can access the unstripped binaries complete
  3725. with their debugging information and also be sure the target is compiled with no optimizations.
  3726. The host GDB must also have local access to all the libraries used by the
  3727. debugged program.
  3728. Because Gdbserver does not need any local debugging information, the binaries on
  3729. the remote target can remain stripped.
  3730. However, the binaries must also be compiled without optimization
  3731. so they match the host's binaries.
  3732. </para>
  3733. <para>
  3734. To remain consistent with GDB documentation and terminology, the binary being debugged
  3735. on the remote target machine is referred to as the "inferior" binary.
  3736. For documentation on GDB see the
  3737. <ulink url="http://sourceware.org/gdb/documentation/">GDB site</ulink>.
  3738. </para>
  3739. <para>
  3740. The remainder of this section describes the steps you need to take
  3741. to debug using the GNU project debugger.
  3742. </para>
  3743. <section id='platdev-gdb-remotedebug-setup'>
  3744. <title>Set Up the Cross-Development Debugging Environment</title>
  3745. <para>
  3746. Before you can initiate a remote debugging session, you need
  3747. to be sure you have set up the cross-development environment,
  3748. toolchain, and sysroot.
  3749. The "<ulink url='&YOCTO_DOCS_ADT_URL;#adt-prepare'>Preparing for Application Development</ulink>"
  3750. chapter of the Yocto Project Application Developer's Guide
  3751. describes this process.
  3752. Be sure you have read that chapter and have set up
  3753. your environment.
  3754. </para>
  3755. </section>
  3756. <section id="platdev-gdb-remotedebug-launch-gdbserver">
  3757. <title>Launch Gdbserver on the Target</title>
  3758. <para>
  3759. Make sure Gdbserver is installed on the target.
  3760. If it is not, install the package
  3761. <filename>gdbserver</filename>, which needs the
  3762. <filename>libthread-db1</filename> package.
  3763. </para>
  3764. <para>
  3765. Here is an example that when entered from the host
  3766. connects to the target and launches Gdbserver in order to
  3767. "debug" a binary named <filename>helloworld</filename>:
  3768. <literallayout class='monospaced'>
  3769. $ gdbserver localhost:2345 /usr/bin/helloworld
  3770. </literallayout>
  3771. Gdbserver should now be listening on port 2345 for debugging
  3772. commands coming from a remote GDB process that is running on
  3773. the host computer.
  3774. Communication between Gdbserver and the host GDB are done
  3775. using TCP.
  3776. To use other communication protocols, please refer to the
  3777. <ulink url='http://www.gnu.org/software/gdb/'>Gdbserver documentation</ulink>.
  3778. </para>
  3779. </section>
  3780. <section id="platdev-gdb-remotedebug-launch-gdb">
  3781. <title>Launch GDB on the Host Computer</title>
  3782. <para>
  3783. Running GDB on the host computer takes a number of stages, which
  3784. this section describes.
  3785. </para>
  3786. <section id="platdev-gdb-remotedebug-launch-gdb-buildcross">
  3787. <title>Build the Cross-GDB Package</title>
  3788. <para>
  3789. A suitable GDB cross-binary is required that runs on your
  3790. host computer but also knows about the the ABI of the
  3791. remote target.
  3792. You can get this binary from the
  3793. <link linkend='cross-development-toolchain'>Cross-Development Toolchain</link>.
  3794. Here is an example where the toolchain has been installed
  3795. in the default directory
  3796. <filename>/opt/poky/&DISTRO;</filename>:
  3797. <literallayout class='monospaced'>
  3798. /opt/poky/1.4/sysroots/i686-pokysdk-linux/usr/bin/armv7a-vfp-neon-poky-linux-gnueabi/arm-poky-linux-gnueabi-gdb
  3799. </literallayout>
  3800. where <filename>arm</filename> is the target architecture
  3801. and <filename>linux-gnueabi</filename> is the target ABI.
  3802. </para>
  3803. <para>
  3804. Alternatively, you can use BitBake to build the
  3805. <filename>gdb-cross</filename> binary.
  3806. Here is an example:
  3807. <literallayout class='monospaced'>
  3808. $ bitbake gdb-cross
  3809. </literallayout>
  3810. Once the binary is built, you can find it here:
  3811. <literallayout class='monospaced'>
  3812. tmp/sysroots/&lt;host-arch&gt;/usr/bin/&lt;target-platform&gt;/&lt;target-abi&gt;-gdb
  3813. </literallayout>
  3814. </para>
  3815. </section>
  3816. <section id='create-the-gdb-initialization-file'>
  3817. <title>Create the GDB Initialization File and Point to Your Root Filesystem</title>
  3818. <para>
  3819. Aside from the GDB cross-binary, you also need a GDB
  3820. initialization file in the same top directory in which
  3821. your binary resides.
  3822. When you start GDB on your host development system, GDB
  3823. finds this initialization file and executes all the
  3824. commands within.
  3825. For information on the <filename>.gdbinit</filename>, see
  3826. "<ulink url='http://sourceware.org/gdb/onlinedocs/gdb/'>Debugging with GDB</ulink>",
  3827. which is maintained by
  3828. <ulink url='http://www.sourceware.org'>sourceware.org</ulink>.
  3829. </para>
  3830. <para>
  3831. You need to add a statement in the
  3832. <filename>.gdbinit</filename> file that points to your
  3833. root filesystem.
  3834. Here is an example that points to the root filesystem for
  3835. an ARM-based target device:
  3836. <literallayout class='monospaced'>
  3837. set sysroot /home/jzhang/sysroot_arm
  3838. </literallayout>
  3839. </para>
  3840. </section>
  3841. <section id="platdev-gdb-remotedebug-launch-gdb-launchhost">
  3842. <title>Launch the Host GDB</title>
  3843. <para>
  3844. Before launching the host GDB, you need to be sure
  3845. you have sourced the cross-debugging environment script,
  3846. which if you installed the root filesystem in the default
  3847. location is at <filename>/opt/poky/&DISTRO;</filename>
  3848. and begins with the string "environment-setup".
  3849. For more information, see the
  3850. "<ulink url='&YOCTO_DOCS_ADT_URL;#setting-up-the-cross-development-environment'>Setting Up the Cross-Development Environment</ulink>"
  3851. section in the Yocto Project Application Developer's
  3852. Guide.
  3853. </para>
  3854. <para>
  3855. Finally, switch to the directory where the binary resides
  3856. and run the <filename>cross-gdb</filename> binary.
  3857. Provide the binary file you are going to debug.
  3858. For example, the following command continues with the
  3859. example used in the previous section by loading
  3860. the <filename>helloworld</filename> binary as well as the
  3861. debugging information:
  3862. <literallayout class='monospaced'>
  3863. $ arm-poky-linux-gnuabi-gdb helloworld
  3864. </literallayout>
  3865. The commands in your <filename>.gdbinit</filename> execute
  3866. and the GDB prompt appears.
  3867. </para>
  3868. </section>
  3869. </section>
  3870. <section id='platdev-gdb-connect-to-the-remote-gdb-server'>
  3871. <title>Connect to the Remote GDB Server</title>
  3872. <para>
  3873. From the target, you need to connect to the remote GDB
  3874. server that is running on the host.
  3875. You need to specify the remote host and port.
  3876. Here is the command continuing with the example:
  3877. <literallayout class='monospaced'>
  3878. target remote 192.168.7.2:2345
  3879. </literallayout>
  3880. </para>
  3881. </section>
  3882. <section id="platdev-gdb-remotedebug-launch-gdb-using">
  3883. <title>Use the Debugger</title>
  3884. <para>
  3885. You can now proceed with debugging as normal - as if you were debugging
  3886. on the local machine.
  3887. For example, to instruct GDB to break in the "main" function and then
  3888. continue with execution of the inferior binary use the following commands
  3889. from within GDB:
  3890. <literallayout class='monospaced'>
  3891. (gdb) break main
  3892. (gdb) continue
  3893. </literallayout>
  3894. </para>
  3895. <para>
  3896. For more information about using GDB, see the project's online documentation at
  3897. <ulink url="http://sourceware.org/gdb/download/onlinedocs/"/>.
  3898. </para>
  3899. </section>
  3900. </section>
  3901. <section id="platdev-oprofile">
  3902. <title>Profiling with OProfile</title>
  3903. <para>
  3904. <ulink url="http://oprofile.sourceforge.net/">OProfile</ulink> is a
  3905. statistical profiler well suited for finding performance
  3906. bottlenecks in both user-space software and in the kernel.
  3907. This profiler provides answers to questions like "Which functions does my application spend
  3908. the most time in when doing X?"
  3909. Because the OpenEmbedded build system is well integrated with OProfile, it makes profiling
  3910. applications on target hardware straightforward.
  3911. <note>
  3912. For more information on how to set up and run OProfile, see the
  3913. "<ulink url='&YOCTO_DOCS_PROF_URL;#profile-manual-oprofile'>OProfile</ulink>"
  3914. section in the Yocto Project Profiling and Tracing Manual.
  3915. </note>
  3916. </para>
  3917. <para>
  3918. To use OProfile, you need an image that has OProfile installed.
  3919. The easiest way to do this is with <filename>tools-profile</filename> in the
  3920. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'>IMAGE_FEATURES</ulink></filename> variable.
  3921. You also need debugging symbols to be available on the system where the analysis
  3922. takes place.
  3923. You can gain access to the symbols by using <filename>dbg-pkgs</filename> in the
  3924. <filename>IMAGE_FEATURES</filename> variable or by
  3925. installing the appropriate <filename>-dbg</filename> packages.
  3926. </para>
  3927. <para>
  3928. For successful call graph analysis, the binaries must preserve the frame
  3929. pointer register and should also be compiled with the
  3930. <filename>-fno-omit-framepointer</filename> flag.
  3931. You can achieve this by setting the
  3932. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SELECTED_OPTIMIZATION'>SELECTED_OPTIMIZATION</ulink></filename>
  3933. variable with the following options:
  3934. <literallayout class='monospaced'>
  3935. -fexpensive-optimizations
  3936. -fno-omit-framepointer
  3937. -frename-registers
  3938. -O2
  3939. </literallayout>
  3940. You can also achieve it by setting the
  3941. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-DEBUG_BUILD'>DEBUG_BUILD</ulink></filename>
  3942. variable to "1" in the <filename>local.conf</filename> configuration file.
  3943. If you use the <filename>DEBUG_BUILD</filename> variable,
  3944. you also add extra debugging information that can make the debug
  3945. packages large.
  3946. </para>
  3947. <section id="platdev-oprofile-target">
  3948. <title>Profiling on the Target</title>
  3949. <para>
  3950. Using OProfile you can perform all the profiling work on the target device.
  3951. A simple OProfile session might look like the following:
  3952. </para>
  3953. <para>
  3954. <literallayout class='monospaced'>
  3955. # opcontrol --reset
  3956. # opcontrol --start --separate=lib --no-vmlinux -c 5
  3957. .
  3958. .
  3959. [do whatever is being profiled]
  3960. .
  3961. .
  3962. # opcontrol --stop
  3963. $ opreport -cl
  3964. </literallayout>
  3965. </para>
  3966. <para>
  3967. In this example, the <filename>reset</filename> command clears any previously profiled data.
  3968. The next command starts OProfile.
  3969. The options used when starting the profiler separate dynamic library data
  3970. within applications, disable kernel profiling, and enable callgraphing up to
  3971. five levels deep.
  3972. <note>
  3973. To profile the kernel, you would specify the
  3974. <filename>--vmlinux=/path/to/vmlinux</filename> option.
  3975. The <filename>vmlinux</filename> file is usually in the source directory in the
  3976. <filename>/boot/</filename> directory and must match the running kernel.
  3977. </note>
  3978. </para>
  3979. <para>
  3980. After you perform your profiling tasks, the next command stops the profiler.
  3981. After that, you can view results with the <filename>opreport</filename> command with options
  3982. to see the separate library symbols and callgraph information.
  3983. </para>
  3984. <para>
  3985. Callgraphing logs information about time spent in functions and about a function's
  3986. calling function (parent) and called functions (children).
  3987. The higher the callgraphing depth, the more accurate the results.
  3988. However, higher depths also increase the logging overhead.
  3989. Consequently, you should take care when setting the callgraphing depth.
  3990. <note>
  3991. On ARM, binaries need to have the frame pointer enabled for callgraphing to work.
  3992. To accomplish this use the <filename>-fno-omit-framepointer</filename> option
  3993. with <filename>gcc</filename>.
  3994. </note>
  3995. </para>
  3996. <para>
  3997. For more information on using OProfile, see the OProfile
  3998. online documentation at
  3999. <ulink url="http://oprofile.sourceforge.net/docs/"/>.
  4000. </para>
  4001. </section>
  4002. <section id="platdev-oprofile-oprofileui">
  4003. <title>Using OProfileUI</title>
  4004. <para>
  4005. A graphical user interface for OProfile is also available.
  4006. You can download and build this interface from the Yocto Project at
  4007. <ulink url="&YOCTO_GIT_URL;/cgit.cgi/oprofileui/"></ulink>.
  4008. If the "tools-profile" image feature is selected, all necessary binaries
  4009. are installed onto the target device for OProfileUI interaction.
  4010. For a list of image features that ship with the Yocto Project,
  4011. see the
  4012. "<ulink url='&YOCTO_DOCS_REF_URL;#ref-features-image'>Images</ulink>"
  4013. section in the Yocto Project Reference Manual.
  4014. </para>
  4015. <para>
  4016. Even though the source directory usually includes all needed patches on the target device, you
  4017. might find you need other OProfile patches for recent OProfileUI features.
  4018. If so, see the <ulink url='&YOCTO_GIT_URL;/cgit.cgi/oprofileui/tree/README'>
  4019. OProfileUI README</ulink> for the most recent information.
  4020. </para>
  4021. <section id="platdev-oprofile-oprofileui-online">
  4022. <title>Online Mode</title>
  4023. <para>
  4024. Using OProfile in online mode assumes a working network connection with the target
  4025. hardware.
  4026. With this connection, you just need to run "oprofile-server" on the device.
  4027. By default, OProfile listens on port 4224.
  4028. <note>
  4029. You can change the port using the <filename>--port</filename> command-line
  4030. option.
  4031. </note>
  4032. </para>
  4033. <para>
  4034. The client program is called <filename>oprofile-viewer</filename> and its UI is relatively
  4035. straightforward.
  4036. You access key functionality through the buttons on the toolbar, which
  4037. are duplicated in the menus.
  4038. Here are the buttons:
  4039. <itemizedlist>
  4040. <listitem><para><emphasis>Connect:</emphasis> Connects to the remote host.
  4041. You can also supply the IP address or hostname.</para></listitem>
  4042. <listitem><para><emphasis>Disconnect:</emphasis> Disconnects from the target.
  4043. </para></listitem>
  4044. <listitem><para><emphasis>Start:</emphasis> Starts profiling on the device.
  4045. </para></listitem>
  4046. <listitem><para><emphasis>Stop:</emphasis> Stops profiling on the device and
  4047. downloads the data to the local host.
  4048. Stopping the profiler generates the profile and displays it in the viewer.
  4049. </para></listitem>
  4050. <listitem><para><emphasis>Download:</emphasis> Downloads the data from the
  4051. target and generates the profile, which appears in the viewer.</para></listitem>
  4052. <listitem><para><emphasis>Reset:</emphasis> Resets the sample data on the device.
  4053. Resetting the data removes sample information collected from previous
  4054. sampling runs.
  4055. Be sure you reset the data if you do not want to include old sample information.
  4056. </para></listitem>
  4057. <listitem><para><emphasis>Save:</emphasis> Saves the data downloaded from the
  4058. target to another directory for later examination.</para></listitem>
  4059. <listitem><para><emphasis>Open:</emphasis> Loads previously saved data.
  4060. </para></listitem>
  4061. </itemizedlist>
  4062. </para>
  4063. <para>
  4064. The client downloads the complete 'profile archive' from
  4065. the target to the host for processing.
  4066. This archive is a directory that contains the sample data, the object files,
  4067. and the debug information for the object files.
  4068. The archive is then converted using the <filename>oparchconv</filename> script, which is
  4069. included in this distribution.
  4070. The script uses <filename>opimport</filename> to convert the archive from
  4071. the target to something that can be processed on the host.
  4072. </para>
  4073. <para>
  4074. Downloaded archives reside in the
  4075. <link linkend='build-directory'>Build Directory</link> in
  4076. <filename>/tmp</filename> and are cleared up when they are no longer in use.
  4077. </para>
  4078. <para>
  4079. If you wish to perform kernel profiling, you need to be sure
  4080. a <filename>vmlinux</filename> file that matches the running kernel is available.
  4081. In the source directory, that file is usually located in
  4082. <filename>/boot/vmlinux-KERNELVERSION</filename>, where
  4083. <filename>KERNEL-version</filename> is the version of the kernel.
  4084. The OpenEmbedded build system generates separate <filename>vmlinux</filename>
  4085. packages for each kernel it builds.
  4086. Thus, it should just be a question of making sure a matching package is
  4087. installed (e.g. <filename>opkg install kernel-vmlinux</filename>).
  4088. The files are automatically installed into development and profiling images
  4089. alongside OProfile.
  4090. A configuration option exists within the OProfileUI settings page that you can use to
  4091. enter the location of the <filename>vmlinux</filename> file.
  4092. </para>
  4093. <para>
  4094. Waiting for debug symbols to transfer from the device can be slow, and it
  4095. is not always necessary to actually have them on the device for OProfile use.
  4096. All that is needed is a copy of the filesystem with the debug symbols present
  4097. on the viewer system.
  4098. The "<link linkend='platdev-gdb-remotedebug-launch-gdb'>Launch GDB on the Host Computer</link>"
  4099. section covers how to create such a directory with
  4100. the <link linkend='source-directory'>Source Directory</link>
  4101. and how to use the OProfileUI Settings Dialog to specify the location.
  4102. If you specify the directory, it will be used when the file checksums
  4103. match those on the system you are profiling.
  4104. </para>
  4105. </section>
  4106. <section id="platdev-oprofile-oprofileui-offline">
  4107. <title>Offline Mode</title>
  4108. <para>
  4109. If network access to the target is unavailable, you can generate
  4110. an archive for processing in <filename>oprofile-viewer</filename> as follows:
  4111. <literallayout class='monospaced'>
  4112. # opcontrol --reset
  4113. # opcontrol --start --separate=lib --no-vmlinux -c 5
  4114. .
  4115. .
  4116. [do whatever is being profiled]
  4117. .
  4118. .
  4119. # opcontrol --stop
  4120. # oparchive -o my_archive
  4121. </literallayout>
  4122. </para>
  4123. <para>
  4124. In the above example, <filename>my_archive</filename> is the name of the
  4125. archive directory where you would like the profile archive to be kept.
  4126. After the directory is created, you can copy it to another host and load it
  4127. using <filename>oprofile-viewer</filename> open functionality.
  4128. If necessary, the archive is converted.
  4129. </para>
  4130. </section>
  4131. </section>
  4132. </section>
  4133. <section id='maintaining-open-source-license-compliance-during-your-products-lifecycle'>
  4134. <title>Maintaining Open Source License Compliance During Your Product's Lifecycle</title>
  4135. <para>
  4136. One of the concerns for a development organization using open source
  4137. software is how to maintain compliance with various open source
  4138. licensing during the lifecycle of the product.
  4139. While this section does not provide legal advice or
  4140. comprehensively cover all scenarios, it does
  4141. present methods that you can use to
  4142. assist you in meeting the compliance requirements during a software
  4143. release.
  4144. </para>
  4145. <para>
  4146. With hundreds of different open source licenses that the Yocto
  4147. Project tracks, it is difficult to know the requirements of each
  4148. and every license.
  4149. However, we can begin to cover the requirements of the major FLOSS licenses, by
  4150. assuming that there are three main areas of concern:
  4151. <itemizedlist>
  4152. <listitem><para>Source code must be provided.</para></listitem>
  4153. <listitem><para>License text for the software must be
  4154. provided.</para></listitem>
  4155. <listitem><para>Compilation scripts and modifications to the
  4156. source code must be provided.
  4157. </para></listitem>
  4158. </itemizedlist>
  4159. There are other requirements beyond the scope of these
  4160. three and the methods described in this section
  4161. (e.g. the mechanism through which source code is distributed).
  4162. </para>
  4163. <para>
  4164. As different organizations have different methods of complying with
  4165. open source licensing, this section is not meant to imply that
  4166. there is only one single way to meet your compliance obligations,
  4167. but rather to describe one method of achieving compliance.
  4168. The remainder of this section describes methods supported to meet the
  4169. previously mentioned three requirements.
  4170. Once you take steps to meet these requirements,
  4171. and prior to releasing images, sources, and the build system,
  4172. you should audit all artifacts to ensure completeness.
  4173. <note>
  4174. The Yocto Project generates a license manifest during
  4175. image creation that is located
  4176. in <filename>${DEPLOY_DIR}/licenses/&lt;image_name-datestamp&gt;</filename>
  4177. to assist with any audits.
  4178. </note>
  4179. </para>
  4180. <section id='providing-the-source-code'>
  4181. <title>Providing the Source Code</title>
  4182. <para>
  4183. Compliance activities should begin before you generate the
  4184. final image.
  4185. The first thing you should look at is the requirement that
  4186. tops the list for most compliance groups - providing
  4187. the source.
  4188. The Yocto Project has a few ways of meeting this
  4189. requirement.
  4190. </para>
  4191. <para>
  4192. One of the easiest ways to meet this requirement is
  4193. to provide the entire
  4194. <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
  4195. used by the build.
  4196. This method, however, has a few issues.
  4197. The most obvious is the size of the directory since it includes
  4198. all sources used in the build and not just the source used in
  4199. the released image.
  4200. It will include toolchain source, and other artifacts, which
  4201. you would not generally release.
  4202. However, the more serious issue for most companies is accidental
  4203. release of proprietary software.
  4204. The Yocto Project provides an archiver class to help avoid
  4205. some of these concerns.
  4206. See the
  4207. "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-archiver'>Archiving Sources - <filename>archive*.bbclass</filename></ulink>"
  4208. section in the Yocto Project Reference Manual for information
  4209. on this class.
  4210. </para>
  4211. <para>
  4212. Before you employ <filename>DL_DIR</filename> or the
  4213. archiver class, you need to decide how you choose to
  4214. provide source.
  4215. The source archiver class can generate tarballs and SRPMs
  4216. and can create them with various levels of compliance in mind.
  4217. One way of doing this (but certainly not the only way) is to
  4218. release just the original source as a tarball.
  4219. You can do this by adding the following to the
  4220. <filename>local.conf</filename> file found in the
  4221. <link linkend='build-directory'>Build Directory</link>:
  4222. <literallayout class='monospaced'>
  4223. ARCHIVER_MODE ?= "original"
  4224. ARCHIVER_CLASS = "${@'archive-${ARCHIVER_MODE}-source' if
  4225. ARCHIVER_MODE != 'none' else ''}"
  4226. INHERIT += "${ARCHIVER_CLASS}"
  4227. SOURCE_ARCHIVE_PACKAGE_TYPE = "tar"
  4228. </literallayout>
  4229. During the creation of your image, the source from all
  4230. recipes that deploy packages to the image is placed within
  4231. subdirectories of
  4232. <filename>DEPLOY_DIR/sources</filename> based on the
  4233. <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
  4234. for each recipe.
  4235. Releasing the entire directory enables you to comply with
  4236. requirements concerning providing the unmodified source.
  4237. It is important to note that the size of the directory can
  4238. get large.
  4239. </para>
  4240. <para>
  4241. A way to help mitigate the size issue is to only release
  4242. tarballs for licenses that require the release of
  4243. source.
  4244. Let's assume you are only concerned with GPL code as
  4245. identified with the following:
  4246. <literallayout class='monospaced'>
  4247. $ cd poky/build/tmp/deploy/sources
  4248. $ mkdir ~/gpl_source_release
  4249. $ for dir in */*GPL*; do cp -r $dir ~/gpl_source_release; done
  4250. </literallayout>
  4251. At this point, you could create a tarball from the
  4252. <filename>gpl_source_release</filename> directory and
  4253. provide that to the end user.
  4254. This method would be a step toward achieving compliance
  4255. with section 3a of GPLv2 and with section 6 of GPLv3.
  4256. </para>
  4257. </section>
  4258. <section id='providing-license-text'>
  4259. <title>Providing License Text</title>
  4260. <para>
  4261. One requirement that is often overlooked is inclusion
  4262. of license text.
  4263. This requirement also needs to be dealt with prior to
  4264. generating the final image.
  4265. Some licenses require the license text to accompany
  4266. the binary.
  4267. You can achieve this by adding the following to your
  4268. <filename>local.conf</filename> file:
  4269. <literallayout class='monospaced'>
  4270. COPY_LIC_MANIFEST = "1"
  4271. COPY_LIC_DIRS = "1"
  4272. </literallayout>
  4273. Adding these statements to the configuration file ensures
  4274. that the licenses collected during package generation
  4275. are included on your image.
  4276. As the source archiver has already archived the original
  4277. unmodified source that contains the license files,
  4278. you would have already met the requirements for inclusion
  4279. of the license information with source as defined by the GPL
  4280. and other open source licenses.
  4281. </para>
  4282. </section>
  4283. <section id='providing-compilation-scripts-and-source-code-modifications'>
  4284. <title>Providing Compilation Scripts and Source Code Modifications</title>
  4285. <para>
  4286. At this point, we have addressed all we need to address
  4287. prior to generating the image.
  4288. The next two requirements are addressed during the final
  4289. packaging of the release.
  4290. </para>
  4291. <para>
  4292. By releasing the version of the OpenEmbedded build system
  4293. and the layers used during the build, you will be providing both
  4294. compilation scripts and the source code modifications in one
  4295. step.
  4296. </para>
  4297. <para>
  4298. If the deployment team has a
  4299. <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP layer</ulink>
  4300. and a distro layer, and those those layers are used to patch,
  4301. compile, package, or modify (in any way) any open source
  4302. software included in your released images, you
  4303. may be required to to release those layers under section 3 of
  4304. GPLv2 or section 1 of GPLv3.
  4305. One way of doing that is with a clean
  4306. checkout of the version of the Yocto Project and layers used
  4307. during your build.
  4308. Here is an example:
  4309. <literallayout class='monospaced'>
  4310. # We built using the &DISTRO_NAME; branch of the poky repo
  4311. $ git clone -b &DISTRO_NAME; git://git.yoctoproject.org/poky
  4312. $ cd poky
  4313. # We built using the release_branch for our layers
  4314. $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
  4315. $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
  4316. # clean up the .git repos
  4317. $ find . -name ".git" -type d -exec rm -rf {} \;
  4318. </literallayout>
  4319. One thing a development organization might want to consider
  4320. for end-user convenience is to modify
  4321. <filename>meta-yocto/conf/bblayers.conf.sample</filename> to
  4322. ensure that when the end user utilizes the released build
  4323. system to build an image, the development organization's
  4324. layers are included in the <filename>bblayers.conf</filename>
  4325. file automatically:
  4326. <literallayout class='monospaced'>
  4327. # LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf
  4328. # changes incompatibly
  4329. LCONF_VERSION = "6"
  4330. BBPATH = "${TOPDIR}"
  4331. BBFILES ?= ""
  4332. BBLAYERS ?= " \
  4333. ##COREBASE##/meta \
  4334. ##COREBASE##/meta-yocto \
  4335. ##COREBASE##/meta-yocto-bsp \
  4336. ##COREBASE##/meta-mylayer \
  4337. "
  4338. BBLAYERS_NON_REMOVABLE ?= " \
  4339. ##COREBASE##/meta \
  4340. ##COREBASE##/meta-yocto \
  4341. "
  4342. </literallayout>
  4343. Creating and providing an archive of the
  4344. <link linkend='metadata'>Metadata</link> layers
  4345. (recipes, configuration files, and so forth)
  4346. enables you to meet your
  4347. requirements to include the scripts to control compilation
  4348. as well as any modifications to the original source.
  4349. </para>
  4350. </section>
  4351. </section>
  4352. </chapter>
  4353. <!--
  4354. vim: expandtab tw=80 ts=4
  4355. -->