dev-manual-common-tasks.xml 569 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966
  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 that the procedures documented here occur often in the
  11. development 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 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 Support 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 represent layers typically have names that begin with
  56. the string <filename>meta-</filename>.
  57. <note>
  58. It is not a requirement that a layer name begin with the
  59. prefix <filename>meta-</filename>, but it is a commonly
  60. accepted standard in the Yocto Project community.
  61. </note>
  62. For example, when you set up the Source Directory structure,
  63. you will see several layers:
  64. <filename>meta</filename>,
  65. <filename>meta-skeleton</filename>,
  66. <filename>meta-selftest</filename>,
  67. <filename>meta-poky</filename>, and
  68. <filename>meta-yocto-bsp</filename>.
  69. Each of these folders represents a distinct layer.
  70. </para>
  71. <para>
  72. As another example, if you set up a local copy of the
  73. <filename>meta-intel</filename> Git repository
  74. and then explore the folder of that general layer,
  75. you will discover many Intel-specific BSP layers inside.
  76. For more information on BSP layers, see the
  77. "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
  78. section in the Yocto Project Board Support Package (BSP)
  79. Developer's Guide.
  80. </para>
  81. </section>
  82. <section id='creating-your-own-layer'>
  83. <title>Creating Your Own Layer</title>
  84. <para>
  85. It is very easy to create your own layers to use with the
  86. OpenEmbedded build system.
  87. The Yocto Project ships with scripts that speed up creating
  88. general layers and BSP layers.
  89. This section describes the steps you perform by hand to create
  90. a layer so that you can better understand them.
  91. For information about the layer-creation scripts, see the
  92. "<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>"
  93. section in the Yocto Project Board Support Package (BSP)
  94. Developer's Guide and the
  95. "<link linkend='creating-a-general-layer-using-the-yocto-layer-script'>Creating a General Layer Using the yocto-layer Script</link>"
  96. section further down in this manual.
  97. </para>
  98. <para>
  99. Follow these general steps to create your layer:
  100. <orderedlist>
  101. <listitem><para><emphasis>Check Existing Layers:</emphasis>
  102. Before creating a new layer, you should be sure someone
  103. has not already created a layer containing the Metadata
  104. you need.
  105. You can see the
  106. <ulink url='http://layers.openembedded.org/layerindex/layers/'><filename>OpenEmbedded Metadata Index</filename></ulink>
  107. for a list of layers from the OpenEmbedded community
  108. that can be used in the Yocto Project.
  109. </para></listitem>
  110. <listitem><para><emphasis>Create a Directory:</emphasis>
  111. Create the directory for your layer.
  112. While not strictly required, prepend the name of the
  113. folder with the string <filename>meta-</filename>.
  114. For example:
  115. <literallayout class='monospaced'>
  116. meta-mylayer
  117. meta-GUI_xyz
  118. meta-mymachine
  119. </literallayout>
  120. </para></listitem>
  121. <listitem><para><emphasis>Create a Layer Configuration
  122. File:</emphasis>
  123. Inside your new layer folder, you need to create a
  124. <filename>conf/layer.conf</filename> file.
  125. It is easiest to take an existing layer configuration
  126. file and copy that to your layer's
  127. <filename>conf</filename> directory and then modify the
  128. file as needed.</para>
  129. <para>The
  130. <filename>meta-yocto-bsp/conf/layer.conf</filename> file
  131. demonstrates the required syntax:
  132. <literallayout class='monospaced'>
  133. # We have a conf and classes directory, add to BBPATH
  134. BBPATH .= ":${LAYERDIR}"
  135. # We have recipes-* directories, add to BBFILES
  136. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  137. ${LAYERDIR}/recipes-*/*/*.bbappend"
  138. BBFILE_COLLECTIONS += "yoctobsp"
  139. BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
  140. BBFILE_PRIORITY_yoctobsp = "5"
  141. LAYERVERSION_yoctobsp = "3"
  142. </literallayout></para>
  143. <para>Here is an explanation of the example:
  144. <itemizedlist>
  145. <listitem><para>The configuration and
  146. classes directory is appended to
  147. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>.
  148. <note>
  149. All non-distro layers, which include all BSP
  150. layers, are expected to append the layer
  151. directory to the
  152. <filename>BBPATH</filename>.
  153. On the other hand, distro layers, such as
  154. <filename>meta-poky</filename>, can choose
  155. to enforce their own precedence over
  156. <filename>BBPATH</filename>.
  157. For an example of that syntax, see the
  158. <filename>layer.conf</filename> file for
  159. the <filename>meta-poky</filename> layer.
  160. </note></para></listitem>
  161. <listitem><para>The recipes for the layers are
  162. appended to
  163. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'>BBFILES</ulink></filename>.
  164. </para></listitem>
  165. <listitem><para>The
  166. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_COLLECTIONS'>BBFILE_COLLECTIONS</ulink></filename>
  167. variable is then appended with the layer name.
  168. </para></listitem>
  169. <listitem><para>The
  170. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PATTERN'>BBFILE_PATTERN</ulink></filename>
  171. variable is set to a regular expression and is
  172. used to match files from
  173. <filename>BBFILES</filename> into a particular
  174. layer.
  175. In this case,
  176. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDIR'>LAYERDIR</ulink></filename>
  177. is used to make <filename>BBFILE_PATTERN</filename> match within the
  178. layer's path.</para></listitem>
  179. <listitem><para>The
  180. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'>BBFILE_PRIORITY</ulink></filename>
  181. variable then assigns a priority to the layer.
  182. Applying priorities is useful in situations
  183. where the same recipe might appear in multiple
  184. layers and allows you to choose the layer
  185. that takes precedence.</para></listitem>
  186. <listitem><para>The
  187. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERVERSION'>LAYERVERSION</ulink></filename>
  188. variable optionally specifies the version of a
  189. layer as a single number.</para></listitem>
  190. </itemizedlist></para>
  191. <para>Note the use of the
  192. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDIR'>LAYERDIR</ulink></filename>
  193. variable, which expands to the directory of the current
  194. layer.</para>
  195. <para>Through the use of the <filename>BBPATH</filename>
  196. variable, BitBake locates class files
  197. (<filename>.bbclass</filename>),
  198. configuration files, and files that are included
  199. with <filename>include</filename> and
  200. <filename>require</filename> statements.
  201. For these cases, BitBake uses the first file that
  202. matches the name found in <filename>BBPATH</filename>.
  203. This is similar to the way the <filename>PATH</filename>
  204. variable is used for binaries.
  205. It is recommended, therefore, that you use unique
  206. class and configuration
  207. filenames in your custom layer.</para></listitem>
  208. <listitem><para><emphasis>Add Content:</emphasis> Depending
  209. on the type of layer, add the content.
  210. If the layer adds support for a machine, add the machine
  211. configuration in a <filename>conf/machine/</filename>
  212. file within the layer.
  213. If the layer adds distro policy, add the distro
  214. configuration in a <filename>conf/distro/</filename>
  215. file within the layer.
  216. If the layer introduces new recipes, put the recipes
  217. you need in <filename>recipes-*</filename>
  218. subdirectories within the layer.
  219. <note>In order to be compliant with the Yocto Project,
  220. a layer must contain a
  221. <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-filelayout-readme'>README file.</ulink>
  222. </note></para></listitem>
  223. </orderedlist>
  224. </para>
  225. </section>
  226. <section id='best-practices-to-follow-when-creating-layers'>
  227. <title>Best Practices to Follow When Creating Layers</title>
  228. <para>
  229. To create layers that are easier to maintain and that will
  230. not impact builds for other machines, you should consider the
  231. information in the following sections.
  232. </para>
  233. <section id='avoid-overlaying-entire-recipes'>
  234. <title>Avoid "Overlaying" Entire Recipes</title>
  235. <para>
  236. Avoid "overlaying" entire recipes from other layers in your
  237. configuration.
  238. In other words, do not copy an entire recipe into your
  239. layer and then modify it.
  240. Rather, use an append file (<filename>.bbappend</filename>)
  241. to override
  242. only those parts of the original recipe you need to modify.
  243. </para>
  244. </section>
  245. <section id='avoid-duplicating-include-files'>
  246. <title>Avoid Duplicating Include Files</title>
  247. <para>
  248. Avoid duplicating include files.
  249. Use append files (<filename>.bbappend</filename>)
  250. for each recipe
  251. that uses an include file.
  252. Or, if you are introducing a new recipe that requires
  253. the included file, use the path relative to the original
  254. layer directory to refer to the file.
  255. For example, use
  256. <filename>require recipes-core/</filename><replaceable>package</replaceable><filename>/</filename><replaceable>file</replaceable><filename>.inc</filename>
  257. instead of <filename>require </filename><replaceable>file</replaceable><filename>.inc</filename>.
  258. If you're finding you have to overlay the include file,
  259. it could indicate a deficiency in the include file in
  260. the layer to which it originally belongs.
  261. If this is the case, you should try to address that
  262. deficiency instead of overlaying the include file.
  263. For example, you could address this by getting the
  264. maintainer of the include file to add a variable or
  265. variables to make it easy to override the parts needing
  266. to be overridden.
  267. </para>
  268. </section>
  269. <section id='structure-your-layers'>
  270. <title>Structure Your Layers</title>
  271. <para>
  272. Proper use of overrides within append files and placement
  273. of machine-specific files within your layer can ensure that
  274. a build is not using the wrong Metadata and negatively
  275. impacting a build for a different machine.
  276. Following are some examples:
  277. <itemizedlist>
  278. <listitem><para><emphasis>Modifying Variables to Support
  279. a Different Machine:</emphasis>
  280. Suppose you have a layer named
  281. <filename>meta-one</filename> that adds support
  282. for building machine "one".
  283. To do so, you use an append file named
  284. <filename>base-files.bbappend</filename> and
  285. create a dependency on "foo" by altering the
  286. <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
  287. variable:
  288. <literallayout class='monospaced'>
  289. DEPENDS = "foo"
  290. </literallayout>
  291. The dependency is created during any build that
  292. includes the layer
  293. <filename>meta-one</filename>.
  294. However, you might not want this dependency
  295. for all machines.
  296. For example, suppose you are building for
  297. machine "two" but your
  298. <filename>bblayers.conf</filename> file has the
  299. <filename>meta-one</filename> layer included.
  300. During the build, the
  301. <filename>base-files</filename> for machine
  302. "two" will also have the dependency on
  303. <filename>foo</filename>.</para>
  304. <para>To make sure your changes apply only when
  305. building machine "one", use a machine override
  306. with the <filename>DEPENDS</filename> statement:
  307. <literallayout class='monospaced'>
  308. DEPENDS_one = "foo"
  309. </literallayout>
  310. You should follow the same strategy when using
  311. <filename>_append</filename> and
  312. <filename>_prepend</filename> operations:
  313. <literallayout class='monospaced'>
  314. DEPENDS_append_one = " foo"
  315. DEPENDS_prepend_one = "foo "
  316. </literallayout>
  317. As an actual example, here's a line from the recipe
  318. for gnutls, which adds dependencies on
  319. "argp-standalone" when building with the musl C
  320. library:
  321. <literallayout class='monospaced'>
  322. DEPENDS_append_libc-musl = " argp-standalone"
  323. </literallayout>
  324. <note>
  325. Avoiding "+=" and "=+" and using
  326. machine-specific
  327. <filename>_append</filename>
  328. and <filename>_prepend</filename> operations
  329. is recommended as well.
  330. </note></para></listitem>
  331. <listitem><para><emphasis>Place Machine-Specific Files
  332. in Machine-Specific Locations:</emphasis>
  333. When you have a base recipe, such as
  334. <filename>base-files.bb</filename>, that
  335. contains a
  336. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  337. statement to a file, you can use an append file
  338. to cause the build to use your own version of
  339. the file.
  340. For example, an append file in your layer at
  341. <filename>meta-one/recipes-core/base-files/base-files.bbappend</filename>
  342. could extend
  343. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
  344. using
  345. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
  346. as follows:
  347. <literallayout class='monospaced'>
  348. FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
  349. </literallayout>
  350. The build for machine "one" will pick up your
  351. machine-specific file as long as you have the
  352. file in
  353. <filename>meta-one/recipes-core/base-files/base-files/</filename>.
  354. However, if you are building for a different
  355. machine and the
  356. <filename>bblayers.conf</filename> file includes
  357. the <filename>meta-one</filename> layer and
  358. the location of your machine-specific file is
  359. the first location where that file is found
  360. according to <filename>FILESPATH</filename>,
  361. builds for all machines will also use that
  362. machine-specific file.</para>
  363. <para>You can make sure that a machine-specific
  364. file is used for a particular machine by putting
  365. the file in a subdirectory specific to the
  366. machine.
  367. For example, rather than placing the file in
  368. <filename>meta-one/recipes-core/base-files/base-files/</filename>
  369. as shown above, put it in
  370. <filename>meta-one/recipes-core/base-files/base-files/one/</filename>.
  371. Not only does this make sure the file is used
  372. only when building for machine "one", but the
  373. build process locates the file more quickly.</para>
  374. <para>In summary, you need to place all files
  375. referenced from <filename>SRC_URI</filename>
  376. in a machine-specific subdirectory within the
  377. layer in order to restrict those files to
  378. machine-specific builds.</para></listitem>
  379. </itemizedlist>
  380. </para>
  381. </section>
  382. <section id='other-recommendations'>
  383. <title>Other Recommendations</title>
  384. <para>
  385. We also recommend the following:
  386. <itemizedlist>
  387. <listitem><para>Store custom layers in a Git repository
  388. that uses the
  389. <filename>meta-<replaceable>layer_name</replaceable></filename> format.
  390. </para></listitem>
  391. <listitem><para>Clone the repository alongside other
  392. <filename>meta</filename> directories in the
  393. <link linkend='source-directory'>Source Directory</link>.
  394. </para></listitem>
  395. </itemizedlist>
  396. Following these recommendations keeps your Source Directory and
  397. its configuration entirely inside the Yocto Project's core
  398. base.
  399. </para>
  400. </section>
  401. </section>
  402. <section id='enabling-your-layer'>
  403. <title>Enabling Your Layer</title>
  404. <para>
  405. Before the OpenEmbedded build system can use your new layer,
  406. you need to enable it.
  407. To enable your layer, simply add your layer's path to the
  408. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'>BBLAYERS</ulink></filename>
  409. variable in your <filename>conf/bblayers.conf</filename> file,
  410. which is found in the
  411. <link linkend='build-directory'>Build Directory</link>.
  412. The following example shows how to enable a layer named
  413. <filename>meta-mylayer</filename>:
  414. <literallayout class='monospaced'>
  415. LCONF_VERSION = "6"
  416. BBPATH = "${TOPDIR}"
  417. BBFILES ?= ""
  418. BBLAYERS ?= " \
  419. $HOME/poky/meta \
  420. $HOME/poky/meta-poky \
  421. $HOME/poky/meta-yocto-bsp \
  422. $HOME/poky/meta-mylayer \
  423. "
  424. </literallayout>
  425. </para>
  426. <para>
  427. BitBake parses each <filename>conf/layer.conf</filename> file
  428. as specified in the <filename>BBLAYERS</filename> variable
  429. within the <filename>conf/bblayers.conf</filename> file.
  430. During the processing of each
  431. <filename>conf/layer.conf</filename> file, BitBake adds the
  432. recipes, classes and configurations contained within the
  433. particular layer to the source directory.
  434. </para>
  435. </section>
  436. <section id='using-bbappend-files'>
  437. <title>Using .bbappend Files</title>
  438. <para>
  439. Recipes used to append Metadata to other recipes are called
  440. BitBake append files.
  441. BitBake append files use the <filename>.bbappend</filename> file
  442. type suffix, while the corresponding recipes to which Metadata
  443. is being appended use the <filename>.bb</filename> file type
  444. suffix.
  445. </para>
  446. <para>
  447. A <filename>.bbappend</filename> file allows your layer to make
  448. additions or changes to the content of another layer's recipe
  449. without having to copy the other recipe into your layer.
  450. Your <filename>.bbappend</filename> file resides in your layer,
  451. while the main <filename>.bb</filename> recipe file to
  452. which you are appending Metadata resides in a different layer.
  453. </para>
  454. <para>
  455. Append files must have the same root names as their corresponding
  456. recipes.
  457. For example, the append file
  458. <filename>someapp_&DISTRO;.bbappend</filename> must apply to
  459. <filename>someapp_&DISTRO;.bb</filename>.
  460. This means the original recipe and append file names are version
  461. number-specific.
  462. If the corresponding recipe is renamed to update to a newer
  463. version, the corresponding <filename>.bbappend</filename> file must
  464. be renamed (and possibly updated) as well.
  465. During the build process, BitBake displays an error on starting
  466. if it detects a <filename>.bbappend</filename> file that does
  467. not have a corresponding recipe with a matching name.
  468. See the
  469. <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_DANGLINGAPPENDS_WARNONLY'><filename>BB_DANGLINGAPPENDS_WARNONLY</filename></ulink>
  470. variable for information on how to handle this error.
  471. </para>
  472. <para>
  473. Being able to append information to an existing recipe not only
  474. avoids duplication, but also automatically applies recipe
  475. changes in a different layer to your layer.
  476. If you were copying recipes, you would have to manually merge
  477. changes as they occur.
  478. </para>
  479. <para>
  480. As an example, consider the main formfactor recipe and a
  481. corresponding formfactor append file both from the
  482. <link linkend='source-directory'>Source Directory</link>.
  483. Here is the main formfactor recipe, which is named
  484. <filename>formfactor_0.0.bb</filename> and located in the
  485. "meta" layer at
  486. <filename>meta/recipes-bsp/formfactor</filename>:
  487. <literallayout class='monospaced'>
  488. SUMMARY = "Device formfactor information"
  489. SECTION = "base"
  490. LICENSE = "MIT"
  491. LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
  492. file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
  493. PR = "r45"
  494. SRC_URI = "file://config file://machconfig"
  495. S = "${WORKDIR}"
  496. PACKAGE_ARCH = "${MACHINE_ARCH}"
  497. INHIBIT_DEFAULT_DEPS = "1"
  498. do_install() {
  499. # Install file only if it has contents
  500. install -d ${D}${sysconfdir}/formfactor/
  501. install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
  502. if [ -s "${S}/machconfig" ]; then
  503. install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
  504. fi
  505. }
  506. </literallayout>
  507. In the main recipe, note the
  508. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  509. variable, which tells the OpenEmbedded build system where to
  510. find files during the build.
  511. </para>
  512. <para>
  513. Following is the append file, which is named
  514. <filename>formfactor_0.0.bbappend</filename> and is from the
  515. Raspberry Pi BSP Layer named
  516. <filename>meta-raspberrypi</filename>.
  517. The file is in <filename>recipes-bsp/formfactor</filename>:
  518. <literallayout class='monospaced'>
  519. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
  520. </literallayout>
  521. </para>
  522. <para>
  523. By default, the build system uses the
  524. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
  525. variable to locate files.
  526. This append file extends the locations by setting the
  527. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
  528. variable.
  529. Setting this variable in the <filename>.bbappend</filename>
  530. file is the most reliable and recommended method for adding
  531. directories to the search path used by the build system
  532. to find files.
  533. </para>
  534. <para>
  535. The statement in this example extends the directories to include
  536. <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>,
  537. which resolves to a directory named
  538. <filename>formfactor</filename> in the same directory
  539. in which the append file resides (i.e.
  540. <filename>meta-raspberrypi/recipes-bsp/formfactor/formfactor</filename>.
  541. This implies that you must have the supporting directory
  542. structure set up that will contain any files or patches you
  543. will be including from the layer.
  544. </para>
  545. <para>
  546. Using the immediate expansion assignment operator
  547. <filename>:=</filename> is important because of the reference to
  548. <filename>THISDIR</filename>.
  549. The trailing colon character is important as it ensures that
  550. items in the list remain colon-separated.
  551. <note>
  552. <para>
  553. BitBake automatically defines the
  554. <filename>THISDIR</filename> variable.
  555. You should never set this variable yourself.
  556. Using "_prepend" as part of the
  557. <filename>FILESEXTRAPATHS</filename> ensures your path
  558. will be searched prior to other paths in the final
  559. list.
  560. </para>
  561. <para>
  562. Also, not all append files add extra files.
  563. Many append files simply exist to add build options
  564. (e.g. <filename>systemd</filename>).
  565. For these cases, your append file would not even
  566. use the <filename>FILESEXTRAPATHS</filename> statement.
  567. </para>
  568. </note>
  569. </para>
  570. </section>
  571. <section id='prioritizing-your-layer'>
  572. <title>Prioritizing Your Layer</title>
  573. <para>
  574. Each layer is assigned a priority value.
  575. Priority values control which layer takes precedence if there
  576. are recipe files with the same name in multiple layers.
  577. For these cases, the recipe file from the layer with a higher
  578. priority number takes precedence.
  579. Priority values also affect the order in which multiple
  580. <filename>.bbappend</filename> files for the same recipe are
  581. applied.
  582. You can either specify the priority manually, or allow the
  583. build system to calculate it based on the layer's dependencies.
  584. </para>
  585. <para>
  586. To specify the layer's priority manually, use the
  587. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>
  588. variable.
  589. For example:
  590. <literallayout class='monospaced'>
  591. BBFILE_PRIORITY_mylayer = "1"
  592. </literallayout>
  593. </para>
  594. <note>
  595. <para>It is possible for a recipe with a lower version number
  596. <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
  597. in a layer that has a higher priority to take precedence.</para>
  598. <para>Also, the layer priority does not currently affect the
  599. precedence order of <filename>.conf</filename>
  600. or <filename>.bbclass</filename> files.
  601. Future versions of BitBake might address this.</para>
  602. </note>
  603. </section>
  604. <section id='managing-layers'>
  605. <title>Managing Layers</title>
  606. <para>
  607. You can use the BitBake layer management tool to provide a view
  608. into the structure of recipes across a multi-layer project.
  609. Being able to generate output that reports on configured layers
  610. with their paths and priorities and on
  611. <filename>.bbappend</filename> files and their applicable
  612. recipes can help to reveal potential problems.
  613. </para>
  614. <para>
  615. Use the following form when running the layer management tool.
  616. <literallayout class='monospaced'>
  617. $ bitbake-layers <replaceable>command</replaceable> [<replaceable>arguments</replaceable>]
  618. </literallayout>
  619. The following list describes the available commands:
  620. <itemizedlist>
  621. <listitem><para><filename><emphasis>help:</emphasis></filename>
  622. Displays general help or help on a specified command.
  623. </para></listitem>
  624. <listitem><para><filename><emphasis>show-layers:</emphasis></filename>
  625. Shows the current configured layers.
  626. </para></listitem>
  627. <listitem><para><filename><emphasis>show-recipes:</emphasis></filename>
  628. Lists available recipes and the layers that provide them.
  629. </para></listitem>
  630. <listitem><para><filename><emphasis>show-overlayed:</emphasis></filename>
  631. Lists overlayed recipes.
  632. A recipe is overlayed when a recipe with the same name
  633. exists in another layer that has a higher layer
  634. priority.
  635. </para></listitem>
  636. <listitem><para><filename><emphasis>show-appends:</emphasis></filename>
  637. Lists <filename>.bbappend</filename> files and the
  638. recipe files to which they apply.
  639. </para></listitem>
  640. <listitem><para><filename><emphasis>show-cross-depends:</emphasis></filename>
  641. Lists dependency relationships between recipes that
  642. cross layer boundaries.
  643. </para></listitem>
  644. <listitem><para><filename><emphasis>add-layer:</emphasis></filename>
  645. Adds a layer to <filename>bblayers.conf</filename>.
  646. </para></listitem>
  647. <listitem><para><filename><emphasis>remove-layer:</emphasis></filename>
  648. Removes a layer from <filename>bblayers.conf</filename>
  649. </para></listitem>
  650. <listitem><para><filename><emphasis>flatten:</emphasis></filename>
  651. Flattens the layer configuration into a separate output
  652. directory.
  653. Flattening your layer configuration builds a "flattened"
  654. directory that contains the contents of all layers,
  655. with any overlayed recipes removed and any
  656. <filename>.bbappend</filename> files appended to the
  657. corresponding recipes.
  658. You might have to perform some manual cleanup of the
  659. flattened layer as follows:
  660. <itemizedlist>
  661. <listitem><para>Non-recipe files (such as patches)
  662. are overwritten.
  663. The flatten command shows a warning for these
  664. files.
  665. </para></listitem>
  666. <listitem><para>Anything beyond the normal layer
  667. setup has been added to the
  668. <filename>layer.conf</filename> file.
  669. Only the lowest priority layer's
  670. <filename>layer.conf</filename> is used.
  671. </para></listitem>
  672. <listitem><para>Overridden and appended items from
  673. <filename>.bbappend</filename> files need to be
  674. cleaned up.
  675. The contents of each
  676. <filename>.bbappend</filename> end up in the
  677. flattened recipe.
  678. However, if there are appended or changed
  679. variable values, you need to tidy these up
  680. yourself.
  681. Consider the following example.
  682. Here, the <filename>bitbake-layers</filename>
  683. command adds the line
  684. <filename>#### bbappended ...</filename> so that
  685. you know where the following lines originate:
  686. <literallayout class='monospaced'>
  687. ...
  688. DESCRIPTION = "A useful utility"
  689. ...
  690. EXTRA_OECONF = "--enable-something"
  691. ...
  692. #### bbappended from meta-anotherlayer ####
  693. DESCRIPTION = "Customized utility"
  694. EXTRA_OECONF += "--enable-somethingelse"
  695. </literallayout>
  696. Ideally, you would tidy up these utilities as
  697. follows:
  698. <literallayout class='monospaced'>
  699. ...
  700. DESCRIPTION = "Customized utility"
  701. ...
  702. EXTRA_OECONF = "--enable-something --enable-somethingelse"
  703. ...
  704. </literallayout></para></listitem>
  705. </itemizedlist></para></listitem>
  706. </itemizedlist>
  707. </para>
  708. </section>
  709. <section id='creating-a-general-layer-using-the-yocto-layer-script'>
  710. <title>Creating a General Layer Using the yocto-layer Script</title>
  711. <para>
  712. The <filename>yocto-layer</filename> script simplifies
  713. creating a new general layer.
  714. <note>
  715. For information on BSP layers, see the
  716. "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
  717. section in the Yocto Project Board Specific (BSP)
  718. Developer's Guide.
  719. </note>
  720. The default mode of the script's operation is to prompt you for
  721. information needed to generate the layer:
  722. <itemizedlist>
  723. <listitem><para>The layer priority.
  724. </para></listitem>
  725. <listitem><para>Whether or not to create a sample recipe.
  726. </para></listitem>
  727. <listitem><para>Whether or not to create a sample
  728. append file.
  729. </para></listitem>
  730. </itemizedlist>
  731. </para>
  732. <para>
  733. Use the <filename>yocto-layer create</filename> sub-command
  734. to create a new general layer.
  735. In its simplest form, you can create a layer as follows:
  736. <literallayout class='monospaced'>
  737. $ yocto-layer create mylayer
  738. </literallayout>
  739. The previous example creates a layer named
  740. <filename>meta-mylayer</filename> in the current directory.
  741. </para>
  742. <para>
  743. As the <filename>yocto-layer create</filename> command runs,
  744. default values for the prompts appear in brackets.
  745. Pressing enter without supplying anything for the prompts
  746. or pressing enter and providing an invalid response causes the
  747. script to accept the default value.
  748. Once the script completes, the new layer
  749. is created in the current working directory.
  750. The script names the layer by prepending
  751. <filename>meta-</filename> to the name you provide.
  752. </para>
  753. <para>
  754. Minimally, the script creates the following within the layer:
  755. <itemizedlist>
  756. <listitem><para><emphasis>The <filename>conf</filename>
  757. directory:</emphasis>
  758. This directory contains the layer's configuration file.
  759. The root name for the file is the same as the root name
  760. your provided for the layer (e.g.
  761. <filename><replaceable>layer</replaceable>.conf</filename>).
  762. </para></listitem>
  763. <listitem><para><emphasis>The
  764. <filename>COPYING.MIT</filename> file:</emphasis>
  765. The copyright and use notice for the software.
  766. </para></listitem>
  767. <listitem><para><emphasis>The <filename>README</filename>
  768. file:</emphasis>
  769. A file describing the contents of your new layer.
  770. </para></listitem>
  771. </itemizedlist>
  772. </para>
  773. <para>
  774. If you choose to generate a sample recipe file, the script
  775. prompts you for the name for the recipe and then creates it
  776. in <filename><replaceable>layer</replaceable>/recipes-example/example/</filename>.
  777. The script creates a <filename>.bb</filename> file and a
  778. directory, which contains a sample
  779. <filename>helloworld.c</filename> source file, along with
  780. a sample patch file.
  781. If you do not provide a recipe name, the script uses
  782. "example".
  783. </para>
  784. <para>
  785. If you choose to generate a sample append file, the script
  786. prompts you for the name for the file and then creates it
  787. in <filename><replaceable>layer</replaceable>/recipes-example-bbappend/example-bbappend/</filename>.
  788. The script creates a <filename>.bbappend</filename> file and a
  789. directory, which contains a sample patch file.
  790. If you do not provide a recipe name, the script uses
  791. "example".
  792. The script also prompts you for the version of the append file.
  793. The version should match the recipe to which the append file
  794. is associated.
  795. </para>
  796. <para>
  797. The easiest way to see how the <filename>yocto-layer</filename>
  798. script works is to experiment with the script.
  799. You can also read the usage information by entering the
  800. following:
  801. <literallayout class='monospaced'>
  802. $ yocto-layer help
  803. </literallayout>
  804. </para>
  805. <para>
  806. Once you create your general layer, you must add it to your
  807. <filename>bblayers.conf</filename> file.
  808. Here is an example where a layer named
  809. <filename>meta-mylayer</filename> is added:
  810. <literallayout class='monospaced'>
  811. BBLAYERS = ?" \
  812. /usr/local/src/yocto/meta \
  813. /usr/local/src/yocto/meta-poky \
  814. /usr/local/src/yocto/meta-yocto-bsp \
  815. /usr/local/src/yocto/meta-mylayer \
  816. "
  817. </literallayout>
  818. Adding the layer to this file enables the build system to
  819. locate the layer during the build.
  820. </para>
  821. </section>
  822. </section>
  823. <section id='usingpoky-extend-customimage'>
  824. <title>Customizing Images</title>
  825. <para>
  826. You can customize images to satisfy particular requirements.
  827. This section describes several methods and provides guidelines for each.
  828. </para>
  829. <section id='usingpoky-extend-customimage-localconf'>
  830. <title>Customizing Images Using <filename>local.conf</filename></title>
  831. <para>
  832. Probably the easiest way to customize an image is to add a
  833. package by way of the <filename>local.conf</filename>
  834. configuration file.
  835. Because it is limited to local use, this method generally only
  836. allows you to add packages and is not as flexible as creating
  837. your own customized image.
  838. When you add packages using local variables this way, you need
  839. to realize that these variable changes are in effect for every
  840. build and consequently affect all images, which might not
  841. be what you require.
  842. </para>
  843. <para>
  844. To add a package to your image using the local configuration
  845. file, use the
  846. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
  847. variable with the <filename>_append</filename> operator:
  848. <literallayout class='monospaced'>
  849. IMAGE_INSTALL_append = " strace"
  850. </literallayout>
  851. Use of the syntax is important - specifically, the space between
  852. the quote and the package name, which is
  853. <filename>strace</filename> in this example.
  854. This space is required since the <filename>_append</filename>
  855. operator does not add the space.
  856. </para>
  857. <para>
  858. Furthermore, you must use <filename>_append</filename> instead
  859. of the <filename>+=</filename> operator if you want to avoid
  860. ordering issues.
  861. The reason for this is because doing so unconditionally appends
  862. to the variable and avoids ordering problems due to the
  863. variable being set in image recipes and
  864. <filename>.bbclass</filename> files with operators like
  865. <filename>?=</filename>.
  866. Using <filename>_append</filename> ensures the operation takes
  867. affect.
  868. </para>
  869. <para>
  870. As shown in its simplest use,
  871. <filename>IMAGE_INSTALL_append</filename> affects all images.
  872. It is possible to extend the syntax so that the variable
  873. applies to a specific image only.
  874. Here is an example:
  875. <literallayout class='monospaced'>
  876. IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
  877. </literallayout>
  878. This example adds <filename>strace</filename> to the
  879. <filename>core-image-minimal</filename> image only.
  880. </para>
  881. <para>
  882. You can add packages using a similar approach through the
  883. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'>CORE_IMAGE_EXTRA_INSTALL</ulink></filename>
  884. variable.
  885. If you use this variable, only
  886. <filename>core-image-*</filename> images are affected.
  887. </para>
  888. </section>
  889. <section id='usingpoky-extend-customimage-imagefeatures'>
  890. <title>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and
  891. <filename>EXTRA_IMAGE_FEATURES</filename></title>
  892. <para>
  893. Another method for customizing your image is to enable or
  894. disable high-level image features by using the
  895. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
  896. and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
  897. variables.
  898. Although the functions for both variables are nearly equivalent,
  899. best practices dictate using <filename>IMAGE_FEATURES</filename>
  900. from within a recipe and using
  901. <filename>EXTRA_IMAGE_FEATURES</filename> from within
  902. your <filename>local.conf</filename> file, which is found in the
  903. <link linkend='build-directory'>Build Directory</link>.
  904. </para>
  905. <para>
  906. To understand how these features work, the best reference is
  907. <filename>meta/classes/core-image.bbclass</filename>.
  908. This class lists out the available
  909. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
  910. of which most map to package groups while some, such as
  911. <filename>debug-tweaks</filename> and
  912. <filename>read-only-rootfs</filename>, resolve as general
  913. configuration settings.
  914. </para>
  915. <para>
  916. In summary, the file looks at the contents of the
  917. <filename>IMAGE_FEATURES</filename> variable and then maps
  918. or configures the feature accordingly.
  919. Based on this information, the build system automatically
  920. adds the appropriate packages or configurations to the
  921. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
  922. variable.
  923. Effectively, you are enabling extra features by extending the
  924. class or creating a custom class for use with specialized image
  925. <filename>.bb</filename> files.
  926. </para>
  927. <para>
  928. Use the <filename>EXTRA_IMAGE_FEATURES</filename> variable
  929. from within your local configuration file.
  930. Using a separate area from which to enable features with
  931. this variable helps you avoid overwriting the features in the
  932. image recipe that are enabled with
  933. <filename>IMAGE_FEATURES</filename>.
  934. The value of <filename>EXTRA_IMAGE_FEATURES</filename> is added
  935. to <filename>IMAGE_FEATURES</filename> within
  936. <filename>meta/conf/bitbake.conf</filename>.
  937. </para>
  938. <para>
  939. To illustrate how you can use these variables to modify your
  940. image, consider an example that selects the SSH server.
  941. The Yocto Project ships with two SSH servers you can use
  942. with your images: Dropbear and OpenSSH.
  943. Dropbear is a minimal SSH server appropriate for
  944. resource-constrained environments, while OpenSSH is a
  945. well-known standard SSH server implementation.
  946. By default, the <filename>core-image-sato</filename> image
  947. is configured to use Dropbear.
  948. The <filename>core-image-full-cmdline</filename> and
  949. <filename>core-image-lsb</filename> images both
  950. include OpenSSH.
  951. The <filename>core-image-minimal</filename> image does not
  952. contain an SSH server.
  953. </para>
  954. <para>
  955. You can customize your image and change these defaults.
  956. Edit the <filename>IMAGE_FEATURES</filename> variable
  957. in your recipe or use the
  958. <filename>EXTRA_IMAGE_FEATURES</filename> in your
  959. <filename>local.conf</filename> file so that it configures the
  960. image you are working with to include
  961. <filename>ssh-server-dropbear</filename> or
  962. <filename>ssh-server-openssh</filename>.
  963. </para>
  964. <note>
  965. See the
  966. "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
  967. section in the Yocto Project Reference Manual for a complete
  968. list of image features that ship with the Yocto Project.
  969. </note>
  970. </section>
  971. <section id='usingpoky-extend-customimage-custombb'>
  972. <title>Customizing Images Using Custom .bb Files</title>
  973. <para>
  974. You can also customize an image by creating a custom recipe
  975. that defines additional software as part of the image.
  976. The following example shows the form for the two lines you need:
  977. <literallayout class='monospaced'>
  978. IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
  979. inherit core-image
  980. </literallayout>
  981. </para>
  982. <para>
  983. Defining the software using a custom recipe gives you total
  984. control over the contents of the image.
  985. It is important to use the correct names of packages in the
  986. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
  987. variable.
  988. You must use the OpenEmbedded notation and not the Debian notation for the names
  989. (e.g. <filename>glibc-dev</filename> instead of <filename>libc6-dev</filename>).
  990. </para>
  991. <para>
  992. The other method for creating a custom image is to base it on an existing image.
  993. For example, if you want to create an image based on <filename>core-image-sato</filename>
  994. but add the additional package <filename>strace</filename> to the image,
  995. copy the <filename>meta/recipes-sato/images/core-image-sato.bb</filename> to a
  996. new <filename>.bb</filename> and add the following line to the end of the copy:
  997. <literallayout class='monospaced'>
  998. IMAGE_INSTALL += "strace"
  999. </literallayout>
  1000. </para>
  1001. </section>
  1002. <section id='usingpoky-extend-customimage-customtasks'>
  1003. <title>Customizing Images Using Custom Package Groups</title>
  1004. <para>
  1005. For complex custom images, the best approach for customizing
  1006. an image is to create a custom package group recipe that is
  1007. used to build the image or images.
  1008. A good example of a package group recipe is
  1009. <filename>meta/recipes-core/packagegroups/packagegroup-base.bb</filename>.
  1010. </para>
  1011. <para>
  1012. If you examine that recipe, you see that the
  1013. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename>
  1014. variable lists the package group packages to produce.
  1015. The <filename>inherit packagegroup</filename> statement
  1016. sets appropriate default values and automatically adds
  1017. <filename>-dev</filename>, <filename>-dbg</filename>, and
  1018. <filename>-ptest</filename> complementary packages for each
  1019. package specified in the <filename>PACKAGES</filename>
  1020. statement.
  1021. <note>
  1022. The <filename>inherit packages</filename> should be
  1023. located near the top of the recipe, certainly before
  1024. the <filename>PACKAGES</filename> statement.
  1025. </note>
  1026. </para>
  1027. <para>
  1028. For each package you specify in <filename>PACKAGES</filename>,
  1029. you can use
  1030. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'>RDEPENDS</ulink></filename>
  1031. and
  1032. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'>RRECOMMENDS</ulink></filename>
  1033. entries to provide a list of packages the parent task package
  1034. should contain.
  1035. You can see examples of these further down in the
  1036. <filename>packagegroup-base.bb</filename> recipe.
  1037. </para>
  1038. <para>
  1039. Here is a short, fabricated example showing the same basic
  1040. pieces:
  1041. <literallayout class='monospaced'>
  1042. DESCRIPTION = "My Custom Package Groups"
  1043. inherit packagegroup
  1044. PACKAGES = "\
  1045. packagegroup-custom-apps \
  1046. packagegroup-custom-tools \
  1047. "
  1048. RDEPENDS_packagegroup-custom-apps = "\
  1049. dropbear \
  1050. portmap \
  1051. psplash"
  1052. RDEPENDS_packagegroup-custom-tools = "\
  1053. oprofile \
  1054. oprofileui-server \
  1055. lttng-tools"
  1056. RRECOMMENDS_packagegroup-custom-tools = "\
  1057. kernel-module-oprofile"
  1058. </literallayout>
  1059. </para>
  1060. <para>
  1061. In the previous example, two package group packages are created with their dependencies and their
  1062. recommended package dependencies listed: <filename>packagegroup-custom-apps</filename>, and
  1063. <filename>packagegroup-custom-tools</filename>.
  1064. To build an image using these package group packages, you need to add
  1065. <filename>packagegroup-custom-apps</filename> and/or
  1066. <filename>packagegroup-custom-tools</filename> to
  1067. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>.
  1068. For other forms of image dependencies see the other areas of this section.
  1069. </para>
  1070. </section>
  1071. <section id='usingpoky-extend-customimage-image-name'>
  1072. <title>Customizing an Image Hostname</title>
  1073. <para>
  1074. By default, the configured hostname (i.e.
  1075. <filename>/etc/hostname</filename>) in an image is the
  1076. same as the machine name.
  1077. For example, if
  1078. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
  1079. equals "qemux86", the configured hostname written to
  1080. <filename>/etc/hostname</filename> is "qemux86".
  1081. </para>
  1082. <para>
  1083. You can customize this name by altering the value of the
  1084. "hostname" variable in the
  1085. <filename>base-files</filename> recipe using either
  1086. an append file or a configuration file.
  1087. Use the following in an append file:
  1088. <literallayout class='monospaced'>
  1089. hostname="myhostname"
  1090. </literallayout>
  1091. Use the following in a configuration file:
  1092. <literallayout class='monospaced'>
  1093. hostname_pn-base-files = "myhostname"
  1094. </literallayout>
  1095. </para>
  1096. <para>
  1097. Changing the default value of the variable "hostname" can be
  1098. useful in certain situations.
  1099. For example, suppose you need to do extensive testing on an
  1100. image and you would like to easily identify the image
  1101. under test from existing images with typical default
  1102. hostnames.
  1103. In this situation, you could change the default hostname to
  1104. "testme", which results in all the images using the name
  1105. "testme".
  1106. Once testing is complete and you do not need to rebuild the
  1107. image for test any longer, you can easily reset the default
  1108. hostname.
  1109. </para>
  1110. <para>
  1111. Another point of interest is that if you unset the variable,
  1112. the image will have no default hostname in the filesystem.
  1113. Here is an example that unsets the variable in a
  1114. configuration file:
  1115. <literallayout class='monospaced'>
  1116. hostname_pn-base-files = ""
  1117. </literallayout>
  1118. Having no default hostname in the filesystem is suitable for
  1119. environments that use dynamic hostnames such as virtual
  1120. machines.
  1121. </para>
  1122. </section>
  1123. </section>
  1124. <section id='new-recipe-writing-a-new-recipe'>
  1125. <title>Writing a New Recipe</title>
  1126. <para>
  1127. Recipes (<filename>.bb</filename> files) are fundamental components
  1128. in the Yocto Project environment.
  1129. Each software component built by the OpenEmbedded build system
  1130. requires a recipe to define the component.
  1131. This section describes how to create, write, and test a new
  1132. recipe.
  1133. <note>
  1134. For information on variables that are useful for recipes and
  1135. for information about recipe naming issues, see the
  1136. "<ulink url='&YOCTO_DOCS_REF_URL;#ref-varlocality-recipe-required'>Required</ulink>"
  1137. section of the Yocto Project Reference Manual.
  1138. </note>
  1139. </para>
  1140. <section id='new-recipe-overview'>
  1141. <title>Overview</title>
  1142. <para>
  1143. The following figure shows the basic process for creating a
  1144. new recipe.
  1145. The remainder of the section provides details for the steps.
  1146. <imagedata fileref="figures/recipe-workflow.png" width="6in" depth="7in" align="center" scalefit="1" />
  1147. </para>
  1148. </section>
  1149. <section id='new-recipe-locate-or-automatically-create-a-base-recipe'>
  1150. <title>Locate or Automatically Create a Base Recipe</title>
  1151. <para>
  1152. You can always write a recipe from scratch.
  1153. However, three choices exist that can help you quickly get a
  1154. start on a new recipe:
  1155. <itemizedlist>
  1156. <listitem><para>
  1157. <emphasis><filename>devtool add</filename>:</emphasis>
  1158. A command that assists in creating a recipe and
  1159. an environment conducive to development.
  1160. </para></listitem>
  1161. <listitem><para>
  1162. <emphasis><filename>recipetool create</filename>:</emphasis>
  1163. A command provided by the Yocto Project that automates
  1164. creation of a base recipe based on the source
  1165. files.
  1166. </para></listitem>
  1167. <listitem><para>
  1168. <emphasis>Existing Recipes:</emphasis>
  1169. Location and modification of an existing recipe that is
  1170. similar in function to the recipe you need.
  1171. </para></listitem>
  1172. </itemizedlist>
  1173. </para>
  1174. <section id='new-recipe-creating-the-base-recipe-using-devtool'>
  1175. <title>Creating the Base Recipe Using <filename>devtool add</filename></title>
  1176. <para>
  1177. The <filename>devtool add</filename> command uses the same
  1178. logic for auto-creating the recipe as
  1179. <filename>recipetool create</filename>, which is listed
  1180. below.
  1181. Additionally, however, <filename>devtool add</filename>
  1182. sets up an environment that makes it easy for you to
  1183. patch the source and to make changes to the recipe as
  1184. is often necessary when adding a recipe to build a new
  1185. piece of software to be included in a build.
  1186. </para>
  1187. <para>
  1188. You can find a complete description of the
  1189. <filename>devtool add</filename> command in the
  1190. "<link linkend='use-devtool-to-integrate-new-code'>Use <filename>devtool add</filename> to Add an Application</link>"
  1191. section.
  1192. </para>
  1193. </section>
  1194. <section id='new-recipe-creating-the-base-recipe-using-recipetool'>
  1195. <title>Creating the Base Recipe Using <filename>recipetool create</filename></title>
  1196. <para>
  1197. <filename>recipetool create</filename> automates creation
  1198. of a base recipe given a set of source code files.
  1199. As long as you can extract or point to the source files,
  1200. the tool will construct a recipe and automatically
  1201. configure all pre-build information into the recipe.
  1202. For example, suppose you have an application that builds
  1203. using Autotools.
  1204. Creating the base recipe using
  1205. <filename>recipetool</filename> results in a recipe
  1206. that has the pre-build dependencies, license requirements,
  1207. and checksums configured.
  1208. </para>
  1209. <para>
  1210. To run the tool, you just need to be in your
  1211. <link linkend='build-directory'>Build Directory</link>
  1212. and have sourced the build environment setup script
  1213. (i.e.
  1214. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>
  1215. or
  1216. <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>).
  1217. Here is the basic <filename>recipetool</filename> syntax:
  1218. <note>
  1219. Running <filename>recipetool -h</filename> or
  1220. <filename>recipetool create -h</filename> produces the
  1221. Python-generated help, which presented differently
  1222. than what follows here.
  1223. </note>
  1224. <literallayout class='monospaced'>
  1225. recipetool -h
  1226. recipetool create [-h]
  1227. recipetool [-d] [-q] [--color auto | always | never ] create -o <replaceable>OUTFILE</replaceable> [-m] [-x <replaceable>EXTERNALSRC</replaceable>] <replaceable>source</replaceable>
  1228. -d Enables debug output.
  1229. -q Outputs only errors (quiet mode).
  1230. --color Colorizes the output automatically, always, or never.
  1231. -h Displays Python generated syntax for recipetool.
  1232. create Causes recipetool to create a base recipe. The create
  1233. command is further defined with these options:
  1234. -o <replaceable>OUTFILE</replaceable> Specifies the full path and filename for the generated
  1235. recipe.
  1236. -m Causes the recipe to be machine-specific rather than
  1237. architecture-specific (default).
  1238. -x <replaceable>EXTERNALSRC</replaceable> Fetches and extracts source files from <replaceable>source</replaceable>
  1239. and places them in <replaceable>EXTERNALSRC</replaceable>.
  1240. <replaceable>source</replaceable> must be a URL.
  1241. -h Displays Python-generated syntax for create.
  1242. <replaceable>source</replaceable> Specifies the source code on which to base the
  1243. recipe.
  1244. </literallayout>
  1245. </para>
  1246. <para>
  1247. Running <filename>recipetool create -o</filename>&nbsp;<replaceable>OUTFILE</replaceable>
  1248. creates the base recipe and locates it properly in the
  1249. layer that contains your source files.
  1250. Following are some syntax examples:
  1251. </para>
  1252. <para>
  1253. Use this syntax to generate a recipe based on <replaceable>source</replaceable>.
  1254. Once generated, the recipe resides in the existing source
  1255. code layer:
  1256. <literallayout class='monospaced'>
  1257. recipetool create -o <replaceable>OUTFILE</replaceable>&nbsp;<replaceable>source</replaceable>
  1258. </literallayout>
  1259. Use this syntax to generate a recipe using code that you
  1260. extract from <replaceable>source</replaceable>.
  1261. The extracted code is placed in its own layer defined
  1262. by <replaceable>EXTERNALSRC</replaceable>.
  1263. <literallayout class='monospaced'>
  1264. recipetool create -o <replaceable>OUTFILE</replaceable> -x <replaceable>EXTERNALSRC</replaceable> <replaceable>source</replaceable>
  1265. </literallayout>
  1266. Use this syntax to generate a recipe based on <replaceable>source</replaceable>.
  1267. The options direct <filename>recipetool</filename> to
  1268. run in "quiet mode" and to generate debugging information.
  1269. Once generated, the recipe resides in the existing source
  1270. code layer:
  1271. <literallayout class='monospaced'>
  1272. recipetool create -o <replaceable>OUTFILE</replaceable> <replaceable>source</replaceable>
  1273. </literallayout>
  1274. </para>
  1275. </section>
  1276. <section id='new-recipe-locating-and-using-a-similar-recipe'>
  1277. <title>Locating and Using a Similar Recipe</title>
  1278. <para>
  1279. Before writing a recipe from scratch, it is often useful to
  1280. discover whether someone else has already written one that
  1281. meets (or comes close to meeting) your needs.
  1282. The Yocto Project and OpenEmbedded communities maintain many
  1283. recipes that might be candidates for what you are doing.
  1284. You can find a good central index of these recipes in the
  1285. <ulink url='http://layers.openembedded.org'>OpenEmbedded metadata index</ulink>.
  1286. </para>
  1287. <para>
  1288. Working from an existing recipe or a skeleton recipe is the
  1289. best way to get started.
  1290. Here are some points on both methods:
  1291. <itemizedlist>
  1292. <listitem><para><emphasis>Locate and modify a recipe that
  1293. is close to what you want to do:</emphasis>
  1294. This method works when you are familiar with the
  1295. current recipe space.
  1296. The method does not work so well for those new to
  1297. the Yocto Project or writing recipes.</para>
  1298. <para>Some risks associated with this method are
  1299. using a recipe that has areas totally unrelated to
  1300. what you are trying to accomplish with your recipe,
  1301. not recognizing areas of the recipe that you might
  1302. have to add from scratch, and so forth.
  1303. All these risks stem from unfamiliarity with the
  1304. existing recipe space.</para></listitem>
  1305. <listitem><para><emphasis>Use and modify the following
  1306. skeleton recipe:</emphasis>
  1307. If for some reason you do not want to use
  1308. <filename>recipetool</filename> and you cannot
  1309. find an existing recipe that is close to meeting
  1310. your needs, you can use the following structure to
  1311. provide the fundamental areas of a new recipe.
  1312. <literallayout class='monospaced'>
  1313. DESCRIPTION = ""
  1314. HOMEPAGE = ""
  1315. LICENSE = ""
  1316. SECTION = ""
  1317. DEPENDS = ""
  1318. LIC_FILES_CHKSUM = ""
  1319. SRC_URI = ""
  1320. </literallayout>
  1321. </para></listitem>
  1322. </itemizedlist>
  1323. </para>
  1324. </section>
  1325. </section>
  1326. <section id='new-recipe-storing-and-naming-the-recipe'>
  1327. <title>Storing and Naming the Recipe</title>
  1328. <para>
  1329. Once you have your base recipe, you should put it in your
  1330. own layer and name it appropriately.
  1331. Locating it correctly ensures that the OpenEmbedded build
  1332. system can find it when you use BitBake to process the
  1333. recipe.
  1334. </para>
  1335. <itemizedlist>
  1336. <listitem><para><emphasis>Storing Your Recipe:</emphasis>
  1337. The OpenEmbedded build system locates your recipe
  1338. through the layer's <filename>conf/layer.conf</filename>
  1339. file and the
  1340. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink>
  1341. variable.
  1342. This variable sets up a path from which the build system can
  1343. locate recipes.
  1344. Here is the typical use:
  1345. <literallayout class='monospaced'>
  1346. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  1347. ${LAYERDIR}/recipes-*/*/*.bbappend"
  1348. </literallayout>
  1349. Consequently, you need to be sure you locate your new recipe
  1350. inside your layer such that it can be found.</para>
  1351. <para>You can find more information on how layers are
  1352. structured in the
  1353. "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>"
  1354. section.</para></listitem>
  1355. <listitem><para><emphasis>Naming Your Recipe:</emphasis>
  1356. When you name your recipe, you need to follow this naming
  1357. convention:
  1358. <literallayout class='monospaced'>
  1359. <replaceable>basename</replaceable>_<replaceable>version</replaceable>.bb
  1360. </literallayout>
  1361. Use lower-cased characters and do not include the reserved
  1362. suffixes <filename>-native</filename>,
  1363. <filename>-cross</filename>, <filename>-initial</filename>,
  1364. or <filename>-dev</filename> casually (i.e. do not use them
  1365. as part of your recipe name unless the string applies).
  1366. Here are some examples:
  1367. <literallayout class='monospaced'>
  1368. cups_1.7.0.bb
  1369. gawk_4.0.2.bb
  1370. irssi_0.8.16-rc1.bb
  1371. </literallayout></para></listitem>
  1372. </itemizedlist>
  1373. </section>
  1374. <section id='understanding-recipe-syntax'>
  1375. <title>Understanding Recipe Syntax</title>
  1376. <para>
  1377. Understanding recipe file syntax is important for
  1378. writing recipes.
  1379. The following list overviews the basic items that make up a
  1380. BitBake recipe file.
  1381. For more complete BitBake syntax descriptions, see the
  1382. "<ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>"
  1383. chapter of the BitBake User Manual.
  1384. <itemizedlist>
  1385. <listitem><para><emphasis>Variable Assignments and Manipulations:</emphasis>
  1386. Variable assignments allow a value to be assigned to a
  1387. variable.
  1388. The assignment can be static text or might include
  1389. the contents of other variables.
  1390. In addition to the assignment, appending and prepending
  1391. operations are also supported.</para>
  1392. <para>The following example shows some of the ways
  1393. you can use variables in recipes:
  1394. <literallayout class='monospaced'>
  1395. S = "${WORKDIR}/postfix-${PV}"
  1396. CFLAGS += "-DNO_ASM"
  1397. SRC_URI_append = " file://fixup.patch"
  1398. </literallayout>
  1399. </para></listitem>
  1400. <listitem><para><emphasis>Functions:</emphasis>
  1401. Functions provide a series of actions to be performed.
  1402. You usually use functions to override the default
  1403. implementation of a task function or to complement
  1404. a default function (i.e. append or prepend to an
  1405. existing function).
  1406. Standard functions use <filename>sh</filename> shell
  1407. syntax, although access to OpenEmbedded variables and
  1408. internal methods are also available.</para>
  1409. <para>The following is an example function from the
  1410. <filename>sed</filename> recipe:
  1411. <literallayout class='monospaced'>
  1412. do_install () {
  1413. autotools_do_install
  1414. install -d ${D}${base_bindir}
  1415. mv ${D}${bindir}/sed ${D}${base_bindir}/sed
  1416. rmdir ${D}${bindir}/
  1417. }
  1418. </literallayout>
  1419. It is also possible to implement new functions that
  1420. are called between existing tasks as long as the
  1421. new functions are not replacing or complementing the
  1422. default functions.
  1423. You can implement functions in Python
  1424. instead of shell.
  1425. Both of these options are not seen in the majority of
  1426. recipes.</para></listitem>
  1427. <listitem><para><emphasis>Keywords:</emphasis>
  1428. BitBake recipes use only a few keywords.
  1429. You use keywords to include common
  1430. functions (<filename>inherit</filename>), load parts
  1431. of a recipe from other files
  1432. (<filename>include</filename> and
  1433. <filename>require</filename>) and export variables
  1434. to the environment (<filename>export</filename>).</para>
  1435. <para>The following example shows the use of some of
  1436. these keywords:
  1437. <literallayout class='monospaced'>
  1438. export POSTCONF = "${STAGING_BINDIR}/postconf"
  1439. inherit autoconf
  1440. require otherfile.inc
  1441. </literallayout>
  1442. </para></listitem>
  1443. <listitem><para><emphasis>Comments:</emphasis>
  1444. Any lines that begin with the hash character
  1445. (<filename>#</filename>) are treated as comment lines
  1446. and are ignored:
  1447. <literallayout class='monospaced'>
  1448. # This is a comment
  1449. </literallayout>
  1450. </para></listitem>
  1451. </itemizedlist>
  1452. </para>
  1453. <para>
  1454. This next list summarizes the most important and most commonly
  1455. used parts of the recipe syntax.
  1456. For more information on these parts of the syntax, you can
  1457. reference the
  1458. <ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>
  1459. chapter in the BitBake User Manual.
  1460. <itemizedlist>
  1461. <listitem><para><emphasis>Line Continuation: <filename>\</filename></emphasis> -
  1462. Use the backward slash (<filename>\</filename>)
  1463. character to split a statement over multiple lines.
  1464. Place the slash character at the end of the line that
  1465. is to be continued on the next line:
  1466. <literallayout class='monospaced'>
  1467. VAR = "A really long \
  1468. line"
  1469. </literallayout>
  1470. <note>
  1471. You cannot have any characters including spaces
  1472. or tabs after the slash character.
  1473. </note>
  1474. </para></listitem>
  1475. <listitem><para>
  1476. <emphasis>Using Variables: <filename>${...}</filename></emphasis> -
  1477. Use the <filename>${<replaceable>VARNAME</replaceable>}</filename> syntax to
  1478. access the contents of a variable:
  1479. <literallayout class='monospaced'>
  1480. SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
  1481. </literallayout>
  1482. <note>
  1483. It is important to understand that the value of a
  1484. variable expressed in this form does not get
  1485. substituted automatically.
  1486. The expansion of these expressions happens
  1487. on-demand later (e.g. usually when a function that
  1488. makes reference to the variable executes).
  1489. This behavior ensures that the values are most
  1490. appropriate for the context in which they are
  1491. finally used.
  1492. On the rare occasion that you do need the variable
  1493. expression to be expanded immediately, you can use
  1494. the <filename>:=</filename> operator instead of
  1495. <filename>=</filename> when you make the
  1496. assignment, but this is not generally needed.
  1497. </note>
  1498. </para></listitem>
  1499. <listitem><para><emphasis>Quote All Assignments: <filename>"<replaceable>value</replaceable>"</filename></emphasis> -
  1500. Use double quotes around the value in all variable
  1501. assignments.
  1502. <literallayout class='monospaced'>
  1503. VAR1 = "${OTHERVAR}"
  1504. VAR2 = "The version is ${PV}"
  1505. </literallayout>
  1506. </para></listitem>
  1507. <listitem><para><emphasis>Conditional Assignment: <filename>?=</filename></emphasis> -
  1508. Conditional assignment is used to assign a value to
  1509. a variable, but only when the variable is currently
  1510. unset.
  1511. Use the question mark followed by the equal sign
  1512. (<filename>?=</filename>) to make a "soft" assignment
  1513. used for conditional assignment.
  1514. Typically, "soft" assignments are used in the
  1515. <filename>local.conf</filename> file for variables
  1516. that are allowed to come through from the external
  1517. environment.
  1518. </para>
  1519. <para>Here is an example where
  1520. <filename>VAR1</filename> is set to "New value" if
  1521. it is currently empty.
  1522. However, if <filename>VAR1</filename> has already been
  1523. set, it remains unchanged:
  1524. <literallayout class='monospaced'>
  1525. VAR1 ?= "New value"
  1526. </literallayout>
  1527. In this next example, <filename>VAR1</filename>
  1528. is left with the value "Original value":
  1529. <literallayout class='monospaced'>
  1530. VAR1 = "Original value"
  1531. VAR1 ?= "New value"
  1532. </literallayout>
  1533. </para></listitem>
  1534. <listitem><para><emphasis>Appending: <filename>+=</filename></emphasis> -
  1535. Use the plus character followed by the equals sign
  1536. (<filename>+=</filename>) to append values to existing
  1537. variables.
  1538. <note>
  1539. This operator adds a space between the existing
  1540. content of the variable and the new content.
  1541. </note></para>
  1542. <para>Here is an example:
  1543. <literallayout class='monospaced'>
  1544. SRC_URI += "file://fix-makefile.patch"
  1545. </literallayout>
  1546. </para></listitem>
  1547. <listitem><para><emphasis>Prepending: <filename>=+</filename></emphasis> -
  1548. Use the equals sign followed by the plus character
  1549. (<filename>=+</filename>) to prepend values to existing
  1550. variables.
  1551. <note>
  1552. This operator adds a space between the new content
  1553. and the existing content of the variable.
  1554. </note></para>
  1555. <para>Here is an example:
  1556. <literallayout class='monospaced'>
  1557. VAR =+ "Starts"
  1558. </literallayout>
  1559. </para></listitem>
  1560. <listitem><para><emphasis>Appending: <filename>_append</filename></emphasis> -
  1561. Use the <filename>_append</filename> operator to
  1562. append values to existing variables.
  1563. This operator does not add any additional space.
  1564. Also, the operator is applied after all the
  1565. <filename>+=</filename>, and
  1566. <filename>=+</filename> operators have been applied and
  1567. after all <filename>=</filename> assignments have
  1568. occurred.
  1569. </para>
  1570. <para>The following example shows the space being
  1571. explicitly added to the start to ensure the appended
  1572. value is not merged with the existing value:
  1573. <literallayout class='monospaced'>
  1574. SRC_URI_append = " file://fix-makefile.patch"
  1575. </literallayout>
  1576. You can also use the <filename>_append</filename>
  1577. operator with overrides, which results in the actions
  1578. only being performed for the specified target or
  1579. machine:
  1580. <literallayout class='monospaced'>
  1581. SRC_URI_append_sh4 = " file://fix-makefile.patch"
  1582. </literallayout>
  1583. </para></listitem>
  1584. <listitem><para><emphasis>Prepending: <filename>_prepend</filename></emphasis> -
  1585. Use the <filename>_prepend</filename> operator to
  1586. prepend values to existing variables.
  1587. This operator does not add any additional space.
  1588. Also, the operator is applied after all the
  1589. <filename>+=</filename>, and
  1590. <filename>=+</filename> operators have been applied and
  1591. after all <filename>=</filename> assignments have
  1592. occurred.
  1593. </para>
  1594. <para>The following example shows the space being
  1595. explicitly added to the end to ensure the prepended
  1596. value is not merged with the existing value:
  1597. <literallayout class='monospaced'>
  1598. CFLAGS_prepend = "-I${S}/myincludes "
  1599. </literallayout>
  1600. You can also use the <filename>_prepend</filename>
  1601. operator with overrides, which results in the actions
  1602. only being performed for the specified target or
  1603. machine:
  1604. <literallayout class='monospaced'>
  1605. CFLAGS_prepend_sh4 = "-I${S}/myincludes "
  1606. </literallayout>
  1607. </para></listitem>
  1608. <listitem><para><emphasis>Overrides:</emphasis> -
  1609. You can use overrides to set a value conditionally,
  1610. typically based on how the recipe is being built.
  1611. For example, to set the
  1612. <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'><filename>KBRANCH</filename></ulink>
  1613. variable's value to "standard/base" for any target
  1614. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
  1615. except for qemuarm where it should be set to
  1616. "standard/arm-versatile-926ejs", you would do the
  1617. following:
  1618. <literallayout class='monospaced'>
  1619. KBRANCH = "standard/base"
  1620. KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
  1621. </literallayout>
  1622. Overrides are also used to separate alternate values
  1623. of a variable in other situations.
  1624. For example, when setting variables such as
  1625. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
  1626. and
  1627. <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
  1628. that are specific to individual packages produced by
  1629. a recipe, you should always use an override that
  1630. specifies the name of the package.
  1631. </para></listitem>
  1632. <listitem><para><emphasis>Indentation:</emphasis>
  1633. Use spaces for indentation rather than than tabs.
  1634. For shell functions, both currently work.
  1635. However, it is a policy decision of the Yocto Project
  1636. to use tabs in shell functions.
  1637. Realize that some layers have a policy to use spaces
  1638. for all indentation.
  1639. </para></listitem>
  1640. <listitem><para><emphasis>Using Python for Complex Operations: <filename>${@<replaceable>python_code</replaceable>}</filename></emphasis> -
  1641. For more advanced processing, it is possible to use
  1642. Python code during variable assignments (e.g.
  1643. search and replacement on a variable).</para>
  1644. <para>You indicate Python code using the
  1645. <filename>${@<replaceable>python_code</replaceable>}</filename>
  1646. syntax for the variable assignment:
  1647. <literallayout class='monospaced'>
  1648. SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
  1649. </literallayout>
  1650. </para></listitem>
  1651. <listitem><para><emphasis>Shell Function Syntax:</emphasis>
  1652. Write shell functions as if you were writing a shell
  1653. script when you describe a list of actions to take.
  1654. You should ensure that your script works with a generic
  1655. <filename>sh</filename> and that it does not require
  1656. any <filename>bash</filename> or other shell-specific
  1657. functionality.
  1658. The same considerations apply to various system
  1659. utilities (e.g. <filename>sed</filename>,
  1660. <filename>grep</filename>, <filename>awk</filename>,
  1661. and so forth) that you might wish to use.
  1662. If in doubt, you should check with multiple
  1663. implementations - including those from BusyBox.
  1664. </para></listitem>
  1665. </itemizedlist>
  1666. </para>
  1667. </section>
  1668. <section id='new-recipe-running-a-build-on-the-recipe'>
  1669. <title>Running a Build on the Recipe</title>
  1670. <para>
  1671. Creating a new recipe is usually an iterative process that
  1672. requires using BitBake to process the recipe multiple times in
  1673. order to progressively discover and add information to the
  1674. recipe file.
  1675. </para>
  1676. <para>
  1677. Assuming you have sourced a build environment setup script (i.e.
  1678. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
  1679. or
  1680. <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>)
  1681. and you are in the
  1682. <link linkend='build-directory'>Build Directory</link>,
  1683. use BitBake to process your recipe.
  1684. All you need to provide is the
  1685. <filename><replaceable>basename</replaceable></filename> of the recipe as described
  1686. in the previous section:
  1687. <literallayout class='monospaced'>
  1688. $ bitbake <replaceable>basename</replaceable>
  1689. </literallayout>
  1690. </para>
  1691. <para>
  1692. During the build, the OpenEmbedded build system creates a
  1693. temporary work directory for each recipe
  1694. (<filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>)
  1695. where it keeps extracted source files, log files, intermediate
  1696. compilation and packaging files, and so forth.
  1697. </para>
  1698. <para>
  1699. The path to the per-recipe temporary work directory depends
  1700. on the context in which it is being built.
  1701. The quickest way to find this path is to have BitBake return it
  1702. by running the following:
  1703. <literallayout class='monospaced'>
  1704. $ bitbake -e <replaceable>basename</replaceable> | grep ^WORKDIR=
  1705. </literallayout>
  1706. As an example, assume a Source Directory top-level folder named
  1707. <filename>poky</filename>, a default Build Directory at
  1708. <filename>poky/build</filename>, and a
  1709. <filename>qemux86-poky-linux</filename> machine target system.
  1710. Furthermore, suppose your recipe is named
  1711. <filename>foo_1.3.0.bb</filename>.
  1712. In this case, the work directory the build system uses to
  1713. build the package would be as follows:
  1714. <literallayout class='monospaced'>
  1715. poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
  1716. </literallayout>
  1717. Inside this directory you can find sub-directories such as
  1718. <filename>image</filename>, <filename>packages-split</filename>,
  1719. and <filename>temp</filename>.
  1720. After the build, you can examine these to determine how well
  1721. the build went.
  1722. <note>
  1723. You can find log files for each task in the recipe's
  1724. <filename>temp</filename> directory (e.g.
  1725. <filename>poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp</filename>).
  1726. Log files are named <filename>log.<replaceable>taskname</replaceable></filename>
  1727. (e.g. <filename>log.do_configure</filename>,
  1728. <filename>log.do_fetch</filename>, and
  1729. <filename>log.do_compile</filename>).
  1730. </note>
  1731. </para>
  1732. <para>
  1733. You can find more information about the build process in the
  1734. "<ulink url='&YOCTO_DOCS_REF_URL;#closer-look'>A Closer Look at the Yocto Project Development Environment</ulink>"
  1735. chapter of the Yocto Project Reference Manual.
  1736. </para>
  1737. </section>
  1738. <section id='new-recipe-fetching-code'>
  1739. <title>Fetching Code</title>
  1740. <para>
  1741. The first thing your recipe must do is specify how to fetch
  1742. the source files.
  1743. Fetching is controlled mainly through the
  1744. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  1745. variable.
  1746. Your recipe must have a <filename>SRC_URI</filename> variable
  1747. that points to where the source is located.
  1748. For a graphical representation of source locations, see the
  1749. "<ulink url='&YOCTO_DOCS_REF_URL;#sources-dev-environment'>Sources</ulink>"
  1750. section in the Yocto Project Reference Manual.
  1751. </para>
  1752. <para>
  1753. The
  1754. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
  1755. task uses the prefix of each entry in the
  1756. <filename>SRC_URI</filename> variable value to determine which
  1757. fetcher to use to get your source files.
  1758. It is the <filename>SRC_URI</filename> variable that triggers
  1759. the fetcher.
  1760. The
  1761. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
  1762. task uses the variable after source is fetched to apply
  1763. patches.
  1764. The OpenEmbedded build system uses
  1765. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESOVERRIDES'><filename>FILESOVERRIDES</filename></ulink>
  1766. for scanning directory locations for local files in
  1767. <filename>SRC_URI</filename>.
  1768. </para>
  1769. <para>
  1770. The <filename>SRC_URI</filename> variable in your recipe must
  1771. define each unique location for your source files.
  1772. It is good practice to not hard-code pathnames in an URL used
  1773. in <filename>SRC_URI</filename>.
  1774. Rather than hard-code these paths, use
  1775. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>,
  1776. which causes the fetch process to use the version specified in
  1777. the recipe filename.
  1778. Specifying the version in this manner means that upgrading the
  1779. recipe to a future version is as simple as renaming the recipe
  1780. to match the new version.
  1781. </para>
  1782. <para>
  1783. Here is a simple example from the
  1784. <filename>meta/recipes-devtools/cdrtools/cdrtools-native_3.01a20.bb</filename>
  1785. recipe where the source comes from a single tarball.
  1786. Notice the use of the
  1787. <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
  1788. variable:
  1789. <literallayout class='monospaced'>
  1790. SRC_URI = "ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-${PV}.tar.bz2"
  1791. </literallayout>
  1792. </para>
  1793. <para>
  1794. Files mentioned in <filename>SRC_URI</filename> whose names end
  1795. in a typical archive extension (e.g. <filename>.tar</filename>,
  1796. <filename>.tar.gz</filename>, <filename>.tar.bz2</filename>,
  1797. <filename>.zip</filename>, and so forth), are automatically
  1798. extracted during the
  1799. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
  1800. task.
  1801. For another example that specifies these types of files, see
  1802. the
  1803. "<link linkend='new-recipe-autotooled-package'>Autotooled Package</link>"
  1804. section.
  1805. </para>
  1806. <para>
  1807. Another way of specifying source is from an SCM.
  1808. For Git repositories, you must specify
  1809. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
  1810. and you should specify
  1811. <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
  1812. to include the revision with
  1813. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
  1814. Here is an example from the recipe
  1815. <filename>meta/recipes-kernel/blktrace/blktrace_git.bb</filename>:
  1816. <literallayout class='monospaced'>
  1817. SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
  1818. PR = "r6"
  1819. PV = "1.0.5+git${SRCPV}"
  1820. SRC_URI = "git://git.kernel.dk/blktrace.git \
  1821. file://ldflags.patch"
  1822. </literallayout>
  1823. </para>
  1824. <para>
  1825. If your <filename>SRC_URI</filename> statement includes
  1826. URLs pointing to individual files fetched from a remote server
  1827. other than a version control system, BitBake attempts to
  1828. verify the files against checksums defined in your recipe to
  1829. ensure they have not been tampered with or otherwise modified
  1830. since the recipe was written.
  1831. Two checksums are used:
  1832. <filename>SRC_URI[md5sum]</filename> and
  1833. <filename>SRC_URI[sha256sum]</filename>.
  1834. </para>
  1835. <para>
  1836. If your <filename>SRC_URI</filename> variable points to
  1837. more than a single URL (excluding SCM URLs), you need to
  1838. provide the <filename>md5</filename> and
  1839. <filename>sha256</filename> checksums for each URL.
  1840. For these cases, you provide a name for each URL as part of
  1841. the <filename>SRC_URI</filename> and then reference that name
  1842. in the subsequent checksum statements.
  1843. Here is an example:
  1844. <literallayout class='monospaced'>
  1845. SRC_URI = "${DEBIAN_MIRROR}/main/a/apmd/apmd_3.2.2.orig.tar.gz;name=tarball \
  1846. ${DEBIAN_MIRROR}/main/a/apmd/apmd_${PV}.diff.gz;name=patch"
  1847. SRC_URI[tarball.md5sum] = "b1e6309e8331e0f4e6efd311c2d97fa8"
  1848. SRC_URI[tarball.sha256sum] = "7f7d9f60b7766b852881d40b8ff91d8e39fccb0d1d913102a5c75a2dbb52332d"
  1849. SRC_URI[patch.md5sum] = "57e1b689264ea80f78353519eece0c92"
  1850. SRC_URI[patch.sha256sum] = "7905ff96be93d725544d0040e425c42f9c05580db3c272f11cff75b9aa89d430"
  1851. </literallayout>
  1852. </para>
  1853. <para>
  1854. Proper values for <filename>md5</filename> and
  1855. <filename>sha256</filename> checksums might be available
  1856. with other signatures on the download page for the upstream
  1857. source (e.g. <filename>md5</filename>,
  1858. <filename>sha1</filename>, <filename>sha256</filename>,
  1859. <filename>GPG</filename>, and so forth).
  1860. Because the OpenEmbedded build system only deals with
  1861. <filename>sha256sum</filename> and <filename>md5sum</filename>,
  1862. you should verify all the signatures you find by hand.
  1863. </para>
  1864. <para>
  1865. If no <filename>SRC_URI</filename> checksums are specified
  1866. when you attempt to build the recipe, or you provide an
  1867. incorrect checksum, the build will produce an error for each
  1868. missing or incorrect checksum.
  1869. As part of the error message, the build system provides
  1870. the checksum string corresponding to the fetched file.
  1871. Once you have the correct checksums, you can copy and paste
  1872. them into your recipe and then run the build again to continue.
  1873. <note>
  1874. As mentioned, if the upstream source provides signatures
  1875. for verifying the downloaded source code, you should
  1876. verify those manually before setting the checksum values
  1877. in the recipe and continuing with the build.
  1878. </note>
  1879. </para>
  1880. <para>
  1881. This final example is a bit more complicated and is from the
  1882. <filename>meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb</filename>
  1883. recipe.
  1884. The example's <filename>SRC_URI</filename> statement identifies
  1885. multiple files as the source files for the recipe: a tarball, a
  1886. patch file, a desktop file, and an icon.
  1887. <literallayout class='monospaced'>
  1888. SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
  1889. file://xwc.patch \
  1890. file://rxvt.desktop \
  1891. file://rxvt.png"
  1892. </literallayout>
  1893. </para>
  1894. <para>
  1895. When you specify local files using the
  1896. <filename>file://</filename> URI protocol, the build system
  1897. fetches files from the local machine.
  1898. The path is relative to the
  1899. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
  1900. variable and searches specific directories in a certain order:
  1901. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink><filename>}</filename>,
  1902. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}</filename>,
  1903. and <filename>files</filename>.
  1904. The directories are assumed to be subdirectories of the
  1905. directory in which the recipe or append file resides.
  1906. For another example that specifies these types of files, see the
  1907. "<link linkend='new-recipe-single-c-file-package-hello-world'>Single .c File Package (Hello World!)</link>"
  1908. section.
  1909. </para>
  1910. <para>
  1911. The previous example also specifies a patch file.
  1912. Patch files are files whose names usually end in
  1913. <filename>.patch</filename> or <filename>.diff</filename> but
  1914. can end with compressed suffixes such as
  1915. <filename>diff.gz</filename> and
  1916. <filename>patch.bz2</filename>, for example.
  1917. The build system automatically applies patches as described
  1918. in the
  1919. "<link linkend='new-recipe-patching-code'>Patching Code</link>" section.
  1920. </para>
  1921. </section>
  1922. <section id='new-recipe-unpacking-code'>
  1923. <title>Unpacking Code</title>
  1924. <para>
  1925. During the build, the
  1926. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
  1927. task unpacks the source with
  1928. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>
  1929. pointing to where it is unpacked.
  1930. </para>
  1931. <para>
  1932. If you are fetching your source files from an upstream source
  1933. archived tarball and the tarball's internal structure matches
  1934. the common convention of a top-level subdirectory named
  1935. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}-${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>,
  1936. then you do not need to set <filename>S</filename>.
  1937. However, if <filename>SRC_URI</filename> specifies to fetch
  1938. source from an archive that does not use this convention,
  1939. or from an SCM like Git or Subversion, your recipe needs to
  1940. define <filename>S</filename>.
  1941. </para>
  1942. <para>
  1943. If processing your recipe using BitBake successfully unpacks
  1944. the source files, you need to be sure that the directory
  1945. pointed to by <filename>${S}</filename> matches the structure
  1946. of the source.
  1947. </para>
  1948. </section>
  1949. <section id='new-recipe-patching-code'>
  1950. <title>Patching Code</title>
  1951. <para>
  1952. Sometimes it is necessary to patch code after it has been
  1953. fetched.
  1954. Any files mentioned in <filename>SRC_URI</filename> whose
  1955. names end in <filename>.patch</filename> or
  1956. <filename>.diff</filename> or compressed versions of these
  1957. suffixes (e.g. <filename>diff.gz</filename> are treated as
  1958. patches.
  1959. The
  1960. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
  1961. task automatically applies these patches.
  1962. </para>
  1963. <para>
  1964. The build system should be able to apply patches with the "-p1"
  1965. option (i.e. one directory level in the path will be stripped
  1966. off).
  1967. If your patch needs to have more directory levels stripped off,
  1968. specify the number of levels using the "striplevel" option in
  1969. the <filename>SRC_URI</filename> entry for the patch.
  1970. Alternatively, if your patch needs to be applied in a specific
  1971. subdirectory that is not specified in the patch file, use the
  1972. "patchdir" option in the entry.
  1973. </para>
  1974. <para>
  1975. As with all local files referenced in
  1976. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  1977. using <filename>file://</filename>, you should place
  1978. patch files in a directory next to the recipe either
  1979. named the same as the base name of the recipe
  1980. (<ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
  1981. and
  1982. <ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink>)
  1983. or "files".
  1984. </para>
  1985. </section>
  1986. <section id='new-recipe-licensing'>
  1987. <title>Licensing</title>
  1988. <para>
  1989. Your recipe needs to have both the
  1990. <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
  1991. and
  1992. <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
  1993. variables:
  1994. <itemizedlist>
  1995. <listitem><para><emphasis><filename>LICENSE</filename>:</emphasis>
  1996. This variable specifies the license for the software.
  1997. If you do not know the license under which the software
  1998. you are building is distributed, you should go to the
  1999. source code and look for that information.
  2000. Typical files containing this information include
  2001. <filename>COPYING</filename>,
  2002. <filename>LICENSE</filename>, and
  2003. <filename>README</filename> files.
  2004. You could also find the information near the top of
  2005. a source file.
  2006. For example, given a piece of software licensed under
  2007. the GNU General Public License version 2, you would
  2008. set <filename>LICENSE</filename> as follows:
  2009. <literallayout class='monospaced'>
  2010. LICENSE = "GPLv2"
  2011. </literallayout></para>
  2012. <para>The licenses you specify within
  2013. <filename>LICENSE</filename> can have any name as long
  2014. as you do not use spaces, since spaces are used as
  2015. separators between license names.
  2016. For standard licenses, use the names of the files in
  2017. <filename>meta/files/common-licenses/</filename>
  2018. or the <filename>SPDXLICENSEMAP</filename> flag names
  2019. defined in <filename>meta/conf/licenses.conf</filename>.
  2020. </para></listitem>
  2021. <listitem><para><emphasis><filename>LIC_FILES_CHKSUM</filename>:</emphasis>
  2022. The OpenEmbedded build system uses this variable to
  2023. make sure the license text has not changed.
  2024. If it has, the build produces an error and it affords
  2025. you the chance to figure it out and correct the problem.
  2026. </para>
  2027. <para>You need to specify all applicable licensing
  2028. files for the software.
  2029. At the end of the configuration step, the build process
  2030. will compare the checksums of the files to be sure
  2031. the text has not changed.
  2032. Any differences result in an error with the message
  2033. containing the current checksum.
  2034. For more explanation and examples of how to set the
  2035. <filename>LIC_FILES_CHKSUM</filename> variable, see the
  2036. "<ulink url='&YOCTO_DOCS_REF_URL;#usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</ulink>"
  2037. section in the Yocto Project Reference Manual.</para>
  2038. <para>To determine the correct checksum string, you
  2039. can list the appropriate files in the
  2040. <filename>LIC_FILES_CHKSUM</filename> variable with
  2041. incorrect md5 strings, attempt to build the software,
  2042. and then note the resulting error messages that will
  2043. report the correct md5 strings.
  2044. See the
  2045. "<link linkend='new-recipe-fetching-code'>Fetching Code</link>"
  2046. section for additional information.
  2047. </para>
  2048. <para>
  2049. Here is an example that assumes the software has a
  2050. <filename>COPYING</filename> file:
  2051. <literallayout class='monospaced'>
  2052. LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
  2053. </literallayout>
  2054. When you try to build the software, the build system
  2055. will produce an error and give you the correct string
  2056. that you can substitute into the recipe file for a
  2057. subsequent build.
  2058. </para></listitem>
  2059. </itemizedlist>
  2060. </para>
  2061. <!--
  2062. <para>
  2063. For trying this out I created a new recipe named
  2064. <filename>htop_1.0.2.bb</filename> and put it in
  2065. <filename>poky/meta/recipes-extended/htop</filename>.
  2066. There are two license type statements in my very simple
  2067. recipe:
  2068. <literallayout class='monospaced'>
  2069. LICENSE = ""
  2070. LIC_FILES_CHKSUM = ""
  2071. SRC_URI[md5sum] = ""
  2072. SRC_URI[sha256sum] = ""
  2073. </literallayout>
  2074. Evidently, you need to run a <filename>bitbake -c cleanall htop</filename>.
  2075. Next, you delete or comment out the two <filename>SRC_URI</filename>
  2076. lines at the end and then attempt to build the software with
  2077. <filename>bitbake htop</filename>.
  2078. Doing so causes BitBake to report some errors and and give
  2079. you the actual strings you need for the last two
  2080. <filename>SRC_URI</filename> lines.
  2081. Prior to this, you have to dig around in the home page of the
  2082. source for <filename>htop</filename> and determine that the
  2083. software is released under GPLv2.
  2084. You can provide that in the <filename>LICENSE</filename>
  2085. statement.
  2086. Now you edit your recipe to have those two strings for
  2087. the <filename>SRC_URI</filename> statements:
  2088. <literallayout class='monospaced'>
  2089. LICENSE = "GPLv2"
  2090. LIC_FILES_CHKSUM = ""
  2091. SRC_URI = "${SOURCEFORGE_MIRROR}/htop/htop-${PV}.tar.gz"
  2092. SRC_URI[md5sum] = "0d01cca8df3349c74569cefebbd9919e"
  2093. SRC_URI[sha256sum] = "ee60657b044ece0df096c053060df7abf3cce3a568ab34d260049e6a37ccd8a1"
  2094. </literallayout>
  2095. At this point, you can build the software again using the
  2096. <filename>bitbake htop</filename> command.
  2097. There is just a set of errors now associated with the
  2098. empty <filename>LIC_FILES_CHKSUM</filename> variable now.
  2099. </para>
  2100. -->
  2101. </section>
  2102. <section id='new-dependencies'>
  2103. <title>Dependencies</title>
  2104. <para>
  2105. Most software packages have a short list of other packages
  2106. that they require, which are called dependencies.
  2107. These dependencies fall into two main categories: build-time
  2108. dependencies, which are required when the software is built;
  2109. and runtime dependencies, which are required to be installed
  2110. on the target in order for the software to run.
  2111. </para>
  2112. <para>
  2113. Within a recipe, you specify build-time dependencies using the
  2114. <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
  2115. variable.
  2116. Although nuances exist, items specified in
  2117. <filename>DEPENDS</filename> should be names of other recipes.
  2118. It is important that you specify all build-time dependencies
  2119. explicitly.
  2120. If you do not, due to the parallel nature of BitBake's
  2121. execution, you can end up with a race condition where the
  2122. dependency is present for one task of a recipe (e.g.
  2123. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>)
  2124. and then gone when the next task runs (e.g.
  2125. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>).
  2126. </para>
  2127. <para>
  2128. Another consideration is that configure scripts might
  2129. automatically check for optional dependencies and enable
  2130. corresponding functionality if those dependencies are found.
  2131. This behavior means that to ensure deterministic results and
  2132. thus avoid more race conditions, you need to either explicitly
  2133. specify these dependencies as well, or tell the configure
  2134. script explicitly to disable the functionality.
  2135. If you wish to make a recipe that is more generally useful
  2136. (e.g. publish the recipe in a layer for others to use),
  2137. instead of hard-disabling the functionality, you can use the
  2138. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG'><filename>PACKAGECONFIG</filename></ulink>
  2139. variable to allow functionality and the corresponding
  2140. dependencies to be enabled and disabled easily by other
  2141. users of the recipe.
  2142. </para>
  2143. <para>
  2144. Similar to build-time dependencies, you specify runtime
  2145. dependencies through a variable -
  2146. <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
  2147. which is package-specific.
  2148. All variables that are package-specific need to have the name
  2149. of the package added to the end as an override.
  2150. Since the main package for a recipe has the same name as the
  2151. recipe, and the recipe's name can be found through the
  2152. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
  2153. variable, then you specify the dependencies for the main
  2154. package by setting <filename>RDEPENDS_${PN}</filename>.
  2155. If the package were named <filename>${PN}-tools</filename>,
  2156. then you would set <filename>RDEPENDS_${PN}-tools</filename>,
  2157. and so forth.
  2158. </para>
  2159. <para>
  2160. Some runtime dependencies will be set automatically at
  2161. packaging time.
  2162. These dependencies include any shared library dependencies
  2163. (i.e. if a package "example" contains "libexample" and
  2164. another package "mypackage" contains a binary that links to
  2165. "libexample" then the OpenEmbedded build system will
  2166. automatically add a runtime dependency to "mypackage" on
  2167. "example").
  2168. See the
  2169. "<ulink url='&YOCTO_DOCS_REF_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>"
  2170. in the Yocto Project Reference Manual for further details.
  2171. </para>
  2172. </section>
  2173. <section id='new-recipe-configuring-the-recipe'>
  2174. <title>Configuring the Recipe</title>
  2175. <para>
  2176. Most software provides some means of setting build-time
  2177. configuration options before compilation.
  2178. Typically, setting these options is accomplished by running a
  2179. configure script with some options, or by modifying a build
  2180. configuration file.
  2181. <note>
  2182. As of Yocto Project Release 1.7, some of the core recipes
  2183. that package binary configuration scripts now disable the
  2184. scripts due to the scripts previously requiring error-prone
  2185. path substitution.
  2186. The OpenEmbedded build system uses
  2187. <filename>pkg-config</filename> now, which is much more
  2188. robust.
  2189. You can find a list of the <filename>*-config</filename>
  2190. scripts that are disabled list in the
  2191. "<ulink url='&YOCTO_DOCS_REF_URL;#migration-1.7-binary-configuration-scripts-disabled'>Binary Configuration Scripts Disabled</ulink>"
  2192. section in the Yocto Project Reference Manual.
  2193. </note>
  2194. </para>
  2195. <para>
  2196. A major part of build-time configuration is about checking for
  2197. build-time dependencies and possibly enabling optional
  2198. functionality as a result.
  2199. You need to specify any build-time dependencies for the
  2200. software you are building in your recipe's
  2201. <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
  2202. value, in terms of other recipes that satisfy those
  2203. dependencies.
  2204. You can often find build-time or runtime
  2205. dependencies described in the software's documentation.
  2206. </para>
  2207. <para>
  2208. The following list provides configuration items of note based
  2209. on how your software is built:
  2210. <itemizedlist>
  2211. <listitem><para><emphasis>Autotools:</emphasis>
  2212. If your source files have a
  2213. <filename>configure.ac</filename> file, then your
  2214. software is built using Autotools.
  2215. If this is the case, you just need to worry about
  2216. modifying the configuration.</para>
  2217. <para>When using Autotools, your recipe needs to inherit
  2218. the
  2219. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
  2220. class and your recipe does not have to contain a
  2221. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
  2222. task.
  2223. However, you might still want to make some adjustments.
  2224. For example, you can set
  2225. <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECONF'><filename>EXTRA_OECONF</filename></ulink>
  2226. or
  2227. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
  2228. to pass any needed configure options that are specific
  2229. to the recipe.</para></listitem>
  2230. <listitem><para><emphasis>CMake:</emphasis>
  2231. If your source files have a
  2232. <filename>CMakeLists.txt</filename> file, then your
  2233. software is built using CMake.
  2234. If this is the case, you just need to worry about
  2235. modifying the configuration.</para>
  2236. <para>When you use CMake, your recipe needs to inherit
  2237. the
  2238. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
  2239. class and your recipe does not have to contain a
  2240. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
  2241. task.
  2242. You can make some adjustments by setting
  2243. <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECMAKE'><filename>EXTRA_OECMAKE</filename></ulink>
  2244. to pass any needed configure options that are specific
  2245. to the recipe.</para></listitem>
  2246. <listitem><para><emphasis>Other:</emphasis>
  2247. If your source files do not have a
  2248. <filename>configure.ac</filename> or
  2249. <filename>CMakeLists.txt</filename> file, then your
  2250. software is built using some method other than Autotools
  2251. or CMake.
  2252. If this is the case, you normally need to provide a
  2253. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
  2254. task in your recipe
  2255. unless, of course, there is nothing to configure.
  2256. </para>
  2257. <para>Even if your software is not being built by
  2258. Autotools or CMake, you still might not need to deal
  2259. with any configuration issues.
  2260. You need to determine if configuration is even a required step.
  2261. You might need to modify a Makefile or some configuration file
  2262. used for the build to specify necessary build options.
  2263. Or, perhaps you might need to run a provided, custom
  2264. configure script with the appropriate options.</para>
  2265. <para>For the case involving a custom configure
  2266. script, you would run
  2267. <filename>./configure --help</filename> and look for
  2268. the options you need to set.</para></listitem>
  2269. </itemizedlist>
  2270. </para>
  2271. <para>
  2272. Once configuration succeeds, it is always good practice to
  2273. look at the <filename>log.do_configure</filename> file to
  2274. ensure that the appropriate options have been enabled and no
  2275. additional build-time dependencies need to be added to
  2276. <filename>DEPENDS</filename>.
  2277. For example, if the configure script reports that it found
  2278. something not mentioned in <filename>DEPENDS</filename>, or
  2279. that it did not find something that it needed for some
  2280. desired optional functionality, then you would need to add
  2281. those to <filename>DEPENDS</filename>.
  2282. Looking at the log might also reveal items being checked for,
  2283. enabled, or both that you do not want, or items not being found
  2284. that are in <filename>DEPENDS</filename>, in which case
  2285. you would need to look at passing extra options to the
  2286. configure script as needed.
  2287. For reference information on configure options specific to the
  2288. software you are building, you can consult the output of the
  2289. <filename>./configure --help</filename> command within
  2290. <filename>${S}</filename> or consult the software's upstream
  2291. documentation.
  2292. </para>
  2293. </section>
  2294. <section id='new-recipe-compilation'>
  2295. <title>Compilation</title>
  2296. <para>
  2297. During a build, the <filename>do_compile</filename> task
  2298. happens after source is fetched, unpacked, and configured.
  2299. If the recipe passes through <filename>do_compile</filename>
  2300. successfully, nothing needs to be done.
  2301. </para>
  2302. <para>
  2303. However, if the compile step fails, you need to diagnose the
  2304. failure.
  2305. Here are some common issues that cause failures.
  2306. <note>
  2307. For cases where improper paths are detected for
  2308. configuration files or for when libraries/headers cannot
  2309. be found, be sure you are using the more robust
  2310. <filename>pkg-config</filename>.
  2311. See the note in section
  2312. "<link linkend='new-recipe-configuring-the-recipe'>Configuring the Recipe</link>"
  2313. for additional information.
  2314. </note>
  2315. <itemizedlist>
  2316. <listitem><para><emphasis>Parallel build failures:</emphasis>
  2317. These failures manifest themselves as intermittent
  2318. errors, or errors reporting that a file or directory
  2319. that should be created by some other part of the build
  2320. process could not be found.
  2321. This type of failure can occur even if, upon inspection,
  2322. the file or directory does exist after the build has
  2323. failed, because that part of the build process happened
  2324. in the wrong order.</para>
  2325. <para>To fix the problem, you need to either satisfy
  2326. the missing dependency in the Makefile or whatever
  2327. script produced the Makefile, or (as a workaround)
  2328. set
  2329. <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
  2330. to an empty string:
  2331. <literallayout class='monospaced'>
  2332. PARALLEL_MAKE = ""
  2333. </literallayout></para>
  2334. <para>
  2335. For information on parallel Makefile issues, see the
  2336. "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
  2337. section.
  2338. </para></listitem>
  2339. <listitem><para><emphasis>Improper host path usage:</emphasis>
  2340. This failure applies to recipes building for the target
  2341. or <filename>nativesdk</filename> only.
  2342. The failure occurs when the compilation process uses
  2343. improper headers, libraries, or other files from the
  2344. host system when cross-compiling for the target.
  2345. </para>
  2346. <para>To fix the problem, examine the
  2347. <filename>log.do_compile</filename> file to identify
  2348. the host paths being used (e.g.
  2349. <filename>/usr/include</filename>,
  2350. <filename>/usr/lib</filename>, and so forth) and then
  2351. either add configure options, apply a patch, or do both.
  2352. </para></listitem>
  2353. <listitem><para><emphasis>Failure to find required
  2354. libraries/headers:</emphasis>
  2355. If a build-time dependency is missing because it has
  2356. not been declared in
  2357. <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
  2358. or because the dependency exists but the path used by
  2359. the build process to find the file is incorrect and the
  2360. configure step did not detect it, the compilation
  2361. process could fail.
  2362. For either of these failures, the compilation process
  2363. notes that files could not be found.
  2364. In these cases, you need to go back and add additional
  2365. options to the configure script as well as possibly
  2366. add additional build-time dependencies to
  2367. <filename>DEPENDS</filename>.</para>
  2368. <para>Occasionally, it is necessary to apply a patch
  2369. to the source to ensure the correct paths are used.
  2370. If you need to specify paths to find files staged
  2371. into the sysroot from other recipes, use the variables
  2372. that the OpenEmbedded build system provides
  2373. (e.g.
  2374. <filename>STAGING_BINDIR</filename>,
  2375. <filename>STAGING_INCDIR</filename>,
  2376. <filename>STAGING_DATADIR</filename>, and so forth).
  2377. <!--
  2378. (e.g.
  2379. <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_BINDIR'><filename>STAGING_BINDIR</filename></ulink>,
  2380. <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_INCDIR'><filename>STAGING_INCDIR</filename></ulink>,
  2381. <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DATADIR'><filename>STAGING_DATADIR</filename></ulink>,
  2382. and so forth).
  2383. -->
  2384. </para></listitem>
  2385. </itemizedlist>
  2386. </para>
  2387. </section>
  2388. <section id='new-recipe-installing'>
  2389. <title>Installing</title>
  2390. <para>
  2391. During <filename>do_install</filename>, the task copies the
  2392. built files along with their hierarchy to locations that
  2393. would mirror their locations on the target device.
  2394. The installation process copies files from the
  2395. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
  2396. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-B'><filename>B</filename></ulink><filename>}</filename>,
  2397. and
  2398. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>
  2399. directories to the
  2400. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
  2401. directory to create the structure as it should appear on the
  2402. target system.
  2403. </para>
  2404. <para>
  2405. How your software is built affects what you must do to be
  2406. sure your software is installed correctly.
  2407. The following list describes what you must do for installation
  2408. depending on the type of build system used by the software
  2409. being built:
  2410. <itemizedlist>
  2411. <listitem><para><emphasis>Autotools and CMake:</emphasis>
  2412. If the software your recipe is building uses Autotools
  2413. or CMake, the OpenEmbedded build
  2414. system understands how to install the software.
  2415. Consequently, you do not have to have a
  2416. <filename>do_install</filename> task as part of your
  2417. recipe.
  2418. You just need to make sure the install portion of the
  2419. build completes with no issues.
  2420. However, if you wish to install additional files not
  2421. already being installed by
  2422. <filename>make install</filename>, you should do this
  2423. using a <filename>do_install_append</filename> function
  2424. using the install command as described in
  2425. the "Manual" bulleted item later in this list.
  2426. </para></listitem>
  2427. <listitem><para><emphasis>Other (using
  2428. <filename>make install</filename>):</emphasis>
  2429. You need to define a
  2430. <filename>do_install</filename> function in your
  2431. recipe.
  2432. The function should call
  2433. <filename>oe_runmake install</filename> and will likely
  2434. need to pass in the destination directory as well.
  2435. How you pass that path is dependent on how the
  2436. <filename>Makefile</filename> being run is written
  2437. (e.g. <filename>DESTDIR=${D}</filename>,
  2438. <filename>PREFIX=${D}</filename>,
  2439. <filename>INSTALLROOT=${D}</filename>, and so forth).
  2440. </para>
  2441. <para>For an example recipe using
  2442. <filename>make install</filename>, see the
  2443. "<link linkend='new-recipe-makefile-based-package'>Makefile-Based Package</link>"
  2444. section.</para></listitem>
  2445. <listitem><para><emphasis>Manual:</emphasis>
  2446. You need to define a
  2447. <filename>do_install</filename> function in your
  2448. recipe.
  2449. The function must first use
  2450. <filename>install -d</filename> to create the
  2451. directories under
  2452. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>.
  2453. Once the directories exist, your function can use
  2454. <filename>install</filename> to manually install the
  2455. built software into the directories.</para>
  2456. <para>You can find more information on
  2457. <filename>install</filename> at
  2458. <ulink url='http://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html'></ulink>.
  2459. </para></listitem>
  2460. </itemizedlist>
  2461. </para>
  2462. <para>
  2463. For the scenarios that do not use Autotools or
  2464. CMake, you need to track the installation
  2465. and diagnose and fix any issues until everything installs
  2466. correctly.
  2467. You need to look in the default location of
  2468. <filename>${D}</filename>, which is
  2469. <filename>${WORKDIR}/image</filename>, to be sure your
  2470. files have been installed correctly.
  2471. </para>
  2472. <note><title>Notes</title>
  2473. <itemizedlist>
  2474. <listitem><para>
  2475. During the installation process, you might need to
  2476. modify some of the installed files to suit the target
  2477. layout.
  2478. For example, you might need to replace hard-coded paths
  2479. in an initscript with values of variables provided by
  2480. the build system, such as replacing
  2481. <filename>/usr/bin/</filename> with
  2482. <filename>${bindir}</filename>.
  2483. If you do perform such modifications during
  2484. <filename>do_install</filename>, be sure to modify the
  2485. destination file after copying rather than before
  2486. copying.
  2487. Modifying after copying ensures that the build system
  2488. can re-execute <filename>do_install</filename> if
  2489. needed.
  2490. </para></listitem>
  2491. <listitem><para>
  2492. <filename>oe_runmake install</filename>, which can be
  2493. run directly or can be run indirectly by the
  2494. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
  2495. and
  2496. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
  2497. classes, runs <filename>make install</filename> in
  2498. parallel.
  2499. Sometimes, a Makefile can have missing dependencies
  2500. between targets that can result in race conditions.
  2501. If you experience intermittent failures during
  2502. <filename>do_install</filename>, you might be able to
  2503. work around them by disabling parallel Makefile
  2504. installs by adding the following to the recipe:
  2505. <literallayout class='monospaced'>
  2506. PARALLEL_MAKEINST = ""
  2507. </literallayout>
  2508. See
  2509. <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
  2510. for additional information.
  2511. </para></listitem>
  2512. </itemizedlist>
  2513. </note>
  2514. </section>
  2515. <section id='new-recipe-enabling-system-services'>
  2516. <title>Enabling System Services</title>
  2517. <para>
  2518. If you want to install a service, which is a process that
  2519. usually starts on boot and runs in the background, then
  2520. you must include some additional definitions in your recipe.
  2521. </para>
  2522. <para>
  2523. If you are adding services and the service initialization
  2524. script or the service file itself is not installed, you must
  2525. provide for that installation in your recipe using a
  2526. <filename>do_install_append</filename> function.
  2527. If your recipe already has a <filename>do_install</filename>
  2528. function, update the function near its end rather than
  2529. adding an additional <filename>do_install_append</filename>
  2530. function.
  2531. </para>
  2532. <para>
  2533. When you create the installation for your services, you need
  2534. to accomplish what is normally done by
  2535. <filename>make install</filename>.
  2536. In other words, make sure your installation arranges the output
  2537. similar to how it is arranged on the target system.
  2538. </para>
  2539. <para>
  2540. The OpenEmbedded build system provides support for starting
  2541. services two different ways:
  2542. <itemizedlist>
  2543. <listitem><para><emphasis>SysVinit:</emphasis>
  2544. SysVinit is a system and service manager that
  2545. manages the init system used to control the very basic
  2546. functions of your system.
  2547. The init program is the first program
  2548. started by the Linux kernel when the system boots.
  2549. Init then controls the startup, running and shutdown
  2550. of all other programs.</para>
  2551. <para>To enable a service using SysVinit, your recipe
  2552. needs to inherit the
  2553. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-update-rc.d'><filename>update-rc.d</filename></ulink>
  2554. class.
  2555. The class helps facilitate safely installing the
  2556. package on the target.</para>
  2557. <para>You will need to set the
  2558. <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PACKAGES'><filename>INITSCRIPT_PACKAGES</filename></ulink>,
  2559. <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_NAME'><filename>INITSCRIPT_NAME</filename></ulink>,
  2560. and
  2561. <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PARAMS'><filename>INITSCRIPT_PARAMS</filename></ulink>
  2562. variables within your recipe.</para></listitem>
  2563. <listitem><para><emphasis>systemd:</emphasis>
  2564. System Management Daemon (systemd) was designed to
  2565. replace SysVinit and to provide
  2566. enhanced management of services.
  2567. For more information on systemd, see the systemd
  2568. homepage at
  2569. <ulink url='http://freedesktop.org/wiki/Software/systemd/'></ulink>.
  2570. </para>
  2571. <para>To enable a service using systemd, your recipe
  2572. needs to inherit the
  2573. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-systemd'><filename>systemd</filename></ulink>
  2574. class.
  2575. See the <filename>systemd.bbclass</filename> file
  2576. located in your
  2577. <link linkend='source-directory'>Source Directory</link>.
  2578. section for more information.
  2579. </para></listitem>
  2580. </itemizedlist>
  2581. </para>
  2582. </section>
  2583. <section id='new-recipe-packaging'>
  2584. <title>Packaging</title>
  2585. <para>
  2586. Successful packaging is a combination of automated processes
  2587. performed by the OpenEmbedded build system and some
  2588. specific steps you need to take.
  2589. The following list describes the process:
  2590. <itemizedlist>
  2591. <listitem><para><emphasis>Splitting Files</emphasis>:
  2592. The <filename>do_package</filename> task splits the
  2593. files produced by the recipe into logical components.
  2594. Even software that produces a single binary might
  2595. still have debug symbols, documentation, and other
  2596. logical components that should be split out.
  2597. The <filename>do_package</filename> task ensures
  2598. that files are split up and packaged correctly.
  2599. </para></listitem>
  2600. <listitem><para><emphasis>Running QA Checks</emphasis>:
  2601. The
  2602. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
  2603. class adds a step to
  2604. the package generation process so that output quality
  2605. assurance checks are generated by the OpenEmbedded
  2606. build system.
  2607. This step performs a range of checks to be sure the
  2608. build's output is free of common problems that show
  2609. up during runtime.
  2610. For information on these checks, see the
  2611. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
  2612. class and the
  2613. "<ulink url='&YOCTO_DOCS_REF_URL;#ref-qa-checks'>QA Error and Warning Messages</ulink>"
  2614. chapter in the Yocto Project Reference Manual.
  2615. </para></listitem>
  2616. <listitem><para><emphasis>Hand-Checking Your Packages</emphasis>:
  2617. After you build your software, you need to be sure
  2618. your packages are correct.
  2619. Examine the
  2620. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
  2621. directory and make sure files are where you expect
  2622. them to be.
  2623. If you discover problems, you can set
  2624. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>,
  2625. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
  2626. <filename>do_install(_append)</filename>, and so forth as
  2627. needed.
  2628. </para></listitem>
  2629. <listitem><para><emphasis>Splitting an Application into Multiple Packages</emphasis>:
  2630. If you need to split an application into several
  2631. packages, see the
  2632. "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
  2633. section for an example.
  2634. </para></listitem>
  2635. <listitem><para><emphasis>Installing a Post-Installation Script</emphasis>:
  2636. For an example showing how to install a
  2637. post-installation script, see the
  2638. "<link linkend='new-recipe-post-installation-scripts'>Post-Installation Scripts</link>"
  2639. section.
  2640. </para></listitem>
  2641. <listitem><para><emphasis>Marking Package Architecture</emphasis>:
  2642. Depending on what your recipe is building and how it
  2643. is configured, it might be important to mark the
  2644. packages produced as being specific to a particular
  2645. machine, or to mark them as not being specific to
  2646. a particular machine or architecture at all.</para>
  2647. <para>By default, packages apply to any machine with the
  2648. same architecture as the target machine.
  2649. When a recipe produces packages that are
  2650. machine-specific (e.g. the
  2651. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
  2652. value is passed into the configure script or a patch
  2653. is applied only for a particular machine), you should
  2654. mark them as such by adding the following to the
  2655. recipe:
  2656. <literallayout class='monospaced'>
  2657. PACKAGE_ARCH = "${MACHINE_ARCH}"
  2658. </literallayout></para>
  2659. <para>On the other hand, if the recipe produces packages
  2660. that do not contain anything specific to the target
  2661. machine or architecture at all (e.g. recipes
  2662. that simply package script files or configuration
  2663. files), you should use the
  2664. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
  2665. class to do this for you by adding this to your
  2666. recipe:
  2667. <literallayout class='monospaced'>
  2668. inherit allarch
  2669. </literallayout>
  2670. Ensuring that the package architecture is correct is
  2671. not critical while you are doing the first few builds
  2672. of your recipe.
  2673. However, it is important in order
  2674. to ensure that your recipe rebuilds (or does not
  2675. rebuild) appropriately in response to changes in
  2676. configuration, and to ensure that you get the
  2677. appropriate packages installed on the target machine,
  2678. particularly if you run separate builds for more
  2679. than one target machine.
  2680. </para></listitem>
  2681. </itemizedlist>
  2682. </para>
  2683. </section>
  2684. <section id='new-sharing-files-between-recipes'>
  2685. <title>Sharing Files Between Recipes</title>
  2686. <para>
  2687. Recipes often need to use files provided by other recipes on
  2688. the build host.
  2689. For example, an application linking to a common library needs
  2690. access to the library itself and its associated headers.
  2691. The way this access is accomplished is by populating sysroot
  2692. with files.
  2693. One sysroot exists per "machine" for which the image is
  2694. being built.
  2695. In practical terms, this means a sysroot exists for the target
  2696. machine, and a sysroot exists for the build host.
  2697. <note>
  2698. You could find the term "staging" used within the Yocto
  2699. project regarding files populating sysroot.
  2700. The term "staging" was used for previous releases of
  2701. the Yocto Project.
  2702. </note>
  2703. </para>
  2704. <para>
  2705. Recipes should never populate the sysroot directly (i.e. write
  2706. files into sysroot).
  2707. Instead, files should be installed into standard locations
  2708. during the
  2709. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
  2710. task within the
  2711. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
  2712. directory.
  2713. A subset of these files automatically populates the sysroot.
  2714. The reason for this limitation is that almost all files that
  2715. populate the sysroot are cataloged in manifests in order to
  2716. ensure the files can be removed later when a recipe is either
  2717. modified or removed.
  2718. Thus, the sysroot is able to remain free from stale files.
  2719. </para>
  2720. <para>
  2721. For information on variables you can use to help control how
  2722. files sysroot is populated, see the
  2723. <ulink url='&YOCTO_DOCS_REF_URL;#var-SYSROOT_DIRS'><filename>SYSROOT_DIRS</filename></ulink>,
  2724. <ulink url='&YOCTO_DOCS_REF_URL;#var-SYSROOT_DIRS_NATIVE'><filename>SYSROOT_DIRS_NATIVE</filename></ulink>,
  2725. and
  2726. <ulink url='&YOCTO_DOCS_REF_URL;#var-SYSROOT_DIRS_BLACKLIST'><filename>SYSROOT_DIRS_BLACKLIST</filename></ulink>
  2727. variables.
  2728. </para>
  2729. </section>
  2730. <section id='properly-versioning-pre-release-recipes'>
  2731. <title>Properly Versioning Pre-Release Recipes</title>
  2732. <para>
  2733. Sometimes the name of a recipe can lead to versioning
  2734. problems when the recipe is upgraded to a final release.
  2735. For example, consider the
  2736. <filename>irssi_0.8.16-rc1.bb</filename> recipe file in
  2737. the list of example recipes in the
  2738. "<link linkend='new-recipe-storing-and-naming-the-recipe'>Storing and Naming the Recipe</link>"
  2739. section.
  2740. This recipe is at a release candidate stage (i.e.
  2741. "rc1").
  2742. When the recipe is released, the recipe filename becomes
  2743. <filename>irssi_0.8.16.bb</filename>.
  2744. The version change from <filename>0.8.16-rc1</filename>
  2745. to <filename>0.8.16</filename> is seen as a decrease by the
  2746. build system and package managers, so the resulting packages
  2747. will not correctly trigger an upgrade.
  2748. </para>
  2749. <para>
  2750. In order to ensure the versions compare properly, the
  2751. recommended convention is to set
  2752. <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
  2753. within the recipe to
  2754. "<replaceable>previous_version</replaceable>+<replaceable>current_version</replaceable>".
  2755. You can use an additional variable so that you can use the
  2756. current version elsewhere.
  2757. Here is an example:
  2758. <literallayout class='monospaced'>
  2759. REALPV = "0.8.16-rc1"
  2760. PV = "0.8.15+${REALPV}"
  2761. </literallayout>
  2762. </para>
  2763. </section>
  2764. <section id='new-recipe-post-installation-scripts'>
  2765. <title>Post-Installation Scripts</title>
  2766. <para>
  2767. Post-installation scripts run immediately after installing
  2768. a package on the target or during image creation when a
  2769. package is included in an image.
  2770. To add a post-installation script to a package, add a
  2771. <filename>pkg_postinst_PACKAGENAME()</filename> function to
  2772. the recipe file (<filename>.bb</filename>) and replace
  2773. <filename>PACKAGENAME</filename> with the name of the package
  2774. you want to attach to the <filename>postinst</filename>
  2775. script.
  2776. To apply the post-installation script to the main package
  2777. for the recipe, which is usually what is required, specify
  2778. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
  2779. in place of <filename>PACKAGENAME</filename>.
  2780. </para>
  2781. <para>
  2782. A post-installation function has the following structure:
  2783. <literallayout class='monospaced'>
  2784. pkg_postinst_PACKAGENAME() {
  2785. # Commands to carry out
  2786. }
  2787. </literallayout>
  2788. </para>
  2789. <para>
  2790. The script defined in the post-installation function is
  2791. called when the root filesystem is created.
  2792. If the script succeeds, the package is marked as installed.
  2793. If the script fails, the package is marked as unpacked and
  2794. the script is executed when the image boots again.
  2795. </para>
  2796. <para>
  2797. Sometimes it is necessary for the execution of a
  2798. post-installation script to be delayed until the first boot.
  2799. For example, the script might need to be executed on the
  2800. device itself.
  2801. To delay script execution until boot time, use the following
  2802. structure in the post-installation script:
  2803. <literallayout class='monospaced'>
  2804. pkg_postinst_PACKAGENAME() {
  2805. if [ x"$D" = "x" ]; then
  2806. # Actions to carry out on the device go here
  2807. else
  2808. exit 1
  2809. fi
  2810. }
  2811. </literallayout>
  2812. </para>
  2813. <para>
  2814. The previous example delays execution until the image boots
  2815. again because the environment variable <filename>D</filename>
  2816. points to the directory containing the image when
  2817. the root filesystem is created at build time but is unset
  2818. when executed on the first boot.
  2819. </para>
  2820. <note>
  2821. Equivalent support for pre-install, pre-uninstall, and
  2822. post-uninstall scripts exist by way of
  2823. <filename>pkg_preinst</filename>,
  2824. <filename>pkg_prerm</filename>, and
  2825. <filename>pkg_postrm</filename>, respectively.
  2826. These scrips work in exactly the same way as does
  2827. <filename>pkg_postinst</filename> with the exception that they
  2828. run at different times.
  2829. Also, because of when they run, they are not applicable to
  2830. being run at image creation time like
  2831. <filename>pkg_postinst</filename>.
  2832. </note>
  2833. </section>
  2834. <section id='new-recipe-testing'>
  2835. <title>Testing</title>
  2836. <para>
  2837. The final step for completing your recipe is to be sure that
  2838. the software you built runs correctly.
  2839. To accomplish runtime testing, add the build's output
  2840. packages to your image and test them on the target.
  2841. </para>
  2842. <para>
  2843. For information on how to customize your image by adding
  2844. specific packages, see the
  2845. "<link linkend='usingpoky-extend-customimage'>Customizing Images</link>"
  2846. section.
  2847. </para>
  2848. </section>
  2849. <section id='new-recipe-testing-examples'>
  2850. <title>Examples</title>
  2851. <para>
  2852. To help summarize how to write a recipe, this section provides
  2853. some examples given various scenarios:
  2854. <itemizedlist>
  2855. <listitem><para>Recipes that use local files</para></listitem>
  2856. <listitem><para>Using an Autotooled package</para></listitem>
  2857. <listitem><para>Using a Makefile-based package</para></listitem>
  2858. <listitem><para>Splitting an application into multiple packages</para></listitem>
  2859. <listitem><para>Adding binaries to an image</para></listitem>
  2860. </itemizedlist>
  2861. </para>
  2862. <section id='new-recipe-single-c-file-package-hello-world'>
  2863. <title>Single .c File Package (Hello World!)</title>
  2864. <para>
  2865. Building an application from a single file that is stored
  2866. locally (e.g. under <filename>files</filename>) requires
  2867. a recipe that has the file listed in the
  2868. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
  2869. variable.
  2870. Additionally, you need to manually write the
  2871. <filename>do_compile</filename> and
  2872. <filename>do_install</filename> tasks.
  2873. The <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
  2874. variable defines the directory containing the source code,
  2875. which is set to
  2876. <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
  2877. in this case - the directory BitBake uses for the build.
  2878. <literallayout class='monospaced'>
  2879. SUMMARY = "Simple helloworld application"
  2880. SECTION = "examples"
  2881. LICENSE = "MIT"
  2882. LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
  2883. SRC_URI = "file://helloworld.c"
  2884. S = "${WORKDIR}"
  2885. do_compile() {
  2886. ${CC} helloworld.c -o helloworld
  2887. }
  2888. do_install() {
  2889. install -d ${D}${bindir}
  2890. install -m 0755 helloworld ${D}${bindir}
  2891. }
  2892. </literallayout>
  2893. </para>
  2894. <para>
  2895. By default, the <filename>helloworld</filename>,
  2896. <filename>helloworld-dbg</filename>, and
  2897. <filename>helloworld-dev</filename> packages are built.
  2898. For information on how to customize the packaging process,
  2899. see the
  2900. "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
  2901. section.
  2902. </para>
  2903. </section>
  2904. <section id='new-recipe-autotooled-package'>
  2905. <title>Autotooled Package</title>
  2906. <para>
  2907. Applications that use Autotools such as <filename>autoconf</filename> and
  2908. <filename>automake</filename> require a recipe that has a source archive listed in
  2909. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> and
  2910. also inherit the
  2911. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
  2912. class, which contains the definitions of all the steps
  2913. needed to build an Autotool-based application.
  2914. The result of the build is automatically packaged.
  2915. And, if the application uses NLS for localization, packages with local information are
  2916. generated (one package per language).
  2917. Following is one example: (<filename>hello_2.3.bb</filename>)
  2918. <literallayout class='monospaced'>
  2919. SUMMARY = "GNU Helloworld application"
  2920. SECTION = "examples"
  2921. LICENSE = "GPLv2+"
  2922. LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
  2923. SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
  2924. inherit autotools gettext
  2925. </literallayout>
  2926. </para>
  2927. <para>
  2928. The variable
  2929. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</ulink></filename>
  2930. is used to track source license changes as described in the
  2931. "<ulink url='&YOCTO_DOCS_REF_URL;#usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</ulink>" section.
  2932. You can quickly create Autotool-based recipes in a manner similar to the previous example.
  2933. </para>
  2934. </section>
  2935. <section id='new-recipe-makefile-based-package'>
  2936. <title>Makefile-Based Package</title>
  2937. <para>
  2938. Applications that use GNU <filename>make</filename> also require a recipe that has
  2939. the source archive listed in
  2940. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
  2941. You do not need to add a <filename>do_compile</filename> step since by default BitBake
  2942. starts the <filename>make</filename> command to compile the application.
  2943. If you need additional <filename>make</filename> options, you should store them in the
  2944. <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OEMAKE'><filename>EXTRA_OEMAKE</filename></ulink>
  2945. or
  2946. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
  2947. variables.
  2948. BitBake passes these options into the GNU <filename>make</filename> invocation.
  2949. Note that a <filename>do_install</filename> task is still required.
  2950. Otherwise, BitBake runs an empty <filename>do_install</filename> task by default.
  2951. </para>
  2952. <para>
  2953. Some applications might require extra parameters to be passed to the compiler.
  2954. For example, the application might need an additional header path.
  2955. You can accomplish this by adding to the
  2956. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CFLAGS'>CFLAGS</ulink></filename> variable.
  2957. The following example shows this:
  2958. <literallayout class='monospaced'>
  2959. CFLAGS_prepend = "-I ${S}/include "
  2960. </literallayout>
  2961. </para>
  2962. <para>
  2963. In the following example, <filename>mtd-utils</filename> is a makefile-based package:
  2964. <literallayout class='monospaced'>
  2965. SUMMARY = "Tools for managing memory technology devices"
  2966. SECTION = "base"
  2967. DEPENDS = "zlib lzo e2fsprogs util-linux"
  2968. HOMEPAGE = "http://www.linux-mtd.infradead.org/"
  2969. LICENSE = "GPLv2+"
  2970. LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
  2971. file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
  2972. # Use the latest version at 26 Oct, 2013
  2973. SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
  2974. SRC_URI = "git://git.infradead.org/mtd-utils.git \
  2975. file://add-exclusion-to-mkfs-jffs2-git-2.patch \
  2976. "
  2977. PV = "1.5.1+git${SRCPV}"
  2978. S = "${WORKDIR}/git"
  2979. EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
  2980. do_install () {
  2981. oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
  2982. }
  2983. PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
  2984. FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
  2985. FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
  2986. FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image"
  2987. PARALLEL_MAKE = ""
  2988. BBCLASSEXTEND = "native"
  2989. </literallayout>
  2990. </para>
  2991. </section>
  2992. <section id='splitting-an-application-into-multiple-packages'>
  2993. <title>Splitting an Application into Multiple Packages</title>
  2994. <para>
  2995. You can use the variables
  2996. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> and
  2997. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'>FILES</ulink></filename>
  2998. to split an application into multiple packages.
  2999. </para>
  3000. <para>
  3001. Following is an example that uses the <filename>libxpm</filename> recipe.
  3002. By default, this recipe generates a single package that contains the library along
  3003. with a few binaries.
  3004. You can modify the recipe to split the binaries into separate packages:
  3005. <literallayout class='monospaced'>
  3006. require xorg-lib-common.inc
  3007. SUMMARY = "Xpm: X Pixmap extension library"
  3008. LICENSE = "BSD"
  3009. LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
  3010. DEPENDS += "libxext libsm libxt"
  3011. PE = "1"
  3012. XORG_PN = "libXpm"
  3013. PACKAGES =+ "sxpm cxpm"
  3014. FILES_cxpm = "${bindir}/cxpm"
  3015. FILES_sxpm = "${bindir}/sxpm"
  3016. </literallayout>
  3017. </para>
  3018. <para>
  3019. In the previous example, we want to ship the <filename>sxpm</filename>
  3020. and <filename>cxpm</filename> binaries in separate packages.
  3021. Since <filename>bindir</filename> would be packaged into the main
  3022. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'>PN</ulink></filename>
  3023. package by default, we prepend the <filename>PACKAGES</filename>
  3024. variable so additional package names are added to the start of list.
  3025. This results in the extra <filename>FILES_*</filename>
  3026. variables then containing information that define which files and
  3027. directories go into which packages.
  3028. Files included by earlier packages are skipped by latter packages.
  3029. Thus, the main <filename>PN</filename> package
  3030. does not include the above listed files.
  3031. </para>
  3032. </section>
  3033. <section id='packaging-externally-produced-binaries'>
  3034. <title>Packaging Externally Produced Binaries</title>
  3035. <para>
  3036. Sometimes, you need to add pre-compiled binaries to an
  3037. image.
  3038. For example, suppose that binaries for proprietary code
  3039. exist, which are created by a particular division of a
  3040. company.
  3041. Your part of the company needs to use those binaries as
  3042. part of an image that you are building using the
  3043. OpenEmbedded build system.
  3044. Since you only have the binaries and not the source code,
  3045. you cannot use a typical recipe that expects to fetch the
  3046. source specified in
  3047. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  3048. and then compile it.
  3049. </para>
  3050. <para>
  3051. One method is to package the binaries and then install them
  3052. as part of the image.
  3053. Generally, it is not a good idea to package binaries
  3054. since, among other things, it can hinder the ability to
  3055. reproduce builds and could lead to compatibility problems
  3056. with ABI in the future.
  3057. However, sometimes you have no choice.
  3058. </para>
  3059. <para>
  3060. The easiest solution is to create a recipe that uses
  3061. the
  3062. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-bin-package'><filename>bin_package</filename></ulink>
  3063. class and to be sure that you are using default locations
  3064. for build artifacts.
  3065. In most cases, the <filename>bin_package</filename> class
  3066. handles "skipping" the configure and compile steps as well
  3067. as sets things up to grab packages from the appropriate
  3068. area.
  3069. In particular, this class sets <filename>noexec</filename>
  3070. on both the
  3071. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
  3072. and
  3073. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
  3074. tasks, sets
  3075. <filename>FILES_${PN}</filename> to "/" so that it picks
  3076. up all files, and sets up a
  3077. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
  3078. task, which effectively copies all files from
  3079. <filename>${S}</filename> to <filename>${D}</filename>.
  3080. The <filename>bin_package</filename> class works well when
  3081. the files extracted into <filename>${S}</filename> are
  3082. already laid out in the way they should be laid out
  3083. on the target.
  3084. For more information on these variables, see the
  3085. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
  3086. <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>,
  3087. <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>,
  3088. and
  3089. <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
  3090. variables in the Yocto Project Reference Manual's variable
  3091. glossary.
  3092. <note><title>Notes</title>
  3093. <itemizedlist>
  3094. <listitem><para>
  3095. Using
  3096. <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
  3097. is a good idea even for components distributed
  3098. in binary form, and is often necessary for
  3099. shared libraries.
  3100. For a shared library, listing the library
  3101. dependencies in
  3102. <filename>DEPENDS</filename> makes sure that
  3103. the libraries are available in the staging
  3104. sysroot when other recipes link against the
  3105. library, which might be necessary for
  3106. successful linking.
  3107. </para></listitem>
  3108. <listitem><para>
  3109. Using <filename>DEPENDS</filename> also
  3110. allows runtime dependencies between packages
  3111. to be added automatically.
  3112. See the
  3113. "<ulink url='&YOCTO_DOCS_REF_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>"
  3114. section in the Yocto Project Reference Manual
  3115. for more information.
  3116. </para></listitem>
  3117. </itemizedlist>
  3118. </note>
  3119. </para>
  3120. <para>
  3121. If you cannot use the <filename>bin_package</filename>
  3122. class, you need to be sure you are doing the following:
  3123. <itemizedlist>
  3124. <listitem><para>
  3125. Create a recipe where the
  3126. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
  3127. and
  3128. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
  3129. tasks do nothing:
  3130. It is usually sufficient to just not define these
  3131. tasks in the recipe, because the default
  3132. implementations do nothing unless a Makefile is
  3133. found in
  3134. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>.
  3135. </para>
  3136. <para>If
  3137. <filename>${S}</filename> might contain a Makefile,
  3138. or if you inherit some class that replaces
  3139. <filename>do_configure</filename> and
  3140. <filename>do_compile</filename> with custom
  3141. versions, then you can use the
  3142. <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>noexec</filename></ulink><filename>]</filename>
  3143. flag to turn the tasks into no-ops, as follows:
  3144. <literallayout class='monospaced'>
  3145. do_configure[noexec] = "1"
  3146. do_compile[noexec] = "1"
  3147. </literallayout>
  3148. Unlike
  3149. <ulink url='&YOCTO_DOCS_BB_URL;#deleting-a-task'><filename>deleting the tasks</filename></ulink>,
  3150. using the flag preserves the dependency chain from
  3151. the
  3152. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>, <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>,
  3153. and
  3154. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
  3155. tasks to the
  3156. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
  3157. task.
  3158. </para></listitem>
  3159. <listitem><para>Make sure your
  3160. <filename>do_install</filename> task installs the
  3161. binaries appropriately.
  3162. </para></listitem>
  3163. <listitem><para>Ensure that you set up
  3164. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
  3165. (usually
  3166. <filename>FILES_${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>)
  3167. to point to the files you have installed, which of
  3168. course depends on where you have installed them
  3169. and whether those files are in different locations
  3170. than the defaults.
  3171. </para></listitem>
  3172. </itemizedlist>
  3173. </para>
  3174. </section>
  3175. </section>
  3176. <section id="following-recipe-style-guidelines">
  3177. <title>Following Recipe Style Guidelines</title>
  3178. <para>
  3179. When writing recipes, it is good to conform to existing
  3180. style guidelines.
  3181. The
  3182. <ulink url='http://www.openembedded.org/wiki/Styleguide'>OpenEmbedded Styleguide</ulink>
  3183. wiki page provides rough guidelines for preferred recipe style.
  3184. </para>
  3185. <para>
  3186. It is common for existing recipes to deviate a bit from this
  3187. style.
  3188. However, aiming for at least a consistent style is a good idea.
  3189. Some practices, such as omitting spaces around
  3190. <filename>=</filename> operators in assignments or ordering
  3191. recipe components in an erratic way, are widely seen as poor
  3192. style.
  3193. </para>
  3194. </section>
  3195. </section>
  3196. <section id="platdev-newmachine">
  3197. <title>Adding a New Machine</title>
  3198. <para>
  3199. Adding a new machine to the Yocto Project is a straightforward
  3200. process.
  3201. This section describes how to add machines that are similar
  3202. to those that the Yocto Project already supports.
  3203. <note>
  3204. Although well within the capabilities of the Yocto Project,
  3205. adding a totally new architecture might require
  3206. changes to <filename>gcc/glibc</filename> and to the site
  3207. information, which is beyond the scope of this manual.
  3208. </note>
  3209. </para>
  3210. <para>
  3211. For a complete example that shows how to add a new machine,
  3212. see the
  3213. "<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>"
  3214. section in the Yocto Project Board Support Package (BSP) Developer's Guide.
  3215. </para>
  3216. <section id="platdev-newmachine-conffile">
  3217. <title>Adding the Machine Configuration File</title>
  3218. <para>
  3219. To add a new machine, you need to add a new machine
  3220. configuration file to the layer's
  3221. <filename>conf/machine</filename> directory.
  3222. This configuration file provides details about the device
  3223. you are adding.
  3224. </para>
  3225. <para>
  3226. The OpenEmbedded build system uses the root name of the
  3227. machine configuration file to reference the new machine.
  3228. For example, given a machine configuration file named
  3229. <filename>crownbay.conf</filename>, the build system
  3230. recognizes the machine as "crownbay".
  3231. </para>
  3232. <para>
  3233. The most important variables you must set in your machine
  3234. configuration file or include from a lower-level configuration
  3235. file are as follows:
  3236. <itemizedlist>
  3237. <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_ARCH'>TARGET_ARCH</ulink></filename>
  3238. (e.g. "arm")</para></listitem>
  3239. <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'>PREFERRED_PROVIDER</ulink>_virtual/kernel</filename>
  3240. </para></listitem>
  3241. <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'>MACHINE_FEATURES</ulink></filename>
  3242. (e.g. "apm screen wifi")</para></listitem>
  3243. </itemizedlist>
  3244. </para>
  3245. <para>
  3246. You might also need these variables:
  3247. <itemizedlist>
  3248. <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'>SERIAL_CONSOLES</ulink></filename>
  3249. (e.g. "115200;ttyS0 115200;ttyS1")</para></listitem>
  3250. <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_IMAGETYPE'>KERNEL_IMAGETYPE</ulink></filename>
  3251. (e.g. "zImage")</para></listitem>
  3252. <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'>IMAGE_FSTYPES</ulink></filename>
  3253. (e.g. "tar.gz jffs2")</para></listitem>
  3254. </itemizedlist>
  3255. </para>
  3256. <para>
  3257. You can find full details on these variables in the reference
  3258. section.
  3259. You can leverage existing machine <filename>.conf</filename>
  3260. files from <filename>meta-yocto-bsp/conf/machine/</filename>.
  3261. </para>
  3262. </section>
  3263. <section id="platdev-newmachine-kernel">
  3264. <title>Adding a Kernel for the Machine</title>
  3265. <para>
  3266. The OpenEmbedded build system needs to be able to build a kernel
  3267. for the machine.
  3268. You need to either create a new kernel recipe for this machine,
  3269. or extend an existing kernel recipe.
  3270. You can find several kernel recipe examples in the
  3271. Source Directory at
  3272. <filename>meta/recipes-kernel/linux</filename>
  3273. that you can use as references.
  3274. </para>
  3275. <para>
  3276. If you are creating a new kernel recipe, normal recipe-writing
  3277. rules apply for setting up a
  3278. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
  3279. Thus, you need to specify any necessary patches and set
  3280. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
  3281. to point at the source code.
  3282. You need to create a <filename>do_configure</filename> task that
  3283. configures the unpacked kernel with a
  3284. <filename>defconfig</filename> file.
  3285. You can do this by using a <filename>make defconfig</filename>
  3286. command or, more commonly, by copying in a suitable
  3287. <filename>defconfig</filename> file and then running
  3288. <filename>make oldconfig</filename>.
  3289. By making use of <filename>inherit kernel</filename> and
  3290. potentially some of the <filename>linux-*.inc</filename> files,
  3291. most other functionality is centralized and the defaults of the
  3292. class normally work well.
  3293. </para>
  3294. <para>
  3295. If you are extending an existing kernel recipe, it is usually
  3296. a matter of adding a suitable <filename>defconfig</filename>
  3297. file.
  3298. The file needs to be added into a location similar to
  3299. <filename>defconfig</filename> files used for other machines
  3300. in a given kernel recipe.
  3301. A possible way to do this is by listing the file in the
  3302. <filename>SRC_URI</filename> and adding the machine to the
  3303. expression in
  3304. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'>COMPATIBLE_MACHINE</ulink></filename>:
  3305. <literallayout class='monospaced'>
  3306. COMPATIBLE_MACHINE = '(qemux86|qemumips)'
  3307. </literallayout>
  3308. For more information on <filename>defconfig</filename> files,
  3309. see the
  3310. "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>"
  3311. section in the Yocto Project Linux Kernel Development Manual.
  3312. </para>
  3313. </section>
  3314. <section id="platdev-newmachine-formfactor">
  3315. <title>Adding a Formfactor Configuration File</title>
  3316. <para>
  3317. A formfactor configuration file provides information about the
  3318. target hardware for which the image is being built and information that
  3319. the build system cannot obtain from other sources such as the kernel.
  3320. Some examples of information contained in a formfactor configuration file include
  3321. framebuffer orientation, whether or not the system has a keyboard,
  3322. the positioning of the keyboard in relation to the screen, and
  3323. the screen resolution.
  3324. </para>
  3325. <para>
  3326. The build system uses reasonable defaults in most cases.
  3327. However, if customization is
  3328. necessary, you need to create a <filename>machconfig</filename> file
  3329. in the <filename>meta/recipes-bsp/formfactor/files</filename>
  3330. directory.
  3331. This directory contains directories for specific machines such as
  3332. <filename>qemuarm</filename> and <filename>qemux86</filename>.
  3333. For information about the settings available and the defaults, see the
  3334. <filename>meta/recipes-bsp/formfactor/files/config</filename> file found in the
  3335. same area.
  3336. </para>
  3337. <para>
  3338. Following is an example for "qemuarm" machine:
  3339. <literallayout class='monospaced'>
  3340. HAVE_TOUCHSCREEN=1
  3341. HAVE_KEYBOARD=1
  3342. DISPLAY_CAN_ROTATE=0
  3343. DISPLAY_ORIENTATION=0
  3344. #DISPLAY_WIDTH_PIXELS=640
  3345. #DISPLAY_HEIGHT_PIXELS=480
  3346. #DISPLAY_BPP=16
  3347. DISPLAY_DPI=150
  3348. DISPLAY_SUBPIXEL_ORDER=vrgb
  3349. </literallayout>
  3350. </para>
  3351. </section>
  3352. </section>
  3353. <section id='platdev-building-targets-with-multiple-configurations'>
  3354. <title>Building Targets with Multiple Configurations</title>
  3355. <para>
  3356. Bitbake also has functionality that allows you to build
  3357. multiple targets at the same time, where each target uses
  3358. a different configuration.
  3359. </para>
  3360. <para>
  3361. In order to accomplish this, you setup each of the configurations
  3362. you need to use in parallel by placing the configuration files in
  3363. your current build directory alongside the usual
  3364. <filename>local.conf</filename> file.
  3365. </para>
  3366. <para>
  3367. Follow these guidelines to create an environment that supports
  3368. multiple configurations:
  3369. <itemizedlist>
  3370. <listitem><para>
  3371. <emphasis>Create Configuration Files</emphasis>:
  3372. You need to create a single configuration file for each
  3373. configuration for which you want to add support.
  3374. These files would contain lines such as the following:
  3375. <literallayout class='monospaced'>
  3376. MACHINE = "A"
  3377. </literallayout>
  3378. The files would contain any other variables that can
  3379. be set and built in the same directory.
  3380. <note>
  3381. You can change the
  3382. <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
  3383. to not conflict.
  3384. </note></para>
  3385. <para>
  3386. Furthermore, the configuration file must be located in the
  3387. current build directory in a directory named
  3388. <filename>multiconfig</filename> under the build's
  3389. <filename>conf</filename> directory where
  3390. <filename>local.conf</filename> resides.
  3391. The reason for this restriction is because the
  3392. <filename>BBPATH</filename> variable is not constructed
  3393. until the layers are parsed.
  3394. Consequently, using the configuration file as a
  3395. pre-configuration file is not possible unless it is
  3396. located in the current working directory.
  3397. </para></listitem>
  3398. <listitem><para>
  3399. <emphasis>Add the BitBake Multi-Config Variable to you Local Configuration File</emphasis>:
  3400. Use the
  3401. <filename>BBMULTICONFIG</filename>
  3402. variable in your <filename>conf/local.conf</filename>
  3403. configuration file to specify each separate configuration.
  3404. For example, the following line tells BitBake it should load
  3405. <filename>conf/multiconfig/configA.conf</filename>,
  3406. <filename>conf/multiconfig/configB.conf</filename>, and
  3407. <filename>conf/multiconfig/configC.conf</filename>.
  3408. <literallayout class='monospaced'>
  3409. BBMULTICONFIG = "configA configB configC"
  3410. </literallayout>
  3411. </para></listitem>
  3412. <listitem><para>
  3413. <emphasis>Launch BitBake</emphasis>:
  3414. Use the following BitBake command form to launch the
  3415. build:
  3416. <literallayout class='monospaced'>
  3417. $ bitbake [multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable> [[[multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable>] ... ]
  3418. </literallayout>
  3419. Following is an example that supports building a minimal
  3420. image for configuration A alongside a standard
  3421. <filename>core-image-sato</filename>, which takes its
  3422. configuration from <filename>local.conf</filename>:
  3423. <literallayout class='monospaced'>
  3424. $ bitbake multiconfig:configA:core-image-minimal core-image-sato
  3425. </literallayout>
  3426. </para></listitem>
  3427. </itemizedlist>
  3428. </para>
  3429. <para>
  3430. Support for multiple configurations in this current release of
  3431. the Yocto Project (&DISTRO_NAME; &DISTRO;) has some known issues:
  3432. <itemizedlist>
  3433. <listitem><para>
  3434. No inter-multi-configuration dependencies exist.
  3435. </para></listitem>
  3436. <listitem><para>
  3437. Shared State (sstate) optimizations do not exist.
  3438. Consequently, if the build uses the same object twice
  3439. in, for example, two different
  3440. <filename>TMPDIR</filename> directories, the build
  3441. will either load from an existing sstate cache at the
  3442. start or build the object twice.
  3443. </para></listitem>
  3444. </itemizedlist>
  3445. </para>
  3446. </section>
  3447. <section id="platdev-working-with-libraries">
  3448. <title>Working With Libraries</title>
  3449. <para>
  3450. Libraries are an integral part of your system.
  3451. This section describes some common practices you might find
  3452. helpful when working with libraries to build your system:
  3453. <itemizedlist>
  3454. <listitem><para><link linkend='including-static-library-files'>How to include static library files</link>
  3455. </para></listitem>
  3456. <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>
  3457. </para></listitem>
  3458. <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>
  3459. </para></listitem>
  3460. </itemizedlist>
  3461. </para>
  3462. <section id='including-static-library-files'>
  3463. <title>Including Static Library Files</title>
  3464. <para>
  3465. If you are building a library and the library offers static linking, you can control
  3466. which static library files (<filename>*.a</filename> files) get included in the
  3467. built library.
  3468. </para>
  3469. <para>
  3470. The <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
  3471. and <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES_*</filename></ulink>
  3472. variables in the
  3473. <filename>meta/conf/bitbake.conf</filename> configuration file define how files installed
  3474. by the <filename>do_install</filename> task are packaged.
  3475. By default, the <filename>PACKAGES</filename> variable includes
  3476. <filename>${PN}-staticdev</filename>, which represents all static library files.
  3477. <note>
  3478. Some previously released versions of the Yocto Project
  3479. defined the static library files through
  3480. <filename>${PN}-dev</filename>.
  3481. </note>
  3482. Following is part of the BitBake configuration file, where
  3483. you can see how the static library files are defined:
  3484. <literallayout class='monospaced'>
  3485. PACKAGE_BEFORE_PN ?= ""
  3486. PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
  3487. PACKAGES_DYNAMIC = "^${PN}-locale-.*"
  3488. FILES = ""
  3489. FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
  3490. ${sysconfdir} ${sharedstatedir} ${localstatedir} \
  3491. ${base_bindir}/* ${base_sbindir}/* \
  3492. ${base_libdir}/*${SOLIBS} \
  3493. ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
  3494. ${datadir}/${BPN} ${libdir}/${BPN}/* \
  3495. ${datadir}/pixmaps ${datadir}/applications \
  3496. ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
  3497. ${libdir}/bonobo/servers"
  3498. FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
  3499. FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
  3500. ${datadir}/gnome/help"
  3501. SECTION_${PN}-doc = "doc"
  3502. FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
  3503. FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
  3504. ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
  3505. ${datadir}/aclocal ${base_libdir}/*.o \
  3506. ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
  3507. SECTION_${PN}-dev = "devel"
  3508. ALLOW_EMPTY_${PN}-dev = "1"
  3509. RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
  3510. FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
  3511. SECTION_${PN}-staticdev = "devel"
  3512. RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
  3513. </literallayout>
  3514. </para>
  3515. </section>
  3516. <section id="combining-multiple-versions-library-files-into-one-image">
  3517. <title>Combining Multiple Versions of Library Files into One Image</title>
  3518. <para>
  3519. The build system offers the ability to build libraries with different
  3520. target optimizations or architecture formats and combine these together
  3521. into one system image.
  3522. You can link different binaries in the image
  3523. against the different libraries as needed for specific use cases.
  3524. This feature is called "Multilib."
  3525. </para>
  3526. <para>
  3527. An example would be where you have most of a system compiled in 32-bit
  3528. mode using 32-bit libraries, but you have something large, like a database
  3529. engine, that needs to be a 64-bit application and uses 64-bit libraries.
  3530. Multilib allows you to get the best of both 32-bit and 64-bit libraries.
  3531. </para>
  3532. <para>
  3533. While the Multilib feature is most commonly used for 32 and 64-bit differences,
  3534. the approach the build system uses facilitates different target optimizations.
  3535. You could compile some binaries to use one set of libraries and other binaries
  3536. to use a different set of libraries.
  3537. The libraries could differ in architecture, compiler options, or other
  3538. optimizations.
  3539. </para>
  3540. <para>
  3541. Several examples exist in the
  3542. <filename>meta-skeleton</filename> layer found in the
  3543. <link linkend='source-directory'>Source Directory</link>:
  3544. <itemizedlist>
  3545. <listitem><para><filename>conf/multilib-example.conf</filename>
  3546. configuration file</para></listitem>
  3547. <listitem><para><filename>conf/multilib-example2.conf</filename>
  3548. configuration file</para></listitem>
  3549. <listitem><para><filename>recipes-multilib/images/core-image-multilib-example.bb</filename>
  3550. recipe</para></listitem>
  3551. </itemizedlist>
  3552. </para>
  3553. <section id='preparing-to-use-multilib'>
  3554. <title>Preparing to Use Multilib</title>
  3555. <para>
  3556. User-specific requirements drive the Multilib feature.
  3557. Consequently, there is no one "out-of-the-box" configuration that likely
  3558. exists to meet your needs.
  3559. </para>
  3560. <para>
  3561. In order to enable Multilib, you first need to ensure your recipe is
  3562. extended to support multiple libraries.
  3563. Many standard recipes are already extended and support multiple libraries.
  3564. You can check in the <filename>meta/conf/multilib.conf</filename>
  3565. configuration file in the
  3566. <link linkend='source-directory'>Source Directory</link> to see how this is
  3567. done using the
  3568. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></ulink>
  3569. variable.
  3570. Eventually, all recipes will be covered and this list will
  3571. not be needed.
  3572. </para>
  3573. <para>
  3574. For the most part, the Multilib class extension works automatically to
  3575. extend the package name from <filename>${PN}</filename> to
  3576. <filename>${MLPREFIX}${PN}</filename>, where <filename>MLPREFIX</filename>
  3577. is the particular multilib (e.g. "lib32-" or "lib64-").
  3578. Standard variables such as
  3579. <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
  3580. <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
  3581. <ulink url='&YOCTO_DOCS_REF_URL;#var-RPROVIDES'><filename>RPROVIDES</filename></ulink>,
  3582. <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
  3583. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, and
  3584. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink>
  3585. are automatically extended by the system.
  3586. If you are extending any manual code in the recipe, you can use the
  3587. <filename>${MLPREFIX}</filename> variable to ensure those names are extended
  3588. correctly.
  3589. This automatic extension code resides in <filename>multilib.bbclass</filename>.
  3590. </para>
  3591. </section>
  3592. <section id='using-multilib'>
  3593. <title>Using Multilib</title>
  3594. <para>
  3595. After you have set up the recipes, you need to define the actual
  3596. combination of multiple libraries you want to build.
  3597. You accomplish this through your <filename>local.conf</filename>
  3598. configuration file in the
  3599. <link linkend='build-directory'>Build Directory</link>.
  3600. An example configuration would be as follows:
  3601. <literallayout class='monospaced'>
  3602. MACHINE = "qemux86-64"
  3603. require conf/multilib.conf
  3604. MULTILIBS = "multilib:lib32"
  3605. DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
  3606. IMAGE_INSTALL_append = " lib32-glib-2.0"
  3607. </literallayout>
  3608. This example enables an
  3609. additional library named <filename>lib32</filename> alongside the
  3610. normal target packages.
  3611. When combining these "lib32" alternatives, the example uses "x86" for tuning.
  3612. For information on this particular tuning, see
  3613. <filename>meta/conf/machine/include/ia32/arch-ia32.inc</filename>.
  3614. </para>
  3615. <para>
  3616. The example then includes <filename>lib32-glib-2.0</filename>
  3617. in all the images, which illustrates one method of including a
  3618. multiple library dependency.
  3619. You can use a normal image build to include this dependency,
  3620. for example:
  3621. <literallayout class='monospaced'>
  3622. $ bitbake core-image-sato
  3623. </literallayout>
  3624. You can also build Multilib packages specifically with a command like this:
  3625. <literallayout class='monospaced'>
  3626. $ bitbake lib32-glib-2.0
  3627. </literallayout>
  3628. </para>
  3629. </section>
  3630. <section id='additional-implementation-details'>
  3631. <title>Additional Implementation Details</title>
  3632. <para>
  3633. Generic implementation details as well as details that are
  3634. specific to package management systems exist.
  3635. Following are implementation details that exist regardless
  3636. of the package management system:
  3637. <itemizedlist>
  3638. <listitem><para>The typical convention used for the
  3639. class extension code as used by
  3640. Multilib assumes that all package names specified
  3641. in
  3642. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
  3643. that contain <filename>${PN}</filename> have
  3644. <filename>${PN}</filename> at the start of the name.
  3645. When that convention is not followed and
  3646. <filename>${PN}</filename> appears at
  3647. the middle or the end of a name, problems occur.
  3648. </para></listitem>
  3649. <listitem><para>The
  3650. <ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_VENDOR'><filename>TARGET_VENDOR</filename></ulink>
  3651. value under Multilib will be extended to
  3652. "-<replaceable>vendor</replaceable>ml<replaceable>multilib</replaceable>"
  3653. (e.g. "-pokymllib32" for a "lib32" Multilib with
  3654. Poky).
  3655. The reason for this slightly unwieldy contraction
  3656. is that any "-" characters in the vendor
  3657. string presently break Autoconf's
  3658. <filename>config.sub</filename>, and
  3659. other separators are problematic for different
  3660. reasons.
  3661. </para></listitem>
  3662. </itemizedlist>
  3663. </para>
  3664. '
  3665. <para>
  3666. For the RPM Package Management System, the following implementation details
  3667. exist:
  3668. <itemizedlist>
  3669. <listitem><para>A unique architecture is defined for the Multilib packages,
  3670. along with creating a unique deploy folder under
  3671. <filename>tmp/deploy/rpm</filename> in the
  3672. <link linkend='build-directory'>Build Directory</link>.
  3673. For example, consider <filename>lib32</filename> in a
  3674. <filename>qemux86-64</filename> image.
  3675. The possible architectures in the system are "all", "qemux86_64",
  3676. "lib32_qemux86_64", and "lib32_x86".</para></listitem>
  3677. <listitem><para>The <filename>${MLPREFIX}</filename> variable is stripped from
  3678. <filename>${PN}</filename> during RPM packaging.
  3679. The naming for a normal RPM package and a Multilib RPM package in a
  3680. <filename>qemux86-64</filename> system resolves to something similar to
  3681. <filename>bash-4.1-r2.x86_64.rpm</filename> and
  3682. <filename>bash-4.1.r2.lib32_x86.rpm</filename>, respectively.
  3683. </para></listitem>
  3684. <listitem><para>When installing a Multilib image, the RPM backend first
  3685. installs the base image and then installs the Multilib libraries.
  3686. </para></listitem>
  3687. <listitem><para>The build system relies on RPM to resolve the identical files in the
  3688. two (or more) Multilib packages.</para></listitem>
  3689. </itemizedlist>
  3690. </para>
  3691. <para>
  3692. For the IPK Package Management System, the following implementation details exist:
  3693. <itemizedlist>
  3694. <listitem><para>The <filename>${MLPREFIX}</filename> is not stripped from
  3695. <filename>${PN}</filename> during IPK packaging.
  3696. The naming for a normal RPM package and a Multilib IPK package in a
  3697. <filename>qemux86-64</filename> system resolves to something like
  3698. <filename>bash_4.1-r2.x86_64.ipk</filename> and
  3699. <filename>lib32-bash_4.1-rw_x86.ipk</filename>, respectively.
  3700. </para></listitem>
  3701. <listitem><para>The IPK deploy folder is not modified with
  3702. <filename>${MLPREFIX}</filename> because packages with and without
  3703. the Multilib feature can exist in the same folder due to the
  3704. <filename>${PN}</filename> differences.</para></listitem>
  3705. <listitem><para>IPK defines a sanity check for Multilib installation
  3706. using certain rules for file comparison, overridden, etc.
  3707. </para></listitem>
  3708. </itemizedlist>
  3709. </para>
  3710. </section>
  3711. </section>
  3712. <section id='installing-multiple-versions-of-the-same-library'>
  3713. <title>Installing Multiple Versions of the Same Library</title>
  3714. <para>
  3715. Situations can exist where you need to install and use
  3716. multiple versions of the same library on the same system
  3717. at the same time.
  3718. These situations almost always exist when a library API
  3719. changes and you have multiple pieces of software that
  3720. depend on the separate versions of the library.
  3721. To accommodate these situations, you can install multiple
  3722. versions of the same library in parallel on the same system.
  3723. </para>
  3724. <para>
  3725. The process is straightforward as long as the libraries use
  3726. proper versioning.
  3727. With properly versioned libraries, all you need to do to
  3728. individually specify the libraries is create separate,
  3729. appropriately named recipes where the
  3730. <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> part of the
  3731. name includes a portion that differentiates each library version
  3732. (e.g.the major part of the version number).
  3733. Thus, instead of having a single recipe that loads one version
  3734. of a library (e.g. <filename>clutter</filename>), you provide
  3735. multiple recipes that result in different versions
  3736. of the libraries you want.
  3737. As an example, the following two recipes would allow the
  3738. two separate versions of the <filename>clutter</filename>
  3739. library to co-exist on the same system:
  3740. <literallayout class='monospaced'>
  3741. clutter-1.6_1.6.20.bb
  3742. clutter-1.8_1.8.4.bb
  3743. </literallayout>
  3744. Additionally, if you have other recipes that depend on a given
  3745. library, you need to use the
  3746. <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
  3747. variable to create the dependency.
  3748. Continuing with the same example, if you want to have a recipe
  3749. depend on the 1.8 version of the <filename>clutter</filename>
  3750. library, use the following in your recipe:
  3751. <literallayout class='monospaced'>
  3752. DEPENDS = "clutter-1.8"
  3753. </literallayout>
  3754. </para>
  3755. </section>
  3756. </section>
  3757. <section id='enabling-gobject-introspection-support'>
  3758. <title>Enabling GObject Introspection Support</title>
  3759. <para>
  3760. <ulink url='https://wiki.gnome.org/Projects/GObjectIntrospection'>GObject introspection</ulink>
  3761. is the standard mechanism for accessing GObject-based software
  3762. from runtime environments.
  3763. GObject is a feature of the GLib library that provides an object
  3764. framework for the GNOME desktop and related software.
  3765. GObject Introspection adds information to GObject that allows
  3766. objects created within it to be represented across different
  3767. programming languages.
  3768. If you want to construct GStreamer pipelines using Python, or
  3769. control UPnP infrastructure using Javascript and GUPnP,
  3770. GObject introspection is the only way to do it.
  3771. </para>
  3772. <para>
  3773. This section describes the Yocto Project support for generating
  3774. and packaging GObject introspection data.
  3775. GObject introspection data is a description of the
  3776. API provided by libraries built on top of GLib framework,
  3777. and, in particular, that framework's GObject mechanism.
  3778. GObject Introspection Repository (GIR) files go to
  3779. <filename>-dev</filename> packages,
  3780. <filename>typelib</filename> files go to main packages as they
  3781. are packaged together with libraries that are introspected.
  3782. </para>
  3783. <para>
  3784. The data is generated when building such a library, by linking
  3785. the library with a small executable binary that asks the library
  3786. to describe itself, and then executing the binary and
  3787. processing its output.
  3788. </para>
  3789. <para>
  3790. Generating this data in a cross-compilation environment
  3791. is difficult because the library is produced for the target
  3792. architecture, but its code needs to be executed on the build host.
  3793. This problem is solved with the OpenEmbedded build system by
  3794. running the code through QEMU, which allows precisely that.
  3795. Unfortunately, QEMU does not always work perfectly as mentioned
  3796. in the xxx section.
  3797. </para>
  3798. <section id='enabling-the-generation-of-introspection-data'>
  3799. <title>Enabling the Generation of Introspection Data</title>
  3800. <para>
  3801. Enabling the generation of introspection data (GIR files)
  3802. in your library package involves the following:
  3803. <orderedlist>
  3804. <listitem><para>
  3805. Inherit the
  3806. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-gobject-introspection'><filename>gobject-introspection</filename></ulink>
  3807. class.
  3808. </para></listitem>
  3809. <listitem><para>
  3810. Make sure introspection is not disabled anywhere in
  3811. the recipe or from anything the recipe includes.
  3812. Also, make sure that "gobject-introspection-data" is
  3813. not in
  3814. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
  3815. and that "qemu-usermode" is not in
  3816. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
  3817. If either of these conditions exist, nothing will
  3818. happen.
  3819. </para></listitem>
  3820. <listitem><para>
  3821. Try to build the recipe.
  3822. If you encounter build errors that look like
  3823. something is unable to find
  3824. <filename>.so</filename> libraries, check where these
  3825. libraries are located in the source tree and add
  3826. the following to the recipe:
  3827. <literallayout class='monospaced'>
  3828. GIR_EXTRA_LIBS_PATH = "${B}/<replaceable>something</replaceable>/.libs"
  3829. </literallayout>
  3830. <note>
  3831. See recipes in the <filename>oe-core</filename>
  3832. repository that use that
  3833. <filename>GIR_EXTRA_LIBS_PATH</filename> variable
  3834. as an example.
  3835. </note>
  3836. </para></listitem>
  3837. <listitem><para>
  3838. Look for any other errors, which probably mean that
  3839. introspection support in a package is not entirely
  3840. standard, and thus breaks down in a cross-compilation
  3841. environment.
  3842. For such cases, custom-made fixes are needed.
  3843. A good place to ask and receive help in these cases
  3844. is the
  3845. <ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Yocto Project mailing lists</ulink>.
  3846. </para></listitem>
  3847. </orderedlist>
  3848. <note>
  3849. Using a library that no longer builds against the latest
  3850. Yocto Project release and prints introspection related
  3851. errors is a good candidate for the previous procedure.
  3852. </note>
  3853. </para>
  3854. </section>
  3855. <section id='disabling-the-generation-of-introspection-data'>
  3856. <title>Disabling the Generation of Introspection Data</title>
  3857. <para>
  3858. You might find that you do not want to generate
  3859. introspection data.
  3860. Or, perhaps QEMU does not work on your build host and
  3861. target architecture combination.
  3862. If so, you can use either of the following methods to
  3863. disable GIR file generations:
  3864. <itemizedlist>
  3865. <listitem><para>
  3866. Add the following to your distro configuration:
  3867. <literallayout class='monospaced'>
  3868. DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
  3869. </literallayout>
  3870. Adding this statement disables generating
  3871. introspection data using QEMU but will still enable
  3872. building introspection tools and libraries
  3873. (i.e. building them does not require the use of QEMU).
  3874. </para></listitem>
  3875. <listitem><para>
  3876. Add the following to your machine configuration:
  3877. <literallayout class='monospaced'>
  3878. MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
  3879. </literallayout>
  3880. Adding this statement disables the use of QEMU
  3881. when building packages for your machine.
  3882. Currently, this feature is used only by introspection
  3883. recipes and has the same effect as the previously
  3884. described option.
  3885. <note>
  3886. Future releases of the Yocto Project might have
  3887. other features affected by this option.
  3888. </note>
  3889. </para></listitem>
  3890. </itemizedlist>
  3891. If you disable introspection data, you can still
  3892. obtain it through other means such as copying the data
  3893. from a suitable sysroot, or by generating it on the
  3894. target hardware.
  3895. The OpenEmbedded build system does not currently
  3896. provide specific support for these techniques.
  3897. </para>
  3898. </section>
  3899. <section id='testing-that-introspection-works-in-an-image'>
  3900. <title>Testing that Introspection Works in an Image</title>
  3901. <para>
  3902. Use the following procedure to test if generating
  3903. introspection data is working in an image:
  3904. <orderedlist>
  3905. <listitem><para>
  3906. Make sure that "gobject-introspection-data" is not in
  3907. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
  3908. and that "qemu-usermode" is not in
  3909. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
  3910. </para></listitem>
  3911. <listitem><para>
  3912. Build <filename>core-image-sato</filename>.
  3913. </para></listitem>
  3914. <listitem><para>
  3915. Launch a Terminal and then start Python in the
  3916. terminal.
  3917. </para></listitem>
  3918. <listitem><para>
  3919. Enter the following in the terminal:
  3920. <literallayout class='monospaced'>
  3921. >>> from gi.repository import GLib
  3922. >>> GLib.get_host_name()
  3923. </literallayout>
  3924. </para></listitem>
  3925. <listitem><para>
  3926. For something a little more advanced, enter the
  3927. following:
  3928. <literallayout class='monospaced'>
  3929. http://python-gtk-3-tutorial.readthedocs.org/en/latest/introduction.html
  3930. </literallayout>
  3931. </para></listitem>
  3932. </orderedlist>
  3933. </para>
  3934. </section>
  3935. <section id='known-issues'>
  3936. <title>Known Issues</title>
  3937. <para>
  3938. The following know issues exist for
  3939. GObject Introspection Support:
  3940. <itemizedlist>
  3941. <listitem><para>
  3942. <filename>qemu-ppc64</filename> immediately crashes.
  3943. Consequently, you cannot build introspection data on
  3944. that architecture.
  3945. </para></listitem>
  3946. <listitem><para>
  3947. x32 is not supported by QEMU.
  3948. Consequently, introspection data is disabled.
  3949. </para></listitem>
  3950. <listitem><para>
  3951. musl causes transient GLib binaries to crash on
  3952. assertion failures.
  3953. Consequently, generating introspection data is
  3954. disabled.
  3955. </para></listitem>
  3956. <listitem><para>
  3957. Because QEMU is not able to run the binaries correctly,
  3958. introspection is disabled for some specific packages
  3959. under specific architectures (e.g.
  3960. <filename>gcr</filename>,
  3961. <filename>libsecret</filename>, and
  3962. <filename>webkit</filename>).
  3963. </para></listitem>
  3964. <listitem><para>
  3965. QEMU usermode might not work properly when running
  3966. 64-bit binaries under 32-bit host machines.
  3967. In particular, "qemumips64" is known to not work under
  3968. i686.
  3969. </para></listitem>
  3970. </itemizedlist>
  3971. </para>
  3972. </section>
  3973. </section>
  3974. <section id='dev-optionally-using-an-external-toolchain'>
  3975. <title>Optionally Using an External Toolchain</title>
  3976. <para>
  3977. You might want to use an external toolchain as part of your
  3978. development.
  3979. If this is the case, the fundamental steps you need to accomplish
  3980. are as follows:
  3981. <itemizedlist>
  3982. <listitem><para>
  3983. Understand where the installed toolchain resides.
  3984. For cases where you need to build the external toolchain,
  3985. you would need to take separate steps to build and install
  3986. the toolchain.
  3987. </para></listitem>
  3988. <listitem><para>
  3989. Make sure you add the layer that contains the toolchain to
  3990. your <filename>bblayers.conf</filename> file through the
  3991. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
  3992. variable.
  3993. </para></listitem>
  3994. <listitem><para>
  3995. Set the
  3996. <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNAL_TOOLCHAIN'><filename>EXTERNAL_TOOLCHAIN</filename></ulink>
  3997. variable in your <filename>local.conf</filename> file
  3998. to the location in which you installed the toolchain.
  3999. </para></listitem>
  4000. </itemizedlist>
  4001. A good example of an external toolchain used with the Yocto Project
  4002. is <trademark class='registered'>Mentor Graphics</trademark>
  4003. Sourcery G++ Toolchain.
  4004. You can see information on how to use that particular layer in the
  4005. <filename>README</filename> file at
  4006. <ulink url='http://github.com/MentorEmbedded/meta-sourcery/'></ulink>.
  4007. You can find further information by reading about the
  4008. <ulink url='&YOCTO_DOCS_REF_URL;#var-TCMODE'><filename>TCMODE</filename></ulink>
  4009. variable in the Yocto Project Reference Manual's variable glossary.
  4010. </para>
  4011. </section>
  4012. <section id='creating-partitioned-images'>
  4013. <title>Creating Partitioned Images</title>
  4014. <para>
  4015. Creating an image for a particular hardware target using the
  4016. OpenEmbedded build system does not necessarily mean you can boot
  4017. that image as is on your device.
  4018. Physical devices accept and boot images in various ways depending
  4019. on the specifics of the device.
  4020. Usually, information about the hardware can tell you what image
  4021. format the device requires.
  4022. Should your device require multiple partitions on an SD card, flash,
  4023. or an HDD, you can use the OpenEmbedded Image Creator,
  4024. <filename>wic</filename>, to create the properly partitioned image.
  4025. </para>
  4026. <para>
  4027. The <filename>wic</filename> command generates partitioned images
  4028. from existing OpenEmbedded build artifacts.
  4029. Image generation is driven by partitioning commands contained
  4030. in an Openembedded kickstart file (<filename>.wks</filename>)
  4031. specified either directly on the command line or as one of a
  4032. selection of canned <filename>.wks</filename> files as shown
  4033. with the <filename>wic list images</filename> command in the
  4034. "<link linkend='using-a-provided-kickstart_file'>Using an Existing Kickstart File</link>"
  4035. section.
  4036. When applied to a given set of build artifacts, the result is an
  4037. image or set of images that can be directly written onto media and
  4038. used on a particular system.
  4039. </para>
  4040. <para>
  4041. The <filename>wic</filename> command and the infrastructure
  4042. it is based on is by definition incomplete.
  4043. Its purpose is to allow the generation of customized images,
  4044. and as such was designed to be completely extensible through a
  4045. plug-in interface.
  4046. See the
  4047. "<link linkend='openembedded-kickstart-plugins'>Plug-ins</link>"
  4048. section for information on these plug-ins.
  4049. </para>
  4050. <para>
  4051. This section provides some background information on
  4052. <filename>wic</filename>, describes what you need to have in
  4053. place to run the tool, provides instruction on how to use
  4054. <filename>wic</filename>, and provides several examples.
  4055. </para>
  4056. <section id='wic-background'>
  4057. <title>Background</title>
  4058. <para>
  4059. This section provides some background on the
  4060. <filename>wic</filename> utility.
  4061. While none of this information is required to use
  4062. <filename>wic</filename>, you might find it interesting.
  4063. <itemizedlist>
  4064. <listitem><para>
  4065. The name "wic" is derived from OpenEmbedded
  4066. Image Creator (oeic).
  4067. The "oe" diphthong in "oeic" was promoted to the
  4068. letter "w", because "oeic" is both difficult to remember and
  4069. pronounce.</para></listitem>
  4070. <listitem><para>
  4071. <filename>wic</filename> is loosely based on the
  4072. Meego Image Creator (<filename>mic</filename>)
  4073. framework.
  4074. The <filename>wic</filename> implementation has been
  4075. heavily modified to make direct use of OpenEmbedded
  4076. build artifacts instead of package installation and
  4077. configuration, which are already incorporated within
  4078. the OpenEmbedded artifacts.</para></listitem>
  4079. <listitem><para>
  4080. <filename>wic</filename> is a completely independent
  4081. standalone utility that initially provides
  4082. easier-to-use and more flexible replacements for a
  4083. couple bits of existing functionality in OE Core's
  4084. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image-live'><filename>image-live</filename></ulink>
  4085. class and <filename>mkefidisk.sh</filename> script.
  4086. The difference between
  4087. <filename>wic</filename> and those examples is
  4088. that with <filename>wic</filename> the
  4089. functionality of those scripts is implemented
  4090. by a general-purpose partitioning language, which is
  4091. based on Redhat kickstart syntax.</para></listitem>
  4092. </itemizedlist>
  4093. </para>
  4094. </section>
  4095. <section id='wic-requirements'>
  4096. <title>Requirements</title>
  4097. <para>
  4098. In order to use the <filename>wic</filename> utility
  4099. with the OpenEmbedded Build system, your system needs
  4100. to meet the following requirements:
  4101. <itemizedlist>
  4102. <listitem><para>The Linux distribution on your
  4103. development host must support the Yocto Project.
  4104. See the
  4105. "<ulink url='&YOCTO_DOCS_REF_URL;#detailed-supported-distros'>Supported Linux Distributions</ulink>"
  4106. section in the Yocto Project Reference Manual for this
  4107. list of distributions.</para></listitem>
  4108. <listitem><para>
  4109. The standard system utilities, such as
  4110. <filename>cp</filename>, must be installed on your
  4111. development host system.
  4112. </para></listitem>
  4113. <listitem><para>
  4114. You need to have the build artifacts already
  4115. available, which typically means that you must
  4116. have already created an image using the
  4117. Openembedded build system (e.g.
  4118. <filename>core-image-minimal</filename>).
  4119. While it might seem redundant to generate an image in
  4120. order to create an image using
  4121. <filename>wic</filename>, the current version of
  4122. <filename>wic</filename> requires the artifacts
  4123. in the form generated by the build system.
  4124. </para></listitem>
  4125. <listitem><para>
  4126. You must build several native tools, which are tools
  4127. built to run on the build system:
  4128. <literallayout class='monospaced'>
  4129. $ bitbake parted-native dosfstools-native mtools-native
  4130. </literallayout>
  4131. </para></listitem>
  4132. <listitem><para>
  4133. You must have sourced one of the build environment
  4134. setup scripts (i.e.
  4135. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
  4136. or
  4137. <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>)
  4138. found in the
  4139. <link linkend='build-directory'>Build Directory</link>.
  4140. </para></listitem>
  4141. </itemizedlist>
  4142. </para>
  4143. </section>
  4144. <section id='wic-getting-help'>
  4145. <title>Getting Help</title>
  4146. <para>
  4147. You can get general help for the <filename>wic</filename>
  4148. by entering the <filename>wic</filename> command by itself
  4149. or by entering the command with a help argument as follows:
  4150. <literallayout class='monospaced'>
  4151. $ wic -h
  4152. $ wic --help
  4153. </literallayout>
  4154. </para>
  4155. <para>
  4156. Currently, <filename>wic</filename> supports two commands:
  4157. <filename>create</filename> and <filename>list</filename>.
  4158. You can get help for these commands as follows:
  4159. <literallayout class='monospaced'>
  4160. $ wic help <replaceable>command</replaceable>
  4161. </literallayout>
  4162. </para>
  4163. <para>
  4164. You can also get detailed help on a number of topics
  4165. from the help system.
  4166. The output of <filename>wic --help</filename>
  4167. displays a list of available help
  4168. topics under a "Help topics" heading.
  4169. You can have the help system display the help text for
  4170. a given topic by prefacing the topic with
  4171. <filename>wic help</filename>:
  4172. <literallayout class='monospaced'>
  4173. $ wic help <replaceable>help_topic</replaceable>
  4174. </literallayout>
  4175. </para>
  4176. <para>
  4177. You can find out more about the images
  4178. <filename>wic</filename> creates using the existing
  4179. kickstart files with the following form of the command:
  4180. <literallayout class='monospaced'>
  4181. $ wic list <replaceable>image</replaceable> help
  4182. </literallayout>
  4183. where <filename><replaceable>image</replaceable></filename> is either
  4184. <filename>directdisk</filename> or
  4185. <filename>mkefidisk</filename>.
  4186. </para>
  4187. </section>
  4188. <section id='operational-modes'>
  4189. <title>Operational Modes</title>
  4190. <para>
  4191. You can use <filename>wic</filename> in two different
  4192. modes, depending on how much control you need for
  4193. specifying the Openembedded build artifacts that are
  4194. used for creating the image: Raw and Cooked:
  4195. <itemizedlist>
  4196. <listitem><para><emphasis>Raw Mode:</emphasis>
  4197. You explicitly specify build artifacts through
  4198. command-line arguments.</para></listitem>
  4199. <listitem><para><emphasis>Cooked Mode:</emphasis>
  4200. The current
  4201. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
  4202. setting and image name are used to automatically locate
  4203. and provide the build artifacts.</para></listitem>
  4204. </itemizedlist>
  4205. </para>
  4206. <para>
  4207. Regardless of the mode you use, you need to have the build
  4208. artifacts ready and available.
  4209. Additionally, the environment must be set up using the
  4210. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
  4211. or
  4212. <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>
  4213. script found in the
  4214. <link linkend='build-directory'>Build Directory</link>.
  4215. </para>
  4216. <section id='raw-mode'>
  4217. <title>Raw Mode</title>
  4218. <para>
  4219. The general form of the 'wic' command in raw mode is:
  4220. <literallayout class='monospaced'>
  4221. $ wic create <replaceable>image_name</replaceable>.wks [<replaceable>options</replaceable>] [...]
  4222. Where:
  4223. <replaceable>image_name</replaceable>.wks
  4224. An OpenEmbedded kickstart file. You can provide
  4225. your own custom file or use a file from a set of
  4226. existing files as described by further options.
  4227. -o <replaceable>OUTDIR</replaceable>, --outdir=<replaceable>OUTDIR</replaceable>
  4228. The name of a directory in which to create image.
  4229. -i <replaceable>PROPERTIES_FILE</replaceable>, --infile=<replaceable>PROPERTIES_FILE</replaceable>
  4230. The name of a file containing the values for image
  4231. properties as a JSON file.
  4232. -e <replaceable>IMAGE_NAME</replaceable>, --image-name=<replaceable>IMAGE_NAME</replaceable>
  4233. The name of the image from which to use the artifacts
  4234. (e.g. <filename>core-image-sato</filename>).
  4235. -r <replaceable>ROOTFS_DIR</replaceable>, --rootfs-dir=<replaceable>ROOTFS_DIR</replaceable>
  4236. The path to the <filename>/rootfs</filename> directory to use as the
  4237. <filename>.wks</filename> rootfs source.
  4238. -b <replaceable>BOOTIMG_DIR</replaceable>, --bootimg-dir=<replaceable>BOOTIMG_DIR</replaceable>
  4239. The path to the directory containing the boot artifacts
  4240. (e.g. <filename>/EFI</filename> or <filename>/syslinux</filename>) to use as the <filename>.wks</filename> bootimg
  4241. source.
  4242. -k <replaceable>KERNEL_DIR</replaceable>, --kernel-dir=<replaceable>KERNEL_DIR</replaceable>
  4243. The path to the directory containing the kernel to use
  4244. in the <filename>.wks</filename> boot image.
  4245. -n <replaceable>NATIVE_SYSROOT</replaceable>, --native-sysroot=<replaceable>NATIVE_SYSROOT</replaceable>
  4246. The path to the native sysroot containing the tools to use
  4247. to build the image.
  4248. -s, --skip-build-check
  4249. Skips the build check.
  4250. -D, --debug
  4251. Output debug information.
  4252. </literallayout>
  4253. <note>
  4254. You do not need root privileges to run
  4255. <filename>wic</filename>.
  4256. In fact, you should not run as root when using the
  4257. utility.
  4258. </note>
  4259. </para>
  4260. </section>
  4261. <section id='cooked-mode'>
  4262. <title>Cooked Mode</title>
  4263. <para>
  4264. The general form of the <filename>wic</filename> command
  4265. using Cooked Mode is:
  4266. <literallayout class='monospaced'>
  4267. $ wic create <replaceable>kickstart_file</replaceable> -e <replaceable>image_name</replaceable>
  4268. Where:
  4269. <replaceable>kickstart_file</replaceable>
  4270. An OpenEmbedded kickstart file. You can provide your own
  4271. custom file or supplied file.
  4272. <replaceable>image_name</replaceable>
  4273. Specifies the image built using the OpenEmbedded build
  4274. system.
  4275. </literallayout>
  4276. This form is the simplest and most user-friendly, as it
  4277. does not require specifying all individual parameters.
  4278. All you need to provide is your own
  4279. <filename>.wks</filename> file or one provided with the
  4280. release.
  4281. </para>
  4282. </section>
  4283. </section>
  4284. <section id='using-a-provided-kickstart_file'>
  4285. <title>Using an Existing Kickstart File</title>
  4286. <para>
  4287. If you do not want to create your own
  4288. <filename>.wks</filename> file, you can use an existing
  4289. file provided by the <filename>wic</filename> installation.
  4290. Use the following command to list the available files:
  4291. <literallayout class='monospaced'>
  4292. $ wic list images
  4293. directdisk Create a 'pcbios' direct disk image
  4294. mkefidisk Create an EFI disk image
  4295. </literallayout>
  4296. When you use an existing file, you do not have to use the
  4297. <filename>.wks</filename> extension.
  4298. Here is an example in Raw Mode that uses the
  4299. <filename>directdisk</filename> file:
  4300. <literallayout class='monospaced'>
  4301. $ wic create directdisk -r <replaceable>rootfs_dir</replaceable> -b <replaceable>bootimg_dir</replaceable> \
  4302. -k <replaceable>kernel_dir</replaceable> -n <replaceable>native_sysroot</replaceable>
  4303. </literallayout>
  4304. </para>
  4305. <para>
  4306. Here are the actual partition language commands
  4307. used in the <filename>mkefidisk.wks</filename> file to generate
  4308. an image:
  4309. <literallayout class='monospaced'>
  4310. # short-description: Create an EFI disk image
  4311. # long-description: Creates a partitioned EFI disk image that the user
  4312. # can directly dd to boot media.
  4313. part /boot --source bootimg-efi --ondisk sda --label msdos --active --align 1024
  4314. part / --source rootfs --ondisk sda --fstype=ext3 --label platform --align 1024
  4315. part swap --ondisk sda --size 44 --label swap1 --fstype=swap
  4316. bootloader --timeout=10 --append="rootwait rootfstype=ext3 console=ttyPCH0,115200 console=tty0 vmalloc=256MB snd-hda-intel.enable_msi=0"
  4317. </literallayout>
  4318. </para>
  4319. </section>
  4320. <section id='wic-usage-examples'>
  4321. <title>Examples</title>
  4322. <para>
  4323. This section provides several examples that show how to use
  4324. the <filename>wic</filename> utility.
  4325. All the examples assume the list of requirements in the
  4326. "<link linkend='wic-requirements'>Requirements</link>" section
  4327. have been met.
  4328. The examples assume the previously generated image is
  4329. <filename>core-image-minimal</filename>.
  4330. </para>
  4331. <section id='generate-an-image-using-a-provided-kickstart-file'>
  4332. <title>Generate an Image using an Existing Kickstart File</title>
  4333. <para>
  4334. This example runs in Cooked Mode and uses the
  4335. <filename>mkefidisk</filename> kickstart file:
  4336. <literallayout class='monospaced'>
  4337. $ wic create mkefidisk -e core-image-minimal
  4338. Checking basic build environment...
  4339. Done.
  4340. Creating image(s)...
  4341. Info: The new image(s) can be found here:
  4342. /var/tmp/wic/build/mkefidisk-201310230946-sda.direct
  4343. The following build artifacts were used to create the image(s):
  4344. ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/minnow-poky-linux/core-image-minimal/1.0-r0/rootfs
  4345. BOOTIMG_DIR: /home/trz/yocto/yocto-image/build/tmp/work/minnow-poky-linux/core-image-minimal/1.0-r0/core-image-minimal-1.0/hddimg
  4346. KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/minnow/usr/src/kernel
  4347. NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/x86_64-linux
  4348. The image(s) were created using OE kickstart file:
  4349. /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/mkefidisk.wks
  4350. </literallayout>
  4351. This example shows the easiest way to create an image
  4352. by running in Cooked Mode and using the
  4353. <filename>-e</filename> option with an existing kickstart
  4354. file.
  4355. All that is necessary is to specify the image used to
  4356. generate the artifacts.
  4357. Your <filename>local.conf</filename> needs to have the
  4358. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
  4359. variable set to the machine you are using, which is
  4360. "minnow" in this example.
  4361. </para>
  4362. <para>
  4363. The output specifies the exact image created as well as
  4364. where it was created.
  4365. The output also names the artifacts used and the exact
  4366. <filename>.wks</filename> script that was used to generate
  4367. the image.
  4368. <note>
  4369. You should always verify the details provided in the
  4370. output to make sure that the image was indeed created
  4371. exactly as expected.
  4372. </note>
  4373. </para>
  4374. <para>
  4375. Continuing with the example, you can now directly
  4376. <filename>dd</filename> the image to a USB stick, or
  4377. whatever media for which you built your image,
  4378. and boot the resulting media:
  4379. <literallayout class='monospaced'>
  4380. $ sudo dd if=/var/tmp/wic/build/mkefidisk-201310230946-sda.direct of=/dev/sdb
  4381. [sudo] password for trz:
  4382. 182274+0 records in
  4383. 182274+0 records out
  4384. 93324288 bytes (93 MB) copied, 14.4777 s, 6.4 MB/s
  4385. [trz@empanada ~]$ sudo eject /dev/sdb
  4386. </literallayout>
  4387. </para>
  4388. </section>
  4389. <section id='using-a-modified-kickstart-file'>
  4390. <title>Using a Modified Kickstart File</title>
  4391. <para>
  4392. Because <filename>wic</filename> image creation is driven
  4393. by the kickstart file, it is easy to affect image creation
  4394. by changing the parameters in the file.
  4395. This next example demonstrates that through modification
  4396. of the <filename>directdisk</filename> kickstart file.
  4397. </para>
  4398. <para>
  4399. As mentioned earlier, you can use the command
  4400. <filename>wic list images</filename> to show the list
  4401. of existing kickstart files.
  4402. The directory in which these files reside is
  4403. <filename>scripts/lib/image/canned-wks/</filename>
  4404. located in the
  4405. <link linkend='source-directory'>Source Directory</link>.
  4406. Because the available files reside in this directory, you
  4407. can create and add your own custom files to the directory.
  4408. Subsequent use of the <filename>wic list images</filename>
  4409. command would then include your kickstart files.
  4410. </para>
  4411. <para>
  4412. In this example, the existing
  4413. <filename>directdisk</filename> file already does most
  4414. of what is needed.
  4415. However, for the hardware in this example, the image will
  4416. need to boot from <filename>sdb</filename> instead of
  4417. <filename>sda</filename>, which is what the
  4418. <filename>directdisk</filename> kickstart file uses.
  4419. </para>
  4420. <para>
  4421. The example begins by making a copy of the
  4422. <filename>directdisk.wks</filename> file in the
  4423. <filename>scripts/lib/image/canned-wks</filename>
  4424. directory and then changing the lines that specify the
  4425. target disk from which to boot.
  4426. <literallayout class='monospaced'>
  4427. $ cp /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisk.wks \
  4428. /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisksdb.wks
  4429. </literallayout>
  4430. Next, the example modifies the
  4431. <filename>directdisksdb.wks</filename> file and changes all
  4432. instances of "<filename>--ondisk sda</filename>"
  4433. to "<filename>--ondisk sdb</filename>".
  4434. The example changes the following two lines and leaves the
  4435. remaining lines untouched:
  4436. <literallayout class='monospaced'>
  4437. part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
  4438. part / --source rootfs --ondisk sdb --fstype=ext3 --label platform --align 1024
  4439. </literallayout>
  4440. Once the lines are changed, the example generates the
  4441. <filename>directdisksdb</filename> image.
  4442. The command points the process at the
  4443. <filename>core-image-minimal</filename> artifacts for the
  4444. Next Unit of Computing (nuc)
  4445. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
  4446. the <filename>local.conf</filename>.
  4447. <literallayout class='monospaced'>
  4448. $ wic create directdisksdb -e core-image-minimal
  4449. Checking basic build environment...
  4450. Done.
  4451. Creating image(s)...
  4452. Info: The new image(s) can be found here:
  4453. /var/tmp/wic/build/directdisksdb-201310231131-sdb.direct
  4454. The following build artifacts were used to create the image(s):
  4455. ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/nuc-poky-linux/core-image-minimal/1.0-r0/rootfs
  4456. BOOTIMG_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/nuc/usr/share
  4457. KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/nuc/usr/src/kernel
  4458. NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/x86_64-linux
  4459. The image(s) were created using OE kickstart file:
  4460. /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisksdb.wks
  4461. </literallayout>
  4462. Continuing with the example, you can now directly
  4463. <filename>dd</filename> the image to a USB stick, or
  4464. whatever media for which you built your image,
  4465. and boot the resulting media:
  4466. <literallayout class='monospaced'>
  4467. $ sudo dd if=/var/tmp/wic/build/directdisksdb-201310231131-sdb.direct of=/dev/sdb
  4468. 86018+0 records in
  4469. 86018+0 records out
  4470. 44041216 bytes (44 MB) copied, 13.0734 s, 3.4 MB/s
  4471. [trz@empanada tmp]$ sudo eject /dev/sdb
  4472. </literallayout>
  4473. </para>
  4474. </section>
  4475. <section id='creating-an-image-based-on-core-image-minimal-and-crownbay-noemgd'>
  4476. <title>Creating an Image Based on <filename>core-image-minimal</filename> and <filename>crownbay-noemgd</filename></title>
  4477. <para>
  4478. This example creates an image based on
  4479. <filename>core-image-minimal</filename> and a
  4480. <filename>crownbay-noemgd</filename>
  4481. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
  4482. that works right out of the box.
  4483. <literallayout class='monospaced'>
  4484. $ wic create directdisk -e core-image-minimal
  4485. Checking basic build environment...
  4486. Done.
  4487. Creating image(s)...
  4488. Info: The new image(s) can be found here:
  4489. /var/tmp/wic/build/directdisk-201309252350-sda.direct
  4490. The following build artifacts were used to create the image(s):
  4491. ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/crownbay_noemgd-poky-linux/core-image-minimal/1.0-r0/rootfs
  4492. BOOTIMG_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/share
  4493. KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel
  4494. NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel
  4495. The image(s) were created using OE kickstart file:
  4496. /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisk.wks
  4497. </literallayout>
  4498. </para>
  4499. </section>
  4500. <section id='using-a-modified-kickstart-file-and-running-in-raw-mode'>
  4501. <title>Using a Modified Kickstart File and Running in Raw Mode</title>
  4502. <para>
  4503. This next example manually specifies each build artifact
  4504. (runs in Raw Mode) and uses a modified kickstart file.
  4505. The example also uses the <filename>-o</filename> option
  4506. to cause <filename>wic</filename> to create the output
  4507. somewhere other than the default
  4508. <filename>/var/tmp/wic</filename> directory:
  4509. <literallayout class='monospaced'>
  4510. $ wic create ~/test.wks -o /home/trz/testwic --rootfs-dir \
  4511. /home/trz/yocto/yocto-image/build/tmp/work/crownbay_noemgd-poky-linux/core-image-minimal/1.0-r0/rootfs \
  4512. --bootimg-dir /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/share \
  4513. --kernel-dir /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel \
  4514. --native-sysroot /home/trz/yocto/yocto-image/build/tmp/sysroots/x86_64-linux
  4515. Creating image(s)...
  4516. Info: The new image(s) can be found here:
  4517. /home/trz/testwic/build/test-201309260032-sda.direct
  4518. The following build artifacts were used to create the image(s):
  4519. ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/crownbay_noemgd-poky-linux/core-image-minimal/1.0-r0/rootfs
  4520. BOOTIMG_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/share
  4521. KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel
  4522. NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel
  4523. The image(s) were created using OE kickstart file:
  4524. /home/trz/test.wks
  4525. </literallayout>
  4526. For this example,
  4527. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
  4528. did not have to be specified in the
  4529. <filename>local.conf</filename> file since the artifact is
  4530. manually specified.
  4531. </para>
  4532. </section>
  4533. </section>
  4534. <section id='openembedded-kickstart-plugins'>
  4535. <title>Plug-ins</title>
  4536. <para>
  4537. Plug-ins allow <filename>wic</filename> functionality to
  4538. be extended and specialized by users.
  4539. This section documents the plugin interface, which is
  4540. currently restricted to source plug ins.
  4541. </para>
  4542. <para>
  4543. Source plug ins provide a mechanism to customize
  4544. various aspects of the image generation process in
  4545. <filename>wic</filename>, mainly the contents of
  4546. partitions.
  4547. The plug ins provide a mechanism for mapping values
  4548. specified in <filename>.wks</filename> files using the
  4549. <filename>--source</filename> keyword to a
  4550. particular plugin implementation that populates a
  4551. corresponding partition.
  4552. </para>
  4553. <para>
  4554. A source plugin is created as a subclass of
  4555. <filename>SourcePlugin</filename>.
  4556. The plugin file containing it is added to
  4557. <filename>scripts/lib/wic/plugins/source/</filename> to
  4558. make the plugin implementation available to the
  4559. <filename>wic</filename> implementation.
  4560. For more information, see
  4561. <filename>scripts/lib/wic/pluginbase.py</filename>.
  4562. </para>
  4563. <para>
  4564. Source plugins can also be implemented and added by
  4565. external layers.
  4566. As such, any plugins found in a
  4567. <filename>scripts/lib/wic/plugins/source/</filename>
  4568. directory in an external layer are also made
  4569. available.
  4570. </para>
  4571. <para>
  4572. When the <filename>wic</filename> implementation needs
  4573. to invoke a partition-specific implementation, it looks
  4574. for the plugin that has the same name as the
  4575. <filename>--source</filename> parameter given to
  4576. that partition.
  4577. For example, if the partition is set up as follows:
  4578. <literallayout class='monospaced'>
  4579. part /boot --source bootimg-pcbios ...
  4580. </literallayout>
  4581. The methods defined as class members of the plugin
  4582. having the matching <filename>bootimg-pcbios.name</filename>
  4583. class member are used.
  4584. </para>
  4585. <para>
  4586. To be more concrete, here is the plugin definition that
  4587. matches a
  4588. <filename>--source bootimg-pcbios</filename> usage,
  4589. along with an example
  4590. method called by the <filename>wic</filename> implementation
  4591. when it needs to invoke an implementation-specific
  4592. partition-preparation function:
  4593. <literallayout class='monospaced'>
  4594. class BootimgPcbiosPlugin(SourcePlugin):
  4595. name = 'bootimg-pcbios'
  4596. @classmethod
  4597. def do_prepare_partition(self, part, ...)
  4598. </literallayout>
  4599. If the subclass itself does not implement a function, a
  4600. default version in a superclass is located and
  4601. used, which is why all plugins must be derived from
  4602. <filename>SourcePlugin</filename>.
  4603. </para>
  4604. <para>
  4605. The <filename>SourcePlugin</filename> class defines the
  4606. following methods, which is the current set of methods
  4607. that can be implemented or overridden by
  4608. <filename>--source</filename> plugins.
  4609. Any methods not implemented by a
  4610. <filename>SourcePlugin</filename> subclass inherit the
  4611. implementations present in the
  4612. <filename>SourcePlugin</filename> class.
  4613. For more information, see the
  4614. <filename>SourcePlugin</filename> source for details:
  4615. </para>
  4616. <para>
  4617. <itemizedlist>
  4618. <listitem><para><emphasis><filename>do_prepare_partition()</filename>:</emphasis>
  4619. Called to do the actual content population for a
  4620. partition.
  4621. In other words, the method prepares the final
  4622. partition image that is incorporated into the
  4623. disk image.
  4624. </para></listitem>
  4625. <listitem><para><emphasis><filename>do_configure_partition()</filename>:</emphasis>
  4626. Called before
  4627. <filename>do_prepare_partition()</filename>.
  4628. This method is typically used to create custom
  4629. configuration files for a partition (e.g. syslinux or
  4630. grub configuration files).
  4631. </para></listitem>
  4632. <listitem><para><emphasis><filename>do_install_disk()</filename>:</emphasis>
  4633. Called after all partitions have been prepared and
  4634. assembled into a disk image.
  4635. This method provides a hook to allow finalization of a
  4636. disk image, (e.g. writing an MBR).
  4637. </para></listitem>
  4638. <listitem><para><emphasis><filename>do_stage_partition()</filename>:</emphasis>
  4639. Special content-staging hook called before
  4640. <filename>do_prepare_partition()</filename>.
  4641. This method is normally empty.</para>
  4642. <para>Typically, a partition just uses the passed-in
  4643. parameters (e.g. the unmodified value of
  4644. <filename>bootimg_dir</filename>).
  4645. However, in some cases things might need to be
  4646. more tailored.
  4647. As an example, certain files might additionally
  4648. need to be taken from
  4649. <filename>bootimg_dir + /boot</filename>.
  4650. This hook allows those files to be staged in a
  4651. customized fashion.
  4652. <note>
  4653. <filename>get_bitbake_var()</filename>
  4654. allows you to access non-standard variables
  4655. that you might want to use for this.
  4656. </note>
  4657. </para></listitem>
  4658. </itemizedlist>
  4659. </para>
  4660. <para>
  4661. This scheme is extensible.
  4662. Adding more hooks is a simple matter of adding more
  4663. plugin methods to <filename>SourcePlugin</filename> and
  4664. derived classes.
  4665. The code that then needs to call the plugin methods uses
  4666. <filename>plugin.get_source_plugin_methods()</filename>
  4667. to find the method or methods needed by the call.
  4668. Retrieval of those methods is accomplished
  4669. by filling up a dict with keys
  4670. containing the method names of interest.
  4671. On success, these will be filled in with the actual
  4672. methods.
  4673. Please see the <filename>wic</filename>
  4674. implementation for examples and details.
  4675. </para>
  4676. </section>
  4677. <section id='openembedded-kickstart-wks-reference'>
  4678. <title>OpenEmbedded Kickstart (.wks) Reference</title>
  4679. <para>
  4680. The current <filename>wic</filename> implementation supports
  4681. only the basic kickstart partitioning commands:
  4682. <filename>partition</filename> (or <filename>part</filename>
  4683. for short) and <filename>bootloader</filename>.
  4684. <note>
  4685. Future updates will implement more commands and options.
  4686. If you use anything that is not specifically
  4687. supported, results can be unpredictable.
  4688. </note>
  4689. </para>
  4690. <para>
  4691. The following is a list of the commands, their syntax,
  4692. and meanings.
  4693. The commands are based on the Fedora
  4694. kickstart versions but with modifications to
  4695. reflect <filename>wic</filename> capabilities.
  4696. You can see the original documentation for those commands
  4697. at the following links:
  4698. <itemizedlist>
  4699. <listitem><para>
  4700. <ulink url='http://fedoraproject.org/wiki/Anaconda/Kickstart#part_or_partition'>http://fedoraproject.org/wiki/Anaconda/Kickstart#part_or_partition</ulink>
  4701. </para></listitem>
  4702. <listitem><para>
  4703. <ulink url='http://fedoraproject.org/wiki/Anaconda/Kickstart#bootloader'>http://fedoraproject.org/wiki/Anaconda/Kickstart#bootloader</ulink>
  4704. </para></listitem>
  4705. </itemizedlist>
  4706. </para>
  4707. <section id='command-part-or-partition'>
  4708. <title>Command: part or partition</title>
  4709. <para>
  4710. Either of these commands create a partition on the system
  4711. and uses the following syntax:
  4712. <literallayout class='monospaced'>
  4713. part [<replaceable>mntpoint</replaceable>]
  4714. partition [<replaceable>mntpoint</replaceable>]
  4715. </literallayout>
  4716. If you do not provide
  4717. <replaceable>mntpoint</replaceable>, wic creates a partition
  4718. but does not mount it.
  4719. </para>
  4720. <para>
  4721. The <filename><replaceable>mntpoint</replaceable></filename>
  4722. is where the
  4723. partition will be mounted and must be of one of the
  4724. following forms:
  4725. <itemizedlist>
  4726. <listitem><para><filename>/<replaceable>path</replaceable></filename>:
  4727. For example, <filename>/</filename>,
  4728. <filename>/usr</filename>, or
  4729. <filename>/home</filename></para></listitem>
  4730. <listitem><para><filename>swap</filename>:
  4731. The created partition is used as swap space.
  4732. </para></listitem>
  4733. </itemizedlist>
  4734. </para>
  4735. <para>
  4736. Specifying a <replaceable>mntpoint</replaceable> causes
  4737. the partition to automatically be mounted.
  4738. Wic achieves this by adding entries to the filesystem
  4739. table (fstab) during image generation.
  4740. In order for wic to generate a valid fstab, you must
  4741. also provide one of the <filename>--ondrive</filename>,
  4742. <filename>--ondisk</filename>, or
  4743. <filename>--use-uuid</filename> partition options as part
  4744. of the command.
  4745. Here is an example using "/" as the mountpoint.
  4746. The command uses "--ondisk" to force the partition onto
  4747. the <filename>sdb</filename> disk:
  4748. <literallayout class='monospaced'>
  4749. part / --source rootfs --ondisk sdb --fstype=ext3 --label platform --align 1024
  4750. </literallayout>
  4751. </para>
  4752. <para>
  4753. Here is a list that describes other supported options you
  4754. can use with the <filename>part</filename> and
  4755. <filename>partition</filename> commands:
  4756. <itemizedlist>
  4757. <listitem><para><emphasis><filename>--size</filename>:</emphasis>
  4758. The minimum partition size in MBytes.
  4759. Specify an integer value such as 500.
  4760. Do not append the number with "MB".
  4761. You do not need this option if you use
  4762. <filename>--source</filename>.</para></listitem>
  4763. <listitem><para><emphasis><filename>--source</filename>:</emphasis>
  4764. This option is a
  4765. <filename>wic</filename>-specific option that
  4766. names the source of the data that populates
  4767. the partition.
  4768. The most common value for this option is
  4769. "rootfs", but you can use any value that maps to
  4770. a valid source plugin.
  4771. For information on the source plugins, see the
  4772. "<link linkend='openembedded-kickstart-plugins'>Plugins</link>"
  4773. section.</para>
  4774. <para>If you use
  4775. <filename>--source rootfs</filename>,
  4776. <filename>wic</filename> creates a partition as
  4777. large as needed and to fill it with the contents of
  4778. the root filesystem pointed to by the
  4779. <filename>-r</filename> command-line option
  4780. or the equivalent rootfs derived from the
  4781. <filename>-e</filename> command-line
  4782. option.
  4783. The filesystem type used to create the
  4784. partition is driven by the value of the
  4785. <filename>--fstype</filename> option
  4786. specified for the partition.
  4787. See the entry on
  4788. <filename>--fstype</filename> that
  4789. follows for more information.
  4790. </para>
  4791. <para>If you use
  4792. <filename>--source <replaceable>plugin-name</replaceable></filename>,
  4793. <filename>wic</filename> creates a partition as
  4794. large as needed and fills it with the contents of
  4795. the partition that is generated by the
  4796. specified plugin name using the data pointed
  4797. to by the <filename>-r</filename> command-line
  4798. option or the equivalent rootfs derived from the
  4799. <filename>-e</filename> command-line
  4800. option.
  4801. Exactly what those contents and filesystem type end
  4802. up being are dependent on the given plugin
  4803. implementation.
  4804. </para>
  4805. <para>If you do not use the
  4806. <filename>--source</filename> option, the
  4807. <filename>wic</filename> command creates an empty
  4808. partition.
  4809. Consequently, you must use the
  4810. <filename>--size</filename> option to specify the
  4811. size of the empty partition.
  4812. </para></listitem>
  4813. <listitem><para><emphasis><filename>--ondisk</filename> or <filename>--ondrive</filename>:</emphasis>
  4814. Forces the partition to be created on a particular
  4815. disk.</para></listitem>
  4816. <listitem><para><emphasis><filename>--fstype</filename>:</emphasis>
  4817. Sets the file system type for the partition.
  4818. Valid values are:
  4819. <itemizedlist>
  4820. <listitem><para><filename>ext4</filename>
  4821. </para></listitem>
  4822. <listitem><para><filename>ext3</filename>
  4823. </para></listitem>
  4824. <listitem><para><filename>ext2</filename>
  4825. </para></listitem>
  4826. <listitem><para><filename>btrfs</filename>
  4827. </para></listitem>
  4828. <listitem><para><filename>squashfs</filename>
  4829. </para></listitem>
  4830. <listitem><para><filename>swap</filename>
  4831. </para></listitem>
  4832. </itemizedlist></para></listitem>
  4833. <listitem><para><emphasis><filename>--fsoptions</filename>:</emphasis>
  4834. Specifies a free-form string of options to be
  4835. used when mounting the filesystem.
  4836. This string will be copied into the
  4837. <filename>/etc/fstab</filename> file of the
  4838. installed system and should be enclosed in
  4839. quotes.
  4840. If not specified, the default string
  4841. is "defaults".
  4842. </para></listitem>
  4843. <listitem><para><emphasis><filename>--label label</filename>:</emphasis>
  4844. Specifies the label to give to the filesystem to
  4845. be made on the partition.
  4846. If the given label is already in use by another
  4847. filesystem, a new label is created for the
  4848. partition.</para></listitem>
  4849. <listitem><para><emphasis><filename>--active</filename>:</emphasis>
  4850. Marks the partition as active.</para></listitem>
  4851. <listitem><para><emphasis><filename>--align (in KBytes)</filename>:</emphasis>
  4852. This option is a <filename>wic</filename>-specific
  4853. option that says to start a partition on an
  4854. x KBytes boundary.</para></listitem>
  4855. <listitem><para><emphasis><filename>--no-table</filename>:</emphasis>
  4856. This option is a <filename>wic</filename>-specific
  4857. option.
  4858. Using the option reserves space for the partition
  4859. and causes it to become populated.
  4860. However, the partition is not added to the
  4861. partition table.
  4862. </para></listitem>
  4863. <listitem><para><emphasis><filename>--extra-space</filename>:</emphasis>
  4864. This option is a <filename>wic</filename>-specific
  4865. option that adds extra space after the space
  4866. filled by the content of the partition.
  4867. The final size can go beyond the size specified
  4868. by the <filename>--size</filename> option.
  4869. The default value is 10 Mbytes.
  4870. </para></listitem>
  4871. <listitem><para><emphasis><filename>--overhead-factor</filename>:</emphasis>
  4872. This option is a <filename>wic</filename>-specific
  4873. option that multiplies the size of the partition by
  4874. the option's value.
  4875. You must supply a value greater than or equal to
  4876. "1".
  4877. The default value is "1.3".
  4878. </para></listitem>
  4879. <listitem><para><emphasis><filename>--part-type</filename>:</emphasis>
  4880. This option is a <filename>wic</filename>-specific
  4881. option that specifies the partition type globally
  4882. unique identifier (GUID) for GPT partitions.
  4883. You can find the list of partition type GUIDs
  4884. at
  4885. <ulink url='http://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs'></ulink>.
  4886. </para></listitem>
  4887. <listitem><para><emphasis><filename>--use-uuid</filename>:</emphasis>
  4888. This option is a <filename>wic</filename>-specific
  4889. option that causes <filename>wic</filename> to
  4890. generate a random GUID for the partition.
  4891. The generated identifier is used in the bootloader
  4892. configuration to specify the root partition.
  4893. </para></listitem>
  4894. <listitem><para><emphasis><filename>--uuid</filename>:</emphasis>
  4895. This option is a <filename>wic</filename>-specific
  4896. option that specifies the partition UUID.
  4897. </para></listitem>
  4898. </itemizedlist>
  4899. </para>
  4900. </section>
  4901. <section id='command-bootloader'>
  4902. <title>Command: bootloader</title>
  4903. <para>
  4904. This command specifies how the boot loader should be
  4905. configured and supports the following options:
  4906. <note>
  4907. Bootloader functionality and boot partitions are
  4908. implemented by the various
  4909. <filename>--source</filename>
  4910. plugins that implement bootloader functionality.
  4911. The bootloader command essentially provides a means of
  4912. modifying bootloader configuration.
  4913. </note>
  4914. <itemizedlist>
  4915. <listitem><para><emphasis><filename>--timeout</filename>:</emphasis>
  4916. Specifies the number of seconds before the
  4917. bootloader times out and boots the default option.
  4918. </para></listitem>
  4919. <listitem><para><emphasis><filename>--append</filename>:</emphasis>
  4920. Specifies kernel parameters.
  4921. These parameters will be added to the syslinux
  4922. <filename>APPEND</filename> or
  4923. <filename>grub</filename> kernel command line.
  4924. </para></listitem>
  4925. <listitem><para><emphasis><filename>--configfile</filename>:</emphasis>
  4926. Specifies a user-defined configuration file for
  4927. the bootloader.
  4928. You can provide a full pathname for the file or
  4929. a file that exists in the
  4930. <filename>canned-wks</filename> folder.
  4931. This option overrides all other bootloader options.
  4932. </para></listitem>
  4933. </itemizedlist>
  4934. </para>
  4935. </section>
  4936. </section>
  4937. </section>
  4938. <section id='configuring-the-kernel'>
  4939. <title>Configuring the Kernel</title>
  4940. <para>
  4941. Configuring the Yocto Project kernel consists of making sure the
  4942. <filename>.config</filename> file has all the right information
  4943. in it for the image you are building.
  4944. You can use the <filename>menuconfig</filename> tool and
  4945. configuration fragments to make sure your
  4946. <filename>.config</filename> file is just how you need it.
  4947. You can also save known configurations in a
  4948. <filename>defconfig</filename> file that the build system can use
  4949. for kernel configuration.
  4950. </para>
  4951. <para>
  4952. This section describes how to use <filename>menuconfig</filename>,
  4953. create and use configuration fragments, and how to interactively
  4954. modify your <filename>.config</filename> file to create the
  4955. leanest kernel configuration file possible.
  4956. </para>
  4957. <para>
  4958. For more information on kernel configuration, see the
  4959. "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>"
  4960. section in the Yocto Project Linux Kernel Development Manual.
  4961. </para>
  4962. <section id='using-menuconfig'>
  4963. <title>Using&nbsp;&nbsp;<filename>menuconfig</filename></title>
  4964. <para>
  4965. The easiest way to define kernel configurations is to set them through the
  4966. <filename>menuconfig</filename> tool.
  4967. This tool provides an interactive method with which
  4968. to set kernel configurations.
  4969. For general information on <filename>menuconfig</filename>, see
  4970. <ulink url='http://en.wikipedia.org/wiki/Menuconfig'></ulink>.
  4971. </para>
  4972. <para>
  4973. To use the <filename>menuconfig</filename> tool in the Yocto Project development
  4974. environment, you must launch it using BitBake.
  4975. Thus, the environment must be set up using the
  4976. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
  4977. or
  4978. <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>
  4979. script found in the
  4980. <link linkend='build-directory'>Build Directory</link>.
  4981. You must also be sure of the state of your build in the
  4982. <link linkend='source-directory'>Source Directory</link>.
  4983. The following commands run <filename>menuconfig</filename>
  4984. assuming the Source Directory's top-level folder is
  4985. <filename>~/poky</filename>:
  4986. <literallayout class='monospaced'>
  4987. $ cd poky
  4988. $ source oe-init-build-env
  4989. $ bitbake linux-yocto -c kernel_configme -f
  4990. $ bitbake linux-yocto -c menuconfig
  4991. </literallayout>
  4992. Once <filename>menuconfig</filename> comes up, its standard
  4993. interface allows you to interactively examine and configure
  4994. all the kernel configuration parameters.
  4995. After making your changes, simply exit the tool and save your
  4996. changes to create an updated version of the
  4997. <filename>.config</filename> configuration file.
  4998. </para>
  4999. <para>
  5000. Consider an example that configures the <filename>linux-yocto-3.14</filename>
  5001. kernel.
  5002. The OpenEmbedded build system recognizes this kernel as
  5003. <filename>linux-yocto</filename>.
  5004. Thus, the following commands from the shell in which you previously sourced the
  5005. environment initialization script cleans the shared state cache and the
  5006. <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
  5007. directory and then runs <filename>menuconfig</filename>:
  5008. <literallayout class='monospaced'>
  5009. $ bitbake linux-yocto -c menuconfig
  5010. </literallayout>
  5011. </para>
  5012. <para>
  5013. Once <filename>menuconfig</filename> launches, use the interface
  5014. to navigate through the selections to find the configuration settings in
  5015. which you are interested.
  5016. For example, consider the <filename>CONFIG_SMP</filename> configuration setting.
  5017. You can find it at <filename>Processor Type and Features</filename> under
  5018. the configuration selection <filename>Symmetric Multi-processing Support</filename>.
  5019. After highlighting the selection, use the arrow keys to select or deselect
  5020. the setting.
  5021. When you are finished with all your selections, exit out and save them.
  5022. </para>
  5023. <para>
  5024. Saving the selections updates the <filename>.config</filename> configuration file.
  5025. This is the file that the OpenEmbedded build system uses to configure the
  5026. kernel during the build.
  5027. You can find and examine this file in the Build Directory in
  5028. <filename>tmp/work/</filename>.
  5029. The actual <filename>.config</filename> is located in the area where the
  5030. specific kernel is built.
  5031. For example, if you were building a Linux Yocto kernel based on the
  5032. Linux 3.14 kernel and you were building a QEMU image targeted for
  5033. <filename>x86</filename> architecture, the
  5034. <filename>.config</filename> file would be located here:
  5035. <literallayout class='monospaced'>
  5036. poky/build/tmp/work/qemux86-poky-linux/linux-yocto-3.14.11+git1+84f...
  5037. ...656ed30-r1/linux-qemux86-standard-build
  5038. </literallayout>
  5039. <note>
  5040. The previous example directory is artificially split and many of the characters
  5041. in the actual filename are omitted in order to make it more readable.
  5042. Also, depending on the kernel you are using, the exact pathname
  5043. for <filename>linux-yocto-3.14...</filename> might differ.
  5044. </note>
  5045. </para>
  5046. <para>
  5047. Within the <filename>.config</filename> file, you can see the kernel settings.
  5048. For example, the following entry shows that symmetric multi-processor support
  5049. is not set:
  5050. <literallayout class='monospaced'>
  5051. # CONFIG_SMP is not set
  5052. </literallayout>
  5053. </para>
  5054. <para>
  5055. A good method to isolate changed configurations is to use a combination of the
  5056. <filename>menuconfig</filename> tool and simple shell commands.
  5057. Before changing configurations with <filename>menuconfig</filename>, copy the
  5058. existing <filename>.config</filename> and rename it to something else,
  5059. use <filename>menuconfig</filename> to make
  5060. as many changes as you want and save them, then compare the renamed configuration
  5061. file against the newly created file.
  5062. You can use the resulting differences as your base to create configuration fragments
  5063. to permanently save in your kernel layer.
  5064. <note>
  5065. Be sure to make a copy of the <filename>.config</filename> and don't just
  5066. rename it.
  5067. The build system needs an existing <filename>.config</filename>
  5068. from which to work.
  5069. </note>
  5070. </para>
  5071. </section>
  5072. <section id='creating-a-defconfig-file'>
  5073. <title>Creating a&nbsp;&nbsp;<filename>defconfig</filename> File</title>
  5074. <para>
  5075. A <filename>defconfig</filename> file is simply a
  5076. <filename>.config</filename> renamed to "defconfig".
  5077. You can use a <filename>defconfig</filename> file
  5078. to retain a known set of kernel configurations from which the
  5079. OpenEmbedded build system can draw to create the final
  5080. <filename>.config</filename> file.
  5081. <note>
  5082. Out-of-the-box, the Yocto Project never ships a
  5083. <filename>defconfig</filename> or
  5084. <filename>.config</filename> file.
  5085. The OpenEmbedded build system creates the final
  5086. <filename>.config</filename> file used to configure the
  5087. kernel.
  5088. </note>
  5089. </para>
  5090. <para>
  5091. To create a <filename>defconfig</filename>, start with a
  5092. complete, working Linux kernel <filename>.config</filename>
  5093. file.
  5094. Copy that file to the appropriate
  5095. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
  5096. directory in your layer's
  5097. <filename>recipes-kernel/linux</filename> directory, and rename
  5098. the copied file to "defconfig".
  5099. Then, add the following lines to the linux-yocto
  5100. <filename>.bbappend</filename> file in your layer:
  5101. <literallayout class='monospaced'>
  5102. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
  5103. SRC_URI += "file://defconfig"
  5104. </literallayout>
  5105. The
  5106. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  5107. tells the build system how to search for the file, while the
  5108. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
  5109. extends the
  5110. <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
  5111. variable (search directories) to include the
  5112. <filename>${PN}</filename> directory you created to hold the
  5113. configuration changes.
  5114. <note>
  5115. The build system applies the configurations from the
  5116. <filename>defconfig</filename> file before applying any
  5117. subsequent configuration fragments.
  5118. The final kernel configuration is a combination of the
  5119. configurations in the <filename>defconfig</filename>
  5120. file and any configuration fragments you provide.
  5121. You need to realize that if you have any configuration
  5122. fragments, the build system applies these on top of and
  5123. after applying the existing defconfig file configurations.
  5124. </note>
  5125. For more information on configuring the kernel, see the
  5126. "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>"
  5127. and
  5128. "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#generating-configuration-files'>Generating Configuration Files</ulink>"
  5129. sections, both in the Yocto Project Linux Kernel Development
  5130. Manual.
  5131. </para>
  5132. </section>
  5133. <section id='creating-config-fragments'>
  5134. <title>Creating Configuration Fragments</title>
  5135. <para>
  5136. Configuration fragments are simply kernel options that appear in a file
  5137. placed where the OpenEmbedded build system can find and apply them.
  5138. Syntactically, the configuration statement is identical to what would appear
  5139. in the <filename>.config</filename> file, which is in the
  5140. <link linkend='build-directory'>Build Directory</link>:
  5141. <literallayout class='monospaced'>
  5142. tmp/work/<replaceable>arch</replaceable>-poky-linux/linux-yocto-<replaceable>release_specific_string</replaceable>/linux-<replaceable>arch</replaceable>-<replaceable>build_type</replaceable>
  5143. </literallayout>
  5144. </para>
  5145. <para>
  5146. It is simple to create a configuration fragment.
  5147. For example, issuing the following from the shell creates a configuration fragment
  5148. file named <filename>my_smp.cfg</filename> that enables multi-processor support
  5149. within the kernel:
  5150. <literallayout class='monospaced'>
  5151. $ echo "CONFIG_SMP=y" >> my_smp.cfg
  5152. </literallayout>
  5153. <note>
  5154. All configuration fragment files must use the
  5155. <filename>.cfg</filename> extension in order for the
  5156. OpenEmbedded build system to recognize them as a
  5157. configuration fragment.
  5158. </note>
  5159. </para>
  5160. <para>
  5161. Where do you put your configuration fragment files?
  5162. You can place these files in the same area pointed to by
  5163. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
  5164. The OpenEmbedded build system picks up the configuration and
  5165. adds it to the kernel's configuration.
  5166. For example, suppose you had a set of configuration options
  5167. in a file called <filename>myconfig.cfg</filename>.
  5168. If you put that file inside a directory named
  5169. <filename>linux-yocto</filename> that resides in the same
  5170. directory as the kernel's append file and then add a
  5171. <filename>SRC_URI</filename> statement such as the following
  5172. to the kernel's append file, those configuration options
  5173. will be picked up and applied when the kernel is built.
  5174. <literallayout class='monospaced'>
  5175. SRC_URI += "file://myconfig.cfg"
  5176. </literallayout>
  5177. </para>
  5178. <para>
  5179. As mentioned earlier, you can group related configurations into multiple files and
  5180. name them all in the <filename>SRC_URI</filename> statement as well.
  5181. For example, you could group separate configurations specifically for Ethernet and graphics
  5182. into their own files and add those by using a <filename>SRC_URI</filename> statement like the
  5183. following in your append file:
  5184. <literallayout class='monospaced'>
  5185. SRC_URI += "file://myconfig.cfg \
  5186. file://eth.cfg \
  5187. file://gfx.cfg"
  5188. </literallayout>
  5189. </para>
  5190. </section>
  5191. <section id='fine-tuning-the-kernel-configuration-file'>
  5192. <title>Fine-Tuning the Kernel Configuration File</title>
  5193. <para>
  5194. You can make sure the <filename>.config</filename> file is as lean or efficient as
  5195. possible by reading the output of the kernel configuration fragment audit,
  5196. noting any issues, making changes to correct the issues, and then repeating.
  5197. </para>
  5198. <para>
  5199. As part of the kernel build process, the
  5200. <filename>do_kernel_configcheck</filename> task runs.
  5201. This task validates the kernel configuration by checking the final
  5202. <filename>.config</filename> file against the input files.
  5203. During the check, the task produces warning messages for the following
  5204. issues:
  5205. <itemizedlist>
  5206. <listitem><para>Requested options that did not make the final
  5207. <filename>.config</filename> file.</para></listitem>
  5208. <listitem><para>Configuration items that appear twice in the same
  5209. configuration fragment.</para></listitem>
  5210. <listitem><para>Configuration items tagged as "required" that were overridden.
  5211. </para></listitem>
  5212. <listitem><para>A board overrides a non-board specific option.</para></listitem>
  5213. <listitem><para>Listed options not valid for the kernel being processed.
  5214. In other words, the option does not appear anywhere.</para></listitem>
  5215. </itemizedlist>
  5216. <note>
  5217. The <filename>do_kernel_configcheck</filename> task can
  5218. also optionally report if an option is overridden during
  5219. processing.
  5220. </note>
  5221. </para>
  5222. <para>
  5223. For each output warning, a message points to the file
  5224. that contains a list of the options and a pointer to the
  5225. configuration fragment that defines them.
  5226. Collectively, the files are the key to streamlining the
  5227. configuration.
  5228. </para>
  5229. <para>
  5230. To streamline the configuration, do the following:
  5231. <orderedlist>
  5232. <listitem><para>Start with a full configuration that you
  5233. know works - it builds and boots successfully.
  5234. This configuration file will be your baseline.
  5235. </para></listitem>
  5236. <listitem><para>Separately run the
  5237. <filename>do_kernel_configme</filename> and
  5238. <filename>do_kernel_configcheck</filename> tasks.
  5239. </para></listitem>
  5240. <listitem><para>Take the resulting list of files from the
  5241. <filename>do_kernel_configcheck</filename> task
  5242. warnings and do the following:
  5243. <itemizedlist>
  5244. <listitem><para>
  5245. Drop values that are redefined in the fragment
  5246. but do not change the final
  5247. <filename>.config</filename> file.
  5248. </para></listitem>
  5249. <listitem><para>
  5250. Analyze and potentially drop values from the
  5251. <filename>.config</filename> file that override
  5252. required configurations.
  5253. </para></listitem>
  5254. <listitem><para>
  5255. Analyze and potentially remove non-board
  5256. specific options.
  5257. </para></listitem>
  5258. <listitem><para>
  5259. Remove repeated and invalid options.
  5260. </para></listitem>
  5261. </itemizedlist></para></listitem>
  5262. <listitem><para>
  5263. After you have worked through the output of the kernel
  5264. configuration audit, you can re-run the
  5265. <filename>do_kernel_configme</filename> and
  5266. <filename>do_kernel_configcheck</filename> tasks to
  5267. see the results of your changes.
  5268. If you have more issues, you can deal with them as
  5269. described in the previous step.
  5270. </para></listitem>
  5271. </orderedlist>
  5272. </para>
  5273. <para>
  5274. Iteratively working through steps two through four eventually yields
  5275. a minimal, streamlined configuration file.
  5276. Once you have the best <filename>.config</filename>, you can build the Linux
  5277. Yocto kernel.
  5278. </para>
  5279. </section>
  5280. <section id='determining-hardware-and-non-hardware-features-for-the-kernel-configuration-audit-phase'>
  5281. <title>Determining Hardware and Non-Hardware Features for the Kernel Configuration Audit Phase</title>
  5282. <para>
  5283. This section describes part of the kernel configuration audit
  5284. phase that most developers can ignore.
  5285. During this part of the audit phase, the contents of the final
  5286. <filename>.config</filename> file are compared against the
  5287. fragments specified by the system.
  5288. These fragments can be system fragments, distro fragments,
  5289. or user specified configuration elements.
  5290. Regardless of their origin, the OpenEmbedded build system
  5291. warns the user if a specific option is not included in the
  5292. final kernel configuration.
  5293. </para>
  5294. <para>
  5295. In order to not overwhelm the user with configuration warnings,
  5296. by default the system only reports on missing "hardware"
  5297. options because a missing hardware option could mean a boot
  5298. failure or that important hardware is not available.
  5299. </para>
  5300. <para>
  5301. To determine whether or not a given option is "hardware" or
  5302. "non-hardware", the kernel Metadata contains files that
  5303. classify individual or groups of options as either hardware
  5304. or non-hardware.
  5305. To better show this, consider a situation where the
  5306. Yocto Project kernel cache contains the following files:
  5307. <literallayout class='monospaced'>
  5308. kernel-cache/features/drm-psb/hardware.cfg
  5309. kernel-cache/features/kgdb/hardware.cfg
  5310. kernel-cache/ktypes/base/hardware.cfg
  5311. kernel-cache/bsp/mti-malta32/hardware.cfg
  5312. kernel-cache/bsp/fsl-mpc8315e-rdb/hardware.cfg
  5313. kernel-cache/bsp/qemu-ppc32/hardware.cfg
  5314. kernel-cache/bsp/qemuarma9/hardware.cfg
  5315. kernel-cache/bsp/mti-malta64/hardware.cfg
  5316. kernel-cache/bsp/arm-versatile-926ejs/hardware.cfg
  5317. kernel-cache/bsp/common-pc/hardware.cfg
  5318. kernel-cache/bsp/common-pc-64/hardware.cfg
  5319. kernel-cache/features/rfkill/non-hardware.cfg
  5320. kernel-cache/ktypes/base/non-hardware.cfg
  5321. kernel-cache/features/aufs/non-hardware.kcf
  5322. kernel-cache/features/ocf/non-hardware.kcf
  5323. kernel-cache/ktypes/base/non-hardware.kcf
  5324. kernel-cache/ktypes/base/hardware.kcf
  5325. kernel-cache/bsp/qemu-ppc32/hardware.kcf
  5326. </literallayout>
  5327. The following list provides explanations for the various
  5328. files:
  5329. <itemizedlist>
  5330. <listitem><para><filename>hardware.kcf</filename>:
  5331. Specifies a list of kernel Kconfig files that contain
  5332. hardware options only.
  5333. </para></listitem>
  5334. <listitem><para><filename>non-hardware.kcf</filename>:
  5335. Specifies a list of kernel Kconfig files that contain
  5336. non-hardware options only.
  5337. </para></listitem>
  5338. <listitem><para><filename>hardware.cfg</filename>:
  5339. Specifies a list of kernel
  5340. <filename>CONFIG_</filename> options that are hardware,
  5341. regardless of whether or not they are within a Kconfig
  5342. file specified by a hardware or non-hardware
  5343. Kconfig file (i.e. <filename>hardware.kcf</filename> or
  5344. <filename>non-hardware.kcf</filename>).
  5345. </para></listitem>
  5346. <listitem><para><filename>non-hardware.cfg</filename>:
  5347. Specifies a list of kernel
  5348. <filename>CONFIG_</filename> options that are
  5349. not hardware, regardless of whether or not they are
  5350. within a Kconfig file specified by a hardware or
  5351. non-hardware Kconfig file (i.e.
  5352. <filename>hardware.kcf</filename> or
  5353. <filename>non-hardware.kcf</filename>).
  5354. </para></listitem>
  5355. </itemizedlist>
  5356. Here is a specific example using the
  5357. <filename>kernel-cache/bsp/mti-malta32/hardware.cfg</filename>:
  5358. <literallayout class='monospaced'>
  5359. CONFIG_SERIAL_8250
  5360. CONFIG_SERIAL_8250_CONSOLE
  5361. CONFIG_SERIAL_8250_NR_UARTS
  5362. CONFIG_SERIAL_8250_PCI
  5363. CONFIG_SERIAL_CORE
  5364. CONFIG_SERIAL_CORE_CONSOLE
  5365. CONFIG_VGA_ARB
  5366. </literallayout>
  5367. The kernel configuration audit automatically detects these
  5368. files (hence the names must be exactly the ones discussed here),
  5369. and uses them as inputs when generating warnings about the
  5370. final <filename>.config</filename> file.
  5371. </para>
  5372. <para>
  5373. A user-specified kernel Metadata repository, or recipe space
  5374. feature, can use these same files to classify options that are
  5375. found within its <filename>.cfg</filename> files as hardware
  5376. or non-hardware, to prevent the OpenEmbedded build system from
  5377. producing an error or warning when an option is not in the
  5378. final <filename>.config</filename> file.
  5379. </para>
  5380. </section>
  5381. </section>
  5382. <section id="patching-the-kernel">
  5383. <title>Patching the Kernel</title>
  5384. <para>
  5385. Patching the kernel involves changing or adding configurations to an existing kernel,
  5386. changing or adding recipes to the kernel that are needed to support specific hardware features,
  5387. or even altering the source code itself.
  5388. <note>
  5389. You can use the <filename>yocto-kernel</filename> script
  5390. found in the <link linkend='source-directory'>Source Directory</link>
  5391. under <filename>scripts</filename> to manage kernel patches and configuration.
  5392. 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>"
  5393. section in the Yocto Project Board Support Packages (BSP) Developer's Guide for
  5394. more information.</note>
  5395. </para>
  5396. <para>
  5397. This example creates a simple patch by adding some QEMU emulator console
  5398. output at boot time through <filename>printk</filename> statements in the kernel's
  5399. <filename>calibrate.c</filename> source code file.
  5400. Applying the patch and booting the modified image causes the added
  5401. messages to appear on the emulator's console.
  5402. </para>
  5403. <para>
  5404. The example assumes a clean build exists for the <filename>qemux86</filename>
  5405. machine in a
  5406. <link linkend='source-directory'>Source Directory</link>
  5407. named <filename>poky</filename>.
  5408. Furthermore, the <link linkend='build-directory'>Build Directory</link> is
  5409. <filename>build</filename> and is located in <filename>poky</filename> and
  5410. the kernel is based on the Linux 3.4 kernel.
  5411. </para>
  5412. <para>
  5413. Also, for more information on patching the kernel, see the
  5414. "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#applying-patches'>Applying Patches</ulink>"
  5415. section in the Yocto Project Linux Kernel Development Manual.
  5416. </para>
  5417. <section id='create-a-layer-for-your-changes'>
  5418. <title>Create a Layer for your Changes</title>
  5419. <para>
  5420. The first step is to create a layer so you can isolate your
  5421. changes.
  5422. Rather than use the <filename>yocto-layer</filename> script
  5423. to create the layer, this example steps through the process
  5424. by hand.
  5425. If you want information on the script that creates a general
  5426. layer, see the
  5427. "<link linkend='creating-a-general-layer-using-the-yocto-layer-script'>Creating a General Layer Using the yocto-layer Script</link>"
  5428. section.
  5429. </para>
  5430. <para>
  5431. These two commands create a directory you can use for your
  5432. layer:
  5433. <literallayout class='monospaced'>
  5434. $ cd ~/poky
  5435. $ mkdir meta-mylayer
  5436. </literallayout>
  5437. Creating a directory that follows the Yocto Project layer naming
  5438. conventions sets up the layer for your changes.
  5439. The layer is where you place your configuration files, append
  5440. files, and patch files.
  5441. To learn more about creating a layer and filling it with the
  5442. files you need, see the "<link linkend='understanding-and-creating-layers'>Understanding
  5443. and Creating Layers</link>" section.
  5444. </para>
  5445. </section>
  5446. <section id='finding-the-kernel-source-code'>
  5447. <title>Finding the Kernel Source Code</title>
  5448. <para>
  5449. Each time you build a kernel image, the kernel source code is fetched
  5450. and unpacked into the following directory:
  5451. <literallayout class='monospaced'>
  5452. ${S}/linux
  5453. </literallayout>
  5454. See the "<link linkend='finding-the-temporary-source-code'>Finding Temporary Source Code</link>"
  5455. section and the
  5456. <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink> variable
  5457. for more information about where source is kept during a build.
  5458. </para>
  5459. <para>
  5460. For this example, we are going to patch the
  5461. <filename>init/calibrate.c</filename> file
  5462. by adding some simple console <filename>printk</filename> statements that we can
  5463. see when we boot the image using QEMU.
  5464. </para>
  5465. </section>
  5466. <section id='creating-the-patch'>
  5467. <title>Creating the Patch</title>
  5468. <para>
  5469. Two methods exist by which you can create the patch:
  5470. <link linkend='using-devtool-in-your-workflow'><filename>devtool</filename></link> and
  5471. <link linkend='using-a-quilt-workflow'>Quilt</link>.
  5472. For kernel patches, the Git workflow is more appropriate.
  5473. This section assumes the Git workflow and shows the steps specific to
  5474. this example.
  5475. <orderedlist>
  5476. <listitem><para><emphasis>Change the working directory</emphasis>:
  5477. Change to where the kernel source code is before making
  5478. your edits to the <filename>calibrate.c</filename> file:
  5479. <literallayout class='monospaced'>
  5480. $ cd ~/poky/build/tmp/work/qemux86-poky-linux/linux-yocto-${PV}-${PR}/linux
  5481. </literallayout>
  5482. Because you are working in an established Git repository,
  5483. you must be in this directory in order to commit your changes
  5484. and create the patch file.
  5485. <note>The <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> and
  5486. <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink> variables
  5487. represent the version and revision for the
  5488. <filename>linux-yocto</filename> recipe.
  5489. The <filename>PV</filename> variable includes the Git meta and machine
  5490. hashes, which make the directory name longer than you might
  5491. expect.
  5492. </note></para></listitem>
  5493. <listitem><para><emphasis>Edit the source file</emphasis>:
  5494. Edit the <filename>init/calibrate.c</filename> file to have the
  5495. following changes:
  5496. <literallayout class='monospaced'>
  5497. void calibrate_delay(void)
  5498. {
  5499. unsigned long lpj;
  5500. static bool printed;
  5501. int this_cpu = smp_processor_id();
  5502. printk("*************************************\n");
  5503. printk("* *\n");
  5504. printk("* HELLO YOCTO KERNEL *\n");
  5505. printk("* *\n");
  5506. printk("*************************************\n");
  5507. if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
  5508. .
  5509. .
  5510. .
  5511. </literallayout></para></listitem>
  5512. <listitem><para><emphasis>Stage and commit your changes</emphasis>:
  5513. These Git commands display the modified file, stage it, and then
  5514. commit the file:
  5515. <literallayout class='monospaced'>
  5516. $ git status
  5517. $ git add init/calibrate.c
  5518. $ git commit -m "calibrate: Add printk example"
  5519. </literallayout></para></listitem>
  5520. <listitem><para><emphasis>Generate the patch file</emphasis>:
  5521. This Git command creates the a patch file named
  5522. <filename>0001-calibrate-Add-printk-example.patch</filename>
  5523. in the current directory.
  5524. <literallayout class='monospaced'>
  5525. $ git format-patch -1
  5526. </literallayout>
  5527. </para></listitem>
  5528. </orderedlist>
  5529. </para>
  5530. </section>
  5531. <section id='set-up-your-layer-for-the-build'>
  5532. <title>Set Up Your Layer for the Build</title>
  5533. <para>These steps get your layer set up for the build:
  5534. <orderedlist>
  5535. <listitem><para><emphasis>Create additional structure</emphasis>:
  5536. Create the additional layer structure:
  5537. <literallayout class='monospaced'>
  5538. $ cd ~/poky/meta-mylayer
  5539. $ mkdir conf
  5540. $ mkdir recipes-kernel
  5541. $ mkdir recipes-kernel/linux
  5542. $ mkdir recipes-kernel/linux/linux-yocto
  5543. </literallayout>
  5544. The <filename>conf</filename> directory holds your configuration files, while the
  5545. <filename>recipes-kernel</filename> directory holds your append file and
  5546. your patch file.</para></listitem>
  5547. <listitem><para><emphasis>Create the layer configuration file</emphasis>:
  5548. Move to the <filename>meta-mylayer/conf</filename> directory and create
  5549. the <filename>layer.conf</filename> file as follows:
  5550. <literallayout class='monospaced'>
  5551. # We have a conf and classes directory, add to BBPATH
  5552. BBPATH .= ":${LAYERDIR}"
  5553. # We have recipes-* directories, add to BBFILES
  5554. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  5555. ${LAYERDIR}/recipes-*/*/*.bbappend"
  5556. BBFILE_COLLECTIONS += "mylayer"
  5557. BBFILE_PATTERN_mylayer = "^${LAYERDIR}/"
  5558. BBFILE_PRIORITY_mylayer = "5"
  5559. </literallayout>
  5560. Notice <filename>mylayer</filename> as part of the last three
  5561. statements.</para></listitem>
  5562. <listitem><para><emphasis>Create the kernel recipe append file</emphasis>:
  5563. Move to the <filename>meta-mylayer/recipes-kernel/linux</filename> directory and create
  5564. the <filename>linux-yocto_3.4.bbappend</filename> file as follows:
  5565. <literallayout class='monospaced'>
  5566. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
  5567. SRC_URI += "file://0001-calibrate-Add-printk-example.patch"
  5568. </literallayout>
  5569. The <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
  5570. and <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  5571. statements enable the OpenEmbedded build system to find the patch file.
  5572. For more information on using append files, see the
  5573. "<link linkend='using-bbappend-files'>Using .bbappend Files</link>"
  5574. section.
  5575. </para></listitem>
  5576. <listitem><para><emphasis>Put the patch file in your layer</emphasis>:
  5577. Move the <filename>0001-calibrate-Add-printk-example.patch</filename> file to
  5578. the <filename>meta-mylayer/recipes-kernel/linux/linux-yocto</filename>
  5579. directory.</para></listitem>
  5580. </orderedlist>
  5581. </para>
  5582. </section>
  5583. <section id='set-up-for-the-build'>
  5584. <title>Set Up for the Build</title>
  5585. <para>
  5586. Do the following to make sure the build parameters are set up for the example.
  5587. Once you set up these build parameters, they do not have to change unless you
  5588. change the target architecture of the machine you are building:
  5589. <itemizedlist>
  5590. <listitem><para><emphasis>Build for the correct target architecture:</emphasis> Your
  5591. selected <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
  5592. definition within the <filename>local.conf</filename> file in the
  5593. <link linkend='build-directory'>Build Directory</link>
  5594. specifies the target architecture used when building the Linux kernel.
  5595. By default, <filename>MACHINE</filename> is set to
  5596. <filename>qemux86</filename>, which specifies a 32-bit
  5597. <trademark class='registered'>Intel</trademark> Architecture
  5598. target machine suitable for the QEMU emulator.</para></listitem>
  5599. <listitem><para><emphasis>Identify your <filename>meta-mylayer</filename>
  5600. layer:</emphasis> The
  5601. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
  5602. variable in the
  5603. <filename>bblayers.conf</filename> file found in the
  5604. <filename>poky/build/conf</filename> directory needs to have the path to your local
  5605. <filename>meta-mylayer</filename> layer.
  5606. By default, the <filename>BBLAYERS</filename> variable contains paths to
  5607. <filename>meta</filename>, <filename>meta-poky</filename>, and
  5608. <filename>meta-yocto-bsp</filename> in the
  5609. <filename>poky</filename> Git repository.
  5610. Add the path to your <filename>meta-mylayer</filename> location:
  5611. <literallayout class='monospaced'>
  5612. BBLAYERS ?= " \
  5613. $HOME/poky/meta \
  5614. $HOME/poky/meta-poky \
  5615. $HOME/poky/meta-yocto-bsp \
  5616. $HOME/poky/meta-mylayer \
  5617. "
  5618. </literallayout></para></listitem>
  5619. </itemizedlist>
  5620. </para>
  5621. </section>
  5622. <section id='build-the-modified-qemu-kernel-image'>
  5623. <title>Build the Modified QEMU Kernel Image</title>
  5624. <para>
  5625. The following steps build your modified kernel image:
  5626. <orderedlist>
  5627. <listitem><para><emphasis>Be sure your build environment is initialized</emphasis>:
  5628. Your environment should be set up since you previously sourced
  5629. the
  5630. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
  5631. script.
  5632. If it is not, source the script again from <filename>poky</filename>.
  5633. <literallayout class='monospaced'>
  5634. $ cd ~/poky
  5635. $ source &OE_INIT_FILE;
  5636. </literallayout>
  5637. </para></listitem>
  5638. <listitem><para><emphasis>Clean up</emphasis>:
  5639. Be sure to clean the shared state out by using BitBake
  5640. to run from within the Build Directory the
  5641. <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleansstate'><filename>do_cleansstate</filename></ulink>
  5642. task as follows:
  5643. <literallayout class='monospaced'>
  5644. $ bitbake -c cleansstate linux-yocto
  5645. </literallayout></para>
  5646. <para>
  5647. <note>
  5648. Never remove any files by hand from the
  5649. <filename>tmp/deploy</filename>
  5650. directory inside the
  5651. <link linkend='build-directory'>Build Directory</link>.
  5652. Always use the various BitBake clean tasks to
  5653. clear out previous build artifacts.
  5654. For information on the clean tasks, see the
  5655. "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-clean'><filename>do_clean</filename></ulink>",
  5656. "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>do_cleanall</filename></ulink>",
  5657. and
  5658. "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleansstate'><filename>do_cleansstate</filename></ulink>"
  5659. sections all in the Yocto Project Reference
  5660. Manual.
  5661. </note>
  5662. </para></listitem>
  5663. <listitem><para><emphasis>Build the image</emphasis>:
  5664. Next, build the kernel image using this command:
  5665. <literallayout class='monospaced'>
  5666. $ bitbake -k linux-yocto
  5667. </literallayout></para></listitem>
  5668. </orderedlist>
  5669. </para>
  5670. </section>
  5671. <section id='boot-the-image-and-verify-your-changes'>
  5672. <title>Boot the Image and Verify Your Changes</title>
  5673. <para>
  5674. These steps boot the image and allow you to see the changes
  5675. <orderedlist>
  5676. <listitem><para><emphasis>Boot the image</emphasis>:
  5677. Boot the modified image in the QEMU emulator
  5678. using this command:
  5679. <literallayout class='monospaced'>
  5680. $ runqemu qemux86
  5681. </literallayout></para></listitem>
  5682. <listitem><para><emphasis>Verify the changes</emphasis>:
  5683. Log into the machine using <filename>root</filename> with no password and then
  5684. use the following shell command to scroll through the console's boot output.
  5685. <literallayout class='monospaced'>
  5686. # dmesg | less
  5687. </literallayout>
  5688. You should see the results of your <filename>printk</filename> statements
  5689. as part of the output.</para></listitem>
  5690. </orderedlist>
  5691. </para>
  5692. </section>
  5693. </section>
  5694. <section id='making-images-more-secure'>
  5695. <title>Making Images More Secure</title>
  5696. <para>
  5697. Security is of increasing concern for embedded devices.
  5698. Consider the issues and problems discussed in just this
  5699. sampling of work found across the Internet:
  5700. <itemizedlist>
  5701. <listitem><para><emphasis>
  5702. "<ulink url='https://www.schneier.com/blog/archives/2014/01/security_risks_9.html'>Security Risks of Embedded Systems</ulink>"</emphasis>
  5703. by Bruce Schneier
  5704. </para></listitem>
  5705. <listitem><para><emphasis>
  5706. "<ulink url='http://internetcensus2012.bitbucket.org/paper.html'>Internet Census 2012</ulink>"</emphasis>
  5707. by Carna Botnet</para></listitem>
  5708. <listitem><para><emphasis>
  5709. "<ulink url='http://elinux.org/images/6/6f/Security-issues.pdf'>Security Issues for Embedded Devices</ulink>"</emphasis>
  5710. by Jake Edge
  5711. </para></listitem>
  5712. </itemizedlist>
  5713. </para>
  5714. <para>
  5715. When securing your image is of concern, there are steps, tools,
  5716. and variables that you can consider to help you reach the
  5717. security goals you need for your particular device.
  5718. Not all situations are identical when it comes to making an
  5719. image secure.
  5720. Consequently, this section provides some guidance and suggestions
  5721. for consideration when you want to make your image more secure.
  5722. <note>
  5723. Because the security requirements and risks are
  5724. different for every type of device, this section cannot
  5725. provide a complete reference on securing your custom OS.
  5726. It is strongly recommended that you also consult other sources
  5727. of information on embedded Linux system hardening and on
  5728. security.
  5729. </note>
  5730. </para>
  5731. <section id='general-considerations'>
  5732. <title>General Considerations</title>
  5733. <para>
  5734. General considerations exist that help you create more
  5735. secure images.
  5736. You should consider the following suggestions to help
  5737. make your device more secure:
  5738. <itemizedlist>
  5739. <listitem><para>
  5740. Scan additional code you are adding to the system
  5741. (e.g. application code) by using static analysis
  5742. tools.
  5743. Look for buffer overflows and other potential
  5744. security problems.
  5745. </para></listitem>
  5746. <listitem><para>
  5747. Pay particular attention to the security for
  5748. any web-based administration interface.
  5749. </para>
  5750. <para>Web interfaces typically need to perform
  5751. administrative functions and tend to need to run with
  5752. elevated privileges.
  5753. Thus, the consequences resulting from the interface's
  5754. security becoming compromised can be serious.
  5755. Look for common web vulnerabilities such as
  5756. cross-site-scripting (XSS), unvalidated inputs,
  5757. and so forth.</para>
  5758. <para>As with system passwords, the default credentials
  5759. for accessing a web-based interface should not be the
  5760. same across all devices.
  5761. This is particularly true if the interface is enabled
  5762. by default as it can be assumed that many end-users
  5763. will not change the credentials.
  5764. </para></listitem>
  5765. <listitem><para>
  5766. Ensure you can update the software on the device to
  5767. mitigate vulnerabilities discovered in the future.
  5768. This consideration especially applies when your
  5769. device is network-enabled.
  5770. </para></listitem>
  5771. <listitem><para>
  5772. Ensure you remove or disable debugging functionality
  5773. before producing the final image.
  5774. For information on how to do this, see the
  5775. "<link linkend='considerations-specific-to-the-openembedded-build-system'>Considerations Specific to the OpenEmbedded Build System</link>"
  5776. section.
  5777. </para></listitem>
  5778. <listitem><para>
  5779. Ensure you have no network services listening that
  5780. are not needed.
  5781. </para></listitem>
  5782. <listitem><para>
  5783. Remove any software from the image that is not needed.
  5784. </para></listitem>
  5785. <listitem><para>
  5786. Enable hardware support for secure boot functionality
  5787. when your device supports this functionality.
  5788. </para></listitem>
  5789. </itemizedlist>
  5790. </para>
  5791. </section>
  5792. <section id='security-flags'>
  5793. <title>Security Flags</title>
  5794. <para>
  5795. The Yocto Project has security flags that you can enable that
  5796. help make your build output more secure.
  5797. The security flags are in the
  5798. <filename>meta/conf/distro/include/security_flags.inc</filename>
  5799. file in your
  5800. <link linkend='source-directory'>Source Directory</link>
  5801. (e.g. <filename>poky</filename>).
  5802. <note>
  5803. Depending on the recipe, certain security flags are enabled
  5804. and disabled by default.
  5805. </note>
  5806. </para>
  5807. <para>
  5808. <!--
  5809. The GCC/LD flags in <filename>security_flags.inc</filename>
  5810. enable more secure code generation.
  5811. By including the <filename>security_flags.inc</filename>
  5812. file, you enable flags to the compiler and linker that cause
  5813. them to generate more secure code.
  5814. <note>
  5815. The GCC/LD flags are enabled by default in the
  5816. <filename>poky-lsb</filename> distribution.
  5817. </note>
  5818. -->
  5819. Use the following line in your
  5820. <filename>local.conf</filename> file or in your custom
  5821. distribution configuration file to enable the security
  5822. compiler and linker flags for your build:
  5823. <literallayout class='monospaced'>
  5824. require conf/distro/include/security_flags.inc
  5825. </literallayout>
  5826. </para>
  5827. </section>
  5828. <section id='considerations-specific-to-the-openembedded-build-system'>
  5829. <title>Considerations Specific to the OpenEmbedded Build System</title>
  5830. <para>
  5831. You can take some steps that are specific to the
  5832. OpenEmbedded build system to make your images more secure:
  5833. <itemizedlist>
  5834. <listitem><para>
  5835. Ensure "debug-tweaks" is not one of your selected
  5836. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>.
  5837. When creating a new project, the default is to provide you
  5838. with an initial <filename>local.conf</filename> file that
  5839. enables this feature using the
  5840. <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> variable with the line:
  5841. <literallayout class='monospaced'>
  5842. EXTRA_IMAGE_FEATURES = "debug-tweaks"
  5843. </literallayout>
  5844. To disable that feature, simply comment out that line in your
  5845. <filename>local.conf</filename> file, or
  5846. make sure <filename>IMAGE_FEATURES</filename> does not contain
  5847. "debug-tweaks" before producing your final image.
  5848. Among other things, leaving this in place sets the
  5849. root password as blank, which makes logging in for
  5850. debugging or inspection easy during
  5851. development but also means anyone can easily log in
  5852. during production.
  5853. </para></listitem>
  5854. <listitem><para>
  5855. It is possible to set a root password for the image
  5856. and also to set passwords for any extra users you might
  5857. add (e.g. administrative or service type users).
  5858. When you set up passwords for multiple images or
  5859. users, you should not duplicate passwords.
  5860. </para>
  5861. <para>
  5862. To set up passwords, use the
  5863. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers</filename></ulink>
  5864. class, which is the preferred method.
  5865. For an example on how to set up both root and user
  5866. passwords, see the
  5867. "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers.bbclass</filename></ulink>"
  5868. section.
  5869. <note>
  5870. When adding extra user accounts or setting a
  5871. root password, be cautious about setting the
  5872. same password on every device.
  5873. If you do this, and the password you have set
  5874. is exposed, then every device is now potentially
  5875. compromised.
  5876. If you need this access but want to ensure
  5877. security, consider setting a different,
  5878. random password for each device.
  5879. Typically, you do this as a separate step after
  5880. you deploy the image onto the device.
  5881. </note>
  5882. </para></listitem>
  5883. <listitem><para>
  5884. Consider enabling a Mandatory Access Control (MAC)
  5885. framework such as SMACK or SELinux and tuning it
  5886. appropriately for your device's usage.
  5887. You can find more information in the
  5888. <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/meta-selinux/'><filename>meta-selinux</filename></ulink>
  5889. layer.
  5890. </para></listitem>
  5891. </itemizedlist>
  5892. </para>
  5893. <para>
  5894. </para>
  5895. </section>
  5896. <section id='tools-for-hardening-your-image'>
  5897. <title>Tools for Hardening Your Image</title>
  5898. <para>
  5899. The Yocto Project provides tools for making your image
  5900. more secure.
  5901. You can find these tools in the
  5902. <filename>meta-security</filename> layer of the
  5903. <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi'>Yocto Project Source Repositories</ulink>.
  5904. </para>
  5905. </section>
  5906. </section>
  5907. <section id='creating-your-own-distribution'>
  5908. <title>Creating Your Own Distribution</title>
  5909. <para>
  5910. When you build an image using the Yocto Project and
  5911. do not alter any distribution
  5912. <link linkend='metadata'>Metadata</link>, you are creating a
  5913. Poky distribution.
  5914. If you wish to gain more control over package alternative
  5915. selections, compile-time options, and other low-level
  5916. configurations, you can create your own distribution.
  5917. </para>
  5918. <para>
  5919. To create your own distribution, the basic steps consist of
  5920. creating your own distribution layer, creating your own
  5921. distribution configuration file, and then adding any needed
  5922. code and Metadata to the layer.
  5923. The following steps provide some more detail:
  5924. <itemizedlist>
  5925. <listitem><para><emphasis>Create a layer for your new distro:</emphasis>
  5926. Create your distribution layer so that you can keep your
  5927. Metadata and code for the distribution separate.
  5928. It is strongly recommended that you create and use your own
  5929. layer for configuration and code.
  5930. Using your own layer as compared to just placing
  5931. configurations in a <filename>local.conf</filename>
  5932. configuration file makes it easier to reproduce the same
  5933. build configuration when using multiple build machines.
  5934. See the
  5935. "<link linkend='creating-a-general-layer-using-the-yocto-layer-script'>Creating a General Layer Using the yocto-layer Script</link>"
  5936. section for information on how to quickly set up a layer.
  5937. </para></listitem>
  5938. <listitem><para><emphasis>Create the distribution configuration file:</emphasis>
  5939. The distribution configuration file needs to be created in
  5940. the <filename>conf/distro</filename> directory of your
  5941. layer.
  5942. You need to name it using your distribution name
  5943. (e.g. <filename>mydistro.conf</filename>).
  5944. <note>
  5945. The
  5946. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
  5947. variable in your
  5948. <filename>local.conf</filename> file determines the
  5949. name of your distribution.
  5950. </note></para>
  5951. <para>You can split out parts of your configuration file
  5952. into include files and then "require" them from within
  5953. your distribution configuration file.
  5954. Be sure to place the include files in the
  5955. <filename>conf/distro/include</filename> directory of
  5956. your layer.
  5957. A common example usage of include files would be to
  5958. separate out the selection of desired version and revisions
  5959. for individual recipes.
  5960. </para>
  5961. <para>Your configuration file needs to set the following
  5962. required variables:
  5963. <literallayout class='monospaced'>
  5964. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_NAME'><filename>DISTRO_NAME</filename></ulink>
  5965. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_VERSION'><filename>DISTRO_VERSION</filename></ulink>
  5966. </literallayout>
  5967. These following variables are optional and you typically
  5968. set them from the distribution configuration file:
  5969. <literallayout class='monospaced'>
  5970. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
  5971. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RDEPENDS'><filename>DISTRO_EXTRA_RDEPENDS</filename></ulink>
  5972. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RRECOMMENDS'><filename>DISTRO_EXTRA_RRECOMMENDS</filename></ulink>
  5973. <ulink url='&YOCTO_DOCS_REF_URL;#var-TCLIBC'><filename>TCLIBC</filename></ulink>
  5974. </literallayout>
  5975. <tip>
  5976. If you want to base your distribution configuration file
  5977. on the very basic configuration from OE-Core, you
  5978. can use
  5979. <filename>conf/distro/defaultsetup.conf</filename> as
  5980. a reference and just include variables that differ
  5981. as compared to <filename>defaultsetup.conf</filename>.
  5982. Alternatively, you can create a distribution
  5983. configuration file from scratch using the
  5984. <filename>defaultsetup.conf</filename> file
  5985. or configuration files from other distributions
  5986. such as Poky or Angstrom as references.
  5987. </tip></para></listitem>
  5988. <listitem><para><emphasis>Provide miscellaneous variables:</emphasis>
  5989. Be sure to define any other variables for which you want to
  5990. create a default or enforce as part of the distribution
  5991. configuration.
  5992. You can include nearly any variable from the
  5993. <filename>local.conf</filename> file.
  5994. The variables you use are not limited to the list in the
  5995. previous bulleted item.</para></listitem>
  5996. <listitem><para><emphasis>Point to Your distribution configuration file:</emphasis>
  5997. In your <filename>local.conf</filename> file in the
  5998. <link linkend='build-directory'>Build Directory</link>,
  5999. set your
  6000. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
  6001. variable to point to your distribution's configuration file.
  6002. For example, if your distribution's configuration file is
  6003. named <filename>mydistro.conf</filename>, then you point
  6004. to it as follows:
  6005. <literallayout class='monospaced'>
  6006. DISTRO = "mydistro"
  6007. </literallayout></para></listitem>
  6008. <listitem><para><emphasis>Add more to the layer if necessary:</emphasis>
  6009. Use your layer to hold other information needed for the
  6010. distribution:
  6011. <itemizedlist>
  6012. <listitem><para>Add recipes for installing
  6013. distro-specific configuration files that are not
  6014. already installed by another recipe.
  6015. If you have distro-specific configuration files
  6016. that are included by an existing recipe, you should
  6017. add an append file (<filename>.bbappend</filename>)
  6018. for those.
  6019. For general information and recommendations
  6020. on how to add recipes to your layer, see the
  6021. "<link linkend='creating-your-own-layer'>Creating Your Own Layer</link>"
  6022. and
  6023. "<link linkend='best-practices-to-follow-when-creating-layers'>Best Practices to Follow When Creating Layers</link>"
  6024. sections.</para></listitem>
  6025. <listitem><para>Add any image recipes that are specific
  6026. to your distribution.</para></listitem>
  6027. <listitem><para>Add a <filename>psplash</filename>
  6028. append file for a branded splash screen.
  6029. For information on append files, see the
  6030. "<link linkend='using-bbappend-files'>Using .bbappend Files</link>"
  6031. section.</para></listitem>
  6032. <listitem><para>Add any other append files to make
  6033. custom changes that are specific to individual
  6034. recipes.</para></listitem>
  6035. </itemizedlist></para></listitem>
  6036. </itemizedlist>
  6037. </para>
  6038. </section>
  6039. <section id='creating-a-custom-template-configuration-directory'>
  6040. <title>Creating a Custom Template Configuration Directory</title>
  6041. <para>
  6042. If you are producing your own customized version
  6043. of the build system for use by other users, you might
  6044. want to customize the message shown by the setup script or
  6045. you might want to change the template configuration files (i.e.
  6046. <filename>local.conf</filename> and
  6047. <filename>bblayers.conf</filename>) that are created in
  6048. a new build directory.
  6049. </para>
  6050. <para>
  6051. The OpenEmbedded build system uses the environment variable
  6052. <filename>TEMPLATECONF</filename> to locate the directory
  6053. from which it gathers configuration information that ultimately
  6054. ends up in the
  6055. <link linkend='build-directory'>Build Directory's</link>
  6056. <filename>conf</filename> directory.
  6057. By default, <filename>TEMPLATECONF</filename> is set as
  6058. follows in the <filename>poky</filename> repository:
  6059. <literallayout class='monospaced'>
  6060. TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
  6061. </literallayout>
  6062. This is the directory used by the build system to find templates
  6063. from which to build some key configuration files.
  6064. If you look at this directory, you will see the
  6065. <filename>bblayers.conf.sample</filename>,
  6066. <filename>local.conf.sample</filename>, and
  6067. <filename>conf-notes.txt</filename> files.
  6068. The build system uses these files to form the respective
  6069. <filename>bblayers.conf</filename> file,
  6070. <filename>local.conf</filename> file, and display the list of
  6071. BitBake targets when running the setup script.
  6072. </para>
  6073. <para>
  6074. To override these default configuration files with
  6075. configurations you want used within every new
  6076. Build Directory, simply set the
  6077. <filename>TEMPLATECONF</filename> variable to your directory.
  6078. The <filename>TEMPLATECONF</filename> variable is set in the
  6079. <filename>.templateconf</filename> file, which is in the
  6080. top-level
  6081. <link linkend='source-directory'>Source Directory</link>
  6082. folder (e.g. <filename>poky</filename>).
  6083. Edit the <filename>.templateconf</filename> so that it can locate
  6084. your directory.
  6085. </para>
  6086. <para>
  6087. Best practices dictate that you should keep your
  6088. template configuration directory in your custom distribution layer.
  6089. For example, suppose you have a layer named
  6090. <filename>meta-mylayer</filename> located in your home directory
  6091. and you want your template configuration directory named
  6092. <filename>myconf</filename>.
  6093. Changing the <filename>.templateconf</filename> as follows
  6094. causes the OpenEmbedded build system to look in your directory
  6095. and base its configuration files on the
  6096. <filename>*.sample</filename> configuration files it finds.
  6097. The final configuration files (i.e.
  6098. <filename>local.conf</filename> and
  6099. <filename>bblayers.conf</filename> ultimately still end up in
  6100. your Build Directory, but they are based on your
  6101. <filename>*.sample</filename> files.
  6102. <literallayout class='monospaced'>
  6103. TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
  6104. </literallayout>
  6105. </para>
  6106. <para>
  6107. Aside from the <filename>*.sample</filename> configuration files,
  6108. the <filename>conf-notes.txt</filename> also resides in the
  6109. default <filename>meta-poky/conf</filename> directory.
  6110. The scripts that set up the build environment
  6111. (i.e.
  6112. <ulink url="&YOCTO_DOCS_REF_URL;#structure-core-script"><filename>&OE_INIT_FILE;</filename></ulink>
  6113. and
  6114. <ulink url="&YOCTO_DOCS_REF_URL;#structure-memres-core-script"><filename>oe-init-build-env-memres</filename></ulink>)
  6115. use this file to display BitBake targets as part of the script
  6116. output.
  6117. Customizing this <filename>conf-notes.txt</filename> file is a
  6118. good way to make sure your list of custom targets appears
  6119. as part of the script's output.
  6120. </para>
  6121. <para>
  6122. Here is the default list of targets displayed as a result of
  6123. running either of the setup scripts:
  6124. <literallayout class='monospaced'>
  6125. You can now run 'bitbake &lt;target&gt;'
  6126. Common targets are:
  6127. core-image-minimal
  6128. core-image-sato
  6129. meta-toolchain
  6130. meta-ide-support
  6131. </literallayout>
  6132. </para>
  6133. <para>
  6134. Changing the listed common targets is as easy as editing your
  6135. version of <filename>conf-notes.txt</filename> in your
  6136. custom template configuration directory and making sure you
  6137. have <filename>TEMPLATECONF</filename> set to your directory.
  6138. </para>
  6139. </section>
  6140. <section id='building-a-tiny-system'>
  6141. <title>Building a Tiny System</title>
  6142. <para>
  6143. Very small distributions have some significant advantages such
  6144. as requiring less on-die or in-package memory (cheaper), better
  6145. performance through efficient cache usage, lower power requirements
  6146. due to less memory, faster boot times, and reduced development
  6147. overhead.
  6148. Some real-world examples where a very small distribution gives
  6149. you distinct advantages are digital cameras, medical devices,
  6150. and small headless systems.
  6151. </para>
  6152. <para>
  6153. This section presents information that shows you how you can
  6154. trim your distribution to even smaller sizes than the
  6155. <filename>poky-tiny</filename> distribution, which is around
  6156. 5 Mbytes, that can be built out-of-the-box using the Yocto Project.
  6157. </para>
  6158. <section id='tiny-system-overview'>
  6159. <title>Overview</title>
  6160. <para>
  6161. The following list presents the overall steps you need to
  6162. consider and perform to create distributions with smaller
  6163. root filesystems, achieve faster boot times, maintain your critical
  6164. functionality, and avoid initial RAM disks:
  6165. <itemizedlist>
  6166. <listitem><para>
  6167. <link linkend='goals-and-guiding-principles'>Determine your goals and guiding principles.</link>
  6168. </para></listitem>
  6169. <listitem><para>
  6170. <link linkend='understand-what-gives-your-image-size'>Understand what contributes to your image size.</link>
  6171. </para></listitem>
  6172. <listitem><para>
  6173. <link linkend='trim-the-root-filesystem'>Reduce the size of the root filesystem.</link>
  6174. </para></listitem>
  6175. <listitem><para>
  6176. <link linkend='trim-the-kernel'>Reduce the size of the kernel.</link>
  6177. </para></listitem>
  6178. <listitem><para>
  6179. <link linkend='remove-package-management-requirements'>Eliminate packaging requirements.</link>
  6180. </para></listitem>
  6181. <listitem><para>
  6182. <link linkend='look-for-other-ways-to-minimize-size'>Look for other ways to minimize size.</link>
  6183. </para></listitem>
  6184. <listitem><para>
  6185. <link linkend='iterate-on-the-process'>Iterate on the process.</link>
  6186. </para></listitem>
  6187. </itemizedlist>
  6188. </para>
  6189. </section>
  6190. <section id='goals-and-guiding-principles'>
  6191. <title>Goals and Guiding Principles</title>
  6192. <para>
  6193. Before you can reach your destination, you need to know
  6194. where you are going.
  6195. Here is an example list that you can use as a guide when
  6196. creating very small distributions:
  6197. <itemizedlist>
  6198. <listitem><para>Determine how much space you need
  6199. (e.g. a kernel that is 1 Mbyte or less and
  6200. a root filesystem that is 3 Mbytes or less).
  6201. </para></listitem>
  6202. <listitem><para>Find the areas that are currently
  6203. taking 90% of the space and concentrate on reducing
  6204. those areas.
  6205. </para></listitem>
  6206. <listitem><para>Do not create any difficult "hacks"
  6207. to achieve your goals.</para></listitem>
  6208. <listitem><para>Leverage the device-specific
  6209. options.</para></listitem>
  6210. <listitem><para>Work in a separate layer so that you
  6211. keep changes isolated.
  6212. For information on how to create layers, see
  6213. the "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" section.
  6214. </para></listitem>
  6215. </itemizedlist>
  6216. </para>
  6217. </section>
  6218. <section id='understand-what-gives-your-image-size'>
  6219. <title>Understand What Contributes to Your Image Size</title>
  6220. <para>
  6221. It is easiest to have something to start with when creating
  6222. your own distribution.
  6223. You can use the Yocto Project out-of-the-box to create the
  6224. <filename>poky-tiny</filename> distribution.
  6225. Ultimately, you will want to make changes in your own
  6226. distribution that are likely modeled after
  6227. <filename>poky-tiny</filename>.
  6228. <note>
  6229. To use <filename>poky-tiny</filename> in your build,
  6230. set the
  6231. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
  6232. variable in your
  6233. <filename>local.conf</filename> file to "poky-tiny"
  6234. as described in the
  6235. "<link linkend='creating-your-own-distribution'>Creating Your Own Distribution</link>"
  6236. section.
  6237. </note>
  6238. </para>
  6239. <para>
  6240. Understanding some memory concepts will help you reduce the
  6241. system size.
  6242. Memory consists of static, dynamic, and temporary memory.
  6243. Static memory is the TEXT (code), DATA (initialized data
  6244. in the code), and BSS (uninitialized data) sections.
  6245. Dynamic memory represents memory that is allocated at runtime:
  6246. stacks, hash tables, and so forth.
  6247. Temporary memory is recovered after the boot process.
  6248. This memory consists of memory used for decompressing
  6249. the kernel and for the <filename>__init__</filename>
  6250. functions.
  6251. </para>
  6252. <para>
  6253. To help you see where you currently are with kernel and root
  6254. filesystem sizes, you can use two tools found in the
  6255. <link linkend='source-directory'>Source Directory</link> in
  6256. the <filename>scripts/tiny/</filename> directory:
  6257. <itemizedlist>
  6258. <listitem><para><filename>ksize.py</filename>: Reports
  6259. component sizes for the kernel build objects.
  6260. </para></listitem>
  6261. <listitem><para><filename>dirsize.py</filename>: Reports
  6262. component sizes for the root filesystem.</para></listitem>
  6263. </itemizedlist>
  6264. This next tool and command help you organize configuration
  6265. fragments and view file dependencies in a human-readable form:
  6266. <itemizedlist>
  6267. <listitem><para><filename>merge_config.sh</filename>:
  6268. Helps you manage configuration files and fragments
  6269. within the kernel.
  6270. With this tool, you can merge individual configuration
  6271. fragments together.
  6272. The tool allows you to make overrides and warns you
  6273. of any missing configuration options.
  6274. The tool is ideal for allowing you to iterate on
  6275. configurations, create minimal configurations, and
  6276. create configuration files for different machines
  6277. without having to duplicate your process.</para>
  6278. <para>The <filename>merge_config.sh</filename> script is
  6279. part of the Linux Yocto kernel Git repositories
  6280. (i.e. <filename>linux-yocto-3.14</filename>,
  6281. <filename>linux-yocto-3.10</filename>,
  6282. <filename>linux-yocto-3.8</filename>, and so forth)
  6283. in the
  6284. <filename>scripts/kconfig</filename> directory.</para>
  6285. <para>For more information on configuration fragments,
  6286. see the
  6287. "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#generating-configuration-files'>Generating Configuration Files</ulink>"
  6288. section of the Yocto Project Linux Kernel Development
  6289. Manual and the "<link linkend='creating-config-fragments'>Creating Configuration Fragments</link>"
  6290. section, which is in this manual.</para></listitem>
  6291. <listitem><para><filename>bitbake -u depexp -g <replaceable>bitbake_target</replaceable></filename>:
  6292. Using the BitBake command with these options brings up
  6293. a Dependency Explorer from which you can view file
  6294. dependencies.
  6295. Understanding these dependencies allows you to make
  6296. informed decisions when cutting out various pieces of the
  6297. kernel and root filesystem.</para></listitem>
  6298. </itemizedlist>
  6299. </para>
  6300. </section>
  6301. <section id='trim-the-root-filesystem'>
  6302. <title>Trim the Root Filesystem</title>
  6303. <para>
  6304. The root filesystem is made up of packages for booting,
  6305. libraries, and applications.
  6306. To change things, you can configure how the packaging happens,
  6307. which changes the way you build them.
  6308. You can also modify the filesystem itself or select a different
  6309. filesystem.
  6310. </para>
  6311. <para>
  6312. First, find out what is hogging your root filesystem by running the
  6313. <filename>dirsize.py</filename> script from your root directory:
  6314. <literallayout class='monospaced'>
  6315. $ cd <replaceable>root-directory-of-image</replaceable>
  6316. $ dirsize.py 100000 > dirsize-100k.log
  6317. $ cat dirsize-100k.log
  6318. </literallayout>
  6319. You can apply a filter to the script to ignore files under
  6320. a certain size.
  6321. The previous example filters out any files below 100 Kbytes.
  6322. The sizes reported by the tool are uncompressed, and thus
  6323. will be smaller by a relatively constant factor in a
  6324. compressed root filesystem.
  6325. When you examine your log file, you can focus on areas of the
  6326. root filesystem that take up large amounts of memory.
  6327. </para>
  6328. <para>
  6329. You need to be sure that what you eliminate does not cripple
  6330. the functionality you need.
  6331. One way to see how packages relate to each other is by using
  6332. the Dependency Explorer UI with the BitBake command:
  6333. <literallayout class='monospaced'>
  6334. $ cd <replaceable>image-directory</replaceable>
  6335. $ bitbake -u depexp -g <replaceable>image</replaceable>
  6336. </literallayout>
  6337. Use the interface to select potential packages you wish to
  6338. eliminate and see their dependency relationships.
  6339. </para>
  6340. <para>
  6341. When deciding how to reduce the size, get rid of packages that
  6342. result in minimal impact on the feature set.
  6343. For example, you might not need a VGA display.
  6344. Or, you might be able to get by with <filename>devtmpfs</filename>
  6345. and <filename>mdev</filename> instead of
  6346. <filename>udev</filename>.
  6347. </para>
  6348. <para>
  6349. Use your <filename>local.conf</filename> file to make changes.
  6350. For example, to eliminate <filename>udev</filename> and
  6351. <filename>glib</filename>, set the following in the
  6352. local configuration file:
  6353. <literallayout class='monospaced'>
  6354. VIRTUAL-RUNTIME_dev_manager = ""
  6355. </literallayout>
  6356. </para>
  6357. <para>
  6358. Finally, you should consider exactly the type of root
  6359. filesystem you need to meet your needs while also reducing
  6360. its size.
  6361. For example, consider <filename>cramfs</filename>,
  6362. <filename>squashfs</filename>, <filename>ubifs</filename>,
  6363. <filename>ext2</filename>, or an <filename>initramfs</filename>
  6364. using <filename>initramfs</filename>.
  6365. Be aware that <filename>ext3</filename> requires a 1 Mbyte
  6366. journal.
  6367. If you are okay with running read-only, you do not need this
  6368. journal.
  6369. </para>
  6370. <note>
  6371. After each round of elimination, you need to rebuild your
  6372. system and then use the tools to see the effects of your
  6373. reductions.
  6374. </note>
  6375. </section>
  6376. <section id='trim-the-kernel'>
  6377. <title>Trim the Kernel</title>
  6378. <para>
  6379. The kernel is built by including policies for hardware-independent
  6380. aspects.
  6381. What subsystems do you enable?
  6382. For what architecture are you building?
  6383. Which drivers do you build by default?
  6384. <note>You can modify the kernel source if you want to help
  6385. with boot time.
  6386. </note>
  6387. </para>
  6388. <para>
  6389. Run the <filename>ksize.py</filename> script from the top-level
  6390. Linux build directory to get an idea of what is making up
  6391. the kernel:
  6392. <literallayout class='monospaced'>
  6393. $ cd <replaceable>top-level-linux-build-directory</replaceable>
  6394. $ ksize.py > ksize.log
  6395. $ cat ksize.log
  6396. </literallayout>
  6397. When you examine the log, you will see how much space is
  6398. taken up with the built-in <filename>.o</filename> files for
  6399. drivers, networking, core kernel files, filesystem, sound,
  6400. and so forth.
  6401. The sizes reported by the tool are uncompressed, and thus
  6402. will be smaller by a relatively constant factor in a compressed
  6403. kernel image.
  6404. Look to reduce the areas that are large and taking up around
  6405. the "90% rule."
  6406. </para>
  6407. <para>
  6408. To examine, or drill down, into any particular area, use the
  6409. <filename>-d</filename> option with the script:
  6410. <literallayout class='monospaced'>
  6411. $ ksize.py -d > ksize.log
  6412. </literallayout>
  6413. Using this option breaks out the individual file information
  6414. for each area of the kernel (e.g. drivers, networking, and
  6415. so forth).
  6416. </para>
  6417. <para>
  6418. Use your log file to see what you can eliminate from the kernel
  6419. based on features you can let go.
  6420. For example, if you are not going to need sound, you do not
  6421. need any drivers that support sound.
  6422. </para>
  6423. <para>
  6424. After figuring out what to eliminate, you need to reconfigure
  6425. the kernel to reflect those changes during the next build.
  6426. You could run <filename>menuconfig</filename> and make all your
  6427. changes at once.
  6428. However, that makes it difficult to see the effects of your
  6429. individual eliminations and also makes it difficult to replicate
  6430. the changes for perhaps another target device.
  6431. A better method is to start with no configurations using
  6432. <filename>allnoconfig</filename>, create configuration
  6433. fragments for individual changes, and then manage the
  6434. fragments into a single configuration file using
  6435. <filename>merge_config.sh</filename>.
  6436. The tool makes it easy for you to iterate using the
  6437. configuration change and build cycle.
  6438. </para>
  6439. <para>
  6440. Each time you make configuration changes, you need to rebuild
  6441. the kernel and check to see what impact your changes had on
  6442. the overall size.
  6443. </para>
  6444. </section>
  6445. <section id='remove-package-management-requirements'>
  6446. <title>Remove Package Management Requirements</title>
  6447. <para>
  6448. Packaging requirements add size to the image.
  6449. One way to reduce the size of the image is to remove all the
  6450. packaging requirements from the image.
  6451. This reduction includes both removing the package manager
  6452. and its unique dependencies as well as removing the package
  6453. management data itself.
  6454. </para>
  6455. <para>
  6456. To eliminate all the packaging requirements for an image,
  6457. be sure that "package-management" is not part of your
  6458. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
  6459. statement for the image.
  6460. When you remove this feature, you are removing the package
  6461. manager as well as its dependencies from the root filesystem.
  6462. </para>
  6463. </section>
  6464. <section id='look-for-other-ways-to-minimize-size'>
  6465. <title>Look for Other Ways to Minimize Size</title>
  6466. <para>
  6467. Depending on your particular circumstances, other areas that you
  6468. can trim likely exist.
  6469. The key to finding these areas is through tools and methods
  6470. described here combined with experimentation and iteration.
  6471. Here are a couple of areas to experiment with:
  6472. <itemizedlist>
  6473. <listitem><para><filename>glibc</filename>:
  6474. In general, follow this process:
  6475. <orderedlist>
  6476. <listitem><para>Remove <filename>glibc</filename>
  6477. features from
  6478. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
  6479. that you think you do not need.</para></listitem>
  6480. <listitem><para>Build your distribution.
  6481. </para></listitem>
  6482. <listitem><para>If the build fails due to missing
  6483. symbols in a package, determine if you can
  6484. reconfigure the package to not need those
  6485. features.
  6486. For example, change the configuration to not
  6487. support wide character support as is done for
  6488. <filename>ncurses</filename>.
  6489. Or, if support for those characters is needed,
  6490. determine what <filename>glibc</filename>
  6491. features provide the support and restore the
  6492. configuration.
  6493. </para></listitem>
  6494. <listitem><para>Rebuild and repeat the process.
  6495. </para></listitem>
  6496. </orderedlist></para></listitem>
  6497. <listitem><para><filename>busybox</filename>:
  6498. For BusyBox, use a process similar as described for
  6499. <filename>glibc</filename>.
  6500. A difference is you will need to boot the resulting
  6501. system to see if you are able to do everything you
  6502. expect from the running system.
  6503. You need to be sure to integrate configuration fragments
  6504. into Busybox because BusyBox handles its own core
  6505. features and then allows you to add configuration
  6506. fragments on top.
  6507. </para></listitem>
  6508. </itemizedlist>
  6509. </para>
  6510. </section>
  6511. <section id='iterate-on-the-process'>
  6512. <title>Iterate on the Process</title>
  6513. <para>
  6514. If you have not reached your goals on system size, you need
  6515. to iterate on the process.
  6516. The process is the same.
  6517. Use the tools and see just what is taking up 90% of the root
  6518. filesystem and the kernel.
  6519. Decide what you can eliminate without limiting your device
  6520. beyond what you need.
  6521. </para>
  6522. <para>
  6523. Depending on your system, a good place to look might be
  6524. Busybox, which provides a stripped down
  6525. version of Unix tools in a single, executable file.
  6526. You might be able to drop virtual terminal services or perhaps
  6527. ipv6.
  6528. </para>
  6529. </section>
  6530. </section>
  6531. <section id='building-images-for-more-than-one-machine'>
  6532. <title>Building Images for More than One Machine</title>
  6533. <para>
  6534. A common scenario developers face is creating images for several
  6535. different machines that use the same software environment.
  6536. In this situation, it is tempting to set the
  6537. tunings and optimization flags for each build specifically for
  6538. the targeted hardware (i.e. "maxing out" the tunings).
  6539. Doing so can considerably add to build times and package feed
  6540. maintenance collectively for the machines.
  6541. For example, selecting tunes that are extremely specific to a
  6542. CPU core used in a system might enable some micro optimizations
  6543. in GCC for that particular system but would otherwise not gain
  6544. you much of a performance difference across the other systems
  6545. as compared to using a more general tuning across all the builds
  6546. (e.g. setting
  6547. <ulink url='var-DEFAULTTUNE'><filename>DEFAULTTUNE</filename></ulink>
  6548. specifically for each machine's build).
  6549. Rather than "max out" each build's tunings, you can take steps that
  6550. cause the OpenEmbedded build system to reuse software across the
  6551. various machines where it makes sense.
  6552. </para>
  6553. <para>
  6554. If build speed and package feed maintenance are considerations,
  6555. you should consider the points in this section that can help you
  6556. optimize your tunings to best consider build times and package
  6557. feed maintenance.
  6558. <itemizedlist>
  6559. <listitem><para><emphasis>Share the Build Directory:</emphasis>
  6560. If at all possible, share the
  6561. <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
  6562. across builds.
  6563. The Yocto Project supports switching between different
  6564. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
  6565. values in the same <filename>TMPDIR</filename>.
  6566. This practice is well supported and regularly used by
  6567. developers when building for multiple machines.
  6568. When you use the same <filename>TMPDIR</filename> for
  6569. multiple machine builds, the OpenEmbedded build system can
  6570. reuse the existing native and often cross-recipes for
  6571. multiple machines.
  6572. Thus, build time decreases.
  6573. <note>
  6574. If
  6575. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
  6576. settings change or fundamental configuration settings
  6577. such as the filesystem layout, you need to work with
  6578. a clean <filename>TMPDIR</filename>.
  6579. Sharing <filename>TMPDIR</filename> under these
  6580. circumstances might work but since it is not
  6581. guaranteed, you should use a clean
  6582. <filename>TMPDIR</filename>.
  6583. </note>
  6584. </para></listitem>
  6585. <listitem><para><emphasis>Enable the Appropriate Package Architecture:</emphasis>
  6586. By default, the OpenEmbedded build system enables three
  6587. levels of package architectures: "all", "tune" or "package",
  6588. and "machine".
  6589. Any given recipe usually selects one of these package
  6590. architectures (types) for its output.
  6591. Depending for what a given recipe creates packages, making
  6592. sure you enable the appropriate package architecture can
  6593. directly impact the build time.</para>
  6594. <para>A recipe that just generates scripts can enable
  6595. "all" architecture because there are no binaries to build.
  6596. To specifically enable "all" architecture, be sure your
  6597. recipe inherits the
  6598. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
  6599. class.
  6600. This class is useful for "all" architectures because it
  6601. configures many variables so packages can be used across
  6602. multiple architectures.</para>
  6603. <para>If your recipe needs to generate packages that are
  6604. machine-specific or when one of the build or runtime
  6605. dependencies is already machine-architecture dependent,
  6606. which makes your recipe also machine-architecture dependent,
  6607. make sure your recipe enables the "machine" package
  6608. architecture through the
  6609. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>
  6610. variable:
  6611. <literallayout class='monospaced'>
  6612. PACKAGE_ARCH = "${MACHINE_ARCH}"
  6613. </literallayout>
  6614. When you do not specifically enable a package
  6615. architecture through the
  6616. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>,
  6617. The OpenEmbedded build system defaults to the
  6618. <ulink url='&YOCTO_DOCS_REF_URL;#var-TUNE_PKGARCH'><filename>TUNE_PKGARCH</filename></ulink>
  6619. setting:
  6620. <literallayout class='monospaced'>
  6621. PACKAGE_ARCH = "${TUNE_PKGARCH}"
  6622. </literallayout>
  6623. </para></listitem>
  6624. <listitem><para><emphasis>Choose a Generic Tuning File if Possible:</emphasis>
  6625. Some tunes are more generic and can run on multiple targets
  6626. (e.g. an <filename>armv5</filename> set of packages could
  6627. run on <filename>armv6</filename> and
  6628. <filename>armv7</filename> processors in most cases).
  6629. Similarly, <filename>i486</filename> binaries could work
  6630. on <filename>i586</filename> and higher processors.
  6631. You should realize, however, that advances on newer
  6632. processor versions would not be used.</para>
  6633. <para>If you select the same tune for several different
  6634. machines, the OpenEmbedded build system reuses software
  6635. previously built, thus speeding up the overall build time.
  6636. Realize that even though a new sysroot for each machine is
  6637. generated, the software is not recompiled and only one
  6638. package feed exists.
  6639. </para></listitem>
  6640. <listitem><para><emphasis>Manage Granular Level Packaging:</emphasis>
  6641. Sometimes cases exist where injecting another level
  6642. of package architecture beyond the three higher levels
  6643. noted earlier can be useful.
  6644. For example, consider the <filename>emgd</filename>
  6645. graphics stack in the
  6646. <filename>meta-intel</filename> layer.
  6647. In this layer, a subset of software exists that is
  6648. compiled against something different from the rest of the
  6649. generic packages.
  6650. You can examine the key code in the
  6651. <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi'>Source Repositories</ulink>
  6652. "daisy" branch in
  6653. <filename>classes/emgd-gl.bbclass</filename>.
  6654. For a specific set of packages, the code redefines
  6655. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>.
  6656. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXTRA_ARCHS'><filename>PACKAGE_EXTRA_ARCHS</filename></ulink>
  6657. is then appended with this extra tune name in
  6658. <filename>meta-intel-emgd.inc</filename>.
  6659. The result is that when searching for packages, the
  6660. build system uses a four-level search and the packages
  6661. in this new level are preferred as compared to the standard
  6662. tune.
  6663. The overall result is that the build system reuses most
  6664. software from the common tune except for specific cases
  6665. as needed.
  6666. </para></listitem>
  6667. <listitem><para><emphasis>Use Tools to Debug Issues:</emphasis>
  6668. Sometimes you can run into situations where software is
  6669. being rebuilt when you think it should not be.
  6670. For example, the OpenEmbedded build system might not be
  6671. using shared state between machines when you think it
  6672. should be.
  6673. These types of situations are usually due to references
  6674. to machine-specific variables such as
  6675. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
  6676. <ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLE'><filename>SERIAL_CONSOLE</filename></ulink>,
  6677. <ulink url='&YOCTO_DOCS_REF_URL;#var-XSERVER'><filename>XSERVER</filename></ulink>,
  6678. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'><filename>MACHINE_FEATURES</filename></ulink>,
  6679. and so forth in code that is supposed to only be
  6680. tune-specific or when the recipe depends
  6681. (<ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
  6682. <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
  6683. <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
  6684. <ulink url='&YOCTO_DOCS_REF_URL;#var-RSUGGESTS'><filename>RSUGGESTS</filename></ulink>,
  6685. and so forth) on some other recipe that already has
  6686. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
  6687. defined as "${MACHINE_ARCH}".
  6688. <note>
  6689. Patches to fix any issues identified are most welcome
  6690. as these issues occasionally do occur.
  6691. </note></para>
  6692. <para>For such cases, you can use some tools to help you
  6693. sort out the situation:
  6694. <itemizedlist>
  6695. <listitem><para><emphasis><filename>sstate-diff-machines.sh</filename>:</emphasis>
  6696. You can find this tool in the
  6697. <filename>scripts</filename> directory of the
  6698. Source Repositories.
  6699. See the comments in the script for information on
  6700. how to use the tool.
  6701. </para></listitem>
  6702. <listitem><para><emphasis>BitBake's "-S printdiff" Option:</emphasis>
  6703. Using this option causes BitBake to try to
  6704. establish the closest signature match it can
  6705. (e.g. in the shared state cache) and then run
  6706. <filename>bitbake-diffsigs</filename> over the
  6707. matches to determine the stamps and delta where
  6708. these two stamp trees diverge.
  6709. </para></listitem>
  6710. </itemizedlist>
  6711. </para></listitem>
  6712. </itemizedlist>
  6713. </para>
  6714. </section>
  6715. <section id='working-with-packages'>
  6716. <title>Working with Packages</title>
  6717. <para>
  6718. This section describes a few tasks that involve packages:
  6719. <itemizedlist>
  6720. <listitem><para>
  6721. <link linkend='excluding-packages-from-an-image'>Excluding packages from an image</link>
  6722. </para></listitem>
  6723. <listitem><para>
  6724. <link linkend='incrementing-a-package-revision-number'>Incrementing a package revision number</link>
  6725. </para></listitem>
  6726. <listitem><para>
  6727. <link linkend='handling-optional-module-packaging'>Handling optional module packaging</link>
  6728. </para></listitem>
  6729. <listitem><para>
  6730. <link linkend='using-runtime-package-management'>Using Runtime Package Management</link>
  6731. </para></listitem>
  6732. <listitem><para>
  6733. <link linkend='testing-packages-with-ptest'>Setting up and running package test (ptest)</link>
  6734. </para></listitem>
  6735. </itemizedlist>
  6736. </para>
  6737. <section id='excluding-packages-from-an-image'>
  6738. <title>Excluding Packages from an Image</title>
  6739. <para>
  6740. You might find it necessary to prevent specific packages
  6741. from being installed into an image.
  6742. If so, you can use several variables to direct the build
  6743. system to essentially ignore installing recommended packages
  6744. or to not install a package at all.
  6745. </para>
  6746. <para>
  6747. The following list introduces variables you can use to
  6748. prevent packages from being installed into your image.
  6749. Each of these variables only works with IPK and RPM
  6750. package types.
  6751. Support for Debian packages does not exist.
  6752. Also, you can use these variables from your
  6753. <filename>local.conf</filename> file or attach them to a
  6754. specific image recipe by using a recipe name override.
  6755. For more detail on the variables, see the descriptions in the
  6756. Yocto Project Reference Manual's glossary chapter.
  6757. <itemizedlist>
  6758. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-BAD_RECOMMENDATIONS'><filename>BAD_RECOMMENDATIONS</filename></ulink>:
  6759. Use this variable to specify "recommended-only"
  6760. packages that you do not want installed.
  6761. </para></listitem>
  6762. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-NO_RECOMMENDATIONS'><filename>NO_RECOMMENDATIONS</filename></ulink>:
  6763. Use this variable to prevent all "recommended-only"
  6764. packages from being installed.
  6765. </para></listitem>
  6766. <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXCLUDE'><filename>PACKAGE_EXCLUDE</filename></ulink>:
  6767. Use this variable to prevent specific packages from
  6768. being installed regardless of whether they are
  6769. "recommended-only" or not.
  6770. You need to realize that the build process could
  6771. fail with an error when you
  6772. prevent the installation of a package whose presence
  6773. is required by an installed package.
  6774. </para></listitem>
  6775. </itemizedlist>
  6776. </para>
  6777. </section>
  6778. <section id='incrementing-a-package-revision-number'>
  6779. <title>Incrementing a Package Revision Number</title>
  6780. <para>
  6781. If a committed change results in changing the package output,
  6782. then the value of the
  6783. <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
  6784. variable needs to be increased (or "bumped").
  6785. Increasing <filename>PR</filename> occurs one of two ways:
  6786. <itemizedlist>
  6787. <listitem><para>Automatically using a Package Revision
  6788. Service (PR Service).</para></listitem>
  6789. <listitem><para>Manually incrementing the
  6790. <filename>PR</filename> variable.</para></listitem>
  6791. </itemizedlist>
  6792. </para>
  6793. <para>
  6794. Given that one of the challenges any build system and its
  6795. users face is how to maintain a package feed that is compatible
  6796. with existing package manager applications such as
  6797. RPM, APT, and OPKG, using an automated system is much
  6798. preferred over a manual system.
  6799. In either system, the main requirement is that version
  6800. numbering increases in a linear fashion and that a number of
  6801. version components exist that support that linear progression.
  6802. </para>
  6803. <para>
  6804. The following two sections provide information on the PR Service
  6805. and on manual <filename>PR</filename> bumping.
  6806. </para>
  6807. <section id='working-with-a-pr-service'>
  6808. <title>Working With a PR Service</title>
  6809. <para>
  6810. As mentioned, attempting to maintain revision numbers in the
  6811. <ulink url='&YOCTO_DOCS_DEV_URL;#metadata'>Metadata</ulink>
  6812. is error prone, inaccurate, and causes problems for people
  6813. submitting recipes.
  6814. Conversely, the PR Service automatically generates
  6815. increasing numbers, particularly the revision field,
  6816. which removes the human element.
  6817. <note>
  6818. For additional information on using a PR Service, you
  6819. can see the
  6820. <ulink url='&YOCTO_WIKI_URL;/wiki/PR_Service'>PR Service</ulink>
  6821. wiki page.
  6822. </note>
  6823. </para>
  6824. <para>
  6825. The Yocto Project uses variables in order of
  6826. decreasing priority to facilitate revision numbering (i.e.
  6827. <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>,
  6828. <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>, and
  6829. <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
  6830. for epoch, version, and revision, respectively).
  6831. The values are highly dependent on the policies and
  6832. procedures of a given distribution and package feed.
  6833. </para>
  6834. <para>
  6835. Because the OpenEmbedded build system uses
  6836. "<ulink url='&YOCTO_DOCS_REF_URL;#checksums'>signatures</ulink>",
  6837. which are unique to a given build, the build system
  6838. knows when to rebuild packages.
  6839. All the inputs into a given task are represented by a
  6840. signature, which can trigger a rebuild when different.
  6841. Thus, the build system itself does not rely on the
  6842. <filename>PR</filename> numbers to trigger a rebuild.
  6843. The signatures, however, can be used to generate
  6844. <filename>PR</filename> values.
  6845. </para>
  6846. <para>
  6847. The PR Service works with both
  6848. <filename>OEBasic</filename> and
  6849. <filename>OEBasicHash</filename> generators.
  6850. The value of <filename>PR</filename> bumps when the
  6851. checksum changes and the different generator mechanisms
  6852. change signatures under different circumstances.
  6853. </para>
  6854. <para>
  6855. As implemented, the build system includes values from
  6856. the PR Service into the <filename>PR</filename> field as
  6857. an addition using the form "<filename>.x</filename>" so
  6858. <filename>r0</filename> becomes <filename>r0.1</filename>,
  6859. <filename>r0.2</filename> and so forth.
  6860. This scheme allows existing <filename>PR</filename> values
  6861. to be used for whatever reasons, which include manual
  6862. <filename>PR</filename> bumps, should it be necessary.
  6863. </para>
  6864. <para>
  6865. By default, the PR Service is not enabled or running.
  6866. Thus, the packages generated are just "self consistent".
  6867. The build system adds and removes packages and
  6868. there are no guarantees about upgrade paths but images
  6869. will be consistent and correct with the latest changes.
  6870. </para>
  6871. <para>
  6872. The simplest form for a PR Service is for it to exist
  6873. for a single host development system that builds the
  6874. package feed (building system).
  6875. For this scenario, you can enable a local PR Service by
  6876. setting
  6877. <ulink url='&YOCTO_DOCS_REF_URL;#var-PRSERV_HOST'><filename>PRSERV_HOST</filename></ulink>
  6878. in your <filename>local.conf</filename> file in the
  6879. <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>:
  6880. <literallayout class='monospaced'>
  6881. PRSERV_HOST = "localhost:0"
  6882. </literallayout>
  6883. Once the service is started, packages will automatically
  6884. get increasing <filename>PR</filename> values and
  6885. BitBake will take care of starting and stopping the server.
  6886. </para>
  6887. <para>
  6888. If you have a more complex setup where multiple host
  6889. development systems work against a common, shared package
  6890. feed, you have a single PR Service running and it is
  6891. connected to each building system.
  6892. For this scenario, you need to start the PR Service using
  6893. the <filename>bitbake-prserv</filename> command:
  6894. <literallayout class='monospaced'>
  6895. bitbake-prserv --host <replaceable>ip</replaceable> --port <replaceable>port</replaceable> --start
  6896. </literallayout>
  6897. In addition to hand-starting the service, you need to
  6898. update the <filename>local.conf</filename> file of each
  6899. building system as described earlier so each system
  6900. points to the server and port.
  6901. </para>
  6902. <para>
  6903. It is also recommended you use build history, which adds
  6904. some sanity checks to package versions, in conjunction with
  6905. the server that is running the PR Service.
  6906. To enable build history, add the following to each building
  6907. system's <filename>local.conf</filename> file:
  6908. <literallayout class='monospaced'>
  6909. # It is recommended to activate "buildhistory" for testing the PR service
  6910. INHERIT += "buildhistory"
  6911. BUILDHISTORY_COMMIT = "1"
  6912. </literallayout>
  6913. For information on build history, see the
  6914. "<ulink url='&YOCTO_DOCS_REF_URL;#maintaining-build-output-quality'>Maintaining Build Output Quality</ulink>"
  6915. section in the Yocto Project Reference Manual.
  6916. </para>
  6917. <note>
  6918. <para>The OpenEmbedded build system does not maintain
  6919. <filename>PR</filename> information as part of the
  6920. shared state (sstate) packages.
  6921. If you maintain an sstate feed, its expected that either
  6922. all your building systems that contribute to the sstate
  6923. feed use a shared PR Service, or you do not run a PR
  6924. Service on any of your building systems.
  6925. Having some systems use a PR Service while others do
  6926. not leads to obvious problems.</para>
  6927. <para>For more information on shared state, see the
  6928. "<ulink url='&YOCTO_DOCS_REF_URL;#shared-state-cache'>Shared State Cache</ulink>"
  6929. section in the Yocto Project Reference Manual.</para>
  6930. </note>
  6931. </section>
  6932. <section id='manually-bumping-pr'>
  6933. <title>Manually Bumping PR</title>
  6934. <para>
  6935. The alternative to setting up a PR Service is to manually
  6936. bump the
  6937. <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
  6938. variable.
  6939. </para>
  6940. <para>
  6941. If a committed change results in changing the package output,
  6942. then the value of the PR variable needs to be increased
  6943. (or "bumped") as part of that commit.
  6944. For new recipes you should add the <filename>PR</filename>
  6945. variable and set its initial value equal to "r0", which is the default.
  6946. Even though the default value is "r0", the practice of adding it to a new recipe makes
  6947. it harder to forget to bump the variable when you make changes
  6948. to the recipe in future.
  6949. </para>
  6950. <para>
  6951. If you are sharing a common <filename>.inc</filename> file with multiple recipes,
  6952. you can also use the
  6953. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-INC_PR'>INC_PR</ulink></filename>
  6954. variable to ensure that
  6955. the recipes sharing the <filename>.inc</filename> file are rebuilt when the
  6956. <filename>.inc</filename> file itself is changed.
  6957. The <filename>.inc</filename> file must set <filename>INC_PR</filename>
  6958. (initially to "r0"), and all recipes referring to it should set <filename>PR</filename>
  6959. to "$(INC_PR).0" initially, incrementing the last number when the recipe is changed.
  6960. If the <filename>.inc</filename> file is changed then its
  6961. <filename>INC_PR</filename> should be incremented.
  6962. </para>
  6963. <para>
  6964. When upgrading the version of a package, assuming the
  6965. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'>PV</ulink></filename>
  6966. changes, the <filename>PR</filename> variable should be
  6967. reset to "r0" (or "$(INC_PR).0" if you are using
  6968. <filename>INC_PR</filename>).
  6969. </para>
  6970. <para>
  6971. Usually, version increases occur only to packages.
  6972. However, if for some reason <filename>PV</filename> changes but does not
  6973. increase, you can increase the
  6974. <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PE'>PE</ulink></filename>
  6975. variable (Package Epoch).
  6976. The <filename>PE</filename> variable defaults to "0".
  6977. </para>
  6978. <para>
  6979. Version numbering strives to follow the
  6980. <ulink url='http://www.debian.org/doc/debian-policy/ch-controlfields.html'>
  6981. Debian Version Field Policy Guidelines</ulink>.
  6982. These guidelines define how versions are compared and what "increasing" a version means.
  6983. </para>
  6984. </section>
  6985. </section>
  6986. <section id='handling-optional-module-packaging'>
  6987. <title>Handling Optional Module Packaging</title>
  6988. <para>
  6989. Many pieces of software split functionality into optional
  6990. modules (or plug-ins) and the plug-ins that are built
  6991. might depend on configuration options.
  6992. To avoid having to duplicate the logic that determines what
  6993. modules are available in your recipe or to avoid having
  6994. to package each module by hand, the OpenEmbedded build system
  6995. provides functionality to handle module packaging dynamically.
  6996. </para>
  6997. <para>
  6998. To handle optional module packaging, you need to do two things:
  6999. <itemizedlist>
  7000. <listitem><para>Ensure the module packaging is actually
  7001. done.</para></listitem>
  7002. <listitem><para>Ensure that any dependencies on optional
  7003. modules from other recipes are satisfied by your recipe.
  7004. </para></listitem>
  7005. </itemizedlist>
  7006. </para>
  7007. <section id='making-sure-the-packaging-is-done'>
  7008. <title>Making Sure the Packaging is Done</title>
  7009. <para>
  7010. To ensure the module packaging actually gets done, you use
  7011. the <filename>do_split_packages</filename> function within
  7012. the <filename>populate_packages</filename> Python function
  7013. in your recipe.
  7014. The <filename>do_split_packages</filename> function
  7015. searches for a pattern of files or directories under a
  7016. specified path and creates a package for each one it finds
  7017. by appending to the
  7018. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
  7019. variable and setting the appropriate values for
  7020. <filename>FILES_packagename</filename>,
  7021. <filename>RDEPENDS_packagename</filename>,
  7022. <filename>DESCRIPTION_packagename</filename>, and so forth.
  7023. Here is an example from the <filename>lighttpd</filename>
  7024. recipe:
  7025. <literallayout class='monospaced'>
  7026. python populate_packages_prepend () {
  7027. lighttpd_libdir = d.expand('${libdir}')
  7028. do_split_packages(d, lighttpd_libdir, '^mod_(.*)\.so$',
  7029. 'lighttpd-module-%s', 'Lighttpd module for %s',
  7030. extra_depends='')
  7031. }
  7032. </literallayout>
  7033. The previous example specifies a number of things in the
  7034. call to <filename>do_split_packages</filename>.
  7035. <itemizedlist>
  7036. <listitem><para>A directory within the files installed
  7037. by your recipe through <filename>do_install</filename>
  7038. in which to search.</para></listitem>
  7039. <listitem><para>A regular expression used to match module
  7040. files in that directory.
  7041. In the example, note the parentheses () that mark
  7042. the part of the expression from which the module
  7043. name should be derived.</para></listitem>
  7044. <listitem><para>A pattern to use for the package names.
  7045. </para></listitem>
  7046. <listitem><para>A description for each package.
  7047. </para></listitem>
  7048. <listitem><para>An empty string for
  7049. <filename>extra_depends</filename>, which disables
  7050. the default dependency on the main
  7051. <filename>lighttpd</filename> package.
  7052. Thus, if a file in <filename>${libdir}</filename>
  7053. called <filename>mod_alias.so</filename> is found,
  7054. a package called <filename>lighttpd-module-alias</filename>
  7055. is created for it and the
  7056. <ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
  7057. is set to "Lighttpd module for alias".</para></listitem>
  7058. </itemizedlist>
  7059. </para>
  7060. <para>
  7061. Often, packaging modules is as simple as the previous
  7062. example.
  7063. However, more advanced options exist that you can use
  7064. within <filename>do_split_packages</filename> to modify its
  7065. behavior.
  7066. And, if you need to, you can add more logic by specifying
  7067. a hook function that is called for each package.
  7068. It is also perfectly acceptable to call
  7069. <filename>do_split_packages</filename> multiple times if
  7070. you have more than one set of modules to package.
  7071. </para>
  7072. <para>
  7073. For more examples that show how to use
  7074. <filename>do_split_packages</filename>, see the
  7075. <filename>connman.inc</filename> file in the
  7076. <filename>meta/recipes-connectivity/connman/</filename>
  7077. directory of the <filename>poky</filename>
  7078. <link linkend='yocto-project-repositories'>source repository</link>.
  7079. You can also find examples in
  7080. <filename>meta/classes/kernel.bbclass</filename>.
  7081. </para>
  7082. <para>
  7083. Following is a reference that shows
  7084. <filename>do_split_packages</filename> mandatory and
  7085. optional arguments:
  7086. <literallayout class='monospaced'>
  7087. Mandatory arguments
  7088. root
  7089. The path in which to search
  7090. file_regex
  7091. Regular expression to match searched files.
  7092. Use parentheses () to mark the part of this
  7093. expression that should be used to derive the
  7094. module name (to be substituted where %s is
  7095. used in other function arguments as noted below)
  7096. output_pattern
  7097. Pattern to use for the package names. Must
  7098. include %s.
  7099. description
  7100. Description to set for each package. Must
  7101. include %s.
  7102. Optional arguments
  7103. postinst
  7104. Postinstall script to use for all packages
  7105. (as a string)
  7106. recursive
  7107. True to perform a recursive search - default
  7108. False
  7109. hook
  7110. A hook function to be called for every match.
  7111. The function will be called with the following
  7112. arguments (in the order listed):
  7113. f
  7114. Full path to the file/directory match
  7115. pkg
  7116. The package name
  7117. file_regex
  7118. As above
  7119. output_pattern
  7120. As above
  7121. modulename
  7122. The module name derived using file_regex
  7123. extra_depends
  7124. Extra runtime dependencies (RDEPENDS) to be
  7125. set for all packages. The default value of None
  7126. causes a dependency on the main package
  7127. (${PN}) - if you do not want this, pass empty
  7128. string '' for this parameter.
  7129. aux_files_pattern
  7130. Extra item(s) to be added to FILES for each
  7131. package. Can be a single string item or a list
  7132. of strings for multiple items. Must include %s.
  7133. postrm
  7134. postrm script to use for all packages (as a
  7135. string)
  7136. allow_dirs
  7137. True to allow directories to be matched -
  7138. default False
  7139. prepend
  7140. If True, prepend created packages to PACKAGES
  7141. instead of the default False which appends them
  7142. match_path
  7143. match file_regex on the whole relative path to
  7144. the root rather than just the file name
  7145. aux_files_pattern_verbatim
  7146. Extra item(s) to be added to FILES for each
  7147. package, using the actual derived module name
  7148. rather than converting it to something legal
  7149. for a package name. Can be a single string item
  7150. or a list of strings for multiple items. Must
  7151. include %s.
  7152. allow_links
  7153. True to allow symlinks to be matched - default
  7154. False
  7155. summary
  7156. Summary to set for each package. Must include %s;
  7157. defaults to description if not set.
  7158. </literallayout>
  7159. </para>
  7160. </section>
  7161. <section id='satisfying-dependencies'>
  7162. <title>Satisfying Dependencies</title>
  7163. <para>
  7164. The second part for handling optional module packaging
  7165. is to ensure that any dependencies on optional modules
  7166. from other recipes are satisfied by your recipe.
  7167. You can be sure these dependencies are satisfied by
  7168. using the
  7169. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> variable.
  7170. Here is an example that continues with the
  7171. <filename>lighttpd</filename> recipe shown earlier:
  7172. <literallayout class='monospaced'>
  7173. PACKAGES_DYNAMIC = "lighttpd-module-.*"
  7174. </literallayout>
  7175. The name specified in the regular expression can of
  7176. course be anything.
  7177. In this example, it is <filename>lighttpd-module-</filename>
  7178. and is specified as the prefix to ensure that any
  7179. <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
  7180. and <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
  7181. on a package name starting with the prefix are satisfied
  7182. during build time.
  7183. If you are using <filename>do_split_packages</filename>
  7184. as described in the previous section, the value you put in
  7185. <filename>PACKAGES_DYNAMIC</filename> should correspond to
  7186. the name pattern specified in the call to
  7187. <filename>do_split_packages</filename>.
  7188. </para>
  7189. </section>
  7190. </section>
  7191. <section id='using-runtime-package-management'>
  7192. <title>Using Runtime Package Management</title>
  7193. <para>
  7194. During a build, BitBake always transforms a recipe into one or
  7195. more packages.
  7196. For example, BitBake takes the <filename>bash</filename> recipe
  7197. and currently produces the <filename>bash-dbg</filename>,
  7198. <filename>bash-staticdev</filename>,
  7199. <filename>bash-dev</filename>, <filename>bash-doc</filename>,
  7200. <filename>bash-locale</filename>, and
  7201. <filename>bash</filename> packages.
  7202. Not all generated packages are included in an image.
  7203. </para>
  7204. <para>
  7205. In several situations, you might need to update, add, remove,
  7206. or query the packages on a target device at runtime
  7207. (i.e. without having to generate a new image).
  7208. Examples of such situations include:
  7209. <itemizedlist>
  7210. <listitem><para>
  7211. You want to provide in-the-field updates to deployed
  7212. devices (e.g. security updates).
  7213. </para></listitem>
  7214. <listitem><para>
  7215. You want to have a fast turn-around development cycle
  7216. for one or more applications that run on your device.
  7217. </para></listitem>
  7218. <listitem><para>
  7219. You want to temporarily install the "debug" packages
  7220. of various applications on your device so that
  7221. debugging can be greatly improved by allowing
  7222. access to symbols and source debugging.
  7223. </para></listitem>
  7224. <listitem><para>
  7225. You want to deploy a more minimal package selection of
  7226. your device but allow in-the-field updates to add a
  7227. larger selection for customization.
  7228. </para></listitem>
  7229. </itemizedlist>
  7230. </para>
  7231. <para>
  7232. In all these situations, you have something similar to a more
  7233. traditional Linux distribution in that in-field devices
  7234. are able to receive pre-compiled packages from a server for
  7235. installation or update.
  7236. Being able to install these packages on a running,
  7237. in-field device is what is termed "runtime package
  7238. management".
  7239. </para>
  7240. <para>
  7241. In order to use runtime package management, you
  7242. need a host/server machine that serves up the pre-compiled
  7243. packages plus the required metadata.
  7244. You also need package manipulation tools on the target.
  7245. The build machine is a likely candidate to act as the server.
  7246. However, that machine does not necessarily have to be the
  7247. package server.
  7248. The build machine could push its artifacts to another machine
  7249. that acts as the server (e.g. Internet-facing).
  7250. </para>
  7251. <para>
  7252. A simple build that targets just one device produces
  7253. more than one package database.
  7254. In other words, the packages produced by a build are separated
  7255. out into a couple of different package groupings based on
  7256. criteria such as the target's CPU architecture, the target
  7257. board, or the C library used on the target.
  7258. For example, a build targeting the <filename>qemuarm</filename>
  7259. device produces the following three package databases:
  7260. <filename>all</filename>, <filename>armv5te</filename>, and
  7261. <filename>qemuarm</filename>.
  7262. If you wanted your <filename>qemuarm</filename> device to be
  7263. aware of all the packages that were available to it,
  7264. you would need to point it to each of these databases
  7265. individually.
  7266. In a similar way, a traditional Linux distribution usually is
  7267. configured to be aware of a number of software repositories
  7268. from which it retrieves packages.
  7269. </para>
  7270. <para>
  7271. Using runtime package management is completely optional and
  7272. not required for a successful build or deployment in any
  7273. way.
  7274. But if you want to make use of runtime package management,
  7275. you need to do a couple things above and beyond the basics.
  7276. The remainder of this section describes what you need to do.
  7277. </para>
  7278. <section id='runtime-package-management-build'>
  7279. <title>Build Considerations</title>
  7280. <para>
  7281. This section describes build considerations of which you
  7282. need to be aware in order to provide support for runtime
  7283. package management.
  7284. </para>
  7285. <para>
  7286. When BitBake generates packages, it needs to know
  7287. what format or formats to use.
  7288. In your configuration, you use the
  7289. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
  7290. variable to specify the format:
  7291. <orderedlist>
  7292. <listitem><para>
  7293. Open the <filename>local.conf</filename> file
  7294. inside your
  7295. <link linkend='build-directory'>Build Directory</link>
  7296. (e.g. <filename>~/poky/build/conf/local.conf</filename>).
  7297. </para></listitem>
  7298. <listitem><para>
  7299. Select the desired package format as follows:
  7300. <literallayout class='monospaced'>
  7301. PACKAGE_CLASSES ?= “package_<replaceable>packageformat</replaceable>”
  7302. </literallayout>
  7303. where <replaceable>packageformat</replaceable>
  7304. can be "ipk", "rpm", and "deb", which are the
  7305. supported package formats.
  7306. <note>
  7307. Because the Yocto Project supports three
  7308. different package formats, you can set the
  7309. variable with more than one argument.
  7310. However, the OpenEmbedded build system only
  7311. uses the first argument when creating an image
  7312. or Software Development Kit (SDK).
  7313. </note>
  7314. </para></listitem>
  7315. </orderedlist>
  7316. </para>
  7317. <para>
  7318. If you would like your image to start off with a basic
  7319. package database containing the packages in your current
  7320. build as well as to have the relevant tools available on the
  7321. target for runtime package management, you can include
  7322. "package-management" in the
  7323. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
  7324. variable.
  7325. Including "package-management" in this
  7326. configuration variable ensures that when the image
  7327. is assembled for your target, the image includes
  7328. the currently-known package databases as well as
  7329. the target-specific tools required for runtime
  7330. package management to be performed on the target.
  7331. However, this is not strictly necessary.
  7332. You could start your image off without any databases
  7333. but only include the required on-target package
  7334. tool(s).
  7335. As an example, you could include "opkg" in your
  7336. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
  7337. variable if you are using the IPK package format.
  7338. You can then initialize your target's package database(s)
  7339. later once your image is up and running.
  7340. </para>
  7341. <para>
  7342. Whenever you perform any sort of build step that can
  7343. potentially generate a package or modify an existing
  7344. package, it is always a good idea to re-generate the
  7345. package index with:
  7346. <literallayout class='monospaced'>
  7347. $ bitbake package-index
  7348. </literallayout>
  7349. Realize that it is not sufficient to simply do the
  7350. following:
  7351. <literallayout class='monospaced'>
  7352. $ bitbake <replaceable>some-package</replaceable> package-index
  7353. </literallayout>
  7354. The reason for this restriction is because BitBake does not
  7355. properly schedule the <filename>package-index</filename>
  7356. target fully after any other target has completed.
  7357. Thus, be sure to run the package update step separately.
  7358. </para>
  7359. <para>
  7360. You can use the
  7361. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
  7362. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
  7363. and
  7364. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
  7365. variables to pre-configure target images to use a package
  7366. feed.
  7367. If you do not define these variables, then manual steps
  7368. as described in the subsequent sections are necessary to
  7369. configure the target.
  7370. You should set these variables before building the image
  7371. in order to produce a correctly configured image.
  7372. </para>
  7373. <para>
  7374. When your build is complete, your packages reside in the
  7375. <filename>${TMPDIR}/deploy/<replaceable>packageformat</replaceable></filename>
  7376. directory.
  7377. For example, if
  7378. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename>
  7379. is <filename>tmp</filename> and your selected package type
  7380. is IPK, then your IPK packages are available in
  7381. <filename>tmp/deploy/ipk</filename>.
  7382. </para>
  7383. </section>
  7384. <section id='runtime-package-management-server'>
  7385. <title>Host or Server Machine Setup</title>
  7386. <para>
  7387. Although other protocols are possible, a server using HTTP
  7388. typically serves packages.
  7389. If you want to use HTTP, then set up and configure a
  7390. web server such as Apache 2, lighttpd, or
  7391. SimpleHTTPServer on the machine serving the packages.
  7392. </para>
  7393. <para>
  7394. To keep things simple, this section describes how to set
  7395. up a SimpleHTTPServer web server to share package feeds
  7396. from the developer's machine.
  7397. Although this server might not be the best for a production
  7398. environment, the setup is simple and straight forward.
  7399. Should you want to use a different server more suited for
  7400. production (e.g. Apache 2, Lighttpd, or Nginx), take the
  7401. appropriate steps to do so.
  7402. </para>
  7403. <para>
  7404. From within the build directory where you have built an
  7405. image based on your packaging choice (i.e. the
  7406. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
  7407. setting), simply start the server.
  7408. The following example assumes a build directory of
  7409. <filename>~/poky/build/tmp/deploy/rpm</filename> and a
  7410. <filename>PACKAGE_CLASSES</filename> setting of
  7411. "package_rpm":
  7412. <literallayout class='monospaced'>
  7413. $ cd ~/poky/build/tmp/deploy/rpm
  7414. $ python -m SimpleHTTPServer
  7415. </literallayout>
  7416. </para>
  7417. </section>
  7418. <section id='runtime-package-management-target'>
  7419. <title>Target Setup</title>
  7420. <para>
  7421. Setting up the target differs depending on the
  7422. package management system.
  7423. This section provides information for RPM, IPK, and DEB.
  7424. </para>
  7425. <section id='runtime-package-management-target-rpm'>
  7426. <title>Using RPM</title>
  7427. <para>
  7428. The <filename>smart</filename> application performs
  7429. runtime package management of RPM packages.
  7430. You must perform an initial setup for
  7431. <filename>smart</filename> on the target machine
  7432. if the
  7433. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
  7434. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
  7435. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
  7436. variables have not been set or the target image was
  7437. built before the variables were set.
  7438. </para>
  7439. <para>
  7440. As an example, assume the target is able to use the
  7441. following package databases:
  7442. <filename>all</filename>, <filename>i586</filename>,
  7443. and <filename>qemux86</filename> from a server named
  7444. <filename>my.server</filename>.
  7445. You must inform <filename>smart</filename> of the
  7446. availability of these databases by issuing the
  7447. following commands on the target:
  7448. <literallayout class='monospaced'>
  7449. # smart channel --add i585 type=rpm-md baseurl=http://my.server/rpm/i586
  7450. # smart channel --add qemux86 type=rpm-md baseurl=http://my.server/rpm/qemux86
  7451. # smart channel --add all type=rpm-md baseurl=http://my.server/rpm/all
  7452. </literallayout>
  7453. From the target machine, fetch the repository:
  7454. <literallayout class='monospaced'>
  7455. # smart update
  7456. </literallayout>
  7457. After everything is set up, <filename>smart</filename>
  7458. is able to find, install, and upgrade packages from
  7459. the specified repository.
  7460. </para>
  7461. </section>
  7462. <section id='runtime-package-management-target-ipk'>
  7463. <title>Using IPK</title>
  7464. <para>
  7465. The <filename>opkg</filename> application performs
  7466. runtime package management of IPK packages.
  7467. You must perform an initial setup for
  7468. <filename>opkg</filename> on the target machine
  7469. if the
  7470. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
  7471. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
  7472. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
  7473. variables have not been set or the target image was
  7474. built before the variables were set.
  7475. </para>
  7476. <para>
  7477. The <filename>opkg</filename> application uses
  7478. configuration files to find available package
  7479. databases.
  7480. Thus, you need to create a configuration file inside
  7481. the <filename>/etc/opkg/</filename> direction, which
  7482. informs <filename>opkg</filename> of any repository
  7483. you want to use.
  7484. </para>
  7485. <para>
  7486. As an example, suppose you are serving packages from a
  7487. <filename>ipk/</filename> directory containing the
  7488. <filename>i586</filename>,
  7489. <filename>all</filename>, and
  7490. <filename>qemux86</filename> databases through an
  7491. HTTP server named <filename>my.server</filename>.
  7492. On the target, create a configuration file
  7493. (e.g. <filename>my_repo.conf</filename>) inside the
  7494. <filename>/etc/opkg/</filename> directory containing
  7495. the following:
  7496. <literallayout class='monospaced'>
  7497. src/gz all http://my.server/ipk/all
  7498. src/gz i586 http://my.server/ipk/i586
  7499. src/gz qemux86 http://my.server/ipk/qemux86
  7500. </literallayout>
  7501. Next, instruct <filename>opkg</filename> to fetch
  7502. the repository information:
  7503. <literallayout class='monospaced'>
  7504. # opkg update
  7505. </literallayout>
  7506. The <filename>opkg</filename> application is now able
  7507. to find, install, and upgrade packages from the
  7508. specified repository.
  7509. </para>
  7510. </section>
  7511. <section id='runtime-package-management-target-deb'>
  7512. <title>Using DEB</title>
  7513. <para>
  7514. The <filename>apt</filename> application performs
  7515. runtime package management of DEB packages.
  7516. This application uses a source list file to find
  7517. available package databases.
  7518. You must perform an initial setup for
  7519. <filename>apt</filename> on the target machine
  7520. if the
  7521. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
  7522. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
  7523. <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
  7524. variables have not been set or the target image was
  7525. built before the variables were set.
  7526. </para>
  7527. <para>
  7528. To inform <filename>apt</filename> of the repository
  7529. you want to use, you might create a list file (e.g.
  7530. <filename>my_repo.list</filename>) inside the
  7531. <filename>/etc/apt/sources.list.d/</filename>
  7532. directory.
  7533. As an example, suppose you are serving packages from a
  7534. <filename>deb/</filename> directory containing the
  7535. <filename>i586</filename>,
  7536. <filename>all</filename>, and
  7537. <filename>qemux86</filename> databases through an
  7538. HTTP server named <filename>my.server</filename>.
  7539. The list file should contain:
  7540. <literallayout class='monospaced'>
  7541. deb http://my.server/deb/all ./
  7542. deb http://my.server/deb/i586 ./
  7543. deb http://my.server/deb/qemux86 ./
  7544. </literallayout>
  7545. Next, instruct the <filename>apt</filename>
  7546. application to fetch the repository information:
  7547. <literallayout class='monospaced'>
  7548. # apt-get update
  7549. </literallayout>
  7550. After this step, <filename>apt</filename> is able
  7551. to find, install, and upgrade packages from the
  7552. specified repository.
  7553. </para>
  7554. </section>
  7555. </section>
  7556. </section>
  7557. <section id='testing-packages-with-ptest'>
  7558. <title>Testing Packages With ptest</title>
  7559. <para>
  7560. A Package Test (ptest) runs tests against packages built
  7561. by the OpenEmbedded build system on the target machine.
  7562. A ptest contains at least two items: the actual test, and
  7563. a shell script (<filename>run-ptest</filename>) that starts
  7564. the test.
  7565. The shell script that starts the test must not contain
  7566. the actual test - the script only starts the test.
  7567. On the other hand, the test can be anything from a simple
  7568. shell script that runs a binary and checks the output to
  7569. an elaborate system of test binaries and data files.
  7570. </para>
  7571. <para>
  7572. The test generates output in the format used by
  7573. Automake:
  7574. <literallayout class='monospaced'>
  7575. <replaceable>result</replaceable>: <replaceable>testname</replaceable>
  7576. </literallayout>
  7577. where the result can be <filename>PASS</filename>,
  7578. <filename>FAIL</filename>, or <filename>SKIP</filename>,
  7579. and the testname can be any identifying string.
  7580. </para>
  7581. <para>
  7582. For a list of Yocto Project recipes that are already
  7583. enabled with ptest, see the
  7584. <ulink url='https://wiki.yoctoproject.org/wiki/Ptest'>Ptest</ulink>
  7585. wiki page.
  7586. <note>
  7587. A recipe is "ptest-enabled" if it inherits the
  7588. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
  7589. class.
  7590. </note>
  7591. </para>
  7592. <section id='adding-ptest-to-your-build'>
  7593. <title>Adding ptest to Your Build</title>
  7594. <para>
  7595. To add package testing to your build, add the
  7596. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
  7597. and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
  7598. variables to your <filename>local.conf</filename> file,
  7599. which is found in the
  7600. <link linkend='build-directory'>Build Directory</link>:
  7601. <literallayout class='monospaced'>
  7602. DISTRO_FEATURES_append = " ptest"
  7603. EXTRA_IMAGE_FEATURES += "ptest-pkgs"
  7604. </literallayout>
  7605. Once your build is complete, the ptest files are installed
  7606. into the
  7607. <filename>/usr/lib/<replaceable>package</replaceable>/ptest</filename>
  7608. directory within the image, where
  7609. <filename><replaceable>package</replaceable></filename>
  7610. is the name of the package.
  7611. </para>
  7612. </section>
  7613. <section id='running-ptest'>
  7614. <title>Running ptest</title>
  7615. <para>
  7616. The <filename>ptest-runner</filename> package installs a
  7617. shell script that loops through all installed ptest test
  7618. suites and runs them in sequence.
  7619. Consequently, you might want to add this package to
  7620. your image.
  7621. </para>
  7622. </section>
  7623. <section id='getting-your-package-ready'>
  7624. <title>Getting Your Package Ready</title>
  7625. <para>
  7626. In order to enable a recipe to run installed ptests
  7627. on target hardware,
  7628. you need to prepare the recipes that build the packages
  7629. you want to test.
  7630. Here is what you have to do for each recipe:
  7631. <itemizedlist>
  7632. <listitem><para><emphasis>Be sure the recipe
  7633. inherits the
  7634. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
  7635. class:</emphasis>
  7636. Include the following line in each recipe:
  7637. <literallayout class='monospaced'>
  7638. inherit ptest
  7639. </literallayout>
  7640. </para></listitem>
  7641. <listitem><para><emphasis>Create <filename>run-ptest</filename>:</emphasis>
  7642. This script starts your test.
  7643. Locate the script where you will refer to it
  7644. using
  7645. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
  7646. Here is an example that starts a test for
  7647. <filename>dbus</filename>:
  7648. <literallayout class='monospaced'>
  7649. #!/bin/sh
  7650. cd test
  7651. make -k runtest-TESTS
  7652. </literallayout>
  7653. </para></listitem>
  7654. <listitem><para><emphasis>Ensure dependencies are
  7655. met:</emphasis>
  7656. If the test adds build or runtime dependencies
  7657. that normally do not exist for the package
  7658. (such as requiring "make" to run the test suite),
  7659. use the
  7660. <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
  7661. and
  7662. <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
  7663. variables in your recipe in order for the package
  7664. to meet the dependencies.
  7665. Here is an example where the package has a runtime
  7666. dependency on "make":
  7667. <literallayout class='monospaced'>
  7668. RDEPENDS_${PN}-ptest += "make"
  7669. </literallayout>
  7670. </para></listitem>
  7671. <listitem><para><emphasis>Add a function to build the
  7672. test suite:</emphasis>
  7673. Not many packages support cross-compilation of
  7674. their test suites.
  7675. Consequently, you usually need to add a
  7676. cross-compilation function to the package.
  7677. </para>
  7678. <para>Many packages based on Automake compile and
  7679. run the test suite by using a single command
  7680. such as <filename>make check</filename>.
  7681. However, the host <filename>make check</filename>
  7682. builds and runs on the same computer, while
  7683. cross-compiling requires that the package is built
  7684. on the host but executed for the target
  7685. architecture (though often, as in the case for
  7686. ptest, the execution occurs on the host).
  7687. The built version of Automake that ships with the
  7688. Yocto Project includes a patch that separates
  7689. building and execution.
  7690. Consequently, packages that use the unaltered,
  7691. patched version of <filename>make check</filename>
  7692. automatically cross-compiles.</para>
  7693. <para>Regardless, you still must add a
  7694. <filename>do_compile_ptest</filename> function to
  7695. build the test suite.
  7696. Add a function similar to the following to your
  7697. recipe:
  7698. <literallayout class='monospaced'>
  7699. do_compile_ptest() {
  7700. oe_runmake buildtest-TESTS
  7701. }
  7702. </literallayout>
  7703. </para></listitem>
  7704. <listitem><para><emphasis>Ensure special configurations
  7705. are set:</emphasis>
  7706. If the package requires special configurations
  7707. prior to compiling the test code, you must
  7708. insert a <filename>do_configure_ptest</filename>
  7709. function into the recipe.
  7710. </para></listitem>
  7711. <listitem><para><emphasis>Install the test
  7712. suite:</emphasis>
  7713. The <filename>ptest</filename> class
  7714. automatically copies the file
  7715. <filename>run-ptest</filename> to the target and
  7716. then runs make <filename>install-ptest</filename>
  7717. to run the tests.
  7718. If this is not enough, you need to create a
  7719. <filename>do_install_ptest</filename> function and
  7720. make sure it gets called after the
  7721. "make install-ptest" completes.
  7722. </para></listitem>
  7723. </itemizedlist>
  7724. </para>
  7725. </section>
  7726. </section>
  7727. </section>
  7728. <section id='working-with-source-files'>
  7729. <title>Working with Source Files</title>
  7730. <para>
  7731. The OpenEmbedded build system works with source files located
  7732. through the
  7733. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  7734. variable.
  7735. When you build something using BitBake, a big part of the operation
  7736. is locating and downloading all the source tarballs.
  7737. For images, downloading all the source for various packages can
  7738. take a significant amount of time.
  7739. </para>
  7740. <para>
  7741. This section presents information for working with source
  7742. files that can lead to more efficient use of resources and
  7743. time.
  7744. </para>
  7745. <section id='setting-up-effective-mirrors'>
  7746. <title>Setting up Effective Mirrors</title>
  7747. <para>
  7748. As mentioned, a good deal that goes into a Yocto Project
  7749. build is simply downloading all of the source tarballs.
  7750. Maybe you have been working with another build system
  7751. (OpenEmbedded or Angstrom) for which you have built up a
  7752. sizable directory of source tarballs.
  7753. Or, perhaps someone else has such a directory for which you
  7754. have read access.
  7755. If so, you can save time by adding statements to your
  7756. configuration file so that the build process checks local
  7757. directories first for existing tarballs before checking the
  7758. Internet.
  7759. </para>
  7760. <para>
  7761. Here is an efficient way to set it up in your
  7762. <filename>local.conf</filename> file:
  7763. <literallayout class='monospaced'>
  7764. SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
  7765. INHERIT += "own-mirrors"
  7766. BB_GENERATE_MIRROR_TARBALLS = "1"
  7767. # BB_NO_NETWORK = "1"
  7768. </literallayout>
  7769. </para>
  7770. <para>
  7771. In the previous example, the
  7772. <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
  7773. variable causes the OpenEmbedded build system to generate
  7774. tarballs of the Git repositories and store them in the
  7775. <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
  7776. directory.
  7777. Due to performance reasons, generating and storing these
  7778. tarballs is not the build system's default behavior.
  7779. </para>
  7780. <para>
  7781. You can also use the
  7782. <ulink url='&YOCTO_DOCS_REF_URL;#var-PREMIRRORS'><filename>PREMIRRORS</filename></ulink>
  7783. variable.
  7784. For an example, see the variable's glossary entry in the
  7785. Yocto Project Reference Manual.
  7786. </para>
  7787. </section>
  7788. <section id='getting-source-files-and-suppressing-the-build'>
  7789. <title>Getting Source Files and Suppressing the Build</title>
  7790. <para>
  7791. Another technique you can use to ready yourself for a
  7792. successive string of build operations, is to pre-fetch
  7793. all the source files without actually starting a build.
  7794. This technique lets you work through any download issues
  7795. and ultimately gathers all the source files into your
  7796. download directory
  7797. <ulink url='&YOCTO_DOCS_REF_URL;#structure-build-downloads'><filename>build/downloads</filename></ulink>,
  7798. which is located with
  7799. <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>.
  7800. </para>
  7801. <para>
  7802. Use the following BitBake command form to fetch all the
  7803. necessary sources without starting the build:
  7804. <literallayout class='monospaced'>
  7805. $ bitbake -c fetchall <replaceable>target</replaceable>
  7806. </literallayout>
  7807. This variation of the BitBake command guarantees that you
  7808. have all the sources for that BitBake target should you
  7809. disconnect from the Internet and want to do the build
  7810. later offline.
  7811. </para>
  7812. </section>
  7813. </section>
  7814. <section id="building-software-from-an-external-source">
  7815. <title>Building Software from an External Source</title>
  7816. <para>
  7817. By default, the OpenEmbedded build system uses the
  7818. <link linkend='build-directory'>Build Directory</link> when
  7819. building source code.
  7820. The build process involves fetching the source files, unpacking
  7821. them, and then patching them if necessary before the build takes
  7822. place.
  7823. </para>
  7824. <para>
  7825. Situations exist where you might want to build software from source
  7826. files that are external to and thus outside of the
  7827. OpenEmbedded build system.
  7828. For example, suppose you have a project that includes a new BSP with
  7829. a heavily customized kernel.
  7830. And, you want to minimize exposing the build system to the
  7831. development team so that they can focus on their project and
  7832. maintain everyone's workflow as much as possible.
  7833. In this case, you want a kernel source directory on the development
  7834. machine where the development occurs.
  7835. You want the recipe's
  7836. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  7837. variable to point to the external directory and use it as is, not
  7838. copy it.
  7839. </para>
  7840. <para>
  7841. To build from software that comes from an external source, all you
  7842. need to do is inherit the
  7843. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
  7844. class and then set the
  7845. <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>
  7846. variable to point to your external source code.
  7847. Here are the statements to put in your
  7848. <filename>local.conf</filename> file:
  7849. <literallayout class='monospaced'>
  7850. INHERIT += "externalsrc"
  7851. EXTERNALSRC_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
  7852. </literallayout>
  7853. </para>
  7854. <para>
  7855. This next example shows how to accomplish the same thing by setting
  7856. <filename>EXTERNALSRC</filename> in the recipe itself or in the
  7857. recipe's append file:
  7858. <literallayout class='monospaced'>
  7859. EXTERNALSRC = "<replaceable>path</replaceable>"
  7860. EXTERNALSRC_BUILD = "<replaceable>path</replaceable>"
  7861. </literallayout>
  7862. <note>
  7863. In order for these settings to take effect, you must globally
  7864. or locally inherit the
  7865. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
  7866. class.
  7867. </note>
  7868. </para>
  7869. <para>
  7870. By default, <filename>externalsrc.bbclass</filename> builds
  7871. the source code in a directory separate from the external source
  7872. directory as specified by
  7873. <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>.
  7874. If you need to have the source built in the same directory in
  7875. which it resides, or some other nominated directory, you can set
  7876. <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC_BUILD'><filename>EXTERNALSRC_BUILD</filename></ulink>
  7877. to point to that directory:
  7878. <literallayout class='monospaced'>
  7879. EXTERNALSRC_BUILD_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
  7880. </literallayout>
  7881. </para>
  7882. </section>
  7883. <section id="selecting-an-initialization-manager">
  7884. <title>Selecting an Initialization Manager</title>
  7885. <para>
  7886. By default, the Yocto Project uses SysVinit as the initialization
  7887. manager.
  7888. However, support also exists for systemd,
  7889. which is a full replacement for init with
  7890. parallel starting of services, reduced shell overhead and other
  7891. features that are used by many distributions.
  7892. </para>
  7893. <para>
  7894. If you want to use SysVinit, you do
  7895. not have to do anything.
  7896. But, if you want to use systemd, you must
  7897. take some steps as described in the following sections.
  7898. </para>
  7899. <section id='using-systemd-exclusively'>
  7900. <title>Using systemd Exclusively</title>
  7901. <para>
  7902. Set the these variables in your distribution configuration
  7903. file as follows:
  7904. <literallayout class='monospaced'>
  7905. DISTRO_FEATURES_append = " systemd"
  7906. VIRTUAL-RUNTIME_init_manager = "systemd"
  7907. </literallayout>
  7908. You can also prevent the SysVinit
  7909. distribution feature from
  7910. being automatically enabled as follows:
  7911. <literallayout class='monospaced'>
  7912. DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
  7913. </literallayout>
  7914. Doing so removes any redundant SysVinit scripts.
  7915. </para>
  7916. <para>
  7917. To remove initscripts from your image altogether,
  7918. set this variable also:
  7919. <literallayout class='monospaced'>
  7920. VIRTUAL-RUNTIME_initscripts = ""
  7921. </literallayout>
  7922. </para>
  7923. <para>
  7924. For information on the backfill variable, see
  7925. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
  7926. </para>
  7927. </section>
  7928. <section id='using-systemd-for-the-main-image-and-using-sysvinit-for-the-rescue-image'>
  7929. <title>Using systemd for the Main Image and Using SysVinit for the Rescue Image</title>
  7930. <para>
  7931. Set these variables in your distribution configuration
  7932. file as follows:
  7933. <literallayout class='monospaced'>
  7934. DISTRO_FEATURES_append = " systemd"
  7935. VIRTUAL-RUNTIME_init_manager = "systemd"
  7936. </literallayout>
  7937. Doing so causes your main image to use the
  7938. <filename>packagegroup-core-boot.bb</filename> recipe and
  7939. systemd.
  7940. The rescue/minimal image cannot use this package group.
  7941. However, it can install SysVinit
  7942. and the appropriate packages will have support for both
  7943. systemd and SysVinit.
  7944. </para>
  7945. </section>
  7946. </section>
  7947. <section id="selecting-dev-manager">
  7948. <title>Selecting a Device Manager</title>
  7949. <para>
  7950. The Yocto Project provides multiple ways to manage the device
  7951. manager (<filename>/dev</filename>):
  7952. <itemizedlist>
  7953. <listitem><para><emphasis>Persistent and Pre-Populated<filename>/dev</filename>:</emphasis>
  7954. For this case, the <filename>/dev</filename> directory
  7955. is persistent and the required device nodes are created
  7956. during the build.
  7957. </para></listitem>
  7958. <listitem><para><emphasis>Use <filename>devtmpfs</filename> with a Device Manager:</emphasis>
  7959. For this case, the <filename>/dev</filename> directory
  7960. is provided by the kernel as an in-memory file system and
  7961. is automatically populated by the kernel at runtime.
  7962. Additional configuration of device nodes is done in user
  7963. space by a device manager like
  7964. <filename>udev</filename> or
  7965. <filename>busybox-mdev</filename>.
  7966. </para></listitem>
  7967. </itemizedlist>
  7968. </para>
  7969. <section id="static-dev-management">
  7970. <title>Using Persistent and Pre-Populated<filename>/dev</filename></title>
  7971. <para>
  7972. To use the static method for device population, you need to
  7973. set the
  7974. <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
  7975. variable to "0" as follows:
  7976. <literallayout class='monospaced'>
  7977. USE_DEVFS = "0"
  7978. </literallayout>
  7979. </para>
  7980. <para>
  7981. The content of the resulting <filename>/dev</filename>
  7982. directory is defined in a Device Table file.
  7983. The
  7984. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_DEVICE_TABLES'><filename>IMAGE_DEVICE_TABLES</filename></ulink>
  7985. variable defines the Device Table to use and should be set
  7986. in the machine or distro configuration file.
  7987. Alternatively, you can set this variable in your
  7988. <filename>local.conf</filename> configuration file.
  7989. </para>
  7990. <para>
  7991. If you do not define the
  7992. <filename>IMAGE_DEVICE_TABLES</filename> variable, the default
  7993. <filename>device_table-minimal.txt</filename> is used:
  7994. <literallayout class='monospaced'>
  7995. IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
  7996. </literallayout>
  7997. </para>
  7998. <para>
  7999. The population is handled by the <filename>makedevs</filename>
  8000. utility during image creation:
  8001. </para>
  8002. </section>
  8003. <section id="devtmpfs-dev-management">
  8004. <title>Using <filename>devtmpfs</filename> and a Device Manager</title>
  8005. <para>
  8006. To use the dynamic method for device population, you need to
  8007. use (or be sure to set) the
  8008. <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
  8009. variable to "1", which is the default:
  8010. <literallayout class='monospaced'>
  8011. USE_DEVFS = "1"
  8012. </literallayout>
  8013. With this setting, the resulting <filename>/dev</filename>
  8014. directory is populated by the kernel using
  8015. <filename>devtmpfs</filename>.
  8016. Make sure the corresponding kernel configuration variable
  8017. <filename>CONFIG_DEVTMPFS</filename> is set when building
  8018. you build a Linux kernel.
  8019. </para>
  8020. <para>
  8021. All devices created by <filename>devtmpfs</filename> will be
  8022. owned by <filename>root</filename> and have permissions
  8023. <filename>0600</filename>.
  8024. </para>
  8025. <para>
  8026. To have more control over the device nodes, you can use a
  8027. device manager like <filename>udev</filename> or
  8028. <filename>busybox-mdev</filename>.
  8029. You choose the device manager by defining the
  8030. <filename>VIRTUAL-RUNTIME_dev_manager</filename> variable
  8031. in your machine or distro configuration file.
  8032. Alternatively, you can set this variable in your
  8033. <filename>local.conf</filename> configuration file:
  8034. <literallayout class='monospaced'>
  8035. VIRTUAL-RUNTIME_dev_manager = "udev"
  8036. # Some alternative values
  8037. # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
  8038. # VIRTUAL-RUNTIME_dev_manager = "systemd"
  8039. </literallayout>
  8040. </para>
  8041. </section>
  8042. </section>
  8043. <section id="platdev-appdev-srcrev">
  8044. <title>Using an External SCM</title>
  8045. <para>
  8046. If you're working on a recipe that pulls from an external Source
  8047. Code Manager (SCM), it is possible to have the OpenEmbedded build
  8048. system notice new recipe changes added to the SCM and then build
  8049. the resulting packages that depend on the new recipes by using
  8050. the latest versions.
  8051. This only works for SCMs from which it is possible to get a
  8052. sensible revision number for changes.
  8053. Currently, you can do this with Apache Subversion (SVN), Git, and
  8054. Bazaar (BZR) repositories.
  8055. </para>
  8056. <para>
  8057. To enable this behavior, the
  8058. <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
  8059. of the recipe needs to reference
  8060. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
  8061. Here is an example:
  8062. <literallayout class='monospaced'>
  8063. PV = "1.2.3+git${SRCPV}"
  8064. </literallayout>
  8065. Then, you can add the following to your
  8066. <filename>local.conf</filename>:
  8067. <literallayout class='monospaced'>
  8068. SRCREV_pn-<replaceable>PN</replaceable> = "${AUTOREV}"
  8069. </literallayout>
  8070. <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
  8071. is the name of the recipe for which you want to enable automatic source
  8072. revision updating.
  8073. </para>
  8074. <para>
  8075. If you do not want to update your local configuration file, you can
  8076. add the following directly to the recipe to finish enabling
  8077. the feature:
  8078. <literallayout class='monospaced'>
  8079. SRCREV = "${AUTOREV}"
  8080. </literallayout>
  8081. </para>
  8082. <para>
  8083. The Yocto Project provides a distribution named
  8084. <filename>poky-bleeding</filename>, whose configuration
  8085. file contains the line:
  8086. <literallayout class='monospaced'>
  8087. require conf/distro/include/poky-floating-revisions.inc
  8088. </literallayout>
  8089. This line pulls in the listed include file that contains
  8090. numerous lines of exactly that form:
  8091. <literallayout class='monospaced'>
  8092. #SRCREV_pn-opkg-native ?= "${AUTOREV}"
  8093. #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
  8094. #SRCREV_pn-opkg ?= "${AUTOREV}"
  8095. #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
  8096. #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
  8097. SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
  8098. SRCREV_pn-matchbox-common ?= "${AUTOREV}"
  8099. SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
  8100. SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
  8101. SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
  8102. SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
  8103. SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
  8104. SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
  8105. SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
  8106. SRCREV_pn-settings-daemon ?= "${AUTOREV}"
  8107. SRCREV_pn-screenshot ?= "${AUTOREV}"
  8108. .
  8109. .
  8110. .
  8111. </literallayout>
  8112. These lines allow you to experiment with building a
  8113. distribution that tracks the latest development source
  8114. for numerous packages.
  8115. <note><title>Caution</title>
  8116. The <filename>poky-bleeding</filename> distribution
  8117. is not tested on a regular basis.
  8118. Keep this in mind if you use it.
  8119. </note>
  8120. </para>
  8121. </section>
  8122. <section id='creating-a-read-only-root-filesystem'>
  8123. <title>Creating a Read-Only Root Filesystem</title>
  8124. <para>
  8125. Suppose, for security reasons, you need to disable
  8126. your target device's root filesystem's write permissions
  8127. (i.e. you need a read-only root filesystem).
  8128. Or, perhaps you are running the device's operating system
  8129. from a read-only storage device.
  8130. For either case, you can customize your image for
  8131. that behavior.
  8132. </para>
  8133. <note>
  8134. Supporting a read-only root filesystem requires that the system and
  8135. applications do not try to write to the root filesystem.
  8136. You must configure all parts of the target system to write
  8137. elsewhere, or to gracefully fail in the event of attempting to
  8138. write to the root filesystem.
  8139. </note>
  8140. <section id='creating-the-root-filesystem'>
  8141. <title>Creating the Root Filesystem</title>
  8142. <para>
  8143. To create the read-only root filesystem, simply add the
  8144. "read-only-rootfs" feature to your image.
  8145. Using either of the following statements in your
  8146. image recipe or from within the
  8147. <filename>local.conf</filename> file found in the
  8148. <link linkend='build-directory'>Build Directory</link>
  8149. causes the build system to create a read-only root filesystem:
  8150. <literallayout class='monospaced'>
  8151. IMAGE_FEATURES = "read-only-rootfs"
  8152. </literallayout>
  8153. or
  8154. <literallayout class='monospaced'>
  8155. EXTRA_IMAGE_FEATURES += "read-only-rootfs"
  8156. </literallayout>
  8157. </para>
  8158. <para>
  8159. For more information on how to use these variables, see the
  8160. "<link linkend='usingpoky-extend-customimage-imagefeatures'>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and <filename>EXTRA_IMAGE_FEATURES</filename></link>"
  8161. section.
  8162. For information on the variables, see
  8163. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
  8164. and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>.
  8165. </para>
  8166. </section>
  8167. <section id='post-installation-scripts'>
  8168. <title>Post-Installation Scripts</title>
  8169. <para>
  8170. It is very important that you make sure all
  8171. post-Installation (<filename>pkg_postinst</filename>) scripts
  8172. for packages that are installed into the image can be run
  8173. at the time when the root filesystem is created during the
  8174. build on the host system.
  8175. These scripts cannot attempt to run during first-boot on the
  8176. target device.
  8177. With the "read-only-rootfs" feature enabled,
  8178. the build system checks during root filesystem creation to make
  8179. sure all post-installation scripts succeed.
  8180. If any of these scripts still need to be run after the root
  8181. filesystem is created, the build immediately fails.
  8182. These build-time checks ensure that the build fails
  8183. rather than the target device fails later during its
  8184. initial boot operation.
  8185. </para>
  8186. <para>
  8187. Most of the common post-installation scripts generated by the
  8188. build system for the out-of-the-box Yocto Project are engineered
  8189. so that they can run during root filesystem creation
  8190. (e.g. post-installation scripts for caching fonts).
  8191. However, if you create and add custom scripts, you need
  8192. to be sure they can be run during this file system creation.
  8193. </para>
  8194. <para>
  8195. Here are some common problems that prevent
  8196. post-installation scripts from running during root filesystem
  8197. creation:
  8198. <itemizedlist>
  8199. <listitem><para>
  8200. <emphasis>Not using $D in front of absolute
  8201. paths:</emphasis>
  8202. The build system defines
  8203. <filename>$</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
  8204. when the root filesystem is created.
  8205. Furthermore, <filename>$D</filename> is blank when the
  8206. script is run on the target device.
  8207. This implies two purposes for <filename>$D</filename>:
  8208. ensuring paths are valid in both the host and target
  8209. environments, and checking to determine which
  8210. environment is being used as a method for taking
  8211. appropriate actions.
  8212. </para></listitem>
  8213. <listitem><para>
  8214. <emphasis>Attempting to run processes that are
  8215. specific to or dependent on the target
  8216. architecture:</emphasis>
  8217. You can work around these attempts by using native
  8218. tools, which run on the host system,
  8219. to accomplish the same tasks, or
  8220. by alternatively running the processes under QEMU,
  8221. which has the <filename>qemu_run_binary</filename>
  8222. function.
  8223. For more information, see the
  8224. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-qemu'><filename>qemu</filename></ulink>
  8225. class.</para></listitem>
  8226. </itemizedlist>
  8227. </para>
  8228. </section>
  8229. <section id='areas-with-write-access'>
  8230. <title>Areas With Write Access</title>
  8231. <para>
  8232. With the "read-only-rootfs" feature enabled,
  8233. any attempt by the target to write to the root filesystem at
  8234. runtime fails.
  8235. Consequently, you must make sure that you configure processes
  8236. and applications that attempt these types of writes do so
  8237. to directories with write access (e.g.
  8238. <filename>/tmp</filename> or <filename>/var/run</filename>).
  8239. </para>
  8240. </section>
  8241. </section>
  8242. <section id="performing-automated-runtime-testing">
  8243. <title>Performing Automated Runtime Testing</title>
  8244. <para>
  8245. The OpenEmbedded build system makes available a series of automated
  8246. tests for images to verify runtime functionality.
  8247. You can run these tests on either QEMU or actual target hardware.
  8248. Tests are written in Python making use of the
  8249. <filename>unittest</filename> module, and the majority of them
  8250. run commands on the target system over SSH.
  8251. This section describes how you set up the environment to use these
  8252. tests, run available tests, and write and add your own tests.
  8253. </para>
  8254. <section id='enabling-tests'>
  8255. <title>Enabling Tests</title>
  8256. <para>
  8257. Depending on whether you are planning to run tests using
  8258. QEMU or on the hardware, you have to take
  8259. different steps to enable the tests.
  8260. See the following subsections for information on how to
  8261. enable both types of tests.
  8262. </para>
  8263. <section id='qemu-image-enabling-tests'>
  8264. <title>Enabling Runtime Tests on QEMU</title>
  8265. <para>
  8266. In order to run tests, you need to do the following:
  8267. <itemizedlist>
  8268. <listitem><para><emphasis>Set up to avoid interaction
  8269. with <filename>sudo</filename> for networking:</emphasis>
  8270. To accomplish this, you must do one of the
  8271. following:
  8272. <itemizedlist>
  8273. <listitem><para>Add
  8274. <filename>NOPASSWD</filename> for your user
  8275. in <filename>/etc/sudoers</filename> either for
  8276. all commands or just for
  8277. <filename>runqemu-ifup</filename>.
  8278. You must provide the full path as that can
  8279. change if you are using multiple clones of the
  8280. source repository.
  8281. <note>
  8282. On some distributions, you also need to
  8283. comment out "Defaults requiretty" in
  8284. <filename>/etc/sudoers</filename>.
  8285. </note></para></listitem>
  8286. <listitem><para>Manually configure a tap interface
  8287. for your system.</para></listitem>
  8288. <listitem><para>Run as root the script in
  8289. <filename>scripts/runqemu-gen-tapdevs</filename>,
  8290. which should generate a list of tap devices.
  8291. This is the option typically chosen for
  8292. Autobuilder-type environments.
  8293. </para></listitem>
  8294. </itemizedlist></para></listitem>
  8295. <listitem><para><emphasis>Set the
  8296. <filename>DISPLAY</filename> variable:</emphasis>
  8297. You need to set this variable so that you have an X
  8298. server available (e.g. start
  8299. <filename>vncserver</filename> for a headless machine).
  8300. </para></listitem>
  8301. <listitem><para><emphasis>Be sure your host's firewall
  8302. accepts incoming connections from
  8303. 192.168.7.0/24:</emphasis>
  8304. Some of the tests (in particular smart tests) start an
  8305. HTTP server on a random high number port, which is
  8306. used to serve files to the target.
  8307. The smart module serves
  8308. <filename>${DEPLOY_DIR}/rpm</filename> so it can run
  8309. smart channel commands. That means your host's firewall
  8310. must accept incoming connections from 192.168.7.0/24,
  8311. which is the default IP range used for tap devices
  8312. by <filename>runqemu</filename>.</para></listitem>
  8313. <listitem><para><emphasis>Be sure your host has the
  8314. correct packages installed:</emphasis>
  8315. Depending your host's distribution, you need
  8316. to have the following packages installed:
  8317. <itemizedlist>
  8318. <listitem><para>Ubuntu and Debian:
  8319. <filename>sysstat</filename> and
  8320. <filename>iproute2</filename>
  8321. </para></listitem>
  8322. <listitem><para>OpenSUSE:
  8323. <filename>sysstat</filename> and
  8324. <filename>iproute2</filename>
  8325. </para></listitem>
  8326. <listitem><para>Fedora:
  8327. <filename>sysstat</filename> and
  8328. <filename>iproute</filename>
  8329. </para></listitem>
  8330. <listitem><para>CentOS:
  8331. <filename>sysstat</filename> and
  8332. <filename>iproute</filename>
  8333. </para></listitem>
  8334. </itemizedlist>
  8335. </para></listitem>
  8336. </itemizedlist>
  8337. </para>
  8338. <para>
  8339. Once you start running the tests, the following happens:
  8340. <orderedlist>
  8341. <listitem><para>A copy of the root filesystem is written
  8342. to <filename>${WORKDIR}/testimage</filename>.
  8343. </para></listitem>
  8344. <listitem><para>The image is booted under QEMU using the
  8345. standard <filename>runqemu</filename> script.
  8346. </para></listitem>
  8347. <listitem><para>A default timeout of 500 seconds occurs
  8348. to allow for the boot process to reach the login prompt.
  8349. You can change the timeout period by setting
  8350. <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_QEMUBOOT_TIMEOUT'><filename>TEST_QEMUBOOT_TIMEOUT</filename></ulink>
  8351. in the <filename>local.conf</filename> file.
  8352. </para></listitem>
  8353. <listitem><para>Once the boot process is reached and the
  8354. login prompt appears, the tests run.
  8355. The full boot log is written to
  8356. <filename>${WORKDIR}/testimage/qemu_boot_log</filename>.
  8357. </para></listitem>
  8358. <listitem><para>Each test module loads in the order found
  8359. in <filename>TEST_SUITES</filename>.
  8360. You can find the full output of the commands run over
  8361. SSH in
  8362. <filename>${WORKDIR}/testimgage/ssh_target_log</filename>.
  8363. </para></listitem>
  8364. <listitem><para>If no failures occur, the task running the
  8365. tests ends successfully.
  8366. You can find the output from the
  8367. <filename>unittest</filename> in the task log at
  8368. <filename>${WORKDIR}/temp/log.do_testimage</filename>.
  8369. </para></listitem>
  8370. </orderedlist>
  8371. </para>
  8372. </section>
  8373. <section id='hardware-image-enabling-tests'>
  8374. <title>Enabling Runtime Tests on Hardware</title>
  8375. <para>
  8376. The OpenEmbedded build system can run tests on real
  8377. hardware, and for certain devices it can also deploy
  8378. the image to be tested onto the device beforehand.
  8379. </para>
  8380. <para>
  8381. For automated deployment, a "master image" is installed
  8382. onto the hardware once as part of setup.
  8383. Then, each time tests are to be run, the following
  8384. occurs:
  8385. <orderedlist>
  8386. <listitem><para>The master image is booted into and
  8387. used to write the image to be tested to
  8388. a second partition.
  8389. </para></listitem>
  8390. <listitem><para>The device is then rebooted using an
  8391. external script that you need to provide.
  8392. </para></listitem>
  8393. <listitem><para>The device boots into the image to be
  8394. tested.
  8395. </para></listitem>
  8396. </orderedlist>
  8397. </para>
  8398. <para>
  8399. When running tests (independent of whether the image
  8400. has been deployed automatically or not), the device is
  8401. expected to be connected to a network on a
  8402. pre-determined IP address.
  8403. You can either use static IP addresses written into
  8404. the image, or set the image to use DHCP and have your
  8405. DHCP server on the test network assign a known IP address
  8406. based on the MAC address of the device.
  8407. </para>
  8408. <para>
  8409. In order to run tests on hardware, you need to set
  8410. <filename>TEST_TARGET</filename> to an appropriate value.
  8411. For QEMU, you do not have to change anything, the default
  8412. value is "QemuTarget".
  8413. For running tests on hardware, the following options exist:
  8414. <itemizedlist>
  8415. <listitem><para><emphasis>"SimpleRemoteTarget":</emphasis>
  8416. Choose "SimpleRemoteTarget" if you are going to
  8417. run tests on a target system that is already
  8418. running the image to be tested and is available
  8419. on the network.
  8420. You can use "SimpleRemoteTarget" in conjunction
  8421. with either real hardware or an image running
  8422. within a separately started QEMU or any
  8423. other virtual machine manager.
  8424. </para></listitem>
  8425. <listitem><para><emphasis>"Systemd-bootTarget":</emphasis>
  8426. Choose "Systemd-bootTarget" if your hardware is
  8427. an EFI-based machine with
  8428. <filename>systemd-boot</filename> as bootloader and
  8429. <filename>core-image-testmaster</filename>
  8430. (or something similar) is installed.
  8431. Also, your hardware under test must be in a
  8432. DHCP-enabled network that gives it the same IP
  8433. address for each reboot.</para>
  8434. <para>If you choose "Systemd-bootTarget", there are
  8435. additional requirements and considerations.
  8436. See the
  8437. "<link linkend='selecting-systemd-boottarget'>Selecting Systemd-bootTarget</link>"
  8438. section, which follows, for more information.
  8439. </para></listitem>
  8440. <listitem><para><emphasis>"BeagleBoneTarget":</emphasis>
  8441. Choose "BeagleBoneTarget" if you are deploying
  8442. images and running tests on the BeagleBone
  8443. "Black" or original "White" hardware.
  8444. For information on how to use these tests, see the
  8445. comments at the top of the BeagleBoneTarget
  8446. <filename>meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py</filename>
  8447. file.
  8448. </para></listitem>
  8449. <listitem><para><emphasis>"EdgeRouterTarget":</emphasis>
  8450. Choose "EdgeRouterTarget" is you are deploying
  8451. images and running tests on the Ubiquiti Networks
  8452. EdgeRouter Lite.
  8453. For information on how to use these tests, see the
  8454. comments at the top of the EdgeRouterTarget
  8455. <filename>meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py</filename>
  8456. file.
  8457. </para></listitem>
  8458. <listitem><para><emphasis>"GrubTarget":</emphasis>
  8459. Choose the "supports deploying images and running
  8460. tests on any generic PC that boots using GRUB.
  8461. For information on how to use these tests, see the
  8462. comments at the top of the GrubTarget
  8463. <filename>meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py</filename>
  8464. file.
  8465. </para></listitem>
  8466. <listitem><para><emphasis>"<replaceable>your-target</replaceable>":</emphasis>
  8467. Create your own custom target if you want to run
  8468. tests when you are deploying images and running
  8469. tests on a custom machine within your BSP layer.
  8470. To do this, you need to add a Python unit that
  8471. defines the target class under
  8472. <filename>lib/oeqa/controllers/</filename> within
  8473. your layer.
  8474. You must also provide an empty
  8475. <filename>__init__.py</filename>.
  8476. For examples, see files in
  8477. <filename>meta-yocto-bsp/lib/oeqa/controllers/</filename>.
  8478. </para></listitem>
  8479. </itemizedlist>
  8480. </para>
  8481. </section>
  8482. <section id='selecting-systemd-boottarget'>
  8483. <title>Selecting Systemd-bootTarget</title>
  8484. <para>
  8485. If you did not set <filename>TEST_TARGET</filename> to
  8486. "Systemd-bootTarget", then you do not need any information
  8487. in this section.
  8488. You can skip down to the
  8489. "<link linkend='qemu-image-running-tests'>Running Tests</link>"
  8490. section.
  8491. </para>
  8492. <para>
  8493. If you did set <filename>TEST_TARGET</filename> to
  8494. "Systemd-bootTarget", you also need to perform a one-time
  8495. setup of your master image by doing the following:
  8496. <orderedlist>
  8497. <listitem><para><emphasis>Set <filename>EFI_PROVIDER</filename>:</emphasis>
  8498. Be sure that <filename>EFI_PROVIDER</filename>
  8499. is as follows:
  8500. <literallayout class='monospaced'>
  8501. EFI_PROVIDER = "systemd-boot"
  8502. </literallayout>
  8503. </para></listitem>
  8504. <listitem><para><emphasis>Build the master image:</emphasis>
  8505. Build the <filename>core-image-testmaster</filename>
  8506. image.
  8507. The <filename>core-image-testmaster</filename>
  8508. recipe is provided as an example for a
  8509. "master" image and you can customize the image
  8510. recipe as you would any other recipe.
  8511. </para>
  8512. <para>Here are the image recipe requirements:
  8513. <itemizedlist>
  8514. <listitem><para>Inherits
  8515. <filename>core-image</filename>
  8516. so that kernel modules are installed.
  8517. </para></listitem>
  8518. <listitem><para>Installs normal linux utilities
  8519. not busybox ones (e.g.
  8520. <filename>bash</filename>,
  8521. <filename>coreutils</filename>,
  8522. <filename>tar</filename>,
  8523. <filename>gzip</filename>, and
  8524. <filename>kmod</filename>).
  8525. </para></listitem>
  8526. <listitem><para>Uses a custom
  8527. Initial RAM Disk (initramfs) image with a
  8528. custom installer.
  8529. A normal image that you can install usually
  8530. creates a single rootfs partition.
  8531. This image uses another installer that
  8532. creates a specific partition layout.
  8533. Not all Board Support Packages (BSPs)
  8534. can use an installer.
  8535. For such cases, you need to manually create
  8536. the following partition layout on the
  8537. target:
  8538. <itemizedlist>
  8539. <listitem><para>First partition mounted
  8540. under <filename>/boot</filename>,
  8541. labeled "boot".
  8542. </para></listitem>
  8543. <listitem><para>The main rootfs
  8544. partition where this image gets
  8545. installed, which is mounted under
  8546. <filename>/</filename>.
  8547. </para></listitem>
  8548. <listitem><para>Another partition
  8549. labeled "testrootfs" where test
  8550. images get deployed.
  8551. </para></listitem>
  8552. </itemizedlist>
  8553. </para></listitem>
  8554. </itemizedlist>
  8555. </para></listitem>
  8556. <listitem><para><emphasis>Install image:</emphasis>
  8557. Install the image that you just built on the target
  8558. system.
  8559. </para></listitem>
  8560. </orderedlist>
  8561. </para>
  8562. <para>
  8563. The final thing you need to do when setting
  8564. <filename>TEST_TARGET</filename> to "Systemd-bootTarget" is
  8565. to set up the test image:
  8566. <orderedlist>
  8567. <listitem><para><emphasis>Set up your <filename>local.conf</filename> file:</emphasis>
  8568. Make sure you have the following statements in
  8569. your <filename>local.conf</filename> file:
  8570. <literallayout class='monospaced'>
  8571. IMAGE_FSTYPES += "tar.gz"
  8572. INHERIT += "testimage"
  8573. TEST_TARGET = "Systemd-bootTarget"
  8574. TEST_TARGET_IP = "192.168.2.3"
  8575. </literallayout>
  8576. </para></listitem>
  8577. <listitem><para><emphasis>Build your test image:</emphasis>
  8578. Use BitBake to build the image:
  8579. <literallayout class='monospaced'>
  8580. $ bitbake core-image-sato
  8581. </literallayout>
  8582. </para></listitem>
  8583. </orderedlist>
  8584. </para>
  8585. </section>
  8586. <section id='power-control'>
  8587. <title>Power Control</title>
  8588. <para>
  8589. For most hardware targets other than SimpleRemoteTarget,
  8590. you can control power:
  8591. <itemizedlist>
  8592. <listitem><para>
  8593. You can use
  8594. <filename>TEST_POWERCONTROL_CMD</filename>
  8595. together with
  8596. <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
  8597. as a command that runs on the host and does power
  8598. cycling.
  8599. The test code passes one argument to that command:
  8600. off, on or cycle (off then on).
  8601. Here is an example that could appear in your
  8602. <filename>local.conf</filename> file:
  8603. <literallayout class='monospaced'>
  8604. TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
  8605. </literallayout>
  8606. In this example, the expect script does the
  8607. following:
  8608. <literallayout class='monospaced'>
  8609. ssh test@10.11.12.1 "pyctl nuc1 <replaceable>arg</replaceable>"
  8610. </literallayout>
  8611. It then runs a Python script that controls power
  8612. for a label called <filename>nuc1</filename>.
  8613. <note>
  8614. You need to customize
  8615. <filename>TEST_POWERCONTROL_CMD</filename>
  8616. and
  8617. <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
  8618. for your own setup.
  8619. The one requirement is that it accepts
  8620. "on", "off", and "cycle" as the last argument.
  8621. </note>
  8622. </para></listitem>
  8623. <listitem><para>
  8624. When no command is defined, it connects to the
  8625. device over SSH and uses the classic reboot command
  8626. to reboot the device.
  8627. Classic reboot is fine as long as the machine
  8628. actually reboots (i.e. the SSH test has not
  8629. failed).
  8630. It is useful for scenarios where you have a simple
  8631. setup, typically with a single board, and where
  8632. some manual interaction is okay from time to time.
  8633. </para></listitem>
  8634. </itemizedlist>
  8635. If you have no hardware to automatically perform power
  8636. control but still wish to experiment with automated
  8637. hardware testing, you can use the dialog-power-control
  8638. script that shows a dialog prompting you to perform the
  8639. required power action.
  8640. This script requires either KDialog or Zenity to be
  8641. installed.
  8642. To use this script, set the
  8643. <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_POWERCONTROL_CMD'><filename>TEST_POWERCONTROL_CMD</filename></ulink>
  8644. variable as follows:
  8645. <literallayout class='monospaced'>
  8646. TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
  8647. </literallayout>
  8648. </para>
  8649. </section>
  8650. <section id='serial-console-connection'>
  8651. <title>Serial Console Connection</title>
  8652. <para>
  8653. For test target classes requiring a serial console
  8654. to interact with the bootloader (e.g. BeagleBoneTarget,
  8655. EdgeRouterTarget, and GrubTarget), you need to
  8656. specify a command to use to connect to the serial console
  8657. of the target machine by using the
  8658. <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_CMD'><filename>TEST_SERIALCONTROL_CMD</filename></ulink>
  8659. variable and optionally the
  8660. <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_EXTRA_ARGS'><filename>TEST_SERIALCONTROL_EXTRA_ARGS</filename></ulink>
  8661. variable.
  8662. </para>
  8663. <para>
  8664. These cases could be a serial terminal program if the
  8665. machine is connected to a local serial port, or a
  8666. <filename>telnet</filename> or
  8667. <filename>ssh</filename> command connecting to a remote
  8668. console server.
  8669. Regardless of the case, the command simply needs to
  8670. connect to the serial console and forward that connection
  8671. to standard input and output as any normal terminal
  8672. program does.
  8673. For example, to use the picocom terminal program on
  8674. serial device <filename>/dev/ttyUSB0</filename>
  8675. at 115200bps, you would set the variable as follows:
  8676. <literallayout class='monospaced'>
  8677. TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
  8678. </literallayout>
  8679. For local devices where the serial port device disappears
  8680. when the device reboots, an additional "serdevtry" wrapper
  8681. script is provided.
  8682. To use this wrapper, simply prefix the terminal command
  8683. with
  8684. <filename>${COREBASE}/scripts/contrib/serdevtry</filename>:
  8685. <literallayout class='monospaced'>
  8686. TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b
  8687. 115200 /dev/ttyUSB0"
  8688. </literallayout>
  8689. </para>
  8690. </section>
  8691. </section>
  8692. <section id="qemu-image-running-tests">
  8693. <title>Running Tests</title>
  8694. <para>
  8695. You can start the tests automatically or manually:
  8696. <itemizedlist>
  8697. <listitem><para><emphasis>Automatically running tests:</emphasis>
  8698. To run the tests automatically after the
  8699. OpenEmbedded build system successfully creates an image,
  8700. first set the
  8701. <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_IMAGE'><filename>TEST_IMAGE</filename></ulink>
  8702. variable to "1" in your <filename>local.conf</filename>
  8703. file in the
  8704. <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>:
  8705. <literallayout class='monospaced'>
  8706. TEST_IMAGE = "1"
  8707. </literallayout>
  8708. Next, build your image.
  8709. If the image successfully builds, the tests will be
  8710. run:
  8711. <literallayout class='monospaced'>
  8712. bitbake core-image-sato
  8713. </literallayout></para></listitem>
  8714. <listitem><para><emphasis>Manually running tests:</emphasis>
  8715. To manually run the tests, first globally inherit the
  8716. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
  8717. class by editing your <filename>local.conf</filename>
  8718. file:
  8719. <literallayout class='monospaced'>
  8720. INHERIT += "testimage"
  8721. </literallayout>
  8722. Next, use BitBake to run the tests:
  8723. <literallayout class='monospaced'>
  8724. bitbake -c testimage <replaceable>image</replaceable>
  8725. </literallayout></para></listitem>
  8726. </itemizedlist>
  8727. </para>
  8728. <para>
  8729. All test files reside in
  8730. <filename>meta/lib/oeqa/runtime</filename> in the
  8731. <link linkend='source-directory'>Source Directory</link>.
  8732. A test name maps directly to a Python module.
  8733. Each test module may contain a number of individual tests.
  8734. Tests are usually grouped together by the area
  8735. tested (e.g tests for systemd reside in
  8736. <filename>meta/lib/oeqa/runtime/systemd.py</filename>).
  8737. </para>
  8738. <para>
  8739. You can add tests to any layer provided you place them in the
  8740. proper area and you extend
  8741. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
  8742. in the <filename>local.conf</filename> file as normal.
  8743. Be sure that tests reside in
  8744. <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>.
  8745. <note>
  8746. Be sure that module names do not collide with module names
  8747. used in the default set of test modules in
  8748. <filename>meta/lib/oeqa/runtime</filename>.
  8749. </note>
  8750. </para>
  8751. <para>
  8752. You can change the set of tests run by appending or overriding
  8753. <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>
  8754. variable in <filename>local.conf</filename>.
  8755. Each name in <filename>TEST_SUITES</filename> represents a
  8756. required test for the image.
  8757. Test modules named within <filename>TEST_SUITES</filename>
  8758. cannot be skipped even if a test is not suitable for an image
  8759. (e.g. running the RPM tests on an image without
  8760. <filename>rpm</filename>).
  8761. Appending "auto" to <filename>TEST_SUITES</filename> causes the
  8762. build system to try to run all tests that are suitable for the
  8763. image (i.e. each test module may elect to skip itself).
  8764. </para>
  8765. <para>
  8766. The order you list tests in <filename>TEST_SUITES</filename>
  8767. is important and influences test dependencies.
  8768. Consequently, tests that depend on other tests should be added
  8769. after the test on which they depend.
  8770. For example, since the <filename>ssh</filename> test
  8771. depends on the
  8772. <filename>ping</filename> test, "ssh" needs to come after
  8773. "ping" in the list.
  8774. The test class provides no re-ordering or dependency handling.
  8775. <note>
  8776. Each module can have multiple classes with multiple test
  8777. methods.
  8778. And, Python <filename>unittest</filename> rules apply.
  8779. </note>
  8780. </para>
  8781. <para>
  8782. Here are some things to keep in mind when running tests:
  8783. <itemizedlist>
  8784. <listitem><para>The default tests for the image are defined
  8785. as:
  8786. <literallayout class='monospaced'>
  8787. DEFAULT_TEST_SUITES_pn-<replaceable>image</replaceable> = "ping ssh df connman syslog xorg scp vnc date rpm smart dmesg"
  8788. </literallayout></para></listitem>
  8789. <listitem><para>Add your own test to the list of the
  8790. by using the following:
  8791. <literallayout class='monospaced'>
  8792. TEST_SUITES_append = " mytest"
  8793. </literallayout></para></listitem>
  8794. <listitem><para>Run a specific list of tests as follows:
  8795. <literallayout class='monospaced'>
  8796. TEST_SUITES = "test1 test2 test3"
  8797. </literallayout>
  8798. Remember, order is important.
  8799. Be sure to place a test that is dependent on another test
  8800. later in the order.</para></listitem>
  8801. </itemizedlist>
  8802. </para>
  8803. </section>
  8804. <section id="exporting-tests">
  8805. <title>Exporting Tests</title>
  8806. <para>
  8807. You can export tests so that they can run independently of
  8808. the build system.
  8809. Exporting tests is required if you want to be able to hand
  8810. the test execution off to a scheduler.
  8811. You can only export tests that are defined in
  8812. <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>.
  8813. </para>
  8814. <para>
  8815. If your image is already built, make sure the following are set
  8816. in your <filename>local.conf</filename> file.
  8817. Be sure to provide the IP address you need:
  8818. <literallayout class='monospaced'>
  8819. INHERIT +="testexport"
  8820. TEST_TARGET_IP = "192.168.7.2"
  8821. TEST_SERVER_IP = "192.168.7.1"
  8822. </literallayout>
  8823. You can then export the tests with the following:
  8824. <literallayout class='monospaced'>
  8825. $ bitbake core-image-sato -c testexport
  8826. </literallayout>
  8827. Exporting the tests places them in the
  8828. <link linkend='build-directory'>Build Directory</link> in
  8829. <filename>tmp/testexport/core-image-sato</filename>, which
  8830. is controlled by the
  8831. <filename>TEST_EXPORT_DIR</filename> variable.
  8832. </para>
  8833. <para>
  8834. You can now run the tests outside of the build environment:
  8835. <literallayout class='monospaced'>
  8836. $ cd tmp/testexport/core-image-sato
  8837. $ ./runexported.py testdata.json
  8838. </literallayout>
  8839. </para>
  8840. </section>
  8841. <section id="qemu-image-writing-new-tests">
  8842. <title>Writing New Tests</title>
  8843. <para>
  8844. As mentioned previously, all new test files need to be in the
  8845. proper place for the build system to find them.
  8846. New tests for additional functionality outside of the core
  8847. should be added to the layer that adds the functionality, in
  8848. <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>
  8849. (as long as
  8850. <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
  8851. is extended in the layer's
  8852. <filename>layer.conf</filename> file as normal).
  8853. Just remember the following:
  8854. <itemizedlist>
  8855. <listitem><para>Filenames need to map directly to test
  8856. (module) names.
  8857. </para></listitem>
  8858. <listitem><para>Do not use module names that
  8859. collide with existing core tests.
  8860. </para></listitem>
  8861. <listitem><para>Minimally, an empty
  8862. <filename>__init__.py</filename> file must exist
  8863. in the runtime directory.
  8864. </para></listitem>
  8865. </itemizedlist>
  8866. </para>
  8867. <para>
  8868. To create a new test, start by copying an existing module
  8869. (e.g. <filename>syslog.py</filename> or
  8870. <filename>gcc.py</filename> are good ones to use).
  8871. Test modules can use code from
  8872. <filename>meta/lib/oeqa/utils</filename>, which are helper
  8873. classes.
  8874. </para>
  8875. <note>
  8876. Structure shell commands such that you rely on them and they
  8877. return a single code for success.
  8878. Be aware that sometimes you will need to parse the output.
  8879. See the <filename>df.py</filename> and
  8880. <filename>date.py</filename> modules for examples.
  8881. </note>
  8882. <para>
  8883. You will notice that all test classes inherit
  8884. <filename>oeRuntimeTest</filename>, which is found in
  8885. <filename>meta/lib/oetest.py</filename>.
  8886. This base class offers some helper attributes, which are
  8887. described in the following sections:
  8888. </para>
  8889. <section id='qemu-image-writing-tests-class-methods'>
  8890. <title>Class Methods</title>
  8891. <para>
  8892. Class methods are as follows:
  8893. <itemizedlist>
  8894. <listitem><para><emphasis><filename>hasPackage(pkg)</filename>:</emphasis>
  8895. Returns "True" if <filename>pkg</filename> is in the
  8896. installed package list of the image, which is based
  8897. on the manifest file that is generated during the
  8898. <filename>do_rootfs</filename> task.
  8899. </para></listitem>
  8900. <listitem><para><emphasis><filename>hasFeature(feature)</filename>:</emphasis>
  8901. Returns "True" if the feature is in
  8902. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
  8903. or
  8904. <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>.
  8905. </para></listitem>
  8906. </itemizedlist>
  8907. </para>
  8908. </section>
  8909. <section id='qemu-image-writing-tests-class-attributes'>
  8910. <title>Class Attributes</title>
  8911. <para>
  8912. Class attributes are as follows:
  8913. <itemizedlist>
  8914. <listitem><para><emphasis><filename>pscmd</filename>:</emphasis>
  8915. Equals "ps -ef" if <filename>procps</filename> is
  8916. installed in the image.
  8917. Otherwise, <filename>pscmd</filename> equals
  8918. "ps" (busybox).
  8919. </para></listitem>
  8920. <listitem><para><emphasis><filename>tc</filename>:</emphasis>
  8921. The called test context, which gives access to the
  8922. following attributes:
  8923. <itemizedlist>
  8924. <listitem><para><emphasis><filename>d</filename>:</emphasis>
  8925. The BitBake datastore, which allows you to
  8926. use stuff such as
  8927. <filename>oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")</filename>.
  8928. </para></listitem>
  8929. <listitem><para><emphasis><filename>testslist</filename> and <filename>testsrequired</filename>:</emphasis>
  8930. Used internally.
  8931. The tests do not need these.
  8932. </para></listitem>
  8933. <listitem><para><emphasis><filename>filesdir</filename>:</emphasis>
  8934. The absolute path to
  8935. <filename>meta/lib/oeqa/runtime/files</filename>,
  8936. which contains helper files for tests meant
  8937. for copying on the target such as small
  8938. files written in C for compilation.
  8939. </para></listitem>
  8940. <listitem><para><emphasis><filename>target</filename>:</emphasis>
  8941. The target controller object used to deploy
  8942. and start an image on a particular target
  8943. (e.g. QemuTarget, SimpleRemote, and
  8944. Systemd-bootTarget).
  8945. Tests usually use the following:
  8946. <itemizedlist>
  8947. <listitem><para><emphasis><filename>ip</filename>:</emphasis>
  8948. The target's IP address.
  8949. </para></listitem>
  8950. <listitem><para><emphasis><filename>server_ip</filename>:</emphasis>
  8951. The host's IP address, which is
  8952. usually used by the "smart" test
  8953. suite.
  8954. </para></listitem>
  8955. <listitem><para><emphasis><filename>run(cmd, timeout=None)</filename>:</emphasis>
  8956. The single, most used method.
  8957. This command is a wrapper for:
  8958. <filename>ssh root@host "cmd"</filename>.
  8959. The command returns a tuple:
  8960. (status, output), which are what
  8961. their names imply - the return code
  8962. of "cmd" and whatever output
  8963. it produces.
  8964. The optional timeout argument
  8965. represents the number of seconds the
  8966. test should wait for "cmd" to
  8967. return.
  8968. If the argument is "None", the
  8969. test uses the default instance's
  8970. timeout period, which is 300
  8971. seconds.
  8972. If the argument is "0", the test
  8973. runs until the command returns.
  8974. </para></listitem>
  8975. <listitem><para><emphasis><filename>copy_to(localpath, remotepath)</filename>:</emphasis>
  8976. <filename>scp localpath root@ip:remotepath</filename>.
  8977. </para></listitem>
  8978. <listitem><para><emphasis><filename>copy_from(remotepath, localpath)</filename>:</emphasis>
  8979. <filename>scp root@host:remotepath localpath</filename>.
  8980. </para></listitem>
  8981. </itemizedlist></para></listitem>
  8982. </itemizedlist></para></listitem>
  8983. </itemizedlist>
  8984. </para>
  8985. </section>
  8986. <section id='qemu-image-writing-tests-instance-attributes'>
  8987. <title>Instance Attributes</title>
  8988. <para>
  8989. A single instance attribute exists, which is
  8990. <filename>target</filename>.
  8991. The <filename>target</filename> instance attribute is
  8992. identical to the class attribute of the same name, which
  8993. is described in the previous section.
  8994. This attribute exists as both an instance and class
  8995. attribute so tests can use
  8996. <filename>self.target.run(cmd)</filename> in instance
  8997. methods instead of
  8998. <filename>oeRuntimeTest.tc.target.run(cmd)</filename>.
  8999. </para>
  9000. </section>
  9001. </section>
  9002. <section id='installing-packages-in-the-dut-without-the-package-manager'>
  9003. <title>Installing Packages in the DUT Without the Package Manager</title>
  9004. <para>
  9005. When a test requires a package built by BitBake, it is possible
  9006. to install that package.
  9007. Installing the package does not require a package manager be
  9008. installed in the device under test (DUT).
  9009. It does, however, require an SSH connection and the target must
  9010. be using the <filename>sshcontrol</filename> class.
  9011. <note>
  9012. This method uses <filename>scp</filename> to copy files
  9013. from the host to the target, which causes permissions and
  9014. special attributes to be lost.
  9015. </note>
  9016. </para>
  9017. <para>
  9018. A JSON file is used to define the packages needed by a test.
  9019. This file must be in the same path as the file used to define
  9020. the tests.
  9021. Furthermore, the filename must map directly to the test
  9022. module name with a <filename>.json</filename> extension.
  9023. </para>
  9024. <para>
  9025. The JSON file must include an object with the test name as
  9026. keys of an object or an array.
  9027. This object (or array of objects) uses the following data:
  9028. <itemizedlist>
  9029. <listitem><para>"pkg" - A mandatory string that is the
  9030. name of the package to be installed.
  9031. </para></listitem>
  9032. <listitem><para>"rm" - An optional boolean, which defaults
  9033. to "false", that specifies to remove the package after
  9034. the test.
  9035. </para></listitem>
  9036. <listitem><para>"extract" - An optional boolean, which
  9037. defaults to "false", that specifies if the package must
  9038. be extracted from the package format.
  9039. When set to "true", the package is not automatically
  9040. installed into the DUT.
  9041. </para></listitem>
  9042. </itemizedlist>
  9043. </para>
  9044. <para>
  9045. Following is an example JSON file that handles test "foo"
  9046. installing package "bar" and test "foobar" installing
  9047. packages "foo" and "bar".
  9048. Once the test is complete, the packages are removed from the
  9049. DUT.
  9050. <literallayout class='monospaced'>
  9051. {
  9052. "foo": {
  9053. "pkg": "bar"
  9054. },
  9055. "foobar": [
  9056. {
  9057. "pkg": "foo",
  9058. "rm": true
  9059. },
  9060. {
  9061. "pkg": "bar",
  9062. "rm": true
  9063. }
  9064. ]
  9065. }
  9066. </literallayout>
  9067. </para>
  9068. </section>
  9069. </section>
  9070. <section id="platdev-gdb-remotedebug">
  9071. <title>Debugging With the GNU Project Debugger (GDB) Remotely</title>
  9072. <para>
  9073. GDB allows you to examine running programs, which in turn helps you to understand and fix problems.
  9074. It also allows you to perform post-mortem style analysis of program crashes.
  9075. GDB is available as a package within the Yocto Project and is
  9076. installed in SDK images by default.
  9077. See the "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>" chapter
  9078. in the Yocto Project Reference Manual for a description of these images.
  9079. You can find information on GDB at <ulink url="http://sourceware.org/gdb/"/>.
  9080. </para>
  9081. <tip>
  9082. For best results, install debug (<filename>-dbg</filename>) packages
  9083. for the applications you are going to debug.
  9084. Doing so makes extra debug symbols available that give you more
  9085. meaningful output.
  9086. </tip>
  9087. <para>
  9088. Sometimes, due to memory or disk space constraints, it is not possible
  9089. to use GDB directly on the remote target to debug applications.
  9090. These constraints arise because GDB needs to load the debugging information and the
  9091. binaries of the process being debugged.
  9092. Additionally, GDB needs to perform many computations to locate information such as function
  9093. names, variable names and values, stack traces and so forth - even before starting the
  9094. debugging process.
  9095. These extra computations place more load on the target system and can alter the
  9096. characteristics of the program being debugged.
  9097. </para>
  9098. <para>
  9099. To help get past the previously mentioned constraints, you can use Gdbserver.
  9100. Gdbserver runs on the remote target and does not load any debugging information
  9101. from the debugged process.
  9102. Instead, a GDB instance processes the debugging information that is run on a
  9103. remote computer - the host GDB.
  9104. The host GDB then sends control commands to Gdbserver to make it stop or start the debugged
  9105. program, as well as read or write memory regions of that debugged program.
  9106. All the debugging information loaded and processed as well
  9107. as all the heavy debugging is done by the host GDB.
  9108. Offloading these processes gives the Gdbserver running on the target a chance to remain
  9109. small and fast.
  9110. </para>
  9111. <para>
  9112. Because the host GDB is responsible for loading the debugging information and
  9113. for doing the necessary processing to make actual debugging happen,
  9114. you have to make sure the host can access the unstripped binaries complete
  9115. with their debugging information and also be sure the target is compiled with no optimizations.
  9116. The host GDB must also have local access to all the libraries used by the
  9117. debugged program.
  9118. Because Gdbserver does not need any local debugging information, the binaries on
  9119. the remote target can remain stripped.
  9120. However, the binaries must also be compiled without optimization
  9121. so they match the host's binaries.
  9122. </para>
  9123. <para>
  9124. To remain consistent with GDB documentation and terminology, the binary being debugged
  9125. on the remote target machine is referred to as the "inferior" binary.
  9126. For documentation on GDB see the
  9127. <ulink url="http://sourceware.org/gdb/documentation/">GDB site</ulink>.
  9128. </para>
  9129. <para>
  9130. The following steps show you how to debug using the GNU project
  9131. debugger.
  9132. <orderedlist>
  9133. <listitem><para>
  9134. <emphasis>Configure your build system to construct the
  9135. companion debug filesystem:</emphasis></para>
  9136. <para>In your <filename>local.conf</filename> file, set
  9137. the following:
  9138. <literallayout class='monospaced'>
  9139. IMAGE_GEN_DEBUGFS = "1"
  9140. IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
  9141. </literallayout>
  9142. These options cause the OpenEmbedded build system
  9143. to generate a special companion filesystem fragment,
  9144. which contains the matching source and debug symbols to
  9145. your deployable filesystem.
  9146. The build system does this by looking at what is in the
  9147. deployed filesystem, and pulling the corresponding
  9148. <filename>-dbg</filename> packages.</para>
  9149. <para>The companion debug filesystem is not a complete
  9150. filesystem, but only contains the debug fragments.
  9151. This filesystem must be combined with the full filesystem
  9152. for debugging.
  9153. Subsequent steps in this procedure show how to combine
  9154. the partial filesystem with the full filesystem.
  9155. </para></listitem>
  9156. <listitem><para>
  9157. <emphasis>Configure the system to include Gdbserver in
  9158. the target filesystem:</emphasis></para>
  9159. <para>Make the following addition in either your
  9160. <filename>local.conf</filename> file or in an image
  9161. recipe:
  9162. <literallayout class='monospaced'>
  9163. IMAGE_INSTALL_append = “ gdbserver"
  9164. </literallayout>
  9165. The change makes sure the <filename>gdbserver</filename>
  9166. package is included.
  9167. </para></listitem>
  9168. <listitem><para>
  9169. <emphasis>Build the environment:</emphasis></para>
  9170. <para>Use the following command to construct the image and
  9171. the companion Debug Filesystem:
  9172. <literallayout class='monospaced'>
  9173. $ bitbake <replaceable>image</replaceable>
  9174. </literallayout>
  9175. Build the cross GDB component and make it available
  9176. for debugging.
  9177. Build the SDK that matches the image.
  9178. Building the SDK is best for a production build
  9179. that can be used later for debugging, especially
  9180. during long term maintenance:
  9181. <literallayout class='monospaced'>
  9182. $ bitbake -c populate_sdk <replaceable>image</replaceable>
  9183. </literallayout></para>
  9184. <para>Alternatively, you can build the minimal
  9185. toolchain components that match the target.
  9186. Doing so creates a smaller than typical SDK and only
  9187. contains a minimal set of components with which to
  9188. build simple test applications, as well as run the
  9189. debugger:
  9190. <literallayout class='monospaced'>
  9191. $ bitbake meta-toolchain
  9192. </literallayout></para>
  9193. <para>A final method is to build Gdb itself within
  9194. the build system:
  9195. <literallayout class='monospaced'>
  9196. $ bitbake gdb-cross-<replaceable>architecture</replaceable>
  9197. </literallayout>
  9198. Doing so produces a temporary copy of
  9199. <filename>cross-gdb</filename> you can use for
  9200. debugging during development.
  9201. While this is the quickest approach, the two previous
  9202. methods in this step are better when considering
  9203. long-term maintenance strategies.
  9204. <note>
  9205. If you run
  9206. <filename>bitbake gdb-cross</filename>, the
  9207. OpenEmbedded build system suggests the actual
  9208. image (e.g. <filename>gdb-cross-i586</filename>).
  9209. The suggestion is usually the actual name you want
  9210. to use.
  9211. </note>
  9212. </para></listitem>
  9213. <listitem><para>
  9214. <emphasis>Set up the</emphasis>&nbsp;<filename>debugfs</filename></para>
  9215. <para>Run the following commands to set up the
  9216. <filename>debugfs</filename>:
  9217. <literallayout class='monospaced'>
  9218. $ mkdir debugfs
  9219. $ cd debugfs
  9220. $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>.rootfs.tar.bz2
  9221. $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>-dbg.rootfs.tar.bz2
  9222. </literallayout>
  9223. </para></listitem>
  9224. <listitem><para>
  9225. <emphasis>Set up GDB</emphasis></para>
  9226. <para>Install the SDK (if you built one) and then
  9227. source the correct environment file.
  9228. Sourcing the environment file puts the SDK in your
  9229. <filename>PATH</filename> environment variable.</para>
  9230. <para>If you are using the build system, Gdb is
  9231. located in
  9232. <replaceable>build-dir</replaceable>/tmp/sysroots/<replaceable>host</replaceable>/usr/bin/<replaceable>architecture</replaceable>/<replaceable>architecture</replaceable>-gdb
  9233. </para></listitem>
  9234. <listitem><para>
  9235. <emphasis>Boot the target:</emphasis></para>
  9236. <para>For information on how to run QEMU, see the
  9237. <ulink url='http://wiki.qemu.org/Documentation/GettingStartedDevelopers'>QEMU Documentation</ulink>.
  9238. <note>
  9239. Be sure to verify that your host can access the
  9240. target via TCP.
  9241. </note>
  9242. </para></listitem>
  9243. <listitem><para>
  9244. <emphasis>Debug a program:</emphasis></para>
  9245. <para>Debugging a program involves running Gdbserver
  9246. on the target and then running Gdb on the host.
  9247. The example in this step debugs
  9248. <filename>gzip</filename>:
  9249. <literallayout class='monospaced'>
  9250. root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
  9251. </literallayout>
  9252. For additional Gdbserver options, see the
  9253. <ulink url='https://www.gnu.org/software/gdb/documentation/'>Gdb Server Documentation</ulink>.
  9254. </para>
  9255. <para>After running Gdbserver on the target, you need
  9256. to run Gdb on the host and configure it and connect to
  9257. the target.
  9258. Use these commands:
  9259. <literallayout class='monospaced'>
  9260. $ cd <replaceable>directory-holding-the-debugfs-directory</replaceable>
  9261. $ <replaceable>arch</replaceable>-gdb
  9262. (gdb) set sysroot debugfs
  9263. (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
  9264. (gdb) target remote <replaceable>IP-of-target</replaceable>:1234
  9265. </literallayout>
  9266. At this point, everything should automatically load
  9267. (i.e. matching binaries, symbols and headers).
  9268. <note>
  9269. The Gdb <filename>set</filename> commands in the
  9270. previous example can be placed into the users
  9271. <filename>~/.gdbinit</filename> file.
  9272. Upon starting, Gdb automatically runs whatever
  9273. commands are in that file.
  9274. </note>
  9275. </para></listitem>
  9276. <listitem><para>
  9277. <emphasis>Deploying without a full image
  9278. rebuild:</emphasis></para>
  9279. <para>In many cases, during development you want a
  9280. quick method to deploy a new binary to the target and
  9281. debug it, without waiting for a full image build.
  9282. </para>
  9283. <para>One approach to solving this situation is to
  9284. just build the component you want to debug.
  9285. Once you have built the component, copy the
  9286. executable directly to both the target and the
  9287. host <filename>debugfs</filename>.</para>
  9288. <para>If the binary is processed through the debug
  9289. splitting in OpenEmbedded, you should also
  9290. copy the debug items (i.e. <filename>.debug</filename>
  9291. contents and corresponding
  9292. <filename>/usr/src/debug</filename> files)
  9293. from the work directory.
  9294. Here is an example:
  9295. <literallayout class='monospaced'>
  9296. $ bitbake bash
  9297. $ bitbake -c devshell bash
  9298. $ cd ..
  9299. $ scp packages-split/bash/bin/bash <replaceable>target</replaceable>:/bin/bash
  9300. $ cp -a packages-split/bash-dbg/* <replaceable>path</replaceable>/debugfs
  9301. </literallayout>
  9302. </para></listitem>
  9303. </orderedlist>
  9304. </para>
  9305. </section>
  9306. <!--
  9307. <section id='platdev-gdb-remotedebug-setup'>
  9308. <title>Set Up the Cross-Development Debugging Environment</title>
  9309. <para>
  9310. Before you can initiate a remote debugging session, you need
  9311. to be sure you have set up the cross-development environment,
  9312. toolchain, and sysroot.
  9313. The <ulink url='&YOCTO_DOCS_SDK_URL;#sdk-intro'>Yocto Project Software Development Kit (SDK) Developer's Guide</ulink>
  9314. describes this process.
  9315. </para>
  9316. </section>
  9317. <section id="platdev-gdb-remotedebug-launch-gdbserver">
  9318. <title>Launch Gdbserver on the Target</title>
  9319. <para>
  9320. Make sure Gdbserver is installed on the target.
  9321. If it is not, install the package
  9322. <filename>gdbserver</filename>, which needs the
  9323. <filename>libthread-db1</filename> package.
  9324. </para>
  9325. <para>
  9326. Here is an example, that when entered from the host,
  9327. connects to the target and launches Gdbserver in order to
  9328. "debug" a binary named <filename>helloworld</filename>:
  9329. <literallayout class='monospaced'>
  9330. $ gdbserver localhost:2345 /usr/bin/helloworld
  9331. </literallayout>
  9332. Gdbserver should now be listening on port 2345 for debugging
  9333. commands coming from a remote GDB process that is running on
  9334. the host computer.
  9335. Communication between Gdbserver and the host GDB are done
  9336. using TCP.
  9337. To use other communication protocols, please refer to the
  9338. <ulink url='http://www.gnu.org/software/gdb/'>Gdbserver documentation</ulink>.
  9339. </para>
  9340. </section>
  9341. <section id="platdev-gdb-remotedebug-launch-gdb">
  9342. <title>Launch GDB on the Host Computer</title>
  9343. <para>
  9344. Running GDB on the host computer takes a number of stages, which
  9345. this section describes.
  9346. </para>
  9347. <section id="platdev-gdb-remotedebug-launch-gdb-buildcross">
  9348. <title>Build the Cross-GDB Package</title>
  9349. <para>
  9350. A suitable GDB cross-binary is required that runs on your
  9351. host computer but also knows about the the ABI of the
  9352. remote target.
  9353. You can get this binary from the
  9354. <link linkend='cross-development-toolchain'>Cross-Development Toolchain</link>.
  9355. Here is an example where the toolchain has been installed
  9356. in the default directory
  9357. <filename>/opt/poky/&DISTRO;</filename>:
  9358. <literallayout class='monospaced'>
  9359. /opt/poky/&DISTRO;/sysroots/i686-pokysdk-linux/usr/bin/armv7a-vfp-neon-poky-linux-gnueabi/arm-poky-linux-gnueabi-gdb
  9360. </literallayout>
  9361. where <filename>arm</filename> is the target architecture
  9362. and <filename>linux-gnueabi</filename> is the target ABI.
  9363. </para>
  9364. <para>
  9365. Alternatively, you can use BitBake to build the
  9366. <filename>gdb-cross</filename> binary.
  9367. Here is an example:
  9368. <literallayout class='monospaced'>
  9369. $ bitbake gdb-cross
  9370. </literallayout>
  9371. Once the binary is built, you can find it here:
  9372. <literallayout class='monospaced'>
  9373. tmp/sysroots/<replaceable>host-arch</replaceable>/usr/bin/<replaceable>target-platform</replaceable>/<replaceable>target-abi</replaceable>-gdb
  9374. </literallayout>
  9375. </para>
  9376. </section>
  9377. <section id='create-the-gdb-initialization-file'>
  9378. <title>Create the GDB Initialization File and Point to Your Root Filesystem</title>
  9379. <para>
  9380. Aside from the GDB cross-binary, you also need a GDB
  9381. initialization file in the same top directory in which
  9382. your binary resides.
  9383. When you start GDB on your host development system, GDB
  9384. finds this initialization file and executes all the
  9385. commands within.
  9386. For information on the <filename>.gdbinit</filename>, see
  9387. "<ulink url='http://sourceware.org/gdb/onlinedocs/gdb/'>Debugging with GDB</ulink>",
  9388. which is maintained by
  9389. <ulink url='http://www.sourceware.org'>sourceware.org</ulink>.
  9390. </para>
  9391. <para>
  9392. You need to add a statement in the
  9393. <filename>~/.gdbinit</filename> file that points to your
  9394. root filesystem.
  9395. Here is an example that points to the root filesystem for
  9396. an ARM-based target device:
  9397. <literallayout class='monospaced'>
  9398. set sysroot ~/sysroot_arm
  9399. </literallayout>
  9400. </para>
  9401. </section>
  9402. <section id="platdev-gdb-remotedebug-launch-gdb-launchhost">
  9403. <title>Launch the Host GDB</title>
  9404. <para>
  9405. Before launching the host GDB, you need to be sure
  9406. you have sourced the cross-debugging environment script,
  9407. which if you installed the root filesystem in the default
  9408. location is at <filename>/opt/poky/&DISTRO;</filename>
  9409. and begins with the string "environment-setup".
  9410. For more information, see the
  9411. <ulink url='&YOCTO_DOCS_SDK_URL;#sdk-manual'>Yocto Project Software Development Kit (SDK) Developer's
  9412. Guide</ulink>.
  9413. </para>
  9414. <para>
  9415. Finally, switch to the directory where the binary resides
  9416. and run the <filename>cross-gdb</filename> binary.
  9417. Provide the binary file you are going to debug.
  9418. For example, the following command continues with the
  9419. example used in the previous section by loading
  9420. the <filename>helloworld</filename> binary as well as the
  9421. debugging information:
  9422. <literallayout class='monospaced'>
  9423. $ arm-poky-linux-gnuabi-gdb helloworld
  9424. </literallayout>
  9425. The commands in your <filename>.gdbinit</filename> execute
  9426. and the GDB prompt appears.
  9427. </para>
  9428. </section>
  9429. </section>
  9430. <section id='platdev-gdb-connect-to-the-remote-gdb-server'>
  9431. <title>Connect to the Remote GDB Server</title>
  9432. <para>
  9433. From the target, you need to connect to the remote GDB
  9434. server that is running on the host.
  9435. You need to specify the remote host and port.
  9436. Here is the command continuing with the example:
  9437. <literallayout class='monospaced'>
  9438. target remote 192.168.7.2:2345
  9439. </literallayout>
  9440. </para>
  9441. </section>
  9442. <section id="platdev-gdb-remotedebug-launch-gdb-using">
  9443. <title>Use the Debugger</title>
  9444. <para>
  9445. You can now proceed with debugging as normal - as if you were debugging
  9446. on the local machine.
  9447. For example, to instruct GDB to break in the "main" function and then
  9448. continue with execution of the inferior binary use the following commands
  9449. from within GDB:
  9450. <literallayout class='monospaced'>
  9451. (gdb) break main
  9452. (gdb) continue
  9453. </literallayout>
  9454. </para>
  9455. <para>
  9456. For more information about using GDB, see the project's online documentation at
  9457. <ulink url="http://sourceware.org/gdb/download/onlinedocs/"/>.
  9458. </para>
  9459. </section>
  9460. </section>
  9461. -->
  9462. <section id='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>
  9463. <title>Debugging with the GNU Project Debugger (GDB) on the Target</title>
  9464. <para>
  9465. The previous section addressed using GDB remotely for debugging
  9466. purposes, which is the most usual case due to the inherent
  9467. hardware limitations on many embedded devices.
  9468. However, debugging in the target hardware itself is also possible
  9469. with more powerful devices.
  9470. This section describes what you need to do in order to support
  9471. using GDB to debug on the target hardware.
  9472. </para>
  9473. <para>
  9474. To support this kind of debugging, you need do the following:
  9475. <itemizedlist>
  9476. <listitem><para>
  9477. Ensure that GDB is on the target.
  9478. You can do this by adding "gdb" to
  9479. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>:
  9480. <literallayout class='monospaced'>
  9481. IMAGE_INSTALL_append = " gdb"
  9482. </literallayout>
  9483. Alternatively, you can add "tools-debug" to
  9484. <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>:
  9485. <literallayout class='monospaced'>
  9486. IMAGE_FEATURES_append = " tools-debug"
  9487. </literallayout>
  9488. </para></listitem>
  9489. <listitem><para>
  9490. Ensure that debug symbols are present.
  9491. You can make sure these symbols are present by installing
  9492. <filename>-dbg</filename>:
  9493. <literallayout class='monospaced'>
  9494. IMAGE_INSTALL_append = " <replaceable>packagename</replaceable>-dbg"
  9495. </literallayout>
  9496. Alternatively, you can do the following to include all the
  9497. debug symbols:
  9498. <literallayout class='monospaced'>
  9499. IMAGE_FEATURES_append = " dbg-pkgs"
  9500. </literallayout>
  9501. </para></listitem>
  9502. </itemizedlist>
  9503. <note>
  9504. To improve the debug information accuracy, you can reduce the
  9505. level of optimization used by the compiler.
  9506. For example, when adding the following line to your
  9507. <filename>local.conf</filename> file, you will reduce
  9508. optimization from
  9509. <ulink url='&YOCTO_DOCS_REF_URL;#var-FULL_OPTIMIZATION'><filename>FULL_OPTIMIZATION</filename></ulink>
  9510. of "-O2" to
  9511. <ulink url='&YOCTO_DOCS_REF_URL;#var-DEBUG_OPTIMIZATION'><filename>DEBUG_OPTIMIZATION</filename></ulink>
  9512. of "-O -fno-omit-frame-pointer":
  9513. <literallayout class='monospaced'>
  9514. DEBUG_BUILD = "1"
  9515. </literallayout>
  9516. Consider that this will reduce the application's performance
  9517. and is recommended only for debugging purposes.
  9518. </note>
  9519. </para>
  9520. </section>
  9521. <section id='debugging-parallel-make-races'>
  9522. <title>Debugging Parallel Make Races</title>
  9523. <para>
  9524. A parallel <filename>make</filename> race occurs when the build
  9525. consists of several parts that are run simultaneously and
  9526. a situation occurs when the output or result of one
  9527. part is not ready for use with a different part of the build that
  9528. depends on that output.
  9529. Parallel make races are annoying and can sometimes be difficult
  9530. to reproduce and fix.
  9531. However, some simple tips and tricks exist that can help
  9532. you debug and fix them.
  9533. This section presents a real-world example of an error encountered
  9534. on the Yocto Project autobuilder and the process used to fix it.
  9535. <note>
  9536. If you cannot properly fix a <filename>make</filename> race
  9537. condition, you can work around it by clearing either the
  9538. <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
  9539. or
  9540. <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
  9541. variables.
  9542. </note>
  9543. </para>
  9544. <section id='the-failure'>
  9545. <title>The Failure</title>
  9546. <para>
  9547. For this example, assume that you are building an image that
  9548. depends on the "neard" package.
  9549. And, during the build, BitBake runs into problems and
  9550. creates the following output.
  9551. <note>
  9552. This example log file has longer lines artificially
  9553. broken to make the listing easier to read.
  9554. </note>
  9555. If you examine the output or the log file, you see the
  9556. failure during <filename>make</filename>:
  9557. <literallayout class='monospaced'>
  9558. | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
  9559. | DEBUG: Executing shell function do_compile
  9560. | NOTE: make -j 16
  9561. | make --no-print-directory all-am
  9562. | /bin/mkdir -p include/near
  9563. | /bin/mkdir -p include/near
  9564. | /bin/mkdir -p include/near
  9565. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  9566. 0.14-r0/neard-0.14/include/types.h include/near/types.h
  9567. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  9568. 0.14-r0/neard-0.14/include/log.h include/near/log.h
  9569. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  9570. 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
  9571. | /bin/mkdir -p include/near
  9572. | /bin/mkdir -p include/near
  9573. | /bin/mkdir -p include/near
  9574. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  9575. 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
  9576. | /bin/mkdir -p include/near
  9577. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  9578. 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
  9579. | /bin/mkdir -p include/near
  9580. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  9581. 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
  9582. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  9583. 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
  9584. | /bin/mkdir -p include/near
  9585. | /bin/mkdir -p include/near
  9586. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  9587. 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
  9588. | /bin/mkdir -p include/near
  9589. | /bin/mkdir -p include/near
  9590. | /bin/mkdir -p include/near
  9591. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  9592. 0.14-r0/neard-0.14/include/device.h include/near/device.h
  9593. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  9594. 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
  9595. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  9596. 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
  9597. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  9598. 0.14-r0/neard-0.14/include/version.h include/near/version.h
  9599. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  9600. 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
  9601. | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
  9602. | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
  9603. build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
  9604. yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
  9605. -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
  9606. lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
  9607. tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
  9608. nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
  9609. yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
  9610. -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
  9611. -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
  9612. -o tools/snep-send.o tools/snep-send.c
  9613. | In file included from tools/snep-send.c:16:0:
  9614. | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
  9615. | #include &lt;near/dbus.h&gt;
  9616. | ^
  9617. | compilation terminated.
  9618. | make[1]: *** [tools/snep-send.o] Error 1
  9619. | make[1]: *** Waiting for unfinished jobs....
  9620. | make: *** [all] Error 2
  9621. | ERROR: oe_runmake failed
  9622. </literallayout>
  9623. </para>
  9624. </section>
  9625. <section id='reproducing-the-error'>
  9626. <title>Reproducing the Error</title>
  9627. <para>
  9628. Because race conditions are intermittent, they do not
  9629. manifest themselves every time you do the build.
  9630. In fact, most times the build will complete without problems
  9631. even though the potential race condition exists.
  9632. Thus, once the error surfaces, you need a way to reproduce it.
  9633. </para>
  9634. <para>
  9635. In this example, compiling the "neard" package is causing the
  9636. problem.
  9637. So the first thing to do is build "neard" locally.
  9638. Before you start the build, set the
  9639. <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
  9640. variable in your <filename>local.conf</filename> file to
  9641. a high number (e.g. "-j 20").
  9642. Using a high value for <filename>PARALLEL_MAKE</filename>
  9643. increases the chances of the race condition showing up:
  9644. <literallayout class='monospaced'>
  9645. $ bitbake neard
  9646. </literallayout>
  9647. </para>
  9648. <para>
  9649. Once the local build for "neard" completes, start a
  9650. <filename>devshell</filename> build:
  9651. <literallayout class='monospaced'>
  9652. $ bitbake neard -c devshell
  9653. </literallayout>
  9654. For information on how to use a
  9655. <filename>devshell</filename>, see the
  9656. "<link linkend='platdev-appdev-devshell'>Using a Development Shell</link>"
  9657. section.
  9658. </para>
  9659. <para>
  9660. In the <filename>devshell</filename>, do the following:
  9661. <literallayout class='monospaced'>
  9662. $ make clean
  9663. $ make tools/snep-send.o
  9664. </literallayout>
  9665. The <filename>devshell</filename> commands cause the failure
  9666. to clearly be visible.
  9667. In this case, a missing dependency exists for the "neard"
  9668. Makefile target.
  9669. Here is some abbreviated, sample output with the
  9670. missing dependency clearly visible at the end:
  9671. <literallayout class='monospaced'>
  9672. i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
  9673. .
  9674. .
  9675. .
  9676. tools/snep-send.c
  9677. In file included from tools/snep-send.c:16:0:
  9678. tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
  9679. #include &lt;near/dbus.h&gt;
  9680. ^
  9681. compilation terminated.
  9682. make: *** [tools/snep-send.o] Error 1
  9683. $
  9684. </literallayout>
  9685. </para>
  9686. </section>
  9687. <section id='creating-a-patch-for-the-fix'>
  9688. <title>Creating a Patch for the Fix</title>
  9689. <para>
  9690. Because there is a missing dependency for the Makefile
  9691. target, you need to patch the
  9692. <filename>Makefile.am</filename> file, which is generated
  9693. from <filename>Makefile.in</filename>.
  9694. You can use Quilt to create the patch:
  9695. <literallayout class='monospaced'>
  9696. $ quilt new parallelmake.patch
  9697. Patch patches/parallelmake.patch is now on top
  9698. $ quilt add Makefile.am
  9699. File Makefile.am added to patch patches/parallelmake.patch
  9700. </literallayout>
  9701. For more information on using Quilt, see the
  9702. "<link linkend='using-a-quilt-workflow'>Using Quilt in Your Workflow</link>"
  9703. section.
  9704. </para>
  9705. <para>
  9706. At this point you need to make the edits to
  9707. <filename>Makefile.am</filename> to add the missing
  9708. dependency.
  9709. For our example, you have to add the following line
  9710. to the file:
  9711. <literallayout class='monospaced'>
  9712. tools/snep-send.$(OBJEXT): include/near/dbus.h
  9713. </literallayout>
  9714. </para>
  9715. <para>
  9716. Once you have edited the file, use the
  9717. <filename>refresh</filename> command to create the patch:
  9718. <literallayout class='monospaced'>
  9719. $ quilt refresh
  9720. Refreshed patch patches/parallelmake.patch
  9721. </literallayout>
  9722. Once the patch file exists, you need to add it back to the
  9723. originating recipe folder.
  9724. Here is an example assuming a top-level
  9725. <link linkend='source-directory'>Source Directory</link>
  9726. named <filename>poky</filename>:
  9727. <literallayout class='monospaced'>
  9728. $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
  9729. </literallayout>
  9730. The final thing you need to do to implement the fix in the
  9731. build is to update the "neard" recipe (i.e.
  9732. <filename>neard-0.14.bb</filename>) so that the
  9733. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
  9734. statement includes the patch file.
  9735. The recipe file is in the folder above the patch.
  9736. Here is what the edited <filename>SRC_URI</filename>
  9737. statement would look like:
  9738. <literallayout class='monospaced'>
  9739. SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
  9740. file://neard.in \
  9741. file://neard.service.in \
  9742. file://parallelmake.patch \
  9743. "
  9744. </literallayout>
  9745. </para>
  9746. <para>
  9747. With the patch complete and moved to the correct folder and
  9748. the <filename>SRC_URI</filename> statement updated, you can
  9749. exit the <filename>devshell</filename>:
  9750. <literallayout class='monospaced'>
  9751. $ exit
  9752. </literallayout>
  9753. </para>
  9754. </section>
  9755. <section id='testing-the-build'>
  9756. <title>Testing the Build</title>
  9757. <para>
  9758. With everything in place, you can get back to trying the
  9759. build again locally:
  9760. <literallayout class='monospaced'>
  9761. $ bitbake neard
  9762. </literallayout>
  9763. This build should succeed.
  9764. </para>
  9765. <para>
  9766. Now you can open up a <filename>devshell</filename> again
  9767. and repeat the clean and make operations as follows:
  9768. <literallayout class='monospaced'>
  9769. $ bitbake neard -c devshell
  9770. $ make clean
  9771. $ make tools/snep-send.o
  9772. </literallayout>
  9773. The build should work without issue.
  9774. </para>
  9775. <para>
  9776. As with all solved problems, if they originated upstream, you
  9777. need to submit the fix for the recipe in OE-Core and upstream
  9778. so that the problem is taken care of at its source.
  9779. See the
  9780. "<link linkend='how-to-submit-a-change'>How to Submit a Change</link>"
  9781. section for more information.
  9782. </para>
  9783. </section>
  9784. </section>
  9785. <section id='maintaining-open-source-license-compliance-during-your-products-lifecycle'>
  9786. <title>Maintaining Open Source License Compliance During Your Product's Lifecycle</title>
  9787. <para>
  9788. One of the concerns for a development organization using open source
  9789. software is how to maintain compliance with various open source
  9790. licensing during the lifecycle of the product.
  9791. While this section does not provide legal advice or
  9792. comprehensively cover all scenarios, it does
  9793. present methods that you can use to
  9794. assist you in meeting the compliance requirements during a software
  9795. release.
  9796. </para>
  9797. <para>
  9798. With hundreds of different open source licenses that the Yocto
  9799. Project tracks, it is difficult to know the requirements of each
  9800. and every license.
  9801. However, the requirements of the major FLOSS licenses can begin
  9802. to be covered by
  9803. assuming that three main areas of concern exist:
  9804. <itemizedlist>
  9805. <listitem><para>Source code must be provided.</para></listitem>
  9806. <listitem><para>License text for the software must be
  9807. provided.</para></listitem>
  9808. <listitem><para>Compilation scripts and modifications to the
  9809. source code must be provided.
  9810. </para></listitem>
  9811. </itemizedlist>
  9812. There are other requirements beyond the scope of these
  9813. three and the methods described in this section
  9814. (e.g. the mechanism through which source code is distributed).
  9815. </para>
  9816. <para>
  9817. As different organizations have different methods of complying with
  9818. open source licensing, this section is not meant to imply that
  9819. there is only one single way to meet your compliance obligations,
  9820. but rather to describe one method of achieving compliance.
  9821. The remainder of this section describes methods supported to meet the
  9822. previously mentioned three requirements.
  9823. Once you take steps to meet these requirements,
  9824. and prior to releasing images, sources, and the build system,
  9825. you should audit all artifacts to ensure completeness.
  9826. <note>
  9827. The Yocto Project generates a license manifest during
  9828. image creation that is located
  9829. in <filename>${DEPLOY_DIR}/licenses/<replaceable>image_name-datestamp</replaceable></filename>
  9830. to assist with any audits.
  9831. </note>
  9832. </para>
  9833. <section id='providing-the-source-code'>
  9834. <title>Providing the Source Code</title>
  9835. <para>
  9836. Compliance activities should begin before you generate the
  9837. final image.
  9838. The first thing you should look at is the requirement that
  9839. tops the list for most compliance groups - providing
  9840. the source.
  9841. The Yocto Project has a few ways of meeting this
  9842. requirement.
  9843. </para>
  9844. <para>
  9845. One of the easiest ways to meet this requirement is
  9846. to provide the entire
  9847. <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
  9848. used by the build.
  9849. This method, however, has a few issues.
  9850. The most obvious is the size of the directory since it includes
  9851. all sources used in the build and not just the source used in
  9852. the released image.
  9853. It will include toolchain source, and other artifacts, which
  9854. you would not generally release.
  9855. However, the more serious issue for most companies is accidental
  9856. release of proprietary software.
  9857. The Yocto Project provides an
  9858. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-archiver'><filename>archiver</filename></ulink>
  9859. class to help avoid some of these concerns.
  9860. </para>
  9861. <para>
  9862. Before you employ <filename>DL_DIR</filename> or the
  9863. archiver class, you need to decide how you choose to
  9864. provide source.
  9865. The source archiver class can generate tarballs and SRPMs
  9866. and can create them with various levels of compliance in mind.
  9867. </para>
  9868. <para>
  9869. One way of doing this (but certainly not the only way) is to
  9870. release just the source as a tarball.
  9871. You can do this by adding the following to the
  9872. <filename>local.conf</filename> file found in the
  9873. <link linkend='build-directory'>Build Directory</link>:
  9874. <literallayout class='monospaced'>
  9875. INHERIT += "archiver"
  9876. ARCHIVER_MODE[src] = "original"
  9877. </literallayout>
  9878. During the creation of your image, the source from all
  9879. recipes that deploy packages to the image is placed within
  9880. subdirectories of
  9881. <filename>DEPLOY_DIR/sources</filename> based on the
  9882. <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
  9883. for each recipe.
  9884. Releasing the entire directory enables you to comply with
  9885. requirements concerning providing the unmodified source.
  9886. It is important to note that the size of the directory can
  9887. get large.
  9888. </para>
  9889. <para>
  9890. A way to help mitigate the size issue is to only release
  9891. tarballs for licenses that require the release of
  9892. source.
  9893. Let us assume you are only concerned with GPL code as
  9894. identified by running the following script:
  9895. <literallayout class='monospaced'>
  9896. # Script to archive a subset of packages matching specific license(s)
  9897. # Source and license files are copied into sub folders of package folder
  9898. # Must be run from build folder
  9899. #!/bin/bash
  9900. src_release_dir="source-release"
  9901. mkdir -p $src_release_dir
  9902. for a in tmp/deploy/sources/*; do
  9903. for d in $a/*; do
  9904. # Get package name from path
  9905. p=`basename $d`
  9906. p=${p%-*}
  9907. p=${p%-*}
  9908. # Only archive GPL packages (update *GPL* regex for your license check)
  9909. numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
  9910. if [ $numfiles -gt 1 ]; then
  9911. echo Archiving $p
  9912. mkdir -p $src_release_dir/$p/source
  9913. cp $d/* $src_release_dir/$p/source 2> /dev/null
  9914. mkdir -p $src_release_dir/$p/license
  9915. cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
  9916. fi
  9917. done
  9918. done </literallayout>
  9919. At this point, you could create a tarball from the
  9920. <filename>gpl_source_release</filename> directory and
  9921. provide that to the end user.
  9922. This method would be a step toward achieving compliance
  9923. with section 3a of GPLv2 and with section 6 of GPLv3.
  9924. </para>
  9925. </section>
  9926. <section id='providing-license-text'>
  9927. <title>Providing License Text</title>
  9928. <para>
  9929. One requirement that is often overlooked is inclusion
  9930. of license text.
  9931. This requirement also needs to be dealt with prior to
  9932. generating the final image.
  9933. Some licenses require the license text to accompany
  9934. the binary.
  9935. You can achieve this by adding the following to your
  9936. <filename>local.conf</filename> file:
  9937. <literallayout class='monospaced'>
  9938. COPY_LIC_MANIFEST = "1"
  9939. COPY_LIC_DIRS = "1"
  9940. LICENSE_CREATE_PACKAGE = "1"
  9941. </literallayout>
  9942. Adding these statements to the configuration file ensures
  9943. that the licenses collected during package generation
  9944. are included on your image.
  9945. <note>
  9946. <para>Setting all three variables to "1" results in the
  9947. image having two copies of the same license file.
  9948. One copy resides in
  9949. <filename>/usr/share/common-licenses</filename> and
  9950. the other resides in
  9951. <filename>/usr/share/license</filename>.</para>
  9952. <para>The reason for this behavior is because
  9953. <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_DIRS'><filename>COPY_LIC_DIRS</filename></ulink>
  9954. and
  9955. <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_MANIFEST'><filename>COPY_LIC_MANIFEST</filename></ulink>
  9956. add a copy of the license when the image is built but do not
  9957. offer a path for adding licenses for newly installed packages
  9958. to an image.
  9959. <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_CREATE_PACKAGE'><filename>LICENSE_CREATE_PACKAGE</filename></ulink>
  9960. adds a separate package and an upgrade path for adding
  9961. licenses to an image.</para>
  9962. </note>
  9963. </para>
  9964. <para>
  9965. As the source archiver has already archived the original
  9966. unmodified source that contains the license files,
  9967. you would have already met the requirements for inclusion
  9968. of the license information with source as defined by the GPL
  9969. and other open source licenses.
  9970. </para>
  9971. </section>
  9972. <section id='providing-compilation-scripts-and-source-code-modifications'>
  9973. <title>Providing Compilation Scripts and Source Code Modifications</title>
  9974. <para>
  9975. At this point, we have addressed all we need to address
  9976. prior to generating the image.
  9977. The next two requirements are addressed during the final
  9978. packaging of the release.
  9979. </para>
  9980. <para>
  9981. By releasing the version of the OpenEmbedded build system
  9982. and the layers used during the build, you will be providing both
  9983. compilation scripts and the source code modifications in one
  9984. step.
  9985. </para>
  9986. <para>
  9987. If the deployment team has a
  9988. <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP layer</ulink>
  9989. and a distro layer, and those those layers are used to patch,
  9990. compile, package, or modify (in any way) any open source
  9991. software included in your released images, you
  9992. might be required to to release those layers under section 3 of
  9993. GPLv2 or section 1 of GPLv3.
  9994. One way of doing that is with a clean
  9995. checkout of the version of the Yocto Project and layers used
  9996. during your build.
  9997. Here is an example:
  9998. <literallayout class='monospaced'>
  9999. # We built using the &DISTRO_NAME_NO_CAP; branch of the poky repo
  10000. $ git clone -b &DISTRO_NAME_NO_CAP; git://git.yoctoproject.org/poky
  10001. $ cd poky
  10002. # We built using the release_branch for our layers
  10003. $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
  10004. $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
  10005. # clean up the .git repos
  10006. $ find . -name ".git" -type d -exec rm -rf {} \;
  10007. </literallayout>
  10008. One thing a development organization might want to consider
  10009. for end-user convenience is to modify
  10010. <filename>meta-poky/conf/bblayers.conf.sample</filename> to
  10011. ensure that when the end user utilizes the released build
  10012. system to build an image, the development organization's
  10013. layers are included in the <filename>bblayers.conf</filename>
  10014. file automatically:
  10015. <literallayout class='monospaced'>
  10016. # LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf
  10017. # changes incompatibly
  10018. LCONF_VERSION = "6"
  10019. BBPATH = "${TOPDIR}"
  10020. BBFILES ?= ""
  10021. BBLAYERS ?= " \
  10022. ##OEROOT##/meta \
  10023. ##OEROOT##/meta-poky \
  10024. ##OEROOT##/meta-yocto-bsp \
  10025. ##OEROOT##/meta-mylayer \
  10026. "
  10027. </literallayout>
  10028. Creating and providing an archive of the
  10029. <link linkend='metadata'>Metadata</link> layers
  10030. (recipes, configuration files, and so forth)
  10031. enables you to meet your
  10032. requirements to include the scripts to control compilation
  10033. as well as any modifications to the original source.
  10034. </para>
  10035. </section>
  10036. </section>
  10037. <section id='using-the-error-reporting-tool'>
  10038. <title>Using the Error Reporting Tool</title>
  10039. <para>
  10040. The error reporting tool allows you to
  10041. submit errors encountered during builds to a central database.
  10042. Outside of the build environment, you can use a web interface to
  10043. browse errors, view statistics, and query for errors.
  10044. The tool works using a client-server system where the client
  10045. portion is integrated with the installed Yocto Project
  10046. <link linkend='source-directory'>Source Directory</link>
  10047. (e.g. <filename>poky</filename>).
  10048. The server receives the information collected and saves it in a
  10049. database.
  10050. </para>
  10051. <para>
  10052. A live instance of the error reporting server exists at
  10053. <ulink url='http://errors.yoctoproject.org'></ulink>.
  10054. This server exists so that when you want to get help with
  10055. build failures, you can submit all of the information on the
  10056. failure easily and then point to the URL in your bug report
  10057. or send an email to the mailing list.
  10058. <note>
  10059. If you send error reports to this server, the reports become
  10060. publicly visible.
  10061. </note>
  10062. </para>
  10063. <section id='enabling-and-using-the-tool'>
  10064. <title>Enabling and Using the Tool</title>
  10065. <para>
  10066. By default, the error reporting tool is disabled.
  10067. You can enable it by inheriting the
  10068. <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-report-error'><filename>report-error</filename></ulink>
  10069. class by adding the following statement to the end of
  10070. your <filename>local.conf</filename> file in your
  10071. <link linkend='build-directory'>Build Directory</link>.
  10072. <literallayout class='monospaced'>
  10073. INHERIT += "report-error"
  10074. </literallayout>
  10075. </para>
  10076. <para>
  10077. By default, the error reporting feature stores information in
  10078. <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LOG_DIR'><filename>LOG_DIR</filename></ulink><filename>}/error-report</filename>.
  10079. However, you can specify a directory to use by adding the following
  10080. to your <filename>local.conf</filename> file:
  10081. <literallayout class='monospaced'>
  10082. ERR_REPORT_DIR = "path"
  10083. </literallayout>
  10084. Enabling error reporting causes the build process to collect
  10085. the errors and store them in a file as previously described.
  10086. When the build system encounters an error, it includes a
  10087. command as part of the console output.
  10088. You can run the command to send the error file to the server.
  10089. For example, the following command sends the errors to an
  10090. upstream server:
  10091. <literallayout class='monospaced'>
  10092. $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
  10093. </literallayout>
  10094. In the previous example, the errors are sent to a public
  10095. database available at
  10096. <ulink url='http://errors.yoctoproject.org'></ulink>, which is
  10097. used by the entire community.
  10098. If you specify a particular server, you can send the errors
  10099. to a different database.
  10100. Use the following command for more information on available
  10101. options:
  10102. <literallayout class='monospaced'>
  10103. $ send-error-report --help
  10104. </literallayout>
  10105. </para>
  10106. <para>
  10107. When sending the error file, you are prompted to review the
  10108. data being sent as well as to provide a name and optional
  10109. email address.
  10110. Once you satisfy these prompts, the command returns a link
  10111. from the server that corresponds to your entry in the database.
  10112. For example, here is a typical link:
  10113. <literallayout class='monospaced'>
  10114. http://errors.yoctoproject.org/Errors/Details/9522/
  10115. </literallayout>
  10116. Following the link takes you to a web interface where you can
  10117. browse, query the errors, and view statistics.
  10118. </para>
  10119. </section>
  10120. <section id='disabling-the-tool'>
  10121. <title>Disabling the Tool</title>
  10122. <para>
  10123. To disable the error reporting feature, simply remove or comment
  10124. out the following statement from the end of your
  10125. <filename>local.conf</filename> file in your
  10126. <link linkend='build-directory'>Build Directory</link>.
  10127. <literallayout class='monospaced'>
  10128. INHERIT += "report-error"
  10129. </literallayout>
  10130. </para>
  10131. </section>
  10132. <section id='setting-up-your-own-error-reporting-server'>
  10133. <title>Setting Up Your Own Error Reporting Server</title>
  10134. <para>
  10135. If you want to set up your own error reporting server, you
  10136. can obtain the code from the Git repository at
  10137. <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/error-report-web/'></ulink>.
  10138. Instructions on how to set it up are in the README document.
  10139. </para>
  10140. </section>
  10141. </section>
  10142. </chapter>
  10143. <!--
  10144. vim: expandtab tw=80 ts=4
  10145. -->