dev-manual-common-tasks.xml 303 KB

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