dev-manual-common-tasks.rst 453 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. ************
  3. Common Tasks
  4. ************
  5. This chapter describes fundamental procedures such as creating layers,
  6. adding new software packages, extending or customizing images, porting
  7. work to new hardware (adding a new machine), and so forth. You will find
  8. that the procedures documented here occur often in the development cycle
  9. using the Yocto Project.
  10. Understanding and Creating Layers
  11. =================================
  12. The OpenEmbedded build system supports organizing
  13. :term:`Metadata` into multiple layers.
  14. Layers allow you to isolate different types of customizations from each
  15. other. For introductory information on the Yocto Project Layer Model,
  16. see the
  17. ":ref:`overview-manual/overview-manual-yp-intro:the yocto project layer model`"
  18. section in the Yocto Project Overview and Concepts Manual.
  19. Creating Your Own Layer
  20. -----------------------
  21. It is very easy to create your own layers to use with the OpenEmbedded
  22. build system. The Yocto Project ships with tools that speed up creating
  23. layers. This section describes the steps you perform by hand to create
  24. layers so that you can better understand them. For information about the
  25. layer-creation tools, see the
  26. ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
  27. section in the Yocto Project Board Support Package (BSP) Developer's
  28. Guide and the ":ref:`dev-manual/dev-manual-common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
  29. section further down in this manual.
  30. Follow these general steps to create your layer without using tools:
  31. 1. *Check Existing Layers:* Before creating a new layer, you should be
  32. sure someone has not already created a layer containing the Metadata
  33. you need. You can see the `OpenEmbedded Metadata
  34. Index <https://layers.openembedded.org/layerindex/layers/>`__ for a
  35. list of layers from the OpenEmbedded community that can be used in
  36. the Yocto Project. You could find a layer that is identical or close
  37. to what you need.
  38. 2. *Create a Directory:* Create the directory for your layer. When you
  39. create the layer, be sure to create the directory in an area not
  40. associated with the Yocto Project :term:`Source Directory`
  41. (e.g. the cloned ``poky`` repository).
  42. While not strictly required, prepend the name of the directory with
  43. the string "meta-". For example:
  44. ::
  45. meta-mylayer
  46. meta-GUI_xyz
  47. meta-mymachine
  48. With rare exceptions, a layer's name follows this form:
  49. ::
  50. meta-root_name
  51. Following this layer naming convention can save
  52. you trouble later when tools, components, or variables "assume" your
  53. layer name begins with "meta-". A notable example is in configuration
  54. files as shown in the following step where layer names without the
  55. "meta-" string are appended to several variables used in the
  56. configuration.
  57. 3. *Create a Layer Configuration File:* Inside your new layer folder,
  58. you need to create a ``conf/layer.conf`` file. It is easiest to take
  59. an existing layer configuration file and copy that to your layer's
  60. ``conf`` directory and then modify the file as needed.
  61. The ``meta-yocto-bsp/conf/layer.conf`` file in the Yocto Project
  62. :yocto_git:`Source Repositories </cgit/cgit.cgi/poky/tree/meta-yocto-bsp/conf>`
  63. demonstrates the required syntax. For your layer, you need to replace
  64. "yoctobsp" with a unique identifier for your layer (e.g. "machinexyz"
  65. for a layer named "meta-machinexyz"):
  66. ::
  67. # We have a conf and classes directory, add to BBPATH
  68. BBPATH .= ":${LAYERDIR}"
  69. # We have recipes-* directories, add to BBFILES
  70. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  71. ${LAYERDIR}/recipes-*/*/*.bbappend"
  72. BBFILE_COLLECTIONS += "yoctobsp"
  73. BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
  74. BBFILE_PRIORITY_yoctobsp = "5"
  75. LAYERVERSION_yoctobsp = "4"
  76. LAYERSERIES_COMPAT_yoctobsp = "dunfell"
  77. Following is an explanation of the layer configuration file:
  78. - :term:`BBPATH`: Adds the layer's
  79. root directory to BitBake's search path. Through the use of the
  80. ``BBPATH`` variable, BitBake locates class files (``.bbclass``),
  81. configuration files, and files that are included with ``include``
  82. and ``require`` statements. For these cases, BitBake uses the
  83. first file that matches the name found in ``BBPATH``. This is
  84. similar to the way the ``PATH`` variable is used for binaries. It
  85. is recommended, therefore, that you use unique class and
  86. configuration filenames in your custom layer.
  87. - :term:`BBFILES`: Defines the
  88. location for all recipes in the layer.
  89. - :term:`BBFILE_COLLECTIONS`:
  90. Establishes the current layer through a unique identifier that is
  91. used throughout the OpenEmbedded build system to refer to the
  92. layer. In this example, the identifier "yoctobsp" is the
  93. representation for the container layer named "meta-yocto-bsp".
  94. - :term:`BBFILE_PATTERN`:
  95. Expands immediately during parsing to provide the directory of the
  96. layer.
  97. - :term:`BBFILE_PRIORITY`:
  98. Establishes a priority to use for recipes in the layer when the
  99. OpenEmbedded build finds recipes of the same name in different
  100. layers.
  101. - :term:`LAYERVERSION`:
  102. Establishes a version number for the layer. You can use this
  103. version number to specify this exact version of the layer as a
  104. dependency when using the
  105. :term:`LAYERDEPENDS`
  106. variable.
  107. - :term:`LAYERDEPENDS`:
  108. Lists all layers on which this layer depends (if any).
  109. - :term:`LAYERSERIES_COMPAT`:
  110. Lists the :yocto_wiki:`Yocto Project </wiki/Releases>`
  111. releases for which the current version is compatible. This
  112. variable is a good way to indicate if your particular layer is
  113. current.
  114. 4. *Add Content:* Depending on the type of layer, add the content. If
  115. the layer adds support for a machine, add the machine configuration
  116. in a ``conf/machine/`` file within the layer. If the layer adds
  117. distro policy, add the distro configuration in a ``conf/distro/``
  118. file within the layer. If the layer introduces new recipes, put the
  119. recipes you need in ``recipes-*`` subdirectories within the layer.
  120. .. note::
  121. For an explanation of layer hierarchy that is compliant with the
  122. Yocto Project, see the ":ref:`bsp-guide/bsp:example filesystem layout`"
  123. section in the Yocto Project Board Support Package (BSP) Developer's Guide.
  124. 5. *Optionally Test for Compatibility:* If you want permission to use
  125. the Yocto Project Compatibility logo with your layer or application
  126. that uses your layer, perform the steps to apply for compatibility.
  127. See the "`Making Sure Your Layer is Compatible With Yocto
  128. Project <#making-sure-your-layer-is-compatible-with-yocto-project>`__"
  129. section for more information.
  130. .. _best-practices-to-follow-when-creating-layers:
  131. Following Best Practices When Creating Layers
  132. ---------------------------------------------
  133. To create layers that are easier to maintain and that will not impact
  134. builds for other machines, you should consider the information in the
  135. following list:
  136. - *Avoid "Overlaying" Entire Recipes from Other Layers in Your
  137. Configuration:* In other words, do not copy an entire recipe into
  138. your layer and then modify it. Rather, use an append file
  139. (``.bbappend``) to override only those parts of the original recipe
  140. you need to modify.
  141. - *Avoid Duplicating Include Files:* Use append files (``.bbappend``)
  142. for each recipe that uses an include file. Or, if you are introducing
  143. a new recipe that requires the included file, use the path relative
  144. to the original layer directory to refer to the file. For example,
  145. use ``require recipes-core/``\ `package`\ ``/``\ `file`\ ``.inc`` instead
  146. of ``require`` `file`\ ``.inc``. If you're finding you have to overlay
  147. the include file, it could indicate a deficiency in the include file
  148. in the layer to which it originally belongs. If this is the case, you
  149. should try to address that deficiency instead of overlaying the
  150. include file. For example, you could address this by getting the
  151. maintainer of the include file to add a variable or variables to make
  152. it easy to override the parts needing to be overridden.
  153. - *Structure Your Layers:* Proper use of overrides within append files
  154. and placement of machine-specific files within your layer can ensure
  155. that a build is not using the wrong Metadata and negatively impacting
  156. a build for a different machine. Following are some examples:
  157. - *Modify Variables to Support a Different Machine:* Suppose you
  158. have a layer named ``meta-one`` that adds support for building
  159. machine "one". To do so, you use an append file named
  160. ``base-files.bbappend`` and create a dependency on "foo" by
  161. altering the :term:`DEPENDS`
  162. variable:
  163. ::
  164. DEPENDS = "foo"
  165. The dependency is created during any
  166. build that includes the layer ``meta-one``. However, you might not
  167. want this dependency for all machines. For example, suppose you
  168. are building for machine "two" but your ``bblayers.conf`` file has
  169. the ``meta-one`` layer included. During the build, the
  170. ``base-files`` for machine "two" will also have the dependency on
  171. ``foo``.
  172. To make sure your changes apply only when building machine "one",
  173. use a machine override with the ``DEPENDS`` statement:
  174. ::
  175. DEPENDS_one = "foo"
  176. You should follow the same strategy when using ``_append``
  177. and ``_prepend`` operations:
  178. ::
  179. DEPENDS_append_one = " foo"
  180. DEPENDS_prepend_one = "foo "
  181. As an actual example, here's a
  182. snippet from the generic kernel include file ``linux-yocto.inc``,
  183. wherein the kernel compile and link options are adjusted in the
  184. case of a subset of the supported architectures:
  185. ::
  186. DEPENDS_append_aarch64 = " libgcc"
  187. KERNEL_CC_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
  188. KERNEL_LD_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
  189. DEPENDS_append_nios2 = " libgcc"
  190. KERNEL_CC_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
  191. KERNEL_LD_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
  192. DEPENDS_append_arc = " libgcc"
  193. KERNEL_CC_append_arc = " ${TOOLCHAIN_OPTIONS}"
  194. KERNEL_LD_append_arc = " ${TOOLCHAIN_OPTIONS}"
  195. KERNEL_FEATURES_append_qemuall=" features/debug/printk.scc"
  196. .. note::
  197. Avoiding "+=" and "=+" and using machine-specific ``_append``
  198. and ``_prepend`` operations is recommended as well.
  199. - *Place Machine-Specific Files in Machine-Specific Locations:* When
  200. you have a base recipe, such as ``base-files.bb``, that contains a
  201. :term:`SRC_URI` statement to a
  202. file, you can use an append file to cause the build to use your
  203. own version of the file. For example, an append file in your layer
  204. at ``meta-one/recipes-core/base-files/base-files.bbappend`` could
  205. extend :term:`FILESPATH` using :term:`FILESEXTRAPATHS` as follows:
  206. ::
  207. FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
  208. The build for machine "one" will pick up your machine-specific file as
  209. long as you have the file in
  210. ``meta-one/recipes-core/base-files/base-files/``. However, if you
  211. are building for a different machine and the ``bblayers.conf``
  212. file includes the ``meta-one`` layer and the location of your
  213. machine-specific file is the first location where that file is
  214. found according to ``FILESPATH``, builds for all machines will
  215. also use that machine-specific file.
  216. You can make sure that a machine-specific file is used for a
  217. particular machine by putting the file in a subdirectory specific
  218. to the machine. For example, rather than placing the file in
  219. ``meta-one/recipes-core/base-files/base-files/`` as shown above,
  220. put it in ``meta-one/recipes-core/base-files/base-files/one/``.
  221. Not only does this make sure the file is used only when building
  222. for machine "one", but the build process locates the file more
  223. quickly.
  224. In summary, you need to place all files referenced from
  225. ``SRC_URI`` in a machine-specific subdirectory within the layer in
  226. order to restrict those files to machine-specific builds.
  227. - *Perform Steps to Apply for Yocto Project Compatibility:* If you want
  228. permission to use the Yocto Project Compatibility logo with your
  229. layer or application that uses your layer, perform the steps to apply
  230. for compatibility. See the "`Making Sure Your Layer is Compatible
  231. With Yocto
  232. Project <#making-sure-your-layer-is-compatible-with-yocto-project>`__"
  233. section for more information.
  234. - *Follow the Layer Naming Convention:* Store custom layers in a Git
  235. repository that use the ``meta-layer_name`` format.
  236. - *Group Your Layers Locally:* Clone your repository alongside other
  237. cloned ``meta`` directories from the :term:`Source Directory`.
  238. Making Sure Your Layer is Compatible With Yocto Project
  239. -------------------------------------------------------
  240. When you create a layer used with the Yocto Project, it is advantageous
  241. to make sure that the layer interacts well with existing Yocto Project
  242. layers (i.e. the layer is compatible with the Yocto Project). Ensuring
  243. compatibility makes the layer easy to be consumed by others in the Yocto
  244. Project community and could allow you permission to use the Yocto
  245. Project Compatible Logo.
  246. .. note::
  247. Only Yocto Project member organizations are permitted to use the
  248. Yocto Project Compatible Logo. The logo is not available for general
  249. use. For information on how to become a Yocto Project member
  250. organization, see the :yocto_home:`Yocto Project Website <>`.
  251. The Yocto Project Compatibility Program consists of a layer application
  252. process that requests permission to use the Yocto Project Compatibility
  253. Logo for your layer and application. The process consists of two parts:
  254. 1. Successfully passing a script (``yocto-check-layer``) that when run
  255. against your layer, tests it against constraints based on experiences
  256. of how layers have worked in the real world and where pitfalls have
  257. been found. Getting a "PASS" result from the script is required for
  258. successful compatibility registration.
  259. 2. Completion of an application acceptance form, which you can find at
  260. https://www.yoctoproject.org/webform/yocto-project-compatible-registration.
  261. To be granted permission to use the logo, you need to satisfy the
  262. following:
  263. - Be able to check the box indicating that you got a "PASS" when
  264. running the script against your layer.
  265. - Answer "Yes" to the questions on the form or have an acceptable
  266. explanation for any questions answered "No".
  267. - Be a Yocto Project Member Organization.
  268. The remainder of this section presents information on the registration
  269. form and on the ``yocto-check-layer`` script.
  270. Yocto Project Compatible Program Application
  271. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  272. Use the form to apply for your layer's approval. Upon successful
  273. application, you can use the Yocto Project Compatibility Logo with your
  274. layer and the application that uses your layer.
  275. To access the form, use this link:
  276. https://www.yoctoproject.org/webform/yocto-project-compatible-registration.
  277. Follow the instructions on the form to complete your application.
  278. The application consists of the following sections:
  279. - *Contact Information:* Provide your contact information as the fields
  280. require. Along with your information, provide the released versions
  281. of the Yocto Project for which your layer is compatible.
  282. - *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the
  283. items in the checklist. Space exists at the bottom of the form for
  284. any explanations for items for which you answered "No".
  285. - *Recommendations:* Provide answers for the questions regarding Linux
  286. kernel use and build success.
  287. ``yocto-check-layer`` Script
  288. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  289. The ``yocto-check-layer`` script provides you a way to assess how
  290. compatible your layer is with the Yocto Project. You should run this
  291. script prior to using the form to apply for compatibility as described
  292. in the previous section. You need to achieve a "PASS" result in order to
  293. have your application form successfully processed.
  294. The script divides tests into three areas: COMMON, BSP, and DISTRO. For
  295. example, given a distribution layer (DISTRO), the layer must pass both
  296. the COMMON and DISTRO related tests. Furthermore, if your layer is a BSP
  297. layer, the layer must pass the COMMON and BSP set of tests.
  298. To execute the script, enter the following commands from your build
  299. directory:
  300. ::
  301. $ source oe-init-build-env
  302. $ yocto-check-layer your_layer_directory
  303. Be sure to provide the actual directory for your
  304. layer as part of the command.
  305. Entering the command causes the script to determine the type of layer
  306. and then to execute a set of specific tests against the layer. The
  307. following list overviews the test:
  308. - ``common.test_readme``: Tests if a ``README`` file exists in the
  309. layer and the file is not empty.
  310. - ``common.test_parse``: Tests to make sure that BitBake can parse the
  311. files without error (i.e. ``bitbake -p``).
  312. - ``common.test_show_environment``: Tests that the global or per-recipe
  313. environment is in order without errors (i.e. ``bitbake -e``).
  314. - ``common.test_world``: Verifies that ``bitbake world`` works.
  315. - ``common.test_signatures``: Tests to be sure that BSP and DISTRO
  316. layers do not come with recipes that change signatures.
  317. - ``common.test_layerseries_compat``: Verifies layer compatibility is
  318. set properly.
  319. - ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine
  320. configurations.
  321. - ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not
  322. set the machine when the layer is added.
  323. - ``bsp.test_machine_world``: Verifies that ``bitbake world`` works
  324. regardless of which machine is selected.
  325. - ``bsp.test_machine_signatures``: Verifies that building for a
  326. particular machine affects only the signature of tasks specific to
  327. that machine.
  328. - ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has
  329. distro configurations.
  330. - ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer
  331. does not set the distribution when the layer is added.
  332. Enabling Your Layer
  333. -------------------
  334. Before the OpenEmbedded build system can use your new layer, you need to
  335. enable it. To enable your layer, simply add your layer's path to the
  336. ``BBLAYERS`` variable in your ``conf/bblayers.conf`` file, which is
  337. found in the :term:`Build Directory`.
  338. The following example shows how to enable a layer named
  339. ``meta-mylayer``:
  340. ::
  341. # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
  342. # changes incompatibly
  343. POKY_BBLAYERS_CONF_VERSION = "2"
  344. BBPATH = "${TOPDIR}"
  345. BBFILES ?= ""
  346. BBLAYERS ?= " \
  347. /home/user/poky/meta \
  348. /home/user/poky/meta-poky \
  349. /home/user/poky/meta-yocto-bsp \
  350. /home/user/poky/meta-mylayer \
  351. "
  352. BitBake parses each ``conf/layer.conf`` file from the top down as
  353. specified in the ``BBLAYERS`` variable within the ``conf/bblayers.conf``
  354. file. During the processing of each ``conf/layer.conf`` file, BitBake
  355. adds the recipes, classes and configurations contained within the
  356. particular layer to the source directory.
  357. .. _using-bbappend-files:
  358. Using .bbappend Files in Your Layer
  359. -----------------------------------
  360. A recipe that appends Metadata to another recipe is called a BitBake
  361. append file. A BitBake append file uses the ``.bbappend`` file type
  362. suffix, while the corresponding recipe to which Metadata is being
  363. appended uses the ``.bb`` file type suffix.
  364. You can use a ``.bbappend`` file in your layer to make additions or
  365. changes to the content of another layer's recipe without having to copy
  366. the other layer's recipe into your layer. Your ``.bbappend`` file
  367. resides in your layer, while the main ``.bb`` recipe file to which you
  368. are appending Metadata resides in a different layer.
  369. Being able to append information to an existing recipe not only avoids
  370. duplication, but also automatically applies recipe changes from a
  371. different layer into your layer. If you were copying recipes, you would
  372. have to manually merge changes as they occur.
  373. When you create an append file, you must use the same root name as the
  374. corresponding recipe file. For example, the append file
  375. ``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This
  376. means the original recipe and append file names are version
  377. number-specific. If the corresponding recipe is renamed to update to a
  378. newer version, you must also rename and possibly update the
  379. corresponding ``.bbappend`` as well. During the build process, BitBake
  380. displays an error on starting if it detects a ``.bbappend`` file that
  381. does not have a corresponding recipe with a matching name. See the
  382. :term:`BB_DANGLINGAPPENDS_WARNONLY`
  383. variable for information on how to handle this error.
  384. As an example, consider the main formfactor recipe and a corresponding
  385. formfactor append file both from the :term:`Source Directory`.
  386. Here is the main
  387. formfactor recipe, which is named ``formfactor_0.0.bb`` and located in
  388. the "meta" layer at ``meta/recipes-bsp/formfactor``:
  389. ::
  390. SUMMARY = "Device formfactor information"
  391. DESCRIPTION = "A formfactor configuration file provides information about the \
  392. target hardware for which the image is being built and information that the \
  393. build system cannot obtain from other sources such as the kernel."
  394. SECTION = "base"
  395. LICENSE = "MIT"
  396. LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
  397. PR = "r45"
  398. SRC_URI = "file://config file://machconfig"
  399. S = "${WORKDIR}"
  400. PACKAGE_ARCH = "${MACHINE_ARCH}"
  401. INHIBIT_DEFAULT_DEPS = "1"
  402. do_install() {
  403. # Install file only if it has contents
  404. install -d ${D}${sysconfdir}/formfactor/
  405. install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
  406. if [ -s "${S}/machconfig" ]; then
  407. install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
  408. fi
  409. }
  410. In the main recipe, note the :term:`SRC_URI`
  411. variable, which tells the OpenEmbedded build system where to find files
  412. during the build.
  413. Following is the append file, which is named ``formfactor_0.0.bbappend``
  414. and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The
  415. file is in the layer at ``recipes-bsp/formfactor``:
  416. ::
  417. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
  418. By default, the build system uses the
  419. :term:`FILESPATH` variable to
  420. locate files. This append file extends the locations by setting the
  421. :term:`FILESEXTRAPATHS`
  422. variable. Setting this variable in the ``.bbappend`` file is the most
  423. reliable and recommended method for adding directories to the search
  424. path used by the build system to find files.
  425. The statement in this example extends the directories to include
  426. ``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``,
  427. which resolves to a directory named ``formfactor`` in the same directory
  428. in which the append file resides (i.e.
  429. ``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must
  430. have the supporting directory structure set up that will contain any
  431. files or patches you will be including from the layer.
  432. Using the immediate expansion assignment operator ``:=`` is important
  433. because of the reference to ``THISDIR``. The trailing colon character is
  434. important as it ensures that items in the list remain colon-separated.
  435. .. note::
  436. BitBake automatically defines the ``THISDIR`` variable. You should
  437. never set this variable yourself. Using "_prepend" as part of the
  438. ``FILESEXTRAPATHS`` ensures your path will be searched prior to other
  439. paths in the final list.
  440. Also, not all append files add extra files. Many append files simply
  441. exist to add build options (e.g. ``systemd``). For these cases, your
  442. append file would not even use the ``FILESEXTRAPATHS`` statement.
  443. Prioritizing Your Layer
  444. -----------------------
  445. Each layer is assigned a priority value. Priority values control which
  446. layer takes precedence if there are recipe files with the same name in
  447. multiple layers. For these cases, the recipe file from the layer with a
  448. higher priority number takes precedence. Priority values also affect the
  449. order in which multiple ``.bbappend`` files for the same recipe are
  450. applied. You can either specify the priority manually, or allow the
  451. build system to calculate it based on the layer's dependencies.
  452. To specify the layer's priority manually, use the
  453. :term:`BBFILE_PRIORITY`
  454. variable and append the layer's root name:
  455. ::
  456. BBFILE_PRIORITY_mylayer = "1"
  457. .. note::
  458. It is possible for a recipe with a lower version number
  459. :term:`PV` in a layer that has a higher
  460. priority to take precedence.
  461. Also, the layer priority does not currently affect the precedence
  462. order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake
  463. might address this.
  464. Managing Layers
  465. ---------------
  466. You can use the BitBake layer management tool ``bitbake-layers`` to
  467. provide a view into the structure of recipes across a multi-layer
  468. project. Being able to generate output that reports on configured layers
  469. with their paths and priorities and on ``.bbappend`` files and their
  470. applicable recipes can help to reveal potential problems.
  471. For help on the BitBake layer management tool, use the following
  472. command:
  473. ::
  474. $ bitbake-layers --help
  475. NOTE: Starting bitbake server...
  476. usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] <subcommand> ...
  477. BitBake layers utility
  478. optional arguments:
  479. -d, --debug Enable debug output
  480. -q, --quiet Print only errors
  481. -F, --force Force add without recipe parse verification
  482. --color COLOR Colorize output (where COLOR is auto, always, never)
  483. -h, --help show this help message and exit
  484. subcommands:
  485. <subcommand>
  486. layerindex-fetch Fetches a layer from a layer index along with its
  487. dependent layers, and adds them to conf/bblayers.conf.
  488. layerindex-show-depends
  489. Find layer dependencies from layer index.
  490. add-layer Add one or more layers to bblayers.conf.
  491. remove-layer Remove one or more layers from bblayers.conf.
  492. flatten flatten layer configuration into a separate output
  493. directory.
  494. show-layers show current configured layers.
  495. show-overlayed list overlayed recipes (where the same recipe exists
  496. in another layer)
  497. show-recipes list available recipes, showing the layer they are
  498. provided by
  499. show-appends list bbappend files and recipe files they apply to
  500. show-cross-depends Show dependencies between recipes that cross layer
  501. boundaries.
  502. create-layer Create a basic layer
  503. Use bitbake-layers <subcommand> --help to get help on a specific command
  504. The following list describes the available commands:
  505. - ``help:`` Displays general help or help on a specified command.
  506. - ``show-layers:`` Shows the current configured layers.
  507. - ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed
  508. when a recipe with the same name exists in another layer that has a
  509. higher layer priority.
  510. - ``show-recipes:`` Lists available recipes and the layers that
  511. provide them.
  512. - ``show-appends:`` Lists ``.bbappend`` files and the recipe files to
  513. which they apply.
  514. - ``show-cross-depends:`` Lists dependency relationships between
  515. recipes that cross layer boundaries.
  516. - ``add-layer:`` Adds a layer to ``bblayers.conf``.
  517. - ``remove-layer:`` Removes a layer from ``bblayers.conf``
  518. - ``flatten:`` Flattens the layer configuration into a separate
  519. output directory. Flattening your layer configuration builds a
  520. "flattened" directory that contains the contents of all layers, with
  521. any overlayed recipes removed and any ``.bbappend`` files appended to
  522. the corresponding recipes. You might have to perform some manual
  523. cleanup of the flattened layer as follows:
  524. - Non-recipe files (such as patches) are overwritten. The flatten
  525. command shows a warning for these files.
  526. - Anything beyond the normal layer setup has been added to the
  527. ``layer.conf`` file. Only the lowest priority layer's
  528. ``layer.conf`` is used.
  529. - Overridden and appended items from ``.bbappend`` files need to be
  530. cleaned up. The contents of each ``.bbappend`` end up in the
  531. flattened recipe. However, if there are appended or changed
  532. variable values, you need to tidy these up yourself. Consider the
  533. following example. Here, the ``bitbake-layers`` command adds the
  534. line ``#### bbappended ...`` so that you know where the following
  535. lines originate:
  536. ::
  537. ...
  538. DESCRIPTION = "A useful utility"
  539. ...
  540. EXTRA_OECONF = "--enable-something"
  541. ...
  542. #### bbappended from meta-anotherlayer ####
  543. DESCRIPTION = "Customized utility"
  544. EXTRA_OECONF += "--enable-somethingelse"
  545. Ideally, you would tidy up these utilities as follows:
  546. ::
  547. ...
  548. DESCRIPTION = "Customized utility"
  549. ...
  550. EXTRA_OECONF = "--enable-something --enable-somethingelse"
  551. ...
  552. - ``layerindex-fetch``: Fetches a layer from a layer index, along
  553. with its dependent layers, and adds the layers to the
  554. ``conf/bblayers.conf`` file.
  555. - ``layerindex-show-depends``: Finds layer dependencies from the
  556. layer index.
  557. - ``create-layer``: Creates a basic layer.
  558. Creating a General Layer Using the ``bitbake-layers`` Script
  559. ------------------------------------------------------------
  560. The ``bitbake-layers`` script with the ``create-layer`` subcommand
  561. simplifies creating a new general layer.
  562. .. note::
  563. - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`"
  564. section in the Yocto
  565. Project Board Specific (BSP) Developer's Guide.
  566. - In order to use a layer with the OpenEmbedded build system, you
  567. need to add the layer to your ``bblayers.conf`` configuration
  568. file. See the ":ref:`dev-manual/dev-manual-common-tasks:adding a layer using the \`\`bitbake-layers\`\` script`"
  569. section for more information.
  570. The default mode of the script's operation with this subcommand is to
  571. create a layer with the following:
  572. - A layer priority of 6.
  573. - A ``conf`` subdirectory that contains a ``layer.conf`` file.
  574. - A ``recipes-example`` subdirectory that contains a further
  575. subdirectory named ``example``, which contains an ``example.bb``
  576. recipe file.
  577. - A ``COPYING.MIT``, which is the license statement for the layer. The
  578. script assumes you want to use the MIT license, which is typical for
  579. most layers, for the contents of the layer itself.
  580. - A ``README`` file, which is a file describing the contents of your
  581. new layer.
  582. In its simplest form, you can use the following command form to create a
  583. layer. The command creates a layer whose name corresponds to
  584. "your_layer_name" in the current directory:
  585. ::
  586. $ bitbake-layers create-layer your_layer_name
  587. As an example, the following command creates a layer named ``meta-scottrif``
  588. in your home directory:
  589. ::
  590. $ cd /usr/home
  591. $ bitbake-layers create-layer meta-scottrif
  592. NOTE: Starting bitbake server...
  593. Add your new layer with 'bitbake-layers add-layer meta-scottrif'
  594. If you want to set the priority of the layer to other than the default
  595. value of "6", you can either use the ``--priority`` option or you
  596. can edit the
  597. :term:`BBFILE_PRIORITY` value
  598. in the ``conf/layer.conf`` after the script creates it. Furthermore, if
  599. you want to give the example recipe file some name other than the
  600. default, you can use the ``--example-recipe-name`` option.
  601. The easiest way to see how the ``bitbake-layers create-layer`` command
  602. works is to experiment with the script. You can also read the usage
  603. information by entering the following:
  604. ::
  605. $ bitbake-layers create-layer --help
  606. NOTE: Starting bitbake server...
  607. usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
  608. [--example-recipe-name EXAMPLERECIPE]
  609. layerdir
  610. Create a basic layer
  611. positional arguments:
  612. layerdir Layer directory to create
  613. optional arguments:
  614. -h, --help show this help message and exit
  615. --priority PRIORITY, -p PRIORITY
  616. Layer directory to create
  617. --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
  618. Filename of the example recipe
  619. Adding a Layer Using the ``bitbake-layers`` Script
  620. --------------------------------------------------
  621. Once you create your general layer, you must add it to your
  622. ``bblayers.conf`` file. Adding the layer to this configuration file
  623. makes the OpenEmbedded build system aware of your layer so that it can
  624. search it for metadata.
  625. Add your layer by using the ``bitbake-layers add-layer`` command:
  626. ::
  627. $ bitbake-layers add-layer your_layer_name
  628. Here is an example that adds a
  629. layer named ``meta-scottrif`` to the configuration file. Following the
  630. command that adds the layer is another ``bitbake-layers`` command that
  631. shows the layers that are in your ``bblayers.conf`` file:
  632. ::
  633. $ bitbake-layers add-layer meta-scottrif
  634. NOTE: Starting bitbake server...
  635. Parsing recipes: 100% |##########################################################| Time: 0:00:49
  636. Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
  637. $ bitbake-layers show-layers
  638. NOTE: Starting bitbake server...
  639. layer path priority
  640. ==========================================================================
  641. meta /home/scottrif/poky/meta 5
  642. meta-poky /home/scottrif/poky/meta-poky 5
  643. meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
  644. workspace /home/scottrif/poky/build/workspace 99
  645. meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
  646. Adding the layer to this file
  647. enables the build system to locate the layer during the build.
  648. .. note::
  649. During a build, the OpenEmbedded build system looks in the layers
  650. from the top of the list down to the bottom in that order.
  651. .. _usingpoky-extend-customimage:
  652. Customizing Images
  653. ==================
  654. You can customize images to satisfy particular requirements. This
  655. section describes several methods and provides guidelines for each.
  656. .. _usingpoky-extend-customimage-localconf:
  657. Customizing Images Using ``local.conf``
  658. ---------------------------------------
  659. Probably the easiest way to customize an image is to add a package by
  660. way of the ``local.conf`` configuration file. Because it is limited to
  661. local use, this method generally only allows you to add packages and is
  662. not as flexible as creating your own customized image. When you add
  663. packages using local variables this way, you need to realize that these
  664. variable changes are in effect for every build and consequently affect
  665. all images, which might not be what you require.
  666. To add a package to your image using the local configuration file, use
  667. the ``IMAGE_INSTALL`` variable with the ``_append`` operator:
  668. ::
  669. IMAGE_INSTALL_append = " strace"
  670. Use of the syntax is important -
  671. specifically, the space between the quote and the package name, which is
  672. ``strace`` in this example. This space is required since the ``_append``
  673. operator does not add the space.
  674. Furthermore, you must use ``_append`` instead of the ``+=`` operator if
  675. you want to avoid ordering issues. The reason for this is because doing
  676. so unconditionally appends to the variable and avoids ordering problems
  677. due to the variable being set in image recipes and ``.bbclass`` files
  678. with operators like ``?=``. Using ``_append`` ensures the operation
  679. takes effect.
  680. As shown in its simplest use, ``IMAGE_INSTALL_append`` affects all
  681. images. It is possible to extend the syntax so that the variable applies
  682. to a specific image only. Here is an example:
  683. ::
  684. IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
  685. This example adds ``strace`` to the ``core-image-minimal`` image only.
  686. You can add packages using a similar approach through the
  687. ``CORE_IMAGE_EXTRA_INSTALL`` variable. If you use this variable, only
  688. ``core-image-*`` images are affected.
  689. .. _usingpoky-extend-customimage-imagefeatures:
  690. Customizing Images Using Custom ``IMAGE_FEATURES`` and ``EXTRA_IMAGE_FEATURES``
  691. -------------------------------------------------------------------------------
  692. Another method for customizing your image is to enable or disable
  693. high-level image features by using the
  694. :term:`IMAGE_FEATURES` and
  695. :term:`EXTRA_IMAGE_FEATURES`
  696. variables. Although the functions for both variables are nearly
  697. equivalent, best practices dictate using ``IMAGE_FEATURES`` from within
  698. a recipe and using ``EXTRA_IMAGE_FEATURES`` from within your
  699. ``local.conf`` file, which is found in the
  700. :term:`Build Directory`.
  701. To understand how these features work, the best reference is
  702. ``meta/classes/core-image.bbclass``. This class lists out the available
  703. ``IMAGE_FEATURES`` of which most map to package groups while some, such
  704. as ``debug-tweaks`` and ``read-only-rootfs``, resolve as general
  705. configuration settings.
  706. In summary, the file looks at the contents of the ``IMAGE_FEATURES``
  707. variable and then maps or configures the feature accordingly. Based on
  708. this information, the build system automatically adds the appropriate
  709. packages or configurations to the
  710. :term:`IMAGE_INSTALL` variable.
  711. Effectively, you are enabling extra features by extending the class or
  712. creating a custom class for use with specialized image ``.bb`` files.
  713. Use the ``EXTRA_IMAGE_FEATURES`` variable from within your local
  714. configuration file. Using a separate area from which to enable features
  715. with this variable helps you avoid overwriting the features in the image
  716. recipe that are enabled with ``IMAGE_FEATURES``. The value of
  717. ``EXTRA_IMAGE_FEATURES`` is added to ``IMAGE_FEATURES`` within
  718. ``meta/conf/bitbake.conf``.
  719. To illustrate how you can use these variables to modify your image,
  720. consider an example that selects the SSH server. The Yocto Project ships
  721. with two SSH servers you can use with your images: Dropbear and OpenSSH.
  722. Dropbear is a minimal SSH server appropriate for resource-constrained
  723. environments, while OpenSSH is a well-known standard SSH server
  724. implementation. By default, the ``core-image-sato`` image is configured
  725. to use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb``
  726. images both include OpenSSH. The ``core-image-minimal`` image does not
  727. contain an SSH server.
  728. You can customize your image and change these defaults. Edit the
  729. ``IMAGE_FEATURES`` variable in your recipe or use the
  730. ``EXTRA_IMAGE_FEATURES`` in your ``local.conf`` file so that it
  731. configures the image you are working with to include
  732. ``ssh-server-dropbear`` or ``ssh-server-openssh``.
  733. .. note::
  734. See the ":ref:`ref-manual/ref-features:image features`" section in the Yocto
  735. Project Reference Manual for a complete list of image features that ship
  736. with the Yocto Project.
  737. .. _usingpoky-extend-customimage-custombb:
  738. Customizing Images Using Custom .bb Files
  739. -----------------------------------------
  740. You can also customize an image by creating a custom recipe that defines
  741. additional software as part of the image. The following example shows
  742. the form for the two lines you need:
  743. ::
  744. IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
  745. inherit core-image
  746. Defining the software using a custom recipe gives you total control over
  747. the contents of the image. It is important to use the correct names of
  748. packages in the ``IMAGE_INSTALL`` variable. You must use the
  749. OpenEmbedded notation and not the Debian notation for the names (e.g.
  750. ``glibc-dev`` instead of ``libc6-dev``).
  751. The other method for creating a custom image is to base it on an
  752. existing image. For example, if you want to create an image based on
  753. ``core-image-sato`` but add the additional package ``strace`` to the
  754. image, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new
  755. ``.bb`` and add the following line to the end of the copy:
  756. ::
  757. IMAGE_INSTALL += "strace"
  758. .. _usingpoky-extend-customimage-customtasks:
  759. Customizing Images Using Custom Package Groups
  760. ----------------------------------------------
  761. For complex custom images, the best approach for customizing an image is
  762. to create a custom package group recipe that is used to build the image
  763. or images. A good example of a package group recipe is
  764. ``meta/recipes-core/packagegroups/packagegroup-base.bb``.
  765. If you examine that recipe, you see that the ``PACKAGES`` variable lists
  766. the package group packages to produce. The ``inherit packagegroup``
  767. statement sets appropriate default values and automatically adds
  768. ``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each
  769. package specified in the ``PACKAGES`` statement.
  770. .. note::
  771. The ``inherit packagegroup`` line should be located near the top of the
  772. recipe, certainly before the ``PACKAGES`` statement.
  773. For each package you specify in ``PACKAGES``, you can use ``RDEPENDS``
  774. and ``RRECOMMENDS`` entries to provide a list of packages the parent
  775. task package should contain. You can see examples of these further down
  776. in the ``packagegroup-base.bb`` recipe.
  777. Here is a short, fabricated example showing the same basic pieces for a
  778. hypothetical packagegroup defined in ``packagegroup-custom.bb``, where
  779. the variable ``PN`` is the standard way to abbreviate the reference to
  780. the full packagegroup name ``packagegroup-custom``:
  781. ::
  782. DESCRIPTION = "My Custom Package Groups"
  783. inherit packagegroup
  784. PACKAGES = "\
  785. ${PN}-apps \
  786. ${PN}-tools \
  787. "
  788. RDEPENDS_${PN}-apps = "\
  789. dropbear \
  790. portmap \
  791. psplash"
  792. RDEPENDS_${PN}-tools = "\
  793. oprofile \
  794. oprofileui-server \
  795. lttng-tools"
  796. RRECOMMENDS_${PN}-tools = "\
  797. kernel-module-oprofile"
  798. In the previous example, two package group packages are created with
  799. their dependencies and their recommended package dependencies listed:
  800. ``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To
  801. build an image using these package group packages, you need to add
  802. ``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to
  803. ``IMAGE_INSTALL``. For other forms of image dependencies see the other
  804. areas of this section.
  805. .. _usingpoky-extend-customimage-image-name:
  806. Customizing an Image Hostname
  807. -----------------------------
  808. By default, the configured hostname (i.e. ``/etc/hostname``) in an image
  809. is the same as the machine name. For example, if
  810. :term:`MACHINE` equals "qemux86", the
  811. configured hostname written to ``/etc/hostname`` is "qemux86".
  812. You can customize this name by altering the value of the "hostname"
  813. variable in the ``base-files`` recipe using either an append file or a
  814. configuration file. Use the following in an append file:
  815. ::
  816. hostname = "myhostname"
  817. Use the following in a configuration file:
  818. ::
  819. hostname_pn-base-files = "myhostname"
  820. Changing the default value of the variable "hostname" can be useful in
  821. certain situations. For example, suppose you need to do extensive
  822. testing on an image and you would like to easily identify the image
  823. under test from existing images with typical default hostnames. In this
  824. situation, you could change the default hostname to "testme", which
  825. results in all the images using the name "testme". Once testing is
  826. complete and you do not need to rebuild the image for test any longer,
  827. you can easily reset the default hostname.
  828. Another point of interest is that if you unset the variable, the image
  829. will have no default hostname in the filesystem. Here is an example that
  830. unsets the variable in a configuration file:
  831. ::
  832. hostname_pn-base-files = ""
  833. Having no default hostname in the filesystem is suitable for
  834. environments that use dynamic hostnames such as virtual machines.
  835. .. _new-recipe-writing-a-new-recipe:
  836. Writing a New Recipe
  837. ====================
  838. Recipes (``.bb`` files) are fundamental components in the Yocto Project
  839. environment. Each software component built by the OpenEmbedded build
  840. system requires a recipe to define the component. This section describes
  841. how to create, write, and test a new recipe.
  842. .. note::
  843. For information on variables that are useful for recipes and for
  844. information about recipe naming issues, see the
  845. ":ref:`ref-manual/ref-varlocality:recipes`" section of the Yocto Project
  846. Reference Manual.
  847. .. _new-recipe-overview:
  848. Overview
  849. --------
  850. The following figure shows the basic process for creating a new recipe.
  851. The remainder of the section provides details for the steps.
  852. .. image:: figures/recipe-workflow.png
  853. :align: center
  854. .. _new-recipe-locate-or-automatically-create-a-base-recipe:
  855. Locate or Automatically Create a Base Recipe
  856. --------------------------------------------
  857. You can always write a recipe from scratch. However, three choices exist
  858. that can help you quickly get a start on a new recipe:
  859. - ``devtool add``: A command that assists in creating a recipe and an
  860. environment conducive to development.
  861. - ``recipetool create``: A command provided by the Yocto Project that
  862. automates creation of a base recipe based on the source files.
  863. - *Existing Recipes:* Location and modification of an existing recipe
  864. that is similar in function to the recipe you need.
  865. .. note::
  866. For information on recipe syntax, see the
  867. ":ref:`dev-manual/dev-manual-common-tasks:recipe syntax`" section.
  868. .. _new-recipe-creating-the-base-recipe-using-devtool:
  869. Creating the Base Recipe Using ``devtool add``
  870. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  871. The ``devtool add`` command uses the same logic for auto-creating the
  872. recipe as ``recipetool create``, which is listed below. Additionally,
  873. however, ``devtool add`` sets up an environment that makes it easy for
  874. you to patch the source and to make changes to the recipe as is often
  875. necessary when adding a recipe to build a new piece of software to be
  876. included in a build.
  877. You can find a complete description of the ``devtool add`` command in
  878. the ":ref:`sdk-a-closer-look-at-devtool-add`" section
  879. in the Yocto Project Application Development and the Extensible Software
  880. Development Kit (eSDK) manual.
  881. .. _new-recipe-creating-the-base-recipe-using-recipetool:
  882. Creating the Base Recipe Using ``recipetool create``
  883. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  884. ``recipetool create`` automates creation of a base recipe given a set of
  885. source code files. As long as you can extract or point to the source
  886. files, the tool will construct a recipe and automatically configure all
  887. pre-build information into the recipe. For example, suppose you have an
  888. application that builds using Autotools. Creating the base recipe using
  889. ``recipetool`` results in a recipe that has the pre-build dependencies,
  890. license requirements, and checksums configured.
  891. To run the tool, you just need to be in your
  892. :term:`Build Directory` and have sourced the
  893. build environment setup script (i.e.
  894. :ref:`structure-core-script`).
  895. To get help on the tool, use the following command:
  896. ::
  897. $ recipetool -h
  898. NOTE: Starting bitbake server...
  899. usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ...
  900. OpenEmbedded recipe tool
  901. options:
  902. -d, --debug Enable debug output
  903. -q, --quiet Print only errors
  904. --color COLOR Colorize output (where COLOR is auto, always, never)
  905. -h, --help show this help message and exit
  906. subcommands:
  907. create Create a new recipe
  908. newappend Create a bbappend for the specified target in the specified
  909. layer
  910. setvar Set a variable within a recipe
  911. appendfile Create/update a bbappend to replace a target file
  912. appendsrcfiles Create/update a bbappend to add or replace source files
  913. appendsrcfile Create/update a bbappend to add or replace a source file
  914. Use recipetool <subcommand> --help to get help on a specific command
  915. Running ``recipetool create -o OUTFILE`` creates the base recipe and
  916. locates it properly in the layer that contains your source files.
  917. Following are some syntax examples:
  918. - Use this syntax to generate a recipe based on source. Once generated,
  919. the recipe resides in the existing source code layer:
  920. ::
  921. recipetool create -o OUTFILE source
  922. - Use this syntax to generate a recipe using code that
  923. you extract from source. The extracted code is placed in its own layer
  924. defined by ``EXTERNALSRC``.
  925. ::
  926. recipetool create -o OUTFILE -x EXTERNALSRC source
  927. - Use this syntax to generate a recipe based on source. The options
  928. direct ``recipetool`` to generate debugging information. Once generated,
  929. the recipe resides in the existing source code layer:
  930. ::
  931. recipetool create -d -o OUTFILE source
  932. .. _new-recipe-locating-and-using-a-similar-recipe:
  933. Locating and Using a Similar Recipe
  934. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  935. Before writing a recipe from scratch, it is often useful to discover
  936. whether someone else has already written one that meets (or comes close
  937. to meeting) your needs. The Yocto Project and OpenEmbedded communities
  938. maintain many recipes that might be candidates for what you are doing.
  939. You can find a good central index of these recipes in the `OpenEmbedded
  940. Layer Index <https://layers.openembedded.org>`__.
  941. Working from an existing recipe or a skeleton recipe is the best way to
  942. get started. Here are some points on both methods:
  943. - *Locate and modify a recipe that is close to what you want to do:*
  944. This method works when you are familiar with the current recipe
  945. space. The method does not work so well for those new to the Yocto
  946. Project or writing recipes.
  947. Some risks associated with this method are using a recipe that has
  948. areas totally unrelated to what you are trying to accomplish with
  949. your recipe, not recognizing areas of the recipe that you might have
  950. to add from scratch, and so forth. All these risks stem from
  951. unfamiliarity with the existing recipe space.
  952. - *Use and modify the following skeleton recipe:* If for some reason
  953. you do not want to use ``recipetool`` and you cannot find an existing
  954. recipe that is close to meeting your needs, you can use the following
  955. structure to provide the fundamental areas of a new recipe.
  956. ::
  957. DESCRIPTION = ""
  958. HOMEPAGE = ""
  959. LICENSE = ""
  960. SECTION = ""
  961. DEPENDS = ""
  962. LIC_FILES_CHKSUM = ""
  963. SRC_URI = ""
  964. .. _new-recipe-storing-and-naming-the-recipe:
  965. Storing and Naming the Recipe
  966. -----------------------------
  967. Once you have your base recipe, you should put it in your own layer and
  968. name it appropriately. Locating it correctly ensures that the
  969. OpenEmbedded build system can find it when you use BitBake to process
  970. the recipe.
  971. - *Storing Your Recipe:* The OpenEmbedded build system locates your
  972. recipe through the layer's ``conf/layer.conf`` file and the
  973. :term:`BBFILES` variable. This
  974. variable sets up a path from which the build system can locate
  975. recipes. Here is the typical use:
  976. ::
  977. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  978. ${LAYERDIR}/recipes-*/*/*.bbappend"
  979. Consequently, you need to be sure you locate your new recipe inside
  980. your layer such that it can be found.
  981. You can find more information on how layers are structured in the
  982. "`Understanding and Creating
  983. Layers <#understanding-and-creating-layers>`__" section.
  984. - *Naming Your Recipe:* When you name your recipe, you need to follow
  985. this naming convention:
  986. ::
  987. basename_version.bb
  988. Use lower-cased characters and do not include the reserved suffixes
  989. ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use
  990. them as part of your recipe name unless the string applies). Here are some
  991. examples:
  992. .. code-block:: none
  993. cups_1.7.0.bb
  994. gawk_4.0.2.bb
  995. irssi_0.8.16-rc1.bb
  996. .. _new-recipe-running-a-build-on-the-recipe:
  997. Running a Build on the Recipe
  998. -----------------------------
  999. Creating a new recipe is usually an iterative process that requires
  1000. using BitBake to process the recipe multiple times in order to
  1001. progressively discover and add information to the recipe file.
  1002. Assuming you have sourced the build environment setup script (i.e.
  1003. :ref:`structure-core-script`) and you are in
  1004. the :term:`Build Directory`, use
  1005. BitBake to process your recipe. All you need to provide is the
  1006. ``basename`` of the recipe as described in the previous section:
  1007. ::
  1008. $ bitbake basename
  1009. During the build, the OpenEmbedded build system creates a temporary work
  1010. directory for each recipe
  1011. (``${``\ :term:`WORKDIR`\ ``}``)
  1012. where it keeps extracted source files, log files, intermediate
  1013. compilation and packaging files, and so forth.
  1014. The path to the per-recipe temporary work directory depends on the
  1015. context in which it is being built. The quickest way to find this path
  1016. is to have BitBake return it by running the following:
  1017. ::
  1018. $ bitbake -e basename | grep ^WORKDIR=
  1019. As an example, assume a Source Directory
  1020. top-level folder named ``poky``, a default Build Directory at
  1021. ``poky/build``, and a ``qemux86-poky-linux`` machine target system.
  1022. Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this
  1023. case, the work directory the build system uses to build the package
  1024. would be as follows:
  1025. ::
  1026. poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
  1027. Inside this directory you can find sub-directories such as ``image``,
  1028. ``packages-split``, and ``temp``. After the build, you can examine these
  1029. to determine how well the build went.
  1030. .. note::
  1031. You can find log files for each task in the recipe's ``temp``
  1032. directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``).
  1033. Log files are named ``log.taskname`` (e.g. ``log.do_configure``,
  1034. ``log.do_fetch``, and ``log.do_compile``).
  1035. You can find more information about the build process in
  1036. ":doc:`../overview-manual/overview-manual-development-environment`"
  1037. chapter of the Yocto Project Overview and Concepts Manual.
  1038. .. _new-recipe-fetching-code:
  1039. Fetching Code
  1040. -------------
  1041. The first thing your recipe must do is specify how to fetch the source
  1042. files. Fetching is controlled mainly through the
  1043. :term:`SRC_URI` variable. Your recipe
  1044. must have a ``SRC_URI`` variable that points to where the source is
  1045. located. For a graphical representation of source locations, see the
  1046. ":ref:`sources-dev-environment`" section in
  1047. the Yocto Project Overview and Concepts Manual.
  1048. The :ref:`ref-tasks-fetch` task uses
  1049. the prefix of each entry in the ``SRC_URI`` variable value to determine
  1050. which :ref:`fetcher <bitbake:bb-fetchers>` to use to get your
  1051. source files. It is the ``SRC_URI`` variable that triggers the fetcher.
  1052. The :ref:`ref-tasks-patch` task uses
  1053. the variable after source is fetched to apply patches. The OpenEmbedded
  1054. build system uses
  1055. :term:`FILESOVERRIDES` for
  1056. scanning directory locations for local files in ``SRC_URI``.
  1057. The ``SRC_URI`` variable in your recipe must define each unique location
  1058. for your source files. It is good practice to not hard-code version
  1059. numbers in a URL used in ``SRC_URI``. Rather than hard-code these
  1060. values, use ``${``\ :term:`PV`\ ``}``,
  1061. which causes the fetch process to use the version specified in the
  1062. recipe filename. Specifying the version in this manner means that
  1063. upgrading the recipe to a future version is as simple as renaming the
  1064. recipe to match the new version.
  1065. Here is a simple example from the
  1066. ``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source
  1067. comes from a single tarball. Notice the use of the
  1068. :term:`PV` variable:
  1069. ::
  1070. SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \
  1071. Files mentioned in ``SRC_URI`` whose names end in a typical archive
  1072. extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so
  1073. forth), are automatically extracted during the
  1074. :ref:`ref-tasks-unpack` task. For
  1075. another example that specifies these types of files, see the
  1076. "`Autotooled Package <#new-recipe-autotooled-package>`__" section.
  1077. Another way of specifying source is from an SCM. For Git repositories,
  1078. you must specify :term:`SRCREV` and
  1079. you should specify :term:`PV` to include
  1080. the revision with :term:`SRCPV`. Here
  1081. is an example from the recipe
  1082. ``meta/recipes-kernel/blktrace/blktrace_git.bb``:
  1083. ::
  1084. SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
  1085. PR = "r6"
  1086. PV = "1.0.5+git${SRCPV}"
  1087. SRC_URI = "git://git.kernel.dk/blktrace.git \
  1088. file://ldflags.patch"
  1089. If your ``SRC_URI`` statement includes URLs pointing to individual files
  1090. fetched from a remote server other than a version control system,
  1091. BitBake attempts to verify the files against checksums defined in your
  1092. recipe to ensure they have not been tampered with or otherwise modified
  1093. since the recipe was written. Two checksums are used:
  1094. ``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``.
  1095. If your ``SRC_URI`` variable points to more than a single URL (excluding
  1096. SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for
  1097. each URL. For these cases, you provide a name for each URL as part of
  1098. the ``SRC_URI`` and then reference that name in the subsequent checksum
  1099. statements. Here is an example combining lines from the files
  1100. ``git.inc`` and ``git_2.24.1.bb``:
  1101. ::
  1102. SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
  1103. ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages"
  1104. SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b"
  1105. SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02"
  1106. SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d"
  1107. SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230"
  1108. Proper values for ``md5`` and ``sha256`` checksums might be available
  1109. with other signatures on the download page for the upstream source (e.g.
  1110. ``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the
  1111. OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``,
  1112. you should verify all the signatures you find by hand.
  1113. If no ``SRC_URI`` checksums are specified when you attempt to build the
  1114. recipe, or you provide an incorrect checksum, the build will produce an
  1115. error for each missing or incorrect checksum. As part of the error
  1116. message, the build system provides the checksum string corresponding to
  1117. the fetched file. Once you have the correct checksums, you can copy and
  1118. paste them into your recipe and then run the build again to continue.
  1119. .. note::
  1120. As mentioned, if the upstream source provides signatures for
  1121. verifying the downloaded source code, you should verify those
  1122. manually before setting the checksum values in the recipe and
  1123. continuing with the build.
  1124. This final example is a bit more complicated and is from the
  1125. ``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The
  1126. example's ``SRC_URI`` statement identifies multiple files as the source
  1127. files for the recipe: a tarball, a patch file, a desktop file, and an
  1128. icon.
  1129. ::
  1130. SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
  1131. file://xwc.patch \
  1132. file://rxvt.desktop \
  1133. file://rxvt.png"
  1134. When you specify local files using the ``file://`` URI protocol, the
  1135. build system fetches files from the local machine. The path is relative
  1136. to the :term:`FILESPATH` variable
  1137. and searches specific directories in a certain order:
  1138. ``${``\ :term:`BP`\ ``}``,
  1139. ``${``\ :term:`BPN`\ ``}``, and
  1140. ``files``. The directories are assumed to be subdirectories of the
  1141. directory in which the recipe or append file resides. For another
  1142. example that specifies these types of files, see the "`Single .c File
  1143. Package (Hello
  1144. World!) <#new-recipe-single-c-file-package-hello-world>`__" section.
  1145. The previous example also specifies a patch file. Patch files are files
  1146. whose names usually end in ``.patch`` or ``.diff`` but can end with
  1147. compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example.
  1148. The build system automatically applies patches as described in the
  1149. "`Patching Code <#new-recipe-patching-code>`__" section.
  1150. .. _new-recipe-unpacking-code:
  1151. Unpacking Code
  1152. --------------
  1153. During the build, the
  1154. :ref:`ref-tasks-unpack` task unpacks
  1155. the source with ``${``\ :term:`S`\ ``}``
  1156. pointing to where it is unpacked.
  1157. If you are fetching your source files from an upstream source archived
  1158. tarball and the tarball's internal structure matches the common
  1159. convention of a top-level subdirectory named
  1160. ``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``,
  1161. then you do not need to set ``S``. However, if ``SRC_URI`` specifies to
  1162. fetch source from an archive that does not use this convention, or from
  1163. an SCM like Git or Subversion, your recipe needs to define ``S``.
  1164. If processing your recipe using BitBake successfully unpacks the source
  1165. files, you need to be sure that the directory pointed to by ``${S}``
  1166. matches the structure of the source.
  1167. .. _new-recipe-patching-code:
  1168. Patching Code
  1169. -------------
  1170. Sometimes it is necessary to patch code after it has been fetched. Any
  1171. files mentioned in ``SRC_URI`` whose names end in ``.patch`` or
  1172. ``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are
  1173. treated as patches. The
  1174. :ref:`ref-tasks-patch` task
  1175. automatically applies these patches.
  1176. The build system should be able to apply patches with the "-p1" option
  1177. (i.e. one directory level in the path will be stripped off). If your
  1178. patch needs to have more directory levels stripped off, specify the
  1179. number of levels using the "striplevel" option in the ``SRC_URI`` entry
  1180. for the patch. Alternatively, if your patch needs to be applied in a
  1181. specific subdirectory that is not specified in the patch file, use the
  1182. "patchdir" option in the entry.
  1183. As with all local files referenced in
  1184. :term:`SRC_URI` using ``file://``,
  1185. you should place patch files in a directory next to the recipe either
  1186. named the same as the base name of the recipe
  1187. (:term:`BP` and
  1188. :term:`BPN`) or "files".
  1189. .. _new-recipe-licensing:
  1190. Licensing
  1191. ---------
  1192. Your recipe needs to have both the
  1193. :term:`LICENSE` and
  1194. :term:`LIC_FILES_CHKSUM`
  1195. variables:
  1196. - ``LICENSE``: This variable specifies the license for the software.
  1197. If you do not know the license under which the software you are
  1198. building is distributed, you should go to the source code and look
  1199. for that information. Typical files containing this information
  1200. include ``COPYING``, ``LICENSE``, and ``README`` files. You could
  1201. also find the information near the top of a source file. For example,
  1202. given a piece of software licensed under the GNU General Public
  1203. License version 2, you would set ``LICENSE`` as follows:
  1204. ::
  1205. LICENSE = "GPLv2"
  1206. The licenses you specify within ``LICENSE`` can have any name as long
  1207. as you do not use spaces, since spaces are used as separators between
  1208. license names. For standard licenses, use the names of the files in
  1209. ``meta/files/common-licenses/`` or the ``SPDXLICENSEMAP`` flag names
  1210. defined in ``meta/conf/licenses.conf``.
  1211. - ``LIC_FILES_CHKSUM``: The OpenEmbedded build system uses this
  1212. variable to make sure the license text has not changed. If it has,
  1213. the build produces an error and it affords you the chance to figure
  1214. it out and correct the problem.
  1215. You need to specify all applicable licensing files for the software.
  1216. At the end of the configuration step, the build process will compare
  1217. the checksums of the files to be sure the text has not changed. Any
  1218. differences result in an error with the message containing the
  1219. current checksum. For more explanation and examples of how to set the
  1220. ``LIC_FILES_CHKSUM`` variable, see the
  1221. ":ref:`dev-manual/dev-manual-common-tasks:tracking license changes`" section.
  1222. To determine the correct checksum string, you can list the
  1223. appropriate files in the ``LIC_FILES_CHKSUM`` variable with incorrect
  1224. md5 strings, attempt to build the software, and then note the
  1225. resulting error messages that will report the correct md5 strings.
  1226. See the "`Fetching Code <#new-recipe-fetching-code>`__" section for
  1227. additional information.
  1228. Here is an example that assumes the software has a ``COPYING`` file:
  1229. ::
  1230. LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
  1231. When you try to build the
  1232. software, the build system will produce an error and give you the
  1233. correct string that you can substitute into the recipe file for a
  1234. subsequent build.
  1235. .. _new-dependencies:
  1236. Dependencies
  1237. ------------
  1238. Most software packages have a short list of other packages that they
  1239. require, which are called dependencies. These dependencies fall into two
  1240. main categories: build-time dependencies, which are required when the
  1241. software is built; and runtime dependencies, which are required to be
  1242. installed on the target in order for the software to run.
  1243. Within a recipe, you specify build-time dependencies using the
  1244. :term:`DEPENDS` variable. Although
  1245. nuances exist, items specified in ``DEPENDS`` should be names of other
  1246. recipes. It is important that you specify all build-time dependencies
  1247. explicitly.
  1248. Another consideration is that configure scripts might automatically
  1249. check for optional dependencies and enable corresponding functionality
  1250. if those dependencies are found. If you wish to make a recipe that is
  1251. more generally useful (e.g. publish the recipe in a layer for others to
  1252. use), instead of hard-disabling the functionality, you can use the
  1253. :term:`PACKAGECONFIG` variable to allow functionality and the
  1254. corresponding dependencies to be enabled and disabled easily by other
  1255. users of the recipe.
  1256. Similar to build-time dependencies, you specify runtime dependencies
  1257. through a variable -
  1258. :term:`RDEPENDS`, which is
  1259. package-specific. All variables that are package-specific need to have
  1260. the name of the package added to the end as an override. Since the main
  1261. package for a recipe has the same name as the recipe, and the recipe's
  1262. name can be found through the
  1263. ``${``\ :term:`PN`\ ``}`` variable, then
  1264. you specify the dependencies for the main package by setting
  1265. ``RDEPENDS_${PN}``. If the package were named ``${PN}-tools``, then you
  1266. would set ``RDEPENDS_${PN}-tools``, and so forth.
  1267. Some runtime dependencies will be set automatically at packaging time.
  1268. These dependencies include any shared library dependencies (i.e. if a
  1269. package "example" contains "libexample" and another package "mypackage"
  1270. contains a binary that links to "libexample" then the OpenEmbedded build
  1271. system will automatically add a runtime dependency to "mypackage" on
  1272. "example"). See the
  1273. ":ref:`overview-manual/overview-manual-concepts:automatically added runtime dependencies`"
  1274. section in the Yocto Project Overview and Concepts Manual for further
  1275. details.
  1276. .. _new-recipe-configuring-the-recipe:
  1277. Configuring the Recipe
  1278. ----------------------
  1279. Most software provides some means of setting build-time configuration
  1280. options before compilation. Typically, setting these options is
  1281. accomplished by running a configure script with options, or by modifying
  1282. a build configuration file.
  1283. .. note::
  1284. As of Yocto Project Release 1.7, some of the core recipes that
  1285. package binary configuration scripts now disable the scripts due to
  1286. the scripts previously requiring error-prone path substitution. The
  1287. OpenEmbedded build system uses ``pkg-config`` now, which is much more
  1288. robust. You can find a list of the ``*-config`` scripts that are disabled
  1289. in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section
  1290. in the Yocto Project Reference Manual.
  1291. A major part of build-time configuration is about checking for
  1292. build-time dependencies and possibly enabling optional functionality as
  1293. a result. You need to specify any build-time dependencies for the
  1294. software you are building in your recipe's
  1295. :term:`DEPENDS` value, in terms of
  1296. other recipes that satisfy those dependencies. You can often find
  1297. build-time or runtime dependencies described in the software's
  1298. documentation.
  1299. The following list provides configuration items of note based on how
  1300. your software is built:
  1301. - *Autotools:* If your source files have a ``configure.ac`` file, then
  1302. your software is built using Autotools. If this is the case, you just
  1303. need to worry about modifying the configuration.
  1304. When using Autotools, your recipe needs to inherit the
  1305. :ref:`autotools <ref-classes-autotools>` class
  1306. and your recipe does not have to contain a
  1307. :ref:`ref-tasks-configure` task.
  1308. However, you might still want to make some adjustments. For example,
  1309. you can set
  1310. :term:`EXTRA_OECONF` or
  1311. :term:`PACKAGECONFIG_CONFARGS`
  1312. to pass any needed configure options that are specific to the recipe.
  1313. - *CMake:* If your source files have a ``CMakeLists.txt`` file, then
  1314. your software is built using CMake. If this is the case, you just
  1315. need to worry about modifying the configuration.
  1316. When you use CMake, your recipe needs to inherit the
  1317. :ref:`cmake <ref-classes-cmake>` class and your
  1318. recipe does not have to contain a
  1319. :ref:`ref-tasks-configure` task.
  1320. You can make some adjustments by setting
  1321. :term:`EXTRA_OECMAKE` to
  1322. pass any needed configure options that are specific to the recipe.
  1323. .. note::
  1324. If you need to install one or more custom CMake toolchain files
  1325. that are supplied by the application you are building, install the
  1326. files to ``${D}${datadir}/cmake/Modules`` during ``do_install``.
  1327. - *Other:* If your source files do not have a ``configure.ac`` or
  1328. ``CMakeLists.txt`` file, then your software is built using some
  1329. method other than Autotools or CMake. If this is the case, you
  1330. normally need to provide a
  1331. :ref:`ref-tasks-configure` task
  1332. in your recipe unless, of course, there is nothing to configure.
  1333. Even if your software is not being built by Autotools or CMake, you
  1334. still might not need to deal with any configuration issues. You need
  1335. to determine if configuration is even a required step. You might need
  1336. to modify a Makefile or some configuration file used for the build to
  1337. specify necessary build options. Or, perhaps you might need to run a
  1338. provided, custom configure script with the appropriate options.
  1339. For the case involving a custom configure script, you would run
  1340. ``./configure --help`` and look for the options you need to set.
  1341. Once configuration succeeds, it is always good practice to look at the
  1342. ``log.do_configure`` file to ensure that the appropriate options have
  1343. been enabled and no additional build-time dependencies need to be added
  1344. to ``DEPENDS``. For example, if the configure script reports that it
  1345. found something not mentioned in ``DEPENDS``, or that it did not find
  1346. something that it needed for some desired optional functionality, then
  1347. you would need to add those to ``DEPENDS``. Looking at the log might
  1348. also reveal items being checked for, enabled, or both that you do not
  1349. want, or items not being found that are in ``DEPENDS``, in which case
  1350. you would need to look at passing extra options to the configure script
  1351. as needed. For reference information on configure options specific to
  1352. the software you are building, you can consult the output of the
  1353. ``./configure --help`` command within ``${S}`` or consult the software's
  1354. upstream documentation.
  1355. .. _new-recipe-using-headers-to-interface-with-devices:
  1356. Using Headers to Interface with Devices
  1357. ---------------------------------------
  1358. If your recipe builds an application that needs to communicate with some
  1359. device or needs an API into a custom kernel, you will need to provide
  1360. appropriate header files. Under no circumstances should you ever modify
  1361. the existing
  1362. ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file.
  1363. These headers are used to build ``libc`` and must not be compromised
  1364. with custom or machine-specific header information. If you customize
  1365. ``libc`` through modified headers all other applications that use
  1366. ``libc`` thus become affected.
  1367. .. note::
  1368. Never copy and customize the ``libc`` header file (i.e.
  1369. ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``).
  1370. The correct way to interface to a device or custom kernel is to use a
  1371. separate package that provides the additional headers for the driver or
  1372. other unique interfaces. When doing so, your application also becomes
  1373. responsible for creating a dependency on that specific provider.
  1374. Consider the following:
  1375. - Never modify ``linux-libc-headers.inc``. Consider that file to be
  1376. part of the ``libc`` system, and not something you use to access the
  1377. kernel directly. You should access ``libc`` through specific ``libc``
  1378. calls.
  1379. - Applications that must talk directly to devices should either provide
  1380. necessary headers themselves, or establish a dependency on a special
  1381. headers package that is specific to that driver.
  1382. For example, suppose you want to modify an existing header that adds I/O
  1383. control or network support. If the modifications are used by a small
  1384. number programs, providing a unique version of a header is easy and has
  1385. little impact. When doing so, bear in mind the guidelines in the
  1386. previous list.
  1387. .. note::
  1388. If for some reason your changes need to modify the behavior of the ``libc``,
  1389. and subsequently all other applications on the system, use a ``.bbappend``
  1390. to modify the ``linux-kernel-headers.inc`` file. However, take care to not
  1391. make the changes machine specific.
  1392. Consider a case where your kernel is older and you need an older
  1393. ``libc`` ABI. The headers installed by your recipe should still be a
  1394. standard mainline kernel, not your own custom one.
  1395. When you use custom kernel headers you need to get them from
  1396. :term:`STAGING_KERNEL_DIR`,
  1397. which is the directory with kernel headers that are required to build
  1398. out-of-tree modules. Your recipe will also need the following:
  1399. ::
  1400. do_configure[depends] += "virtual/kernel:do_shared_workdir"
  1401. .. _new-recipe-compilation:
  1402. Compilation
  1403. -----------
  1404. During a build, the ``do_compile`` task happens after source is fetched,
  1405. unpacked, and configured. If the recipe passes through ``do_compile``
  1406. successfully, nothing needs to be done.
  1407. However, if the compile step fails, you need to diagnose the failure.
  1408. Here are some common issues that cause failures.
  1409. .. note::
  1410. For cases where improper paths are detected for configuration files
  1411. or for when libraries/headers cannot be found, be sure you are using
  1412. the more robust ``pkg-config``. See the note in section
  1413. ":ref:`new-recipe-configuring-the-recipe`" for additional information.
  1414. - *Parallel build failures:* These failures manifest themselves as
  1415. intermittent errors, or errors reporting that a file or directory
  1416. that should be created by some other part of the build process could
  1417. not be found. This type of failure can occur even if, upon
  1418. inspection, the file or directory does exist after the build has
  1419. failed, because that part of the build process happened in the wrong
  1420. order.
  1421. To fix the problem, you need to either satisfy the missing dependency
  1422. in the Makefile or whatever script produced the Makefile, or (as a
  1423. workaround) set :term:`PARALLEL_MAKE` to an empty string:
  1424. ::
  1425. PARALLEL_MAKE = ""
  1426. For information on parallel Makefile issues, see the "`Debugging
  1427. Parallel Make Races <#debugging-parallel-make-races>`__" section.
  1428. - *Improper host path usage:* This failure applies to recipes building
  1429. for the target or ``nativesdk`` only. The failure occurs when the
  1430. compilation process uses improper headers, libraries, or other files
  1431. from the host system when cross-compiling for the target.
  1432. To fix the problem, examine the ``log.do_compile`` file to identify
  1433. the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and
  1434. so forth) and then either add configure options, apply a patch, or do
  1435. both.
  1436. - *Failure to find required libraries/headers:* If a build-time
  1437. dependency is missing because it has not been declared in
  1438. :term:`DEPENDS`, or because the
  1439. dependency exists but the path used by the build process to find the
  1440. file is incorrect and the configure step did not detect it, the
  1441. compilation process could fail. For either of these failures, the
  1442. compilation process notes that files could not be found. In these
  1443. cases, you need to go back and add additional options to the
  1444. configure script as well as possibly add additional build-time
  1445. dependencies to ``DEPENDS``.
  1446. Occasionally, it is necessary to apply a patch to the source to
  1447. ensure the correct paths are used. If you need to specify paths to
  1448. find files staged into the sysroot from other recipes, use the
  1449. variables that the OpenEmbedded build system provides (e.g.
  1450. ``STAGING_BINDIR``, ``STAGING_INCDIR``, ``STAGING_DATADIR``, and so
  1451. forth).
  1452. .. _new-recipe-installing:
  1453. Installing
  1454. ----------
  1455. During ``do_install``, the task copies the built files along with their
  1456. hierarchy to locations that would mirror their locations on the target
  1457. device. The installation process copies files from the
  1458. ``${``\ :term:`S`\ ``}``,
  1459. ``${``\ :term:`B`\ ``}``, and
  1460. ``${``\ :term:`WORKDIR`\ ``}``
  1461. directories to the ``${``\ :term:`D`\ ``}``
  1462. directory to create the structure as it should appear on the target
  1463. system.
  1464. How your software is built affects what you must do to be sure your
  1465. software is installed correctly. The following list describes what you
  1466. must do for installation depending on the type of build system used by
  1467. the software being built:
  1468. - *Autotools and CMake:* If the software your recipe is building uses
  1469. Autotools or CMake, the OpenEmbedded build system understands how to
  1470. install the software. Consequently, you do not have to have a
  1471. ``do_install`` task as part of your recipe. You just need to make
  1472. sure the install portion of the build completes with no issues.
  1473. However, if you wish to install additional files not already being
  1474. installed by ``make install``, you should do this using a
  1475. ``do_install_append`` function using the install command as described
  1476. in the "Manual" bulleted item later in this list.
  1477. - *Other (using* ``make install``\ *)*: You need to define a ``do_install``
  1478. function in your recipe. The function should call
  1479. ``oe_runmake install`` and will likely need to pass in the
  1480. destination directory as well. How you pass that path is dependent on
  1481. how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``,
  1482. ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth).
  1483. For an example recipe using ``make install``, see the
  1484. "`Makefile-Based Package <#new-recipe-makefile-based-package>`__"
  1485. section.
  1486. - *Manual:* You need to define a ``do_install`` function in your
  1487. recipe. The function must first use ``install -d`` to create the
  1488. directories under
  1489. ``${``\ :term:`D`\ ``}``. Once the
  1490. directories exist, your function can use ``install`` to manually
  1491. install the built software into the directories.
  1492. You can find more information on ``install`` at
  1493. https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html.
  1494. For the scenarios that do not use Autotools or CMake, you need to track
  1495. the installation and diagnose and fix any issues until everything
  1496. installs correctly. You need to look in the default location of
  1497. ``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been
  1498. installed correctly.
  1499. .. note::
  1500. - During the installation process, you might need to modify some of
  1501. the installed files to suit the target layout. For example, you
  1502. might need to replace hard-coded paths in an initscript with
  1503. values of variables provided by the build system, such as
  1504. replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such
  1505. modifications during ``do_install``, be sure to modify the
  1506. destination file after copying rather than before copying.
  1507. Modifying after copying ensures that the build system can
  1508. re-execute ``do_install`` if needed.
  1509. - ``oe_runmake install``, which can be run directly or can be run
  1510. indirectly by the
  1511. :ref:`autotools <ref-classes-autotools>` and
  1512. :ref:`cmake <ref-classes-cmake>` classes,
  1513. runs ``make install`` in parallel. Sometimes, a Makefile can have
  1514. missing dependencies between targets that can result in race
  1515. conditions. If you experience intermittent failures during
  1516. ``do_install``, you might be able to work around them by disabling
  1517. parallel Makefile installs by adding the following to the recipe:
  1518. ::
  1519. PARALLEL_MAKEINST = ""
  1520. See :term:`PARALLEL_MAKEINST` for additional information.
  1521. - If you need to install one or more custom CMake toolchain files
  1522. that are supplied by the application you are building, install the
  1523. files to ``${D}${datadir}/cmake/Modules`` during
  1524. :ref:`ref-tasks-install`.
  1525. .. _new-recipe-enabling-system-services:
  1526. Enabling System Services
  1527. ------------------------
  1528. If you want to install a service, which is a process that usually starts
  1529. on boot and runs in the background, then you must include some
  1530. additional definitions in your recipe.
  1531. If you are adding services and the service initialization script or the
  1532. service file itself is not installed, you must provide for that
  1533. installation in your recipe using a ``do_install_append`` function. If
  1534. your recipe already has a ``do_install`` function, update the function
  1535. near its end rather than adding an additional ``do_install_append``
  1536. function.
  1537. When you create the installation for your services, you need to
  1538. accomplish what is normally done by ``make install``. In other words,
  1539. make sure your installation arranges the output similar to how it is
  1540. arranged on the target system.
  1541. The OpenEmbedded build system provides support for starting services two
  1542. different ways:
  1543. - *SysVinit:* SysVinit is a system and service manager that manages the
  1544. init system used to control the very basic functions of your system.
  1545. The init program is the first program started by the Linux kernel
  1546. when the system boots. Init then controls the startup, running and
  1547. shutdown of all other programs.
  1548. To enable a service using SysVinit, your recipe needs to inherit the
  1549. :ref:`update-rc.d <ref-classes-update-rc.d>`
  1550. class. The class helps facilitate safely installing the package on
  1551. the target.
  1552. You will need to set the
  1553. :term:`INITSCRIPT_PACKAGES`,
  1554. :term:`INITSCRIPT_NAME`,
  1555. and
  1556. :term:`INITSCRIPT_PARAMS`
  1557. variables within your recipe.
  1558. - *systemd:* System Management Daemon (systemd) was designed to replace
  1559. SysVinit and to provide enhanced management of services. For more
  1560. information on systemd, see the systemd homepage at
  1561. https://freedesktop.org/wiki/Software/systemd/.
  1562. To enable a service using systemd, your recipe needs to inherit the
  1563. :ref:`systemd <ref-classes-systemd>` class. See
  1564. the ``systemd.bbclass`` file located in your :term:`Source Directory`
  1565. section for
  1566. more information.
  1567. .. _new-recipe-packaging:
  1568. Packaging
  1569. ---------
  1570. Successful packaging is a combination of automated processes performed
  1571. by the OpenEmbedded build system and some specific steps you need to
  1572. take. The following list describes the process:
  1573. - *Splitting Files*: The ``do_package`` task splits the files produced
  1574. by the recipe into logical components. Even software that produces a
  1575. single binary might still have debug symbols, documentation, and
  1576. other logical components that should be split out. The ``do_package``
  1577. task ensures that files are split up and packaged correctly.
  1578. - *Running QA Checks*: The
  1579. :ref:`insane <ref-classes-insane>` class adds a
  1580. step to the package generation process so that output quality
  1581. assurance checks are generated by the OpenEmbedded build system. This
  1582. step performs a range of checks to be sure the build's output is free
  1583. of common problems that show up during runtime. For information on
  1584. these checks, see the
  1585. :ref:`insane <ref-classes-insane>` class and
  1586. the ":ref:`ref-manual/ref-qa-checks:qa error and warning messages`"
  1587. chapter in the Yocto Project Reference Manual.
  1588. - *Hand-Checking Your Packages*: After you build your software, you
  1589. need to be sure your packages are correct. Examine the
  1590. ``${``\ :term:`WORKDIR`\ ``}/packages-split``
  1591. directory and make sure files are where you expect them to be. If you
  1592. discover problems, you can set
  1593. :term:`PACKAGES`,
  1594. :term:`FILES`,
  1595. ``do_install(_append)``, and so forth as needed.
  1596. - *Splitting an Application into Multiple Packages*: If you need to
  1597. split an application into several packages, see the "`Splitting an
  1598. Application into Multiple
  1599. Packages <#splitting-an-application-into-multiple-packages>`__"
  1600. section for an example.
  1601. - *Installing a Post-Installation Script*: For an example showing how
  1602. to install a post-installation script, see the "`Post-Installation
  1603. Scripts <#new-recipe-post-installation-scripts>`__" section.
  1604. - *Marking Package Architecture*: Depending on what your recipe is
  1605. building and how it is configured, it might be important to mark the
  1606. packages produced as being specific to a particular machine, or to
  1607. mark them as not being specific to a particular machine or
  1608. architecture at all.
  1609. By default, packages apply to any machine with the same architecture
  1610. as the target machine. When a recipe produces packages that are
  1611. machine-specific (e.g. the
  1612. :term:`MACHINE` value is passed
  1613. into the configure script or a patch is applied only for a particular
  1614. machine), you should mark them as such by adding the following to the
  1615. recipe:
  1616. ::
  1617. PACKAGE_ARCH = "${MACHINE_ARCH}"
  1618. On the other hand, if the recipe produces packages that do not
  1619. contain anything specific to the target machine or architecture at
  1620. all (e.g. recipes that simply package script files or configuration
  1621. files), you should use the
  1622. :ref:`allarch <ref-classes-allarch>` class to
  1623. do this for you by adding this to your recipe:
  1624. ::
  1625. inherit allarch
  1626. Ensuring that the package architecture is correct is not critical
  1627. while you are doing the first few builds of your recipe. However, it
  1628. is important in order to ensure that your recipe rebuilds (or does
  1629. not rebuild) appropriately in response to changes in configuration,
  1630. and to ensure that you get the appropriate packages installed on the
  1631. target machine, particularly if you run separate builds for more than
  1632. one target machine.
  1633. .. _new-sharing-files-between-recipes:
  1634. Sharing Files Between Recipes
  1635. -----------------------------
  1636. Recipes often need to use files provided by other recipes on the build
  1637. host. For example, an application linking to a common library needs
  1638. access to the library itself and its associated headers. The way this
  1639. access is accomplished is by populating a sysroot with files. Each
  1640. recipe has two sysroots in its work directory, one for target files
  1641. (``recipe-sysroot``) and one for files that are native to the build host
  1642. (``recipe-sysroot-native``).
  1643. .. note::
  1644. You could find the term "staging" used within the Yocto project
  1645. regarding files populating sysroots (e.g. the :term:`STAGING_DIR`
  1646. variable).
  1647. Recipes should never populate the sysroot directly (i.e. write files
  1648. into sysroot). Instead, files should be installed into standard
  1649. locations during the
  1650. :ref:`ref-tasks-install` task within
  1651. the ``${``\ :term:`D`\ ``}`` directory. The
  1652. reason for this limitation is that almost all files that populate the
  1653. sysroot are cataloged in manifests in order to ensure the files can be
  1654. removed later when a recipe is either modified or removed. Thus, the
  1655. sysroot is able to remain free from stale files.
  1656. A subset of the files installed by the
  1657. :ref:`ref-tasks-install` task are
  1658. used by the
  1659. :ref:`ref-tasks-populate_sysroot`
  1660. task as defined by the the
  1661. :term:`SYSROOT_DIRS` variable to
  1662. automatically populate the sysroot. It is possible to modify the list of
  1663. directories that populate the sysroot. The following example shows how
  1664. you could add the ``/opt`` directory to the list of directories within a
  1665. recipe:
  1666. ::
  1667. SYSROOT_DIRS += "/opt"
  1668. For a more complete description of the
  1669. :ref:`ref-tasks-populate_sysroot`
  1670. task and its associated functions, see the
  1671. :ref:`staging <ref-classes-staging>` class.
  1672. .. _metadata-virtual-providers:
  1673. Using Virtual Providers
  1674. -----------------------
  1675. Prior to a build, if you know that several different recipes provide the
  1676. same functionality, you can use a virtual provider (i.e. ``virtual/*``)
  1677. as a placeholder for the actual provider. The actual provider is
  1678. determined at build-time.
  1679. A common scenario where a virtual provider is used would be for the
  1680. kernel recipe. Suppose you have three kernel recipes whose
  1681. :term:`PN` values map to ``kernel-big``,
  1682. ``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes
  1683. in some way uses a :term:`PROVIDES`
  1684. statement that essentially identifies itself as being able to provide
  1685. ``virtual/kernel``. Here is one way through the
  1686. :ref:`kernel <ref-classes-kernel>` class:
  1687. ::
  1688. PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }"
  1689. Any recipe that inherits the ``kernel`` class is
  1690. going to utilize a ``PROVIDES`` statement that identifies that recipe as
  1691. being able to provide the ``virtual/kernel`` item.
  1692. Now comes the time to actually build an image and you need a kernel
  1693. recipe, but which one? You can configure your build to call out the
  1694. kernel recipe you want by using the
  1695. :term:`PREFERRED_PROVIDER`
  1696. variable. As an example, consider the
  1697. :yocto_git:`x86-base.inc </cgit/cgit.cgi/poky/tree/meta/conf/machine/include/x86-base.inc>`
  1698. include file, which is a machine (i.e.
  1699. :term:`MACHINE`) configuration file.
  1700. This include file is the reason all x86-based machines use the
  1701. ``linux-yocto`` kernel. Here are the relevant lines from the include
  1702. file:
  1703. ::
  1704. PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
  1705. PREFERRED_VERSION_linux-yocto ??= "4.15%"
  1706. When you use a virtual provider, you do not have to "hard code" a recipe
  1707. name as a build dependency. You can use the
  1708. :term:`DEPENDS` variable to state the
  1709. build is dependent on ``virtual/kernel`` for example:
  1710. ::
  1711. DEPENDS = "virtual/kernel"
  1712. During the build, the OpenEmbedded build system picks
  1713. the correct recipe needed for the ``virtual/kernel`` dependency based on
  1714. the ``PREFERRED_PROVIDER`` variable. If you want to use the small kernel
  1715. mentioned at the beginning of this section, configure your build as
  1716. follows:
  1717. ::
  1718. PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
  1719. .. note::
  1720. Any recipe that ``PROVIDES`` a ``virtual/*`` item that is ultimately not
  1721. selected through ``PREFERRED_PROVIDER`` does not get built. Preventing these
  1722. recipes from building is usually the desired behavior since this mechanism's
  1723. purpose is to select between mutually exclusive alternative providers.
  1724. The following lists specific examples of virtual providers:
  1725. - ``virtual/kernel``: Provides the name of the kernel recipe to use
  1726. when building a kernel image.
  1727. - ``virtual/bootloader``: Provides the name of the bootloader to use
  1728. when building an image.
  1729. - ``virtual/libgbm``: Provides ``gbm.pc``.
  1730. - ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``.
  1731. - ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL).
  1732. - ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM).
  1733. - ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2).
  1734. .. note::
  1735. Virtual providers only apply to build time dependencies specified with
  1736. :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime
  1737. dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`.
  1738. Properly Versioning Pre-Release Recipes
  1739. ---------------------------------------
  1740. Sometimes the name of a recipe can lead to versioning problems when the
  1741. recipe is upgraded to a final release. For example, consider the
  1742. ``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in
  1743. the "`Storing and Naming the
  1744. Recipe <#new-recipe-storing-and-naming-the-recipe>`__" section. This
  1745. recipe is at a release candidate stage (i.e. "rc1"). When the recipe is
  1746. released, the recipe filename becomes ``irssi_0.8.16.bb``. The version
  1747. change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the
  1748. build system and package managers, so the resulting packages will not
  1749. correctly trigger an upgrade.
  1750. In order to ensure the versions compare properly, the recommended
  1751. convention is to set :term:`PV` within the
  1752. recipe to "previous_version+current_version". You can use an additional
  1753. variable so that you can use the current version elsewhere. Here is an
  1754. example:
  1755. ::
  1756. REALPV = "0.8.16-rc1"
  1757. PV = "0.8.15+${REALPV}"
  1758. .. _new-recipe-post-installation-scripts:
  1759. Post-Installation Scripts
  1760. -------------------------
  1761. Post-installation scripts run immediately after installing a package on
  1762. the target or during image creation when a package is included in an
  1763. image. To add a post-installation script to a package, add a
  1764. ``pkg_postinst_``\ `PACKAGENAME`\ ``()`` function to the recipe file
  1765. (``.bb``) and replace `PACKAGENAME` with the name of the package you want
  1766. to attach to the ``postinst`` script. To apply the post-installation
  1767. script to the main package for the recipe, which is usually what is
  1768. required, specify
  1769. ``${``\ :term:`PN`\ ``}`` in place of
  1770. PACKAGENAME.
  1771. A post-installation function has the following structure:
  1772. ::
  1773. pkg_postinst_PACKAGENAME() {
  1774. # Commands to carry out
  1775. }
  1776. The script defined in the post-installation function is called when the
  1777. root filesystem is created. If the script succeeds, the package is
  1778. marked as installed.
  1779. .. note::
  1780. Any RPM post-installation script that runs on the target should
  1781. return a 0 exit code. RPM does not allow non-zero exit codes for
  1782. these scripts, and the RPM package manager will cause the package to
  1783. fail installation on the target.
  1784. Sometimes it is necessary for the execution of a post-installation
  1785. script to be delayed until the first boot. For example, the script might
  1786. need to be executed on the device itself. To delay script execution
  1787. until boot time, you must explicitly mark post installs to defer to the
  1788. target. You can use ``pkg_postinst_ontarget()`` or call
  1789. ``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any
  1790. failure of a ``pkg_postinst()`` script (including exit 1) triggers an
  1791. error during the
  1792. :ref:`ref-tasks-rootfs` task.
  1793. If you have recipes that use ``pkg_postinst`` function and they require
  1794. the use of non-standard native tools that have dependencies during
  1795. rootfs construction, you need to use the
  1796. :term:`PACKAGE_WRITE_DEPS`
  1797. variable in your recipe to list these tools. If you do not use this
  1798. variable, the tools might be missing and execution of the
  1799. post-installation script is deferred until first boot. Deferring the
  1800. script to first boot is undesirable and for read-only rootfs impossible.
  1801. .. note::
  1802. Equivalent support for pre-install, pre-uninstall, and post-uninstall
  1803. scripts exist by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``,
  1804. respectively. These scrips work in exactly the same way as does
  1805. ``pkg_postinst`` with the exception that they run at different times. Also,
  1806. because of when they run, they are not applicable to being run at image
  1807. creation time like ``pkg_postinst``.
  1808. .. _new-recipe-testing:
  1809. Testing
  1810. -------
  1811. The final step for completing your recipe is to be sure that the
  1812. software you built runs correctly. To accomplish runtime testing, add
  1813. the build's output packages to your image and test them on the target.
  1814. For information on how to customize your image by adding specific
  1815. packages, see the "`Customizing
  1816. Images <#usingpoky-extend-customimage>`__" section.
  1817. .. _new-recipe-testing-examples:
  1818. Examples
  1819. --------
  1820. To help summarize how to write a recipe, this section provides some
  1821. examples given various scenarios:
  1822. - Recipes that use local files
  1823. - Using an Autotooled package
  1824. - Using a Makefile-based package
  1825. - Splitting an application into multiple packages
  1826. - Adding binaries to an image
  1827. .. _new-recipe-single-c-file-package-hello-world:
  1828. Single .c File Package (Hello World!)
  1829. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1830. Building an application from a single file that is stored locally (e.g.
  1831. under ``files``) requires a recipe that has the file listed in the
  1832. ``SRC_URI`` variable. Additionally, you need to manually write the
  1833. ``do_compile`` and ``do_install`` tasks. The ``S`` variable defines the
  1834. directory containing the source code, which is set to
  1835. :term:`WORKDIR` in this case - the
  1836. directory BitBake uses for the build.
  1837. ::
  1838. SUMMARY = "Simple helloworld application"
  1839. SECTION = "examples"
  1840. LICENSE = "MIT"
  1841. LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
  1842. SRC_URI = "file://helloworld.c"
  1843. S = "${WORKDIR}"
  1844. do_compile() {
  1845. ${CC} helloworld.c -o helloworld
  1846. }
  1847. do_install() {
  1848. install -d ${D}${bindir}
  1849. install -m 0755 helloworld ${D}${bindir}
  1850. }
  1851. By default, the ``helloworld``, ``helloworld-dbg``, and
  1852. ``helloworld-dev`` packages are built. For information on how to
  1853. customize the packaging process, see the "`Splitting an Application into
  1854. Multiple Packages <#splitting-an-application-into-multiple-packages>`__"
  1855. section.
  1856. .. _new-recipe-autotooled-package:
  1857. Autotooled Package
  1858. ~~~~~~~~~~~~~~~~~~
  1859. Applications that use Autotools such as ``autoconf`` and ``automake``
  1860. require a recipe that has a source archive listed in ``SRC_URI`` and
  1861. also inherit the
  1862. :ref:`autotools <ref-classes-autotools>` class,
  1863. which contains the definitions of all the steps needed to build an
  1864. Autotool-based application. The result of the build is automatically
  1865. packaged. And, if the application uses NLS for localization, packages
  1866. with local information are generated (one package per language).
  1867. Following is one example: (``hello_2.3.bb``)
  1868. ::
  1869. SUMMARY = "GNU Helloworld application"
  1870. SECTION = "examples"
  1871. LICENSE = "GPLv2+"
  1872. LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
  1873. SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
  1874. inherit autotools gettext
  1875. The variable ``LIC_FILES_CHKSUM`` is used to track source license
  1876. changes as described in the
  1877. ":ref:`dev-manual/dev-manual-common-tasks:tracking license changes`" section in
  1878. the Yocto Project Overview and Concepts Manual. You can quickly create
  1879. Autotool-based recipes in a manner similar to the previous example.
  1880. .. _new-recipe-makefile-based-package:
  1881. Makefile-Based Package
  1882. ~~~~~~~~~~~~~~~~~~~~~~
  1883. Applications that use GNU ``make`` also require a recipe that has the
  1884. source archive listed in ``SRC_URI``. You do not need to add a
  1885. ``do_compile`` step since by default BitBake starts the ``make`` command
  1886. to compile the application. If you need additional ``make`` options, you
  1887. should store them in the
  1888. :term:`EXTRA_OEMAKE` or
  1889. :term:`PACKAGECONFIG_CONFARGS`
  1890. variables. BitBake passes these options into the GNU ``make``
  1891. invocation. Note that a ``do_install`` task is still required.
  1892. Otherwise, BitBake runs an empty ``do_install`` task by default.
  1893. Some applications might require extra parameters to be passed to the
  1894. compiler. For example, the application might need an additional header
  1895. path. You can accomplish this by adding to the ``CFLAGS`` variable. The
  1896. following example shows this:
  1897. ::
  1898. CFLAGS_prepend = "-I ${S}/include "
  1899. In the following example, ``mtd-utils`` is a makefile-based package:
  1900. ::
  1901. SUMMARY = "Tools for managing memory technology devices"
  1902. SECTION = "base"
  1903. DEPENDS = "zlib lzo e2fsprogs util-linux"
  1904. HOMEPAGE = "http://www.linux-mtd.infradead.org/"
  1905. LICENSE = "GPLv2+"
  1906. LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
  1907. file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
  1908. # Use the latest version at 26 Oct, 2013
  1909. SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
  1910. SRC_URI = "git://git.infradead.org/mtd-utils.git \
  1911. file://add-exclusion-to-mkfs-jffs2-git-2.patch \
  1912. "
  1913. PV = "1.5.1+git${SRCPV}"
  1914. S = "${WORKDIR}/git"
  1915. EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
  1916. do_install () {
  1917. oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
  1918. }
  1919. PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
  1920. FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
  1921. FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
  1922. FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image"
  1923. PARALLEL_MAKE = ""
  1924. BBCLASSEXTEND = "native"
  1925. Splitting an Application into Multiple Packages
  1926. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1927. You can use the variables ``PACKAGES`` and ``FILES`` to split an
  1928. application into multiple packages.
  1929. Following is an example that uses the ``libxpm`` recipe. By default,
  1930. this recipe generates a single package that contains the library along
  1931. with a few binaries. You can modify the recipe to split the binaries
  1932. into separate packages:
  1933. ::
  1934. require xorg-lib-common.inc
  1935. SUMMARY = "Xpm: X Pixmap extension library"
  1936. LICENSE = "BSD"
  1937. LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
  1938. DEPENDS += "libxext libsm libxt"
  1939. PE = "1"
  1940. XORG_PN = "libXpm"
  1941. PACKAGES =+ "sxpm cxpm"
  1942. FILES_cxpm = "${bindir}/cxpm"
  1943. FILES_sxpm = "${bindir}/sxpm"
  1944. In the previous example, we want to ship the ``sxpm`` and ``cxpm``
  1945. binaries in separate packages. Since ``bindir`` would be packaged into
  1946. the main ``PN`` package by default, we prepend the ``PACKAGES`` variable
  1947. so additional package names are added to the start of list. This results
  1948. in the extra ``FILES_*`` variables then containing information that
  1949. define which files and directories go into which packages. Files
  1950. included by earlier packages are skipped by latter packages. Thus, the
  1951. main ``PN`` package does not include the above listed files.
  1952. Packaging Externally Produced Binaries
  1953. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1954. Sometimes, you need to add pre-compiled binaries to an image. For
  1955. example, suppose that binaries for proprietary code exist, which are
  1956. created by a particular division of a company. Your part of the company
  1957. needs to use those binaries as part of an image that you are building
  1958. using the OpenEmbedded build system. Since you only have the binaries
  1959. and not the source code, you cannot use a typical recipe that expects to
  1960. fetch the source specified in
  1961. :term:`SRC_URI` and then compile it.
  1962. One method is to package the binaries and then install them as part of
  1963. the image. Generally, it is not a good idea to package binaries since,
  1964. among other things, it can hinder the ability to reproduce builds and
  1965. could lead to compatibility problems with ABI in the future. However,
  1966. sometimes you have no choice.
  1967. The easiest solution is to create a recipe that uses the
  1968. :ref:`bin_package <ref-classes-bin-package>` class
  1969. and to be sure that you are using default locations for build artifacts.
  1970. In most cases, the ``bin_package`` class handles "skipping" the
  1971. configure and compile steps as well as sets things up to grab packages
  1972. from the appropriate area. In particular, this class sets ``noexec`` on
  1973. both the :ref:`ref-tasks-configure`
  1974. and :ref:`ref-tasks-compile` tasks,
  1975. sets ``FILES_${PN}`` to "/" so that it picks up all files, and sets up a
  1976. :ref:`ref-tasks-install` task, which
  1977. effectively copies all files from ``${S}`` to ``${D}``. The
  1978. ``bin_package`` class works well when the files extracted into ``${S}``
  1979. are already laid out in the way they should be laid out on the target.
  1980. For more information on these variables, see the
  1981. :term:`FILES`,
  1982. :term:`PN`,
  1983. :term:`S`, and
  1984. :term:`D` variables in the Yocto Project
  1985. Reference Manual's variable glossary.
  1986. .. note::
  1987. - Using :term:`DEPENDS` is a good
  1988. idea even for components distributed in binary form, and is often
  1989. necessary for shared libraries. For a shared library, listing the
  1990. library dependencies in ``DEPENDS`` makes sure that the libraries
  1991. are available in the staging sysroot when other recipes link
  1992. against the library, which might be necessary for successful
  1993. linking.
  1994. - Using ``DEPENDS`` also allows runtime dependencies between
  1995. packages to be added automatically. See the
  1996. ":ref:`overview-manual/overview-manual-concepts:automatically added runtime dependencies`"
  1997. section in the Yocto Project Overview and Concepts Manual for more
  1998. information.
  1999. If you cannot use the ``bin_package`` class, you need to be sure you are
  2000. doing the following:
  2001. - Create a recipe where the
  2002. :ref:`ref-tasks-configure` and
  2003. :ref:`ref-tasks-compile` tasks do
  2004. nothing: It is usually sufficient to just not define these tasks in
  2005. the recipe, because the default implementations do nothing unless a
  2006. Makefile is found in
  2007. ``${``\ :term:`S`\ ``}``.
  2008. If ``${S}`` might contain a Makefile, or if you inherit some class
  2009. that replaces ``do_configure`` and ``do_compile`` with custom
  2010. versions, then you can use the
  2011. ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]``
  2012. flag to turn the tasks into no-ops, as follows:
  2013. ::
  2014. do_configure[noexec] = "1"
  2015. do_compile[noexec] = "1"
  2016. Unlike
  2017. :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`,
  2018. using the flag preserves the dependency chain from the
  2019. :ref:`ref-tasks-fetch`,
  2020. :ref:`ref-tasks-unpack`, and
  2021. :ref:`ref-tasks-patch` tasks to the
  2022. :ref:`ref-tasks-install` task.
  2023. - Make sure your ``do_install`` task installs the binaries
  2024. appropriately.
  2025. - Ensure that you set up :term:`FILES`
  2026. (usually
  2027. ``FILES_${``\ :term:`PN`\ ``}``) to
  2028. point to the files you have installed, which of course depends on
  2029. where you have installed them and whether those files are in
  2030. different locations than the defaults.
  2031. .. note::
  2032. If image prelinking is enabled (e.g. "image-prelink" is in :term:`USER_CLASSES`
  2033. which it is by default), prelink will change the binaries in the generated images
  2034. and this often catches people out. Remove that class to ensure binaries are
  2035. preserved exactly if that is necessary.
  2036. Following Recipe Style Guidelines
  2037. ---------------------------------
  2038. When writing recipes, it is good to conform to existing style
  2039. guidelines. The :oe_home:`OpenEmbedded Styleguide </wiki/Styleguide>` wiki page
  2040. provides rough guidelines for preferred recipe style.
  2041. It is common for existing recipes to deviate a bit from this style.
  2042. However, aiming for at least a consistent style is a good idea. Some
  2043. practices, such as omitting spaces around ``=`` operators in assignments
  2044. or ordering recipe components in an erratic way, are widely seen as poor
  2045. style.
  2046. Recipe Syntax
  2047. -------------
  2048. Understanding recipe file syntax is important for writing recipes. The
  2049. following list overviews the basic items that make up a BitBake recipe
  2050. file. For more complete BitBake syntax descriptions, see the
  2051. ":doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata`"
  2052. chapter of the BitBake User Manual.
  2053. - *Variable Assignments and Manipulations:* Variable assignments allow
  2054. a value to be assigned to a variable. The assignment can be static
  2055. text or might include the contents of other variables. In addition to
  2056. the assignment, appending and prepending operations are also
  2057. supported.
  2058. The following example shows some of the ways you can use variables in
  2059. recipes:
  2060. ::
  2061. S = "${WORKDIR}/postfix-${PV}"
  2062. CFLAGS += "-DNO_ASM"
  2063. SRC_URI_append = " file://fixup.patch"
  2064. - *Functions:* Functions provide a series of actions to be performed.
  2065. You usually use functions to override the default implementation of a
  2066. task function or to complement a default function (i.e. append or
  2067. prepend to an existing function). Standard functions use ``sh`` shell
  2068. syntax, although access to OpenEmbedded variables and internal
  2069. methods are also available.
  2070. The following is an example function from the ``sed`` recipe:
  2071. ::
  2072. do_install () {
  2073. autotools_do_install
  2074. install -d ${D}${base_bindir}
  2075. mv ${D}${bindir}/sed ${D}${base_bindir}/sed
  2076. rmdir ${D}${bindir}/
  2077. }
  2078. It is
  2079. also possible to implement new functions that are called between
  2080. existing tasks as long as the new functions are not replacing or
  2081. complementing the default functions. You can implement functions in
  2082. Python instead of shell. Both of these options are not seen in the
  2083. majority of recipes.
  2084. - *Keywords:* BitBake recipes use only a few keywords. You use keywords
  2085. to include common functions (``inherit``), load parts of a recipe
  2086. from other files (``include`` and ``require``) and export variables
  2087. to the environment (``export``).
  2088. The following example shows the use of some of these keywords:
  2089. ::
  2090. export POSTCONF = "${STAGING_BINDIR}/postconf"
  2091. inherit autoconf
  2092. require otherfile.inc
  2093. - *Comments (#):* Any lines that begin with the hash character (``#``)
  2094. are treated as comment lines and are ignored:
  2095. ::
  2096. # This is a comment
  2097. This next list summarizes the most important and most commonly used
  2098. parts of the recipe syntax. For more information on these parts of the
  2099. syntax, you can reference the
  2100. :doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata` chapter
  2101. in the BitBake User Manual.
  2102. - *Line Continuation (\\):* Use the backward slash (``\``) character to
  2103. split a statement over multiple lines. Place the slash character at
  2104. the end of the line that is to be continued on the next line:
  2105. ::
  2106. VAR = "A really long \
  2107. line"
  2108. .. note::
  2109. You cannot have any characters including spaces or tabs after the
  2110. slash character.
  2111. - *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to
  2112. access the contents of a variable:
  2113. ::
  2114. SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
  2115. .. note::
  2116. It is important to understand that the value of a variable
  2117. expressed in this form does not get substituted automatically. The
  2118. expansion of these expressions happens on-demand later (e.g.
  2119. usually when a function that makes reference to the variable
  2120. executes). This behavior ensures that the values are most
  2121. appropriate for the context in which they are finally used. On the
  2122. rare occasion that you do need the variable expression to be
  2123. expanded immediately, you can use the
  2124. :=
  2125. operator instead of
  2126. =
  2127. when you make the assignment, but this is not generally needed.
  2128. - *Quote All Assignments ("value"):* Use double quotes around values in
  2129. all variable assignments (e.g. ``"value"``). Following is an example:
  2130. ::
  2131. VAR1 = "${OTHERVAR}"
  2132. VAR2 = "The version is ${PV}"
  2133. - *Conditional Assignment (?=):* Conditional assignment is used to
  2134. assign a value to a variable, but only when the variable is currently
  2135. unset. Use the question mark followed by the equal sign (``?=``) to
  2136. make a "soft" assignment used for conditional assignment. Typically,
  2137. "soft" assignments are used in the ``local.conf`` file for variables
  2138. that are allowed to come through from the external environment.
  2139. Here is an example where ``VAR1`` is set to "New value" if it is
  2140. currently empty. However, if ``VAR1`` has already been set, it
  2141. remains unchanged:
  2142. ::
  2143. VAR1 ?= "New value"
  2144. In this next example, ``VAR1`` is left with the value "Original value":
  2145. ::
  2146. VAR1 = "Original value"
  2147. VAR1 ?= "New value"
  2148. - *Appending (+=):* Use the plus character followed by the equals sign
  2149. (``+=``) to append values to existing variables.
  2150. .. note::
  2151. This operator adds a space between the existing content of the
  2152. variable and the new content.
  2153. Here is an example:
  2154. ::
  2155. SRC_URI += "file://fix-makefile.patch"
  2156. - *Prepending (=+):* Use the equals sign followed by the plus character
  2157. (``=+``) to prepend values to existing variables.
  2158. .. note::
  2159. This operator adds a space between the new content and the
  2160. existing content of the variable.
  2161. Here is an example:
  2162. ::
  2163. VAR =+ "Starts"
  2164. - *Appending (_append):* Use the ``_append`` operator to append values
  2165. to existing variables. This operator does not add any additional
  2166. space. Also, the operator is applied after all the ``+=``, and ``=+``
  2167. operators have been applied and after all ``=`` assignments have
  2168. occurred.
  2169. The following example shows the space being explicitly added to the
  2170. start to ensure the appended value is not merged with the existing
  2171. value:
  2172. ::
  2173. SRC_URI_append = " file://fix-makefile.patch"
  2174. You can also use
  2175. the ``_append`` operator with overrides, which results in the actions
  2176. only being performed for the specified target or machine:
  2177. ::
  2178. SRC_URI_append_sh4 = " file://fix-makefile.patch"
  2179. - *Prepending (_prepend):* Use the ``_prepend`` operator to prepend
  2180. values to existing variables. This operator does not add any
  2181. additional space. Also, the operator is applied after all the ``+=``,
  2182. and ``=+`` operators have been applied and after all ``=``
  2183. assignments have occurred.
  2184. The following example shows the space being explicitly added to the
  2185. end to ensure the prepended value is not merged with the existing
  2186. value:
  2187. ::
  2188. CFLAGS_prepend = "-I${S}/myincludes "
  2189. You can also use the
  2190. ``_prepend`` operator with overrides, which results in the actions
  2191. only being performed for the specified target or machine:
  2192. ::
  2193. CFLAGS_prepend_sh4 = "-I${S}/myincludes "
  2194. - *Overrides:* You can use overrides to set a value conditionally,
  2195. typically based on how the recipe is being built. For example, to set
  2196. the :term:`KBRANCH` variable's
  2197. value to "standard/base" for any target
  2198. :term:`MACHINE`, except for
  2199. qemuarm where it should be set to "standard/arm-versatile-926ejs",
  2200. you would do the following:
  2201. ::
  2202. KBRANCH = "standard/base"
  2203. KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
  2204. Overrides are also used to separate
  2205. alternate values of a variable in other situations. For example, when
  2206. setting variables such as
  2207. :term:`FILES` and
  2208. :term:`RDEPENDS` that are
  2209. specific to individual packages produced by a recipe, you should
  2210. always use an override that specifies the name of the package.
  2211. - *Indentation:* Use spaces for indentation rather than tabs. For
  2212. shell functions, both currently work. However, it is a policy
  2213. decision of the Yocto Project to use tabs in shell functions. Realize
  2214. that some layers have a policy to use spaces for all indentation.
  2215. - *Using Python for Complex Operations:* For more advanced processing,
  2216. it is possible to use Python code during variable assignments (e.g.
  2217. search and replacement on a variable).
  2218. You indicate Python code using the ``${@python_code}`` syntax for the
  2219. variable assignment:
  2220. ::
  2221. SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
  2222. - *Shell Function Syntax:* Write shell functions as if you were writing
  2223. a shell script when you describe a list of actions to take. You
  2224. should ensure that your script works with a generic ``sh`` and that
  2225. it does not require any ``bash`` or other shell-specific
  2226. functionality. The same considerations apply to various system
  2227. utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you
  2228. might wish to use. If in doubt, you should check with multiple
  2229. implementations - including those from BusyBox.
  2230. .. _platdev-newmachine:
  2231. Adding a New Machine
  2232. ====================
  2233. Adding a new machine to the Yocto Project is a straightforward process.
  2234. This section describes how to add machines that are similar to those
  2235. that the Yocto Project already supports.
  2236. .. note::
  2237. Although well within the capabilities of the Yocto Project, adding a
  2238. totally new architecture might require changes to ``gcc``/``glibc``
  2239. and to the site information, which is beyond the scope of this
  2240. manual.
  2241. For a complete example that shows how to add a new machine, see the
  2242. ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
  2243. section in the Yocto Project Board Support Package (BSP) Developer's
  2244. Guide.
  2245. .. _platdev-newmachine-conffile:
  2246. Adding the Machine Configuration File
  2247. -------------------------------------
  2248. To add a new machine, you need to add a new machine configuration file
  2249. to the layer's ``conf/machine`` directory. This configuration file
  2250. provides details about the device you are adding.
  2251. The OpenEmbedded build system uses the root name of the machine
  2252. configuration file to reference the new machine. For example, given a
  2253. machine configuration file named ``crownbay.conf``, the build system
  2254. recognizes the machine as "crownbay".
  2255. The most important variables you must set in your machine configuration
  2256. file or include from a lower-level configuration file are as follows:
  2257. - ``TARGET_ARCH`` (e.g. "arm")
  2258. - ``PREFERRED_PROVIDER_virtual/kernel``
  2259. - ``MACHINE_FEATURES`` (e.g. "apm screen wifi")
  2260. You might also need these variables:
  2261. - ``SERIAL_CONSOLES`` (e.g. "115200;ttyS0 115200;ttyS1")
  2262. - ``KERNEL_IMAGETYPE`` (e.g. "zImage")
  2263. - ``IMAGE_FSTYPES`` (e.g. "tar.gz jffs2")
  2264. You can find full details on these variables in the reference section.
  2265. You can leverage existing machine ``.conf`` files from
  2266. ``meta-yocto-bsp/conf/machine/``.
  2267. .. _platdev-newmachine-kernel:
  2268. Adding a Kernel for the Machine
  2269. -------------------------------
  2270. The OpenEmbedded build system needs to be able to build a kernel for the
  2271. machine. You need to either create a new kernel recipe for this machine,
  2272. or extend an existing kernel recipe. You can find several kernel recipe
  2273. examples in the Source Directory at ``meta/recipes-kernel/linux`` that
  2274. you can use as references.
  2275. If you are creating a new kernel recipe, normal recipe-writing rules
  2276. apply for setting up a ``SRC_URI``. Thus, you need to specify any
  2277. necessary patches and set ``S`` to point at the source code. You need to
  2278. create a ``do_configure`` task that configures the unpacked kernel with
  2279. a ``defconfig`` file. You can do this by using a ``make defconfig``
  2280. command or, more commonly, by copying in a suitable ``defconfig`` file
  2281. and then running ``make oldconfig``. By making use of ``inherit kernel``
  2282. and potentially some of the ``linux-*.inc`` files, most other
  2283. functionality is centralized and the defaults of the class normally work
  2284. well.
  2285. If you are extending an existing kernel recipe, it is usually a matter
  2286. of adding a suitable ``defconfig`` file. The file needs to be added into
  2287. a location similar to ``defconfig`` files used for other machines in a
  2288. given kernel recipe. A possible way to do this is by listing the file in
  2289. the ``SRC_URI`` and adding the machine to the expression in
  2290. ``COMPATIBLE_MACHINE``:
  2291. ::
  2292. COMPATIBLE_MACHINE = '(qemux86|qemumips)'
  2293. For more information on ``defconfig`` files, see the
  2294. ":ref:`kernel-dev/kernel-dev-common:changing the configuration`"
  2295. section in the Yocto Project Linux Kernel Development Manual.
  2296. .. _platdev-newmachine-formfactor:
  2297. Adding a Formfactor Configuration File
  2298. --------------------------------------
  2299. A formfactor configuration file provides information about the target
  2300. hardware for which the image is being built and information that the
  2301. build system cannot obtain from other sources such as the kernel. Some
  2302. examples of information contained in a formfactor configuration file
  2303. include framebuffer orientation, whether or not the system has a
  2304. keyboard, the positioning of the keyboard in relation to the screen, and
  2305. the screen resolution.
  2306. The build system uses reasonable defaults in most cases. However, if
  2307. customization is necessary, you need to create a ``machconfig`` file in
  2308. the ``meta/recipes-bsp/formfactor/files`` directory. This directory
  2309. contains directories for specific machines such as ``qemuarm`` and
  2310. ``qemux86``. For information about the settings available and the
  2311. defaults, see the ``meta/recipes-bsp/formfactor/files/config`` file
  2312. found in the same area.
  2313. Following is an example for "qemuarm" machine:
  2314. ::
  2315. HAVE_TOUCHSCREEN=1
  2316. HAVE_KEYBOARD=1
  2317. DISPLAY_CAN_ROTATE=0
  2318. DISPLAY_ORIENTATION=0
  2319. #DISPLAY_WIDTH_PIXELS=640
  2320. #DISPLAY_HEIGHT_PIXELS=480
  2321. #DISPLAY_BPP=16
  2322. DISPLAY_DPI=150
  2323. DISPLAY_SUBPIXEL_ORDER=vrgb
  2324. .. _gs-upgrading-recipes:
  2325. Upgrading Recipes
  2326. =================
  2327. Over time, upstream developers publish new versions for software built
  2328. by layer recipes. It is recommended to keep recipes up-to-date with
  2329. upstream version releases.
  2330. While several methods exist that allow you upgrade a recipe, you might
  2331. consider checking on the upgrade status of a recipe first. You can do so
  2332. using the ``devtool check-upgrade-status`` command. See the
  2333. ":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`"
  2334. section in the Yocto Project Reference Manual for more information.
  2335. The remainder of this section describes three ways you can upgrade a
  2336. recipe. You can use the Automated Upgrade Helper (AUH) to set up
  2337. automatic version upgrades. Alternatively, you can use
  2338. ``devtool upgrade`` to set up semi-automatic version upgrades. Finally,
  2339. you can manually upgrade a recipe by editing the recipe itself.
  2340. .. _gs-using-the-auto-upgrade-helper:
  2341. Using the Auto Upgrade Helper (AUH)
  2342. -----------------------------------
  2343. The AUH utility works in conjunction with the OpenEmbedded build system
  2344. in order to automatically generate upgrades for recipes based on new
  2345. versions being published upstream. Use AUH when you want to create a
  2346. service that performs the upgrades automatically and optionally sends
  2347. you an email with the results.
  2348. AUH allows you to update several recipes with a single use. You can also
  2349. optionally perform build and integration tests using images with the
  2350. results saved to your hard drive and emails of results optionally sent
  2351. to recipe maintainers. Finally, AUH creates Git commits with appropriate
  2352. commit messages in the layer's tree for the changes made to recipes.
  2353. .. note::
  2354. Conditions do exist when you should not use AUH to upgrade recipes
  2355. and you should instead use either ``devtool upgrade`` or upgrade your
  2356. recipes manually:
  2357. - When AUH cannot complete the upgrade sequence. This situation
  2358. usually results because custom patches carried by the recipe
  2359. cannot be automatically rebased to the new version. In this case,
  2360. ``devtool upgrade`` allows you to manually resolve conflicts.
  2361. - When for any reason you want fuller control over the upgrade
  2362. process. For example, when you want special arrangements for
  2363. testing.
  2364. The following steps describe how to set up the AUH utility:
  2365. 1. *Be Sure the Development Host is Set Up:* You need to be sure that
  2366. your development host is set up to use the Yocto Project. For
  2367. information on how to set up your host, see the
  2368. ":ref:`dev-preparing-the-build-host`" section.
  2369. 2. *Make Sure Git is Configured:* The AUH utility requires Git to be
  2370. configured because AUH uses Git to save upgrades. Thus, you must have
  2371. Git user and email configured. The following command shows your
  2372. configurations:
  2373. ::
  2374. $ git config --list
  2375. If you do not have the user and
  2376. email configured, you can use the following commands to do so:
  2377. ::
  2378. $ git config --global user.name some_name
  2379. $ git config --global user.email username@domain.com
  2380. 3. *Clone the AUH Repository:* To use AUH, you must clone the repository
  2381. onto your development host. The following command uses Git to create
  2382. a local copy of the repository on your system:
  2383. ::
  2384. $ git clone git://git.yoctoproject.org/auto-upgrade-helper
  2385. Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done.
  2386. remote: Compressing objects: 100% (300/300), done.
  2387. remote: Total 768 (delta 499), reused 703 (delta 434)
  2388. Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
  2389. Resolving deltas: 100% (499/499), done.
  2390. Checking connectivity... done.
  2391. AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or
  2392. :term:`Poky` repositories.
  2393. 4. *Create a Dedicated Build Directory:* Run the
  2394. :ref:`structure-core-script`
  2395. script to create a fresh build directory that you use exclusively for
  2396. running the AUH utility:
  2397. ::
  2398. $ cd ~/poky
  2399. $ source oe-init-build-env your_AUH_build_directory
  2400. Re-using an existing build directory and its configurations is not
  2401. recommended as existing settings could cause AUH to fail or behave
  2402. undesirably.
  2403. 5. *Make Configurations in Your Local Configuration File:* Several
  2404. settings need to exist in the ``local.conf`` file in the build
  2405. directory you just created for AUH. Make these following
  2406. configurations:
  2407. - If you want to enable :ref:`Build
  2408. History <dev-manual/dev-manual-common-tasks:maintaining build output quality>`,
  2409. which is optional, you need the following lines in the
  2410. ``conf/local.conf`` file:
  2411. ::
  2412. INHERIT =+ "buildhistory"
  2413. BUILDHISTORY_COMMIT = "1"
  2414. With this configuration and a successful
  2415. upgrade, a build history "diff" file appears in the
  2416. ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in
  2417. your build directory.
  2418. - If you want to enable testing through the
  2419. :ref:`testimage <ref-classes-testimage*>`
  2420. class, which is optional, you need to have the following set in
  2421. your ``conf/local.conf`` file:
  2422. ::
  2423. INHERIT += "testimage"
  2424. .. note::
  2425. If your distro does not enable by default ptest, which Poky
  2426. does, you need the following in your ``local.conf`` file:
  2427. ::
  2428. DISTRO_FEATURES_append = " ptest"
  2429. 6. *Optionally Start a vncserver:* If you are running in a server
  2430. without an X11 session, you need to start a vncserver:
  2431. ::
  2432. $ vncserver :1
  2433. $ export DISPLAY=:1
  2434. 7. *Create and Edit an AUH Configuration File:* You need to have the
  2435. ``upgrade-helper/upgrade-helper.conf`` configuration file in your
  2436. build directory. You can find a sample configuration file in the
  2437. :yocto_git:`AUH source repository </cgit/cgit.cgi/auto-upgrade-helper/tree/>`.
  2438. Read through the sample file and make configurations as needed. For
  2439. example, if you enabled build history in your ``local.conf`` as
  2440. described earlier, you must enable it in ``upgrade-helper.conf``.
  2441. Also, if you are using the default ``maintainers.inc`` file supplied
  2442. with Poky and located in ``meta-yocto`` and you do not set a
  2443. "maintainers_whitelist" or "global_maintainer_override" in the
  2444. ``upgrade-helper.conf`` configuration, and you specify "-e all" on
  2445. the AUH command-line, the utility automatically sends out emails to
  2446. all the default maintainers. Please avoid this.
  2447. This next set of examples describes how to use the AUH:
  2448. - *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the
  2449. following form:
  2450. ::
  2451. $ upgrade-helper.py recipe_name
  2452. For example, this command upgrades the ``xmodmap`` recipe:
  2453. ::
  2454. $ upgrade-helper.py xmodmap
  2455. - *Upgrading a Specific Recipe to a Particular Version:* To upgrade a
  2456. specific recipe to a particular version, use the following form:
  2457. ::
  2458. $ upgrade-helper.py recipe_name -t version
  2459. For example, this command upgrades the ``xmodmap`` recipe to version 1.2.3:
  2460. ::
  2461. $ upgrade-helper.py xmodmap -t 1.2.3
  2462. - *Upgrading all Recipes to the Latest Versions and Suppressing Email
  2463. Notifications:* To upgrade all recipes to their most recent versions
  2464. and suppress the email notifications, use the following command:
  2465. ::
  2466. $ upgrade-helper.py all
  2467. - *Upgrading all Recipes to the Latest Versions and Send Email
  2468. Notifications:* To upgrade all recipes to their most recent versions
  2469. and send email messages to maintainers for each attempted recipe as
  2470. well as a status email, use the following command:
  2471. ::
  2472. $ upgrade-helper.py -e all
  2473. Once you have run the AUH utility, you can find the results in the AUH
  2474. build directory:
  2475. ::
  2476. ${BUILDDIR}/upgrade-helper/timestamp
  2477. The AUH utility
  2478. also creates recipe update commits from successful upgrade attempts in
  2479. the layer tree.
  2480. You can easily set up to run the AUH utility on a regular basis by using
  2481. a cron job. See the
  2482. :yocto_git:`weeklyjob.sh </cgit/cgit.cgi/auto-upgrade-helper/tree/weeklyjob.sh>`
  2483. file distributed with the utility for an example.
  2484. .. _gs-using-devtool-upgrade:
  2485. Using ``devtool upgrade``
  2486. -------------------------
  2487. As mentioned earlier, an alternative method for upgrading recipes to
  2488. newer versions is to use
  2489. :doc:`devtool upgrade <../ref-manual/ref-devtool-reference>`.
  2490. You can read about ``devtool upgrade`` in general in the
  2491. ":ref:`sdk-devtool-use-devtool-upgrade-to-create-a-version-of-the-recipe-that-supports-a-newer-version-of-the-software`"
  2492. section in the Yocto Project Application Development and the Extensible
  2493. Software Development Kit (eSDK) Manual.
  2494. To see all the command-line options available with ``devtool upgrade``,
  2495. use the following help command:
  2496. ::
  2497. $ devtool upgrade -h
  2498. If you want to find out what version a recipe is currently at upstream
  2499. without any attempt to upgrade your local version of the recipe, you can
  2500. use the following command:
  2501. ::
  2502. $ devtool latest-version recipe_name
  2503. As mentioned in the previous section describing AUH, ``devtool upgrade``
  2504. works in a less-automated manner than AUH. Specifically,
  2505. ``devtool upgrade`` only works on a single recipe that you name on the
  2506. command line, cannot perform build and integration testing using images,
  2507. and does not automatically generate commits for changes in the source
  2508. tree. Despite all these "limitations", ``devtool upgrade`` updates the
  2509. recipe file to the new upstream version and attempts to rebase custom
  2510. patches contained by the recipe as needed.
  2511. .. note::
  2512. AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat
  2513. of a "wrapper" application for ``devtool upgrade``.
  2514. A typical scenario involves having used Git to clone an upstream
  2515. repository that you use during build operations. Because you have built the
  2516. recipe in the past, the layer is likely added to your
  2517. configuration already. If for some reason, the layer is not added, you
  2518. could add it easily using the
  2519. ":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`"
  2520. script. For example, suppose you use the ``nano.bb`` recipe from the
  2521. ``meta-oe`` layer in the ``meta-openembedded`` repository. For this
  2522. example, assume that the layer has been cloned into following area:
  2523. ::
  2524. /home/scottrif/meta-openembedded
  2525. The following command from your
  2526. :term:`Build Directory` adds the layer to
  2527. your build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``):
  2528. ::
  2529. $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
  2530. NOTE: Starting bitbake server...
  2531. Parsing recipes: 100% |##########################################| Time: 0:00:55
  2532. Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
  2533. Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
  2534. Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
  2535. Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
  2536. Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
  2537. For this example, assume that the ``nano.bb`` recipe that
  2538. is upstream has a 2.9.3 version number. However, the version in the
  2539. local repository is 2.7.4. The following command from your build
  2540. directory automatically upgrades the recipe for you:
  2541. .. note::
  2542. Using the ``-V`` option is not necessary. Omitting the version number causes
  2543. ``devtool upgrade`` to upgrade the recipe to the most recent version.
  2544. ::
  2545. $ devtool upgrade nano -V 2.9.3
  2546. NOTE: Starting bitbake server...
  2547. NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
  2548. Parsing recipes: 100% |##########################################| Time: 0:00:46
  2549. Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
  2550. NOTE: Extracting current version source...
  2551. NOTE: Resolving any missing task queue dependencies
  2552. .
  2553. .
  2554. .
  2555. NOTE: Executing SetScene Tasks
  2556. NOTE: Executing RunQueue Tasks
  2557. NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
  2558. Adding changed files: 100% |#####################################| Time: 0:00:00
  2559. NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
  2560. NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
  2561. Continuing with this example, you can use ``devtool build`` to build the
  2562. newly upgraded recipe:
  2563. ::
  2564. $ devtool build nano
  2565. NOTE: Starting bitbake server...
  2566. Loading cache: 100% |################################################################################################| Time: 0:00:01
  2567. Loaded 2040 entries from dependency cache.
  2568. Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
  2569. Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
  2570. NOTE: Resolving any missing task queue dependencies
  2571. .
  2572. .
  2573. .
  2574. NOTE: Executing SetScene Tasks
  2575. NOTE: Executing RunQueue Tasks
  2576. NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
  2577. NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
  2578. Within the ``devtool upgrade`` workflow, opportunity
  2579. exists to deploy and test your rebuilt software. For this example,
  2580. however, running ``devtool finish`` cleans up the workspace once the
  2581. source in your workspace is clean. This usually means using Git to stage
  2582. and submit commits for the changes generated by the upgrade process.
  2583. Once the tree is clean, you can clean things up in this example with the
  2584. following command from the ``${BUILDDIR}/workspace/sources/nano``
  2585. directory:
  2586. ::
  2587. $ devtool finish nano meta-oe
  2588. NOTE: Starting bitbake server...
  2589. Loading cache: 100% |################################################################################################| Time: 0:00:00
  2590. Loaded 2040 entries from dependency cache.
  2591. Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
  2592. Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
  2593. NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
  2594. NOTE: Updating recipe nano_2.9.3.bb
  2595. NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
  2596. NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
  2597. NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
  2598. Using the ``devtool finish`` command cleans up the workspace and creates a patch
  2599. file based on your commits. The tool puts all patch files back into the
  2600. source directory in a sub-directory named ``nano`` in this case.
  2601. .. _dev-manually-upgrading-a-recipe:
  2602. Manually Upgrading a Recipe
  2603. ---------------------------
  2604. If for some reason you choose not to upgrade recipes using
  2605. :ref:`gs-using-the-auto-upgrade-helper` or by :ref:`gs-using-devtool-upgrade`,
  2606. you can manually edit the recipe files to upgrade the versions.
  2607. .. note::
  2608. Manually updating multiple recipes scales poorly and involves many
  2609. steps. The recommendation to upgrade recipe versions is through AUH
  2610. or ``devtool upgrade``, both of which automate some steps and provide
  2611. guidance for others needed for the manual process.
  2612. To manually upgrade recipe versions, follow these general steps:
  2613. 1. *Change the Version:* Rename the recipe such that the version (i.e.
  2614. the :term:`PV` part of the recipe name)
  2615. changes appropriately. If the version is not part of the recipe name,
  2616. change the value as it is set for ``PV`` within the recipe itself.
  2617. 2. *Update* ``SRCREV`` *if Needed*: If the source code your recipe builds
  2618. is fetched from Git or some other version control system, update
  2619. :term:`SRCREV` to point to the
  2620. commit hash that matches the new version.
  2621. 3. *Build the Software:* Try to build the recipe using BitBake. Typical
  2622. build failures include the following:
  2623. - License statements were updated for the new version. For this
  2624. case, you need to review any changes to the license and update the
  2625. values of :term:`LICENSE` and
  2626. :term:`LIC_FILES_CHKSUM`
  2627. as needed.
  2628. .. note::
  2629. License changes are often inconsequential. For example, the
  2630. license text's copyright year might have changed.
  2631. - Custom patches carried by the older version of the recipe might
  2632. fail to apply to the new version. For these cases, you need to
  2633. review the failures. Patches might not be necessary for the new
  2634. version of the software if the upgraded version has fixed those
  2635. issues. If a patch is necessary and failing, you need to rebase it
  2636. into the new version.
  2637. 4. *Optionally Attempt to Build for Several Architectures:* Once you
  2638. successfully build the new software for a given architecture, you
  2639. could test the build for other architectures by changing the
  2640. :term:`MACHINE` variable and
  2641. rebuilding the software. This optional step is especially important
  2642. if the recipe is to be released publicly.
  2643. 5. *Check the Upstream Change Log or Release Notes:* Checking both these
  2644. reveals if new features exist that could break
  2645. backwards-compatibility. If so, you need to take steps to mitigate or
  2646. eliminate that situation.
  2647. 6. *Optionally Create a Bootable Image and Test:* If you want, you can
  2648. test the new software by booting it onto actual hardware.
  2649. 7. *Create a Commit with the Change in the Layer Repository:* After all
  2650. builds work and any testing is successful, you can create commits for
  2651. any changes in the layer holding your upgraded recipe.
  2652. .. _finding-the-temporary-source-code:
  2653. Finding Temporary Source Code
  2654. =============================
  2655. You might find it helpful during development to modify the temporary
  2656. source code used by recipes to build packages. For example, suppose you
  2657. are developing a patch and you need to experiment a bit to figure out
  2658. your solution. After you have initially built the package, you can
  2659. iteratively tweak the source code, which is located in the
  2660. :term:`Build Directory`, and then you can
  2661. force a re-compile and quickly test your altered code. Once you settle
  2662. on a solution, you can then preserve your changes in the form of
  2663. patches.
  2664. During a build, the unpacked temporary source code used by recipes to
  2665. build packages is available in the Build Directory as defined by the
  2666. :term:`S` variable. Below is the default
  2667. value for the ``S`` variable as defined in the
  2668. ``meta/conf/bitbake.conf`` configuration file in the
  2669. :term:`Source Directory`:
  2670. ::
  2671. S = "${WORKDIR}/${BP}"
  2672. You should be aware that many recipes override the
  2673. ``S`` variable. For example, recipes that fetch their source from Git
  2674. usually set ``S`` to ``${WORKDIR}/git``.
  2675. .. note::
  2676. The :term:`BP` represents the base recipe name, which consists of the name
  2677. and version:
  2678. ::
  2679. BP = "${BPN}-${PV}"
  2680. The path to the work directory for the recipe
  2681. (:term:`WORKDIR`) is defined as
  2682. follows:
  2683. ::
  2684. ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
  2685. The actual directory depends on several things:
  2686. - :term:`TMPDIR`: The top-level build
  2687. output directory.
  2688. - :term:`MULTIMACH_TARGET_SYS`:
  2689. The target system identifier.
  2690. - :term:`PN`: The recipe name.
  2691. - :term:`EXTENDPE`: The epoch - (if
  2692. :term:`PE` is not specified, which is
  2693. usually the case for most recipes, then ``EXTENDPE`` is blank).
  2694. - :term:`PV`: The recipe version.
  2695. - :term:`PR`: The recipe revision.
  2696. As an example, assume a Source Directory top-level folder named
  2697. ``poky``, a default Build Directory at ``poky/build``, and a
  2698. ``qemux86-poky-linux`` machine target system. Furthermore, suppose your
  2699. recipe is named ``foo_1.3.0.bb``. In this case, the work directory the
  2700. build system uses to build the package would be as follows:
  2701. ::
  2702. poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
  2703. .. _using-a-quilt-workflow:
  2704. Using Quilt in Your Workflow
  2705. ============================
  2706. `Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool
  2707. that allows you to capture source code changes without having a clean
  2708. source tree. This section outlines the typical workflow you can use to
  2709. modify source code, test changes, and then preserve the changes in the
  2710. form of a patch all using Quilt.
  2711. .. note::
  2712. With regard to preserving changes to source files, if you clean a
  2713. recipe or have ``rm_work`` enabled, the
  2714. :ref:`devtool workflow <sdk-manual/sdk-extensible:using \`\`devtool\`\` in your sdk workflow>`
  2715. as described in the Yocto Project Application Development and the
  2716. Extensible Software Development Kit (eSDK) manual is a safer
  2717. development flow than the flow that uses Quilt.
  2718. Follow these general steps:
  2719. 1. *Find the Source Code:* Temporary source code used by the
  2720. OpenEmbedded build system is kept in the
  2721. :term:`Build Directory`. See the
  2722. "`Finding Temporary Source
  2723. Code <#finding-the-temporary-source-code>`__" section to learn how to
  2724. locate the directory that has the temporary source code for a
  2725. particular package.
  2726. 2. *Change Your Working Directory:* You need to be in the directory that
  2727. has the temporary source code. That directory is defined by the
  2728. :term:`S` variable.
  2729. 3. *Create a New Patch:* Before modifying source code, you need to
  2730. create a new patch. To create a new patch file, use ``quilt new`` as
  2731. below:
  2732. ::
  2733. $ quilt new my_changes.patch
  2734. 4. *Notify Quilt and Add Files:* After creating the patch, you need to
  2735. notify Quilt about the files you plan to edit. You notify Quilt by
  2736. adding the files to the patch you just created:
  2737. ::
  2738. $ quilt add file1.c file2.c file3.c
  2739. 5. *Edit the Files:* Make your changes in the source code to the files
  2740. you added to the patch.
  2741. 6. *Test Your Changes:* Once you have modified the source code, the
  2742. easiest way to test your changes is by calling the ``do_compile``
  2743. task as shown in the following example:
  2744. ::
  2745. $ bitbake -c compile -f package
  2746. The ``-f`` or ``--force`` option forces the specified task to
  2747. execute. If you find problems with your code, you can just keep
  2748. editing and re-testing iteratively until things work as expected.
  2749. .. note::
  2750. All the modifications you make to the temporary source code disappear
  2751. once you run the ``do_clean`` or ``do_cleanall`` tasks using BitBake
  2752. (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``).
  2753. Modifications will also disappear if you use the ``rm_work`` feature as
  2754. described in the
  2755. ":ref:`dev-manual/dev-manual-common-tasks:conserving disk space during builds`"
  2756. section.
  2757. 7. *Generate the Patch:* Once your changes work as expected, you need to
  2758. use Quilt to generate the final patch that contains all your
  2759. modifications.
  2760. ::
  2761. $ quilt refresh
  2762. At this point, the
  2763. ``my_changes.patch`` file has all your edits made to the ``file1.c``,
  2764. ``file2.c``, and ``file3.c`` files.
  2765. You can find the resulting patch file in the ``patches/``
  2766. subdirectory of the source (``S``) directory.
  2767. 8. *Copy the Patch File:* For simplicity, copy the patch file into a
  2768. directory named ``files``, which you can create in the same directory
  2769. that holds the recipe (``.bb``) file or the append (``.bbappend``)
  2770. file. Placing the patch here guarantees that the OpenEmbedded build
  2771. system will find the patch. Next, add the patch into the ``SRC_URI``
  2772. of the recipe. Here is an example:
  2773. ::
  2774. SRC_URI += "file://my_changes.patch"
  2775. .. _platdev-appdev-devshell:
  2776. Using a Development Shell
  2777. =========================
  2778. When debugging certain commands or even when just editing packages,
  2779. ``devshell`` can be a useful tool. When you invoke ``devshell``, all
  2780. tasks up to and including
  2781. :ref:`ref-tasks-patch` are run for the
  2782. specified target. Then, a new terminal is opened and you are placed in
  2783. ``${``\ :term:`S`\ ``}``, the source
  2784. directory. In the new terminal, all the OpenEmbedded build-related
  2785. environment variables are still defined so you can use commands such as
  2786. ``configure`` and ``make``. The commands execute just as if the
  2787. OpenEmbedded build system were executing them. Consequently, working
  2788. this way can be helpful when debugging a build or preparing software to
  2789. be used with the OpenEmbedded build system.
  2790. Following is an example that uses ``devshell`` on a target named
  2791. ``matchbox-desktop``:
  2792. ::
  2793. $ bitbake matchbox-desktop -c devshell
  2794. This command spawns a terminal with a shell prompt within the
  2795. OpenEmbedded build environment. The
  2796. :term:`OE_TERMINAL` variable
  2797. controls what type of shell is opened.
  2798. For spawned terminals, the following occurs:
  2799. - The ``PATH`` variable includes the cross-toolchain.
  2800. - The ``pkgconfig`` variables find the correct ``.pc`` files.
  2801. - The ``configure`` command finds the Yocto Project site files as well
  2802. as any other necessary files.
  2803. Within this environment, you can run configure or compile commands as if
  2804. they were being run by the OpenEmbedded build system itself. As noted
  2805. earlier, the working directory also automatically changes to the Source
  2806. Directory (:term:`S`).
  2807. To manually run a specific task using ``devshell``, run the
  2808. corresponding ``run.*`` script in the
  2809. ``${``\ :term:`WORKDIR`\ ``}/temp``
  2810. directory (e.g., ``run.do_configure.``\ `pid`). If a task's script does
  2811. not exist, which would be the case if the task was skipped by way of the
  2812. sstate cache, you can create the task by first running it outside of the
  2813. ``devshell``:
  2814. ::
  2815. $ bitbake -c task
  2816. .. note::
  2817. - Execution of a task's ``run.*`` script and BitBake's execution of
  2818. a task are identical. In other words, running the script re-runs
  2819. the task just as it would be run using the ``bitbake -c`` command.
  2820. - Any ``run.*`` file that does not have a ``.pid`` extension is a
  2821. symbolic link (symlink) to the most recent version of that file.
  2822. Remember, that the ``devshell`` is a mechanism that allows you to get
  2823. into the BitBake task execution environment. And as such, all commands
  2824. must be called just as BitBake would call them. That means you need to
  2825. provide the appropriate options for cross-compilation and so forth as
  2826. applicable.
  2827. When you are finished using ``devshell``, exit the shell or close the
  2828. terminal window.
  2829. .. note::
  2830. - It is worth remembering that when using ``devshell`` you need to
  2831. use the full compiler name such as ``arm-poky-linux-gnueabi-gcc``
  2832. instead of just using ``gcc``. The same applies to other
  2833. applications such as ``binutils``, ``libtool`` and so forth.
  2834. BitBake sets up environment variables such as ``CC`` to assist
  2835. applications, such as ``make`` to find the correct tools.
  2836. - It is also worth noting that ``devshell`` still works over X11
  2837. forwarding and similar situations.
  2838. .. _platdev-appdev-devpyshell:
  2839. Using a Development Python Shell
  2840. ================================
  2841. Similar to working within a development shell as described in the
  2842. previous section, you can also spawn and work within an interactive
  2843. Python development shell. When debugging certain commands or even when
  2844. just editing packages, ``devpyshell`` can be a useful tool. When you
  2845. invoke ``devpyshell``, all tasks up to and including
  2846. :ref:`ref-tasks-patch` are run for the
  2847. specified target. Then a new terminal is opened. Additionally, key
  2848. Python objects and code are available in the same way they are to
  2849. BitBake tasks, in particular, the data store 'd'. So, commands such as
  2850. the following are useful when exploring the data store and running
  2851. functions:
  2852. ::
  2853. pydevshell> d.getVar("STAGING_DIR")
  2854. '/media/build1/poky/build/tmp/sysroots'
  2855. pydevshell> d.getVar("STAGING_DIR")
  2856. '${TMPDIR}/sysroots'
  2857. pydevshell> d.setVar("FOO", "bar")
  2858. pydevshell> d.getVar("FOO")
  2859. 'bar'
  2860. pydevshell> d.delVar("FOO")
  2861. pydevshell> d.getVar("FOO")
  2862. pydevshell> bb.build.exec_func("do_unpack", d)
  2863. pydevshell>
  2864. The commands execute just as if the OpenEmbedded build
  2865. system were executing them. Consequently, working this way can be
  2866. helpful when debugging a build or preparing software to be used with the
  2867. OpenEmbedded build system.
  2868. Following is an example that uses ``devpyshell`` on a target named
  2869. ``matchbox-desktop``:
  2870. ::
  2871. $ bitbake matchbox-desktop -c devpyshell
  2872. This command spawns a terminal and places you in an interactive Python
  2873. interpreter within the OpenEmbedded build environment. The
  2874. :term:`OE_TERMINAL` variable
  2875. controls what type of shell is opened.
  2876. When you are finished using ``devpyshell``, you can exit the shell
  2877. either by using Ctrl+d or closing the terminal window.
  2878. .. _dev-building:
  2879. Building
  2880. ========
  2881. This section describes various build procedures. For example, the steps
  2882. needed for a simple build, a target that uses multiple configurations,
  2883. building an image for more than one machine, and so forth.
  2884. .. _dev-building-a-simple-image:
  2885. Building a Simple Image
  2886. -----------------------
  2887. In the development environment, you need to build an image whenever you
  2888. change hardware support, add or change system libraries, or add or
  2889. change services that have dependencies. Several methods exist that allow
  2890. you to build an image within the Yocto Project. This section presents
  2891. the basic steps you need to build a simple image using BitBake from a
  2892. build host running Linux.
  2893. .. note::
  2894. - For information on how to build an image using
  2895. :term:`Toaster`, see the
  2896. :doc:`../toaster-manual/toaster-manual`.
  2897. - For information on how to use ``devtool`` to build images, see the
  2898. ":ref:`sdk-manual/sdk-extensible:using \`\`devtool\`\` in your sdk workflow`"
  2899. section in the Yocto Project Application Development and the
  2900. Extensible Software Development Kit (eSDK) manual.
  2901. - For a quick example on how to build an image using the
  2902. OpenEmbedded build system, see the
  2903. :doc:`../brief-yoctoprojectqs/brief-yoctoprojectqs` document.
  2904. The build process creates an entire Linux distribution from source and
  2905. places it in your :term:`Build Directory` under
  2906. ``tmp/deploy/images``. For detailed information on the build process
  2907. using BitBake, see the ":ref:`images-dev-environment`" section in the
  2908. Yocto Project Overview and Concepts Manual.
  2909. The following figure and list overviews the build process:
  2910. .. image:: figures/bitbake-build-flow.png
  2911. :align: center
  2912. 1. *Set up Your Host Development System to Support Development Using the
  2913. Yocto Project*: See the ":doc:`dev-manual-start`" section for options on how to get a
  2914. build host ready to use the Yocto Project.
  2915. 2. *Initialize the Build Environment:* Initialize the build environment
  2916. by sourcing the build environment script (i.e.
  2917. :ref:`structure-core-script`):
  2918. ::
  2919. $ source oe-init-build-env [build_dir]
  2920. When you use the initialization script, the OpenEmbedded build system
  2921. uses ``build`` as the default :term:`Build Directory` in your current work
  2922. directory. You can use a `build_dir` argument with the script to
  2923. specify a different build directory.
  2924. .. note::
  2925. A common practice is to use a different Build Directory for
  2926. different targets. For example, ``~/build/x86`` for a ``qemux86``
  2927. target, and ``~/build/arm`` for a ``qemuarm`` target.
  2928. 3. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the
  2929. ``conf/local.conf`` configuration file, which is found in the Build
  2930. Directory, is set up how you want it. This file defines many aspects
  2931. of the build environment including the target machine architecture
  2932. through the ``MACHINE`` variable, the packaging format used during
  2933. the build
  2934. (:term:`PACKAGE_CLASSES`),
  2935. and a centralized tarball download directory through the
  2936. :term:`DL_DIR` variable.
  2937. 4. *Build the Image:* Build the image using the ``bitbake`` command:
  2938. ::
  2939. $ bitbake target
  2940. .. note::
  2941. For information on BitBake, see the :doc:`bitbake:index`.
  2942. The target is the name of the recipe you want to build. Common
  2943. targets are the images in ``meta/recipes-core/images``,
  2944. ``meta/recipes-sato/images``, and so forth all found in the
  2945. :term:`Source Directory`. Or, the target
  2946. can be the name of a recipe for a specific piece of software such as
  2947. BusyBox. For more details about the images the OpenEmbedded build
  2948. system supports, see the
  2949. ":ref:`ref-manual/ref-images:Images`" chapter in the Yocto
  2950. Project Reference Manual.
  2951. As an example, the following command builds the
  2952. ``core-image-minimal`` image:
  2953. ::
  2954. $ bitbake core-image-minimal
  2955. Once an
  2956. image has been built, it often needs to be installed. The images and
  2957. kernels built by the OpenEmbedded build system are placed in the
  2958. Build Directory in ``tmp/deploy/images``. For information on how to
  2959. run pre-built images such as ``qemux86`` and ``qemuarm``, see the
  2960. :doc:`../sdk-manual/sdk-manual` manual. For
  2961. information about how to install these images, see the documentation
  2962. for your particular board or machine.
  2963. .. _dev-building-images-for-multiple-targets-using-multiple-configurations:
  2964. Building Images for Multiple Targets Using Multiple Configurations
  2965. ------------------------------------------------------------------
  2966. You can use a single ``bitbake`` command to build multiple images or
  2967. packages for different targets where each image or package requires a
  2968. different configuration (multiple configuration builds). The builds, in
  2969. this scenario, are sometimes referred to as "multiconfigs", and this
  2970. section uses that term throughout.
  2971. This section describes how to set up for multiple configuration builds
  2972. and how to account for cross-build dependencies between the
  2973. multiconfigs.
  2974. .. _dev-setting-up-and-running-a-multiple-configuration-build:
  2975. Setting Up and Running a Multiple Configuration Build
  2976. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2977. To accomplish a multiple configuration build, you must define each
  2978. target's configuration separately using a parallel configuration file in
  2979. the :term:`Build Directory` or configuration directory within a layer, and you
  2980. must follow a required file hierarchy. Additionally, you must enable the
  2981. multiple configuration builds in your ``local.conf`` file.
  2982. Follow these steps to set up and execute multiple configuration builds:
  2983. - *Create Separate Configuration Files*: You need to create a single
  2984. configuration file for each build target (each multiconfig).
  2985. The configuration definitions are implementation dependent but often
  2986. each configuration file will define the machine and the
  2987. temporary directory BitBake uses for the build. Whether the same
  2988. temporary directory (:term:`TMPDIR`) can be shared will depend on what is
  2989. similar and what is different between the configurations. Multiple MACHINE
  2990. targets can share the same (:term:`TMPDIR`) as long as the rest of the
  2991. configuration is the same, multiple DISTRO settings would need separate
  2992. (:term:`TMPDIR`) directories.
  2993. For example, consider a scenario with two different multiconfigs for the same
  2994. :term:`MACHINE`: "qemux86" built
  2995. for two distributions such as "poky" and "poky-lsb". In this case,
  2996. you would need to use the different :term:`TMPDIR`.
  2997. Here is an example showing the minimal statements needed in a
  2998. configuration file for a "qemux86" target whose temporary build
  2999. directory is ``tmpmultix86``::
  3000. MACHINE = "qemux86"
  3001. TMPDIR = "${TOPDIR}/tmpmultix86"
  3002. The location for these multiconfig configuration files is specific.
  3003. They must reside in the current :term:`Build Directory` in a sub-directory of
  3004. ``conf`` named ``multiconfig`` or within a layer's ``conf`` directory
  3005. under a directory named ``multiconfig``. Following is an example that defines
  3006. two configuration files for the "x86" and "arm" multiconfigs:
  3007. .. image:: figures/multiconfig_files.png
  3008. :align: center
  3009. :width: 50%
  3010. The usual :term:`BBPATH` search path is used to locate multiconfig files in
  3011. a similar way to other conf files.
  3012. - *Add the BitBake Multi-configuration Variable to the Local
  3013. Configuration File*: Use the
  3014. :term:`BBMULTICONFIG`
  3015. variable in your ``conf/local.conf`` configuration file to specify
  3016. each multiconfig. Continuing with the example from the previous
  3017. figure, the :term:`BBMULTICONFIG` variable needs to enable two
  3018. multiconfigs: "x86" and "arm" by specifying each configuration file::
  3019. BBMULTICONFIG = "x86 arm"
  3020. .. note::
  3021. A "default" configuration already exists by definition. This
  3022. configuration is named: "" (i.e. empty string) and is defined by
  3023. the variables coming from your ``local.conf``
  3024. file. Consequently, the previous example actually adds two
  3025. additional configurations to your build: "arm" and "x86" along
  3026. with "".
  3027. - *Launch BitBake*: Use the following BitBake command form to launch
  3028. the multiple configuration build::
  3029. $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ]
  3030. For the example in this section, the following command applies::
  3031. $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base
  3032. The previous BitBake command builds a ``core-image-minimal`` image
  3033. that is configured through the ``x86.conf`` configuration file, a
  3034. ``core-image-sato`` image that is configured through the ``arm.conf``
  3035. configuration file and a ``core-image-base`` that is configured
  3036. through your ``local.conf`` configuration file.
  3037. .. note::
  3038. Support for multiple configuration builds in the Yocto Project &DISTRO;
  3039. (&DISTRO_NAME;) Release does not include Shared State (sstate)
  3040. optimizations. Consequently, if a build uses the same object twice
  3041. in, for example, two different :term:`TMPDIR`
  3042. directories, the build either loads from an existing sstate cache for
  3043. that build at the start or builds the object fresh.
  3044. .. _dev-enabling-multiple-configuration-build-dependencies:
  3045. Enabling Multiple Configuration Build Dependencies
  3046. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3047. Sometimes dependencies can exist between targets (multiconfigs) in a
  3048. multiple configuration build. For example, suppose that in order to
  3049. build a ``core-image-sato`` image for an "x86" multiconfig, the root
  3050. filesystem of an "arm" multiconfig must exist. This dependency is
  3051. essentially that the
  3052. :ref:`ref-tasks-image` task in the
  3053. ``core-image-sato`` recipe depends on the completion of the
  3054. :ref:`ref-tasks-rootfs` task of the
  3055. ``core-image-minimal`` recipe.
  3056. To enable dependencies in a multiple configuration build, you must
  3057. declare the dependencies in the recipe using the following statement
  3058. form::
  3059. task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend"
  3060. To better show how to use this statement, consider the example scenario
  3061. from the first paragraph of this section. The following statement needs
  3062. to be added to the recipe that builds the ``core-image-sato`` image::
  3063. do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs"
  3064. In this example, the `from_multiconfig` is "x86". The `to_multiconfig` is "arm". The
  3065. task on which the :ref:`ref-tasks-image` task in the recipe depends is the
  3066. :ref:`ref-tasks-rootfs` task from the ``core-image-minimal`` recipe associated
  3067. with the "arm" multiconfig.
  3068. Once you set up this dependency, you can build the "x86" multiconfig
  3069. using a BitBake command as follows::
  3070. $ bitbake mc:x86:core-image-sato
  3071. This command executes all the tasks needed to create the
  3072. ``core-image-sato`` image for the "x86" multiconfig. Because of the
  3073. dependency, BitBake also executes through the :ref:`ref-tasks-rootfs` task for the
  3074. "arm" multiconfig build.
  3075. Having a recipe depend on the root filesystem of another build might not
  3076. seem that useful. Consider this change to the statement in the
  3077. ``core-image-sato`` recipe::
  3078. do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image"
  3079. In this case, BitBake must
  3080. create the ``core-image-minimal`` image for the "arm" build since the
  3081. "x86" build depends on it.
  3082. Because "x86" and "arm" are enabled for multiple configuration builds
  3083. and have separate configuration files, BitBake places the artifacts for
  3084. each build in the respective temporary build directories (i.e.
  3085. :term:`TMPDIR`).
  3086. .. _building-an-initramfs-image:
  3087. Building an Initial RAM Filesystem (initramfs) Image
  3088. ----------------------------------------------------
  3089. An initial RAM filesystem (initramfs) image provides a temporary root
  3090. filesystem used for early system initialization (e.g. loading of modules
  3091. needed to locate and mount the "real" root filesystem).
  3092. .. note::
  3093. The initramfs image is the successor of initial RAM disk (initrd). It
  3094. is a "copy in and out" (cpio) archive of the initial filesystem that
  3095. gets loaded into memory during the Linux startup process. Because
  3096. Linux uses the contents of the archive during initialization, the
  3097. initramfs image needs to contain all of the device drivers and tools
  3098. needed to mount the final root filesystem.
  3099. Follow these steps to create an initramfs image:
  3100. 1. *Create the initramfs Image Recipe:* You can reference the
  3101. ``core-image-minimal-initramfs.bb`` recipe found in the
  3102. ``meta/recipes-core`` directory of the :term:`Source Directory`
  3103. as an example
  3104. from which to work.
  3105. 2. *Decide if You Need to Bundle the initramfs Image Into the Kernel
  3106. Image:* If you want the initramfs image that is built to be bundled
  3107. in with the kernel image, set the
  3108. :term:`INITRAMFS_IMAGE_BUNDLE`
  3109. variable to "1" in your ``local.conf`` configuration file and set the
  3110. :term:`INITRAMFS_IMAGE`
  3111. variable in the recipe that builds the kernel image.
  3112. .. note::
  3113. It is recommended that you do bundle the initramfs image with the
  3114. kernel image to avoid circular dependencies between the kernel
  3115. recipe and the initramfs recipe should the initramfs image include
  3116. kernel modules.
  3117. Setting the ``INITRAMFS_IMAGE_BUNDLE`` flag causes the initramfs
  3118. image to be unpacked into the ``${B}/usr/`` directory. The unpacked
  3119. initramfs image is then passed to the kernel's ``Makefile`` using the
  3120. :term:`CONFIG_INITRAMFS_SOURCE`
  3121. variable, allowing the initramfs image to be built into the kernel
  3122. normally.
  3123. .. note::
  3124. If you choose to not bundle the initramfs image with the kernel
  3125. image, you are essentially using an
  3126. `Initial RAM Disk (initrd) <https://en.wikipedia.org/wiki/Initrd>`__.
  3127. Creating an initrd is handled primarily through the :term:`INITRD_IMAGE`,
  3128. ``INITRD_LIVE``, and ``INITRD_IMAGE_LIVE`` variables. For more
  3129. information, see the :ref:`ref-classes-image-live` file.
  3130. 3. *Optionally Add Items to the initramfs Image Through the initramfs
  3131. Image Recipe:* If you add items to the initramfs image by way of its
  3132. recipe, you should use
  3133. :term:`PACKAGE_INSTALL`
  3134. rather than
  3135. :term:`IMAGE_INSTALL`.
  3136. ``PACKAGE_INSTALL`` gives more direct control of what is added to the
  3137. image as compared to the defaults you might not necessarily want that
  3138. are set by the :ref:`image <ref-classes-image>`
  3139. or :ref:`core-image <ref-classes-core-image>`
  3140. classes.
  3141. 4. *Build the Kernel Image and the initramfs Image:* Build your kernel
  3142. image using BitBake. Because the initramfs image recipe is a
  3143. dependency of the kernel image, the initramfs image is built as well
  3144. and bundled with the kernel image if you used the
  3145. :term:`INITRAMFS_IMAGE_BUNDLE`
  3146. variable described earlier.
  3147. Building a Tiny System
  3148. ----------------------
  3149. Very small distributions have some significant advantages such as
  3150. requiring less on-die or in-package memory (cheaper), better performance
  3151. through efficient cache usage, lower power requirements due to less
  3152. memory, faster boot times, and reduced development overhead. Some
  3153. real-world examples where a very small distribution gives you distinct
  3154. advantages are digital cameras, medical devices, and small headless
  3155. systems.
  3156. This section presents information that shows you how you can trim your
  3157. distribution to even smaller sizes than the ``poky-tiny`` distribution,
  3158. which is around 5 Mbytes, that can be built out-of-the-box using the
  3159. Yocto Project.
  3160. .. _tiny-system-overview:
  3161. Tiny System Overview
  3162. ~~~~~~~~~~~~~~~~~~~~
  3163. The following list presents the overall steps you need to consider and
  3164. perform to create distributions with smaller root filesystems, achieve
  3165. faster boot times, maintain your critical functionality, and avoid
  3166. initial RAM disks:
  3167. - `Determine your goals and guiding
  3168. principles. <#goals-and-guiding-principles>`__
  3169. - `Understand what contributes to your image
  3170. size. <#understand-what-gives-your-image-size>`__
  3171. - `Reduce the size of the root
  3172. filesystem. <#trim-the-root-filesystem>`__
  3173. - `Reduce the size of the kernel. <#trim-the-kernel>`__
  3174. - `Eliminate packaging
  3175. requirements. <#remove-package-management-requirements>`__
  3176. - `Look for other ways to minimize
  3177. size. <#look-for-other-ways-to-minimize-size>`__
  3178. - `Iterate on the process. <#iterate-on-the-process>`__
  3179. Goals and Guiding Principles
  3180. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3181. Before you can reach your destination, you need to know where you are
  3182. going. Here is an example list that you can use as a guide when creating
  3183. very small distributions:
  3184. - Determine how much space you need (e.g. a kernel that is 1 Mbyte or
  3185. less and a root filesystem that is 3 Mbytes or less).
  3186. - Find the areas that are currently taking 90% of the space and
  3187. concentrate on reducing those areas.
  3188. - Do not create any difficult "hacks" to achieve your goals.
  3189. - Leverage the device-specific options.
  3190. - Work in a separate layer so that you keep changes isolated. For
  3191. information on how to create layers, see the "`Understanding and
  3192. Creating Layers <#understanding-and-creating-layers>`__" section.
  3193. .. _understand-what-gives-your-image-size:
  3194. Understand What Contributes to Your Image Size
  3195. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3196. It is easiest to have something to start with when creating your own
  3197. distribution. You can use the Yocto Project out-of-the-box to create the
  3198. ``poky-tiny`` distribution. Ultimately, you will want to make changes in
  3199. your own distribution that are likely modeled after ``poky-tiny``.
  3200. .. note::
  3201. To use ``poky-tiny`` in your build, set the ``DISTRO`` variable in your
  3202. ``local.conf`` file to "poky-tiny" as described in the
  3203. ":ref:`dev-manual/dev-manual-common-tasks:creating your own distribution`"
  3204. section.
  3205. Understanding some memory concepts will help you reduce the system size.
  3206. Memory consists of static, dynamic, and temporary memory. Static memory
  3207. is the TEXT (code), DATA (initialized data in the code), and BSS
  3208. (uninitialized data) sections. Dynamic memory represents memory that is
  3209. allocated at runtime: stacks, hash tables, and so forth. Temporary
  3210. memory is recovered after the boot process. This memory consists of
  3211. memory used for decompressing the kernel and for the ``__init__``
  3212. functions.
  3213. To help you see where you currently are with kernel and root filesystem
  3214. sizes, you can use two tools found in the :term:`Source Directory`
  3215. in the
  3216. ``scripts/tiny/`` directory:
  3217. - ``ksize.py``: Reports component sizes for the kernel build objects.
  3218. - ``dirsize.py``: Reports component sizes for the root filesystem.
  3219. This next tool and command help you organize configuration fragments and
  3220. view file dependencies in a human-readable form:
  3221. - ``merge_config.sh``: Helps you manage configuration files and
  3222. fragments within the kernel. With this tool, you can merge individual
  3223. configuration fragments together. The tool allows you to make
  3224. overrides and warns you of any missing configuration options. The
  3225. tool is ideal for allowing you to iterate on configurations, create
  3226. minimal configurations, and create configuration files for different
  3227. machines without having to duplicate your process.
  3228. The ``merge_config.sh`` script is part of the Linux Yocto kernel Git
  3229. repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``,
  3230. ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig``
  3231. directory.
  3232. For more information on configuration fragments, see the
  3233. ":ref:`creating-config-fragments`"
  3234. section in the Yocto Project Linux Kernel Development Manual.
  3235. - ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command
  3236. with these options brings up a Dependency Explorer from which you can
  3237. view file dependencies. Understanding these dependencies allows you
  3238. to make informed decisions when cutting out various pieces of the
  3239. kernel and root filesystem.
  3240. Trim the Root Filesystem
  3241. ~~~~~~~~~~~~~~~~~~~~~~~~
  3242. The root filesystem is made up of packages for booting, libraries, and
  3243. applications. To change things, you can configure how the packaging
  3244. happens, which changes the way you build them. You can also modify the
  3245. filesystem itself or select a different filesystem.
  3246. First, find out what is hogging your root filesystem by running the
  3247. ``dirsize.py`` script from your root directory:
  3248. ::
  3249. $ cd root-directory-of-image
  3250. $ dirsize.py 100000 > dirsize-100k.log
  3251. $ cat dirsize-100k.log
  3252. You can apply a filter to the script to ignore files
  3253. under a certain size. The previous example filters out any files below
  3254. 100 Kbytes. The sizes reported by the tool are uncompressed, and thus
  3255. will be smaller by a relatively constant factor in a compressed root
  3256. filesystem. When you examine your log file, you can focus on areas of
  3257. the root filesystem that take up large amounts of memory.
  3258. You need to be sure that what you eliminate does not cripple the
  3259. functionality you need. One way to see how packages relate to each other
  3260. is by using the Dependency Explorer UI with the BitBake command:
  3261. ::
  3262. $ cd image-directory
  3263. $ bitbake -u taskexp -g image
  3264. Use the interface to
  3265. select potential packages you wish to eliminate and see their dependency
  3266. relationships.
  3267. When deciding how to reduce the size, get rid of packages that result in
  3268. minimal impact on the feature set. For example, you might not need a VGA
  3269. display. Or, you might be able to get by with ``devtmpfs`` and ``mdev``
  3270. instead of ``udev``.
  3271. Use your ``local.conf`` file to make changes. For example, to eliminate
  3272. ``udev`` and ``glib``, set the following in the local configuration
  3273. file:
  3274. ::
  3275. VIRTUAL-RUNTIME_dev_manager = ""
  3276. Finally, you should consider exactly the type of root filesystem you
  3277. need to meet your needs while also reducing its size. For example,
  3278. consider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an
  3279. ``initramfs`` using ``initramfs``. Be aware that ``ext3`` requires a 1
  3280. Mbyte journal. If you are okay with running read-only, you do not need
  3281. this journal.
  3282. .. note::
  3283. After each round of elimination, you need to rebuild your system and
  3284. then use the tools to see the effects of your reductions.
  3285. Trim the Kernel
  3286. ~~~~~~~~~~~~~~~
  3287. The kernel is built by including policies for hardware-independent
  3288. aspects. What subsystems do you enable? For what architecture are you
  3289. building? Which drivers do you build by default?
  3290. .. note::
  3291. You can modify the kernel source if you want to help with boot time.
  3292. Run the ``ksize.py`` script from the top-level Linux build directory to
  3293. get an idea of what is making up the kernel:
  3294. ::
  3295. $ cd top-level-linux-build-directory
  3296. $ ksize.py > ksize.log
  3297. $ cat ksize.log
  3298. When you examine the log, you will see how much space is taken up with
  3299. the built-in ``.o`` files for drivers, networking, core kernel files,
  3300. filesystem, sound, and so forth. The sizes reported by the tool are
  3301. uncompressed, and thus will be smaller by a relatively constant factor
  3302. in a compressed kernel image. Look to reduce the areas that are large
  3303. and taking up around the "90% rule."
  3304. To examine, or drill down, into any particular area, use the ``-d``
  3305. option with the script:
  3306. ::
  3307. $ ksize.py -d > ksize.log
  3308. Using this option
  3309. breaks out the individual file information for each area of the kernel
  3310. (e.g. drivers, networking, and so forth).
  3311. Use your log file to see what you can eliminate from the kernel based on
  3312. features you can let go. For example, if you are not going to need
  3313. sound, you do not need any drivers that support sound.
  3314. After figuring out what to eliminate, you need to reconfigure the kernel
  3315. to reflect those changes during the next build. You could run
  3316. ``menuconfig`` and make all your changes at once. However, that makes it
  3317. difficult to see the effects of your individual eliminations and also
  3318. makes it difficult to replicate the changes for perhaps another target
  3319. device. A better method is to start with no configurations using
  3320. ``allnoconfig``, create configuration fragments for individual changes,
  3321. and then manage the fragments into a single configuration file using
  3322. ``merge_config.sh``. The tool makes it easy for you to iterate using the
  3323. configuration change and build cycle.
  3324. Each time you make configuration changes, you need to rebuild the kernel
  3325. and check to see what impact your changes had on the overall size.
  3326. Remove Package Management Requirements
  3327. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3328. Packaging requirements add size to the image. One way to reduce the size
  3329. of the image is to remove all the packaging requirements from the image.
  3330. This reduction includes both removing the package manager and its unique
  3331. dependencies as well as removing the package management data itself.
  3332. To eliminate all the packaging requirements for an image, be sure that
  3333. "package-management" is not part of your
  3334. :term:`IMAGE_FEATURES`
  3335. statement for the image. When you remove this feature, you are removing
  3336. the package manager as well as its dependencies from the root
  3337. filesystem.
  3338. Look for Other Ways to Minimize Size
  3339. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3340. Depending on your particular circumstances, other areas that you can
  3341. trim likely exist. The key to finding these areas is through tools and
  3342. methods described here combined with experimentation and iteration. Here
  3343. are a couple of areas to experiment with:
  3344. - ``glibc``: In general, follow this process:
  3345. 1. Remove ``glibc`` features from
  3346. :term:`DISTRO_FEATURES`
  3347. that you think you do not need.
  3348. 2. Build your distribution.
  3349. 3. If the build fails due to missing symbols in a package, determine
  3350. if you can reconfigure the package to not need those features. For
  3351. example, change the configuration to not support wide character
  3352. support as is done for ``ncurses``. Or, if support for those
  3353. characters is needed, determine what ``glibc`` features provide
  3354. the support and restore the configuration.
  3355. 4. Rebuild and repeat the process.
  3356. - ``busybox``: For BusyBox, use a process similar as described for
  3357. ``glibc``. A difference is you will need to boot the resulting system
  3358. to see if you are able to do everything you expect from the running
  3359. system. You need to be sure to integrate configuration fragments into
  3360. Busybox because BusyBox handles its own core features and then allows
  3361. you to add configuration fragments on top.
  3362. Iterate on the Process
  3363. ~~~~~~~~~~~~~~~~~~~~~~
  3364. If you have not reached your goals on system size, you need to iterate
  3365. on the process. The process is the same. Use the tools and see just what
  3366. is taking up 90% of the root filesystem and the kernel. Decide what you
  3367. can eliminate without limiting your device beyond what you need.
  3368. Depending on your system, a good place to look might be Busybox, which
  3369. provides a stripped down version of Unix tools in a single, executable
  3370. file. You might be able to drop virtual terminal services or perhaps
  3371. ipv6.
  3372. Building Images for More than One Machine
  3373. -----------------------------------------
  3374. A common scenario developers face is creating images for several
  3375. different machines that use the same software environment. In this
  3376. situation, it is tempting to set the tunings and optimization flags for
  3377. each build specifically for the targeted hardware (i.e. "maxing out" the
  3378. tunings). Doing so can considerably add to build times and package feed
  3379. maintenance collectively for the machines. For example, selecting tunes
  3380. that are extremely specific to a CPU core used in a system might enable
  3381. some micro optimizations in GCC for that particular system but would
  3382. otherwise not gain you much of a performance difference across the other
  3383. systems as compared to using a more general tuning across all the builds
  3384. (e.g. setting :term:`DEFAULTTUNE`
  3385. specifically for each machine's build). Rather than "max out" each
  3386. build's tunings, you can take steps that cause the OpenEmbedded build
  3387. system to reuse software across the various machines where it makes
  3388. sense.
  3389. If build speed and package feed maintenance are considerations, you
  3390. should consider the points in this section that can help you optimize
  3391. your tunings to best consider build times and package feed maintenance.
  3392. - *Share the Build Directory:* If at all possible, share the
  3393. :term:`TMPDIR` across builds. The
  3394. Yocto Project supports switching between different
  3395. :term:`MACHINE` values in the same
  3396. ``TMPDIR``. This practice is well supported and regularly used by
  3397. developers when building for multiple machines. When you use the same
  3398. ``TMPDIR`` for multiple machine builds, the OpenEmbedded build system
  3399. can reuse the existing native and often cross-recipes for multiple
  3400. machines. Thus, build time decreases.
  3401. .. note::
  3402. If :term:`DISTRO` settings change or fundamental configuration settings
  3403. such as the filesystem layout, you need to work with a clean ``TMPDIR``.
  3404. Sharing ``TMPDIR`` under these circumstances might work but since it is
  3405. not guaranteed, you should use a clean ``TMPDIR``.
  3406. - *Enable the Appropriate Package Architecture:* By default, the
  3407. OpenEmbedded build system enables three levels of package
  3408. architectures: "all", "tune" or "package", and "machine". Any given
  3409. recipe usually selects one of these package architectures (types) for
  3410. its output. Depending for what a given recipe creates packages,
  3411. making sure you enable the appropriate package architecture can
  3412. directly impact the build time.
  3413. A recipe that just generates scripts can enable "all" architecture
  3414. because there are no binaries to build. To specifically enable "all"
  3415. architecture, be sure your recipe inherits the
  3416. :ref:`allarch <ref-classes-allarch>` class.
  3417. This class is useful for "all" architectures because it configures
  3418. many variables so packages can be used across multiple architectures.
  3419. If your recipe needs to generate packages that are machine-specific
  3420. or when one of the build or runtime dependencies is already
  3421. machine-architecture dependent, which makes your recipe also
  3422. machine-architecture dependent, make sure your recipe enables the
  3423. "machine" package architecture through the
  3424. :term:`MACHINE_ARCH`
  3425. variable:
  3426. ::
  3427. PACKAGE_ARCH = "${MACHINE_ARCH}"
  3428. When you do not
  3429. specifically enable a package architecture through the
  3430. :term:`PACKAGE_ARCH`, The
  3431. OpenEmbedded build system defaults to the
  3432. :term:`TUNE_PKGARCH` setting:
  3433. ::
  3434. PACKAGE_ARCH = "${TUNE_PKGARCH}"
  3435. - *Choose a Generic Tuning File if Possible:* Some tunes are more
  3436. generic and can run on multiple targets (e.g. an ``armv5`` set of
  3437. packages could run on ``armv6`` and ``armv7`` processors in most
  3438. cases). Similarly, ``i486`` binaries could work on ``i586`` and
  3439. higher processors. You should realize, however, that advances on
  3440. newer processor versions would not be used.
  3441. If you select the same tune for several different machines, the
  3442. OpenEmbedded build system reuses software previously built, thus
  3443. speeding up the overall build time. Realize that even though a new
  3444. sysroot for each machine is generated, the software is not recompiled
  3445. and only one package feed exists.
  3446. - *Manage Granular Level Packaging:* Sometimes cases exist where
  3447. injecting another level of package architecture beyond the three
  3448. higher levels noted earlier can be useful. For example, consider how
  3449. NXP (formerly Freescale) allows for the easy reuse of binary packages
  3450. in their layer
  3451. :yocto_git:`meta-freescale </cgit/cgit.cgi/meta-freescale/>`.
  3452. In this example, the
  3453. :yocto_git:`fsl-dynamic-packagearch </cgit/cgit.cgi/meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass>`
  3454. class shares GPU packages for i.MX53 boards because all boards share
  3455. the AMD GPU. The i.MX6-based boards can do the same because all
  3456. boards share the Vivante GPU. This class inspects the BitBake
  3457. datastore to identify if the package provides or depends on one of
  3458. the sub-architecture values. If so, the class sets the
  3459. :term:`PACKAGE_ARCH` value
  3460. based on the ``MACHINE_SUBARCH`` value. If the package does not
  3461. provide or depend on one of the sub-architecture values but it
  3462. matches a value in the machine-specific filter, it sets
  3463. :term:`MACHINE_ARCH`. This
  3464. behavior reduces the number of packages built and saves build time by
  3465. reusing binaries.
  3466. - *Use Tools to Debug Issues:* Sometimes you can run into situations
  3467. where software is being rebuilt when you think it should not be. For
  3468. example, the OpenEmbedded build system might not be using shared
  3469. state between machines when you think it should be. These types of
  3470. situations are usually due to references to machine-specific
  3471. variables such as :term:`MACHINE`,
  3472. :term:`SERIAL_CONSOLES`,
  3473. :term:`XSERVER`,
  3474. :term:`MACHINE_FEATURES`,
  3475. and so forth in code that is supposed to only be tune-specific or
  3476. when the recipe depends
  3477. (:term:`DEPENDS`,
  3478. :term:`RDEPENDS`,
  3479. :term:`RRECOMMENDS`,
  3480. :term:`RSUGGESTS`, and so forth)
  3481. on some other recipe that already has
  3482. :term:`PACKAGE_ARCH` defined
  3483. as "${MACHINE_ARCH}".
  3484. .. note::
  3485. Patches to fix any issues identified are most welcome as these
  3486. issues occasionally do occur.
  3487. For such cases, you can use some tools to help you sort out the
  3488. situation:
  3489. - ``state-diff-machines.sh``*:* You can find this tool in the
  3490. ``scripts`` directory of the Source Repositories. See the comments
  3491. in the script for information on how to use the tool.
  3492. - *BitBake's "-S printdiff" Option:* Using this option causes
  3493. BitBake to try to establish the closest signature match it can
  3494. (e.g. in the shared state cache) and then run ``bitbake-diffsigs``
  3495. over the matches to determine the stamps and delta where these two
  3496. stamp trees diverge.
  3497. Building Software from an External Source
  3498. -----------------------------------------
  3499. By default, the OpenEmbedded build system uses the
  3500. :term:`Build Directory` when building source
  3501. code. The build process involves fetching the source files, unpacking
  3502. them, and then patching them if necessary before the build takes place.
  3503. Situations exist where you might want to build software from source
  3504. files that are external to and thus outside of the OpenEmbedded build
  3505. system. For example, suppose you have a project that includes a new BSP
  3506. with a heavily customized kernel. And, you want to minimize exposing the
  3507. build system to the development team so that they can focus on their
  3508. project and maintain everyone's workflow as much as possible. In this
  3509. case, you want a kernel source directory on the development machine
  3510. where the development occurs. You want the recipe's
  3511. :term:`SRC_URI` variable to point to
  3512. the external directory and use it as is, not copy it.
  3513. To build from software that comes from an external source, all you need
  3514. to do is inherit the
  3515. :ref:`externalsrc <ref-classes-externalsrc>` class
  3516. and then set the
  3517. :term:`EXTERNALSRC` variable to
  3518. point to your external source code. Here are the statements to put in
  3519. your ``local.conf`` file:
  3520. ::
  3521. INHERIT += "externalsrc"
  3522. EXTERNALSRC_pn-myrecipe = "path-to-your-source-tree"
  3523. This next example shows how to accomplish the same thing by setting
  3524. ``EXTERNALSRC`` in the recipe itself or in the recipe's append file:
  3525. ::
  3526. EXTERNALSRC = "path"
  3527. EXTERNALSRC_BUILD = "path"
  3528. .. note::
  3529. In order for these settings to take effect, you must globally or
  3530. locally inherit the :ref:`externalsrc <ref-classes-externalsrc>`
  3531. class.
  3532. By default, ``externalsrc.bbclass`` builds the source code in a
  3533. directory separate from the external source directory as specified by
  3534. :term:`EXTERNALSRC`. If you need
  3535. to have the source built in the same directory in which it resides, or
  3536. some other nominated directory, you can set
  3537. :term:`EXTERNALSRC_BUILD`
  3538. to point to that directory:
  3539. ::
  3540. EXTERNALSRC_BUILD_pn-myrecipe = "path-to-your-source-tree"
  3541. Replicating a Build Offline
  3542. ---------------------------
  3543. It can be useful to take a "snapshot" of upstream sources used in a
  3544. build and then use that "snapshot" later to replicate the build offline.
  3545. To do so, you need to first prepare and populate your downloads
  3546. directory your "snapshot" of files. Once your downloads directory is
  3547. ready, you can use it at any time and from any machine to replicate your
  3548. build.
  3549. Follow these steps to populate your Downloads directory:
  3550. 1. *Create a Clean Downloads Directory:* Start with an empty downloads
  3551. directory (:term:`DL_DIR`). You
  3552. start with an empty downloads directory by either removing the files
  3553. in the existing directory or by setting ``DL_DIR`` to point to either
  3554. an empty location or one that does not yet exist.
  3555. 2. *Generate Tarballs of the Source Git Repositories:* Edit your
  3556. ``local.conf`` configuration file as follows:
  3557. ::
  3558. DL_DIR = "/home/your-download-dir/"
  3559. BB_GENERATE_MIRROR_TARBALLS = "1"
  3560. During
  3561. the fetch process in the next step, BitBake gathers the source files
  3562. and creates tarballs in the directory pointed to by ``DL_DIR``. See
  3563. the
  3564. :term:`BB_GENERATE_MIRROR_TARBALLS`
  3565. variable for more information.
  3566. 3. *Populate Your Downloads Directory Without Building:* Use BitBake to
  3567. fetch your sources but inhibit the build:
  3568. ::
  3569. $ bitbake target --runonly=fetch
  3570. The downloads directory (i.e. ``${DL_DIR}``) now has
  3571. a "snapshot" of the source files in the form of tarballs, which can
  3572. be used for the build.
  3573. 4. *Optionally Remove Any Git or other SCM Subdirectories From the
  3574. Downloads Directory:* If you want, you can clean up your downloads
  3575. directory by removing any Git or other Source Control Management
  3576. (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs
  3577. already contain these subdirectories.
  3578. Once your downloads directory has everything it needs regarding source
  3579. files, you can create your "own-mirror" and build your target.
  3580. Understand that you can use the files to build the target offline from
  3581. any machine and at any time.
  3582. Follow these steps to build your target using the files in the downloads
  3583. directory:
  3584. 1. *Using Local Files Only:* Inside your ``local.conf`` file, add the
  3585. :term:`SOURCE_MIRROR_URL`
  3586. variable, inherit the
  3587. :ref:`own-mirrors <ref-classes-own-mirrors>`
  3588. class, and use the
  3589. :term:`bitbake:BB_NO_NETWORK`
  3590. variable to your ``local.conf``.
  3591. ::
  3592. SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/"
  3593. INHERIT += "own-mirrors"
  3594. BB_NO_NETWORK = "1"
  3595. The ``SOURCE_MIRROR_URL`` and ``own-mirror``
  3596. class set up the system to use the downloads directory as your "own
  3597. mirror". Using the ``BB_NO_NETWORK`` variable makes sure that
  3598. BitBake's fetching process in step 3 stays local, which means files
  3599. from your "own-mirror" are used.
  3600. 2. *Start With a Clean Build:* You can start with a clean build by
  3601. removing the
  3602. ``${``\ :term:`TMPDIR`\ ``}``
  3603. directory or using a new :term:`Build Directory`.
  3604. 3. *Build Your Target:* Use BitBake to build your target:
  3605. ::
  3606. $ bitbake target
  3607. The build completes using the known local "snapshot" of source
  3608. files from your mirror. The resulting tarballs for your "snapshot" of
  3609. source files are in the downloads directory.
  3610. .. note::
  3611. The offline build does not work if recipes attempt to find the
  3612. latest version of software by setting
  3613. :term:`SRCREV` to
  3614. ``${``\ :term:`AUTOREV`\ ``}``:
  3615. ::
  3616. SRCREV = "${AUTOREV}"
  3617. When a recipe sets ``SRCREV`` to
  3618. ``${AUTOREV}``, the build system accesses the network in an
  3619. attempt to determine the latest version of software from the SCM.
  3620. Typically, recipes that use ``AUTOREV`` are custom or modified
  3621. recipes. Recipes that reside in public repositories usually do not
  3622. use ``AUTOREV``.
  3623. If you do have recipes that use ``AUTOREV``, you can take steps to
  3624. still use the recipes in an offline build. Do the following:
  3625. 1. Use a configuration generated by enabling `build
  3626. history <#maintaining-build-output-quality>`__.
  3627. 2. Use the ``buildhistory-collect-srcrevs`` command to collect the
  3628. stored ``SRCREV`` values from the build's history. For more
  3629. information on collecting these values, see the "`Build History
  3630. Package Information <#build-history-package-information>`__"
  3631. section.
  3632. 3. Once you have the correct source revisions, you can modify
  3633. those recipes to to set ``SRCREV`` to specific versions of the
  3634. software.
  3635. Speeding Up a Build
  3636. ===================
  3637. Build time can be an issue. By default, the build system uses simple
  3638. controls to try and maximize build efficiency. In general, the default
  3639. settings for all the following variables result in the most efficient
  3640. build times when dealing with single socket systems (i.e. a single CPU).
  3641. If you have multiple CPUs, you might try increasing the default values
  3642. to gain more speed. See the descriptions in the glossary for each
  3643. variable for more information:
  3644. - :term:`BB_NUMBER_THREADS`:
  3645. The maximum number of threads BitBake simultaneously executes.
  3646. - :term:`bitbake:BB_NUMBER_PARSE_THREADS`:
  3647. The number of threads BitBake uses during parsing.
  3648. - :term:`PARALLEL_MAKE`: Extra
  3649. options passed to the ``make`` command during the
  3650. :ref:`ref-tasks-compile` task in
  3651. order to specify parallel compilation on the local build host.
  3652. - :term:`PARALLEL_MAKEINST`:
  3653. Extra options passed to the ``make`` command during the
  3654. :ref:`ref-tasks-install` task in
  3655. order to specify parallel installation on the local build host.
  3656. As mentioned, these variables all scale to the number of processor cores
  3657. available on the build system. For single socket systems, this
  3658. auto-scaling ensures that the build system fundamentally takes advantage
  3659. of potential parallel operations during the build based on the build
  3660. machine's capabilities.
  3661. Following are additional factors that can affect build speed:
  3662. - File system type: The file system type that the build is being
  3663. performed on can also influence performance. Using ``ext4`` is
  3664. recommended as compared to ``ext2`` and ``ext3`` due to ``ext4``
  3665. improved features such as extents.
  3666. - Disabling the updating of access time using ``noatime``: The
  3667. ``noatime`` mount option prevents the build system from updating file
  3668. and directory access times.
  3669. - Setting a longer commit: Using the "commit=" mount option increases
  3670. the interval in seconds between disk cache writes. Changing this
  3671. interval from the five second default to something longer increases
  3672. the risk of data loss but decreases the need to write to the disk,
  3673. thus increasing the build performance.
  3674. - Choosing the packaging backend: Of the available packaging backends,
  3675. IPK is the fastest. Additionally, selecting a singular packaging
  3676. backend also helps.
  3677. - Using ``tmpfs`` for :term:`TMPDIR`
  3678. as a temporary file system: While this can help speed up the build,
  3679. the benefits are limited due to the compiler using ``-pipe``. The
  3680. build system goes to some lengths to avoid ``sync()`` calls into the
  3681. file system on the principle that if there was a significant failure,
  3682. the :term:`Build Directory`
  3683. contents could easily be rebuilt.
  3684. - Inheriting the
  3685. :ref:`rm_work <ref-classes-rm-work>` class:
  3686. Inheriting this class has shown to speed up builds due to
  3687. significantly lower amounts of data stored in the data cache as well
  3688. as on disk. Inheriting this class also makes cleanup of
  3689. :term:`TMPDIR` faster, at the
  3690. expense of being easily able to dive into the source code. File
  3691. system maintainers have recommended that the fastest way to clean up
  3692. large numbers of files is to reformat partitions rather than delete
  3693. files due to the linear nature of partitions. This, of course,
  3694. assumes you structure the disk partitions and file systems in a way
  3695. that this is practical.
  3696. Aside from the previous list, you should keep some trade offs in mind
  3697. that can help you speed up the build:
  3698. - Remove items from
  3699. :term:`DISTRO_FEATURES`
  3700. that you might not need.
  3701. - Exclude debug symbols and other debug information: If you do not need
  3702. these symbols and other debug information, disabling the ``*-dbg``
  3703. package generation can speed up the build. You can disable this
  3704. generation by setting the
  3705. :term:`INHIBIT_PACKAGE_DEBUG_SPLIT`
  3706. variable to "1".
  3707. - Disable static library generation for recipes derived from
  3708. ``autoconf`` or ``libtool``: Following is an example showing how to
  3709. disable static libraries and still provide an override to handle
  3710. exceptions:
  3711. ::
  3712. STATICLIBCONF = "--disable-static"
  3713. STATICLIBCONF_sqlite3-native = ""
  3714. EXTRA_OECONF += "${STATICLIBCONF}"
  3715. .. note::
  3716. - Some recipes need static libraries in order to work correctly
  3717. (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides,
  3718. as in the previous example, account for these kinds of
  3719. exceptions.
  3720. - Some packages have packaging code that assumes the presence of
  3721. the static libraries. If so, you might need to exclude them as
  3722. well.
  3723. .. _platdev-working-with-libraries:
  3724. Working With Libraries
  3725. ======================
  3726. Libraries are an integral part of your system. This section describes
  3727. some common practices you might find helpful when working with libraries
  3728. to build your system:
  3729. - `How to include static library
  3730. files <#including-static-library-files>`__
  3731. - `How to use the Multilib feature to combine multiple versions of
  3732. library files into a single
  3733. image <#combining-multiple-versions-library-files-into-one-image>`__
  3734. - `How to install multiple versions of the same library in parallel on
  3735. the same
  3736. system <#installing-multiple-versions-of-the-same-library>`__
  3737. Including Static Library Files
  3738. ------------------------------
  3739. If you are building a library and the library offers static linking, you
  3740. can control which static library files (``*.a`` files) get included in
  3741. the built library.
  3742. The :term:`PACKAGES` and
  3743. :term:`FILES_* <FILES>` variables in the
  3744. ``meta/conf/bitbake.conf`` configuration file define how files installed
  3745. by the ``do_install`` task are packaged. By default, the ``PACKAGES``
  3746. variable includes ``${PN}-staticdev``, which represents all static
  3747. library files.
  3748. .. note::
  3749. Some previously released versions of the Yocto Project defined the
  3750. static library files through ``${PN}-dev``.
  3751. Following is part of the BitBake configuration file, where you can see
  3752. how the static library files are defined:
  3753. ::
  3754. PACKAGE_BEFORE_PN ?= ""
  3755. PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
  3756. PACKAGES_DYNAMIC = "^${PN}-locale-.*"
  3757. FILES = ""
  3758. FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
  3759. ${sysconfdir} ${sharedstatedir} ${localstatedir} \
  3760. ${base_bindir}/* ${base_sbindir}/* \
  3761. ${base_libdir}/*${SOLIBS} \
  3762. ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
  3763. ${datadir}/${BPN} ${libdir}/${BPN}/* \
  3764. ${datadir}/pixmaps ${datadir}/applications \
  3765. ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
  3766. ${libdir}/bonobo/servers"
  3767. FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
  3768. FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
  3769. ${datadir}/gnome/help"
  3770. SECTION_${PN}-doc = "doc"
  3771. FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
  3772. FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
  3773. ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
  3774. ${datadir}/aclocal ${base_libdir}/*.o \
  3775. ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
  3776. SECTION_${PN}-dev = "devel"
  3777. ALLOW_EMPTY_${PN}-dev = "1"
  3778. RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
  3779. FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
  3780. SECTION_${PN}-staticdev = "devel"
  3781. RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
  3782. .. _combining-multiple-versions-library-files-into-one-image:
  3783. Combining Multiple Versions of Library Files into One Image
  3784. -----------------------------------------------------------
  3785. The build system offers the ability to build libraries with different
  3786. target optimizations or architecture formats and combine these together
  3787. into one system image. You can link different binaries in the image
  3788. against the different libraries as needed for specific use cases. This
  3789. feature is called "Multilib".
  3790. An example would be where you have most of a system compiled in 32-bit
  3791. mode using 32-bit libraries, but you have something large, like a
  3792. database engine, that needs to be a 64-bit application and uses 64-bit
  3793. libraries. Multilib allows you to get the best of both 32-bit and 64-bit
  3794. libraries.
  3795. While the Multilib feature is most commonly used for 32 and 64-bit
  3796. differences, the approach the build system uses facilitates different
  3797. target optimizations. You could compile some binaries to use one set of
  3798. libraries and other binaries to use a different set of libraries. The
  3799. libraries could differ in architecture, compiler options, or other
  3800. optimizations.
  3801. Several examples exist in the ``meta-skeleton`` layer found in the
  3802. :term:`Source Directory`:
  3803. - ``conf/multilib-example.conf`` configuration file
  3804. - ``conf/multilib-example2.conf`` configuration file
  3805. - ``recipes-multilib/images/core-image-multilib-example.bb`` recipe
  3806. Preparing to Use Multilib
  3807. ~~~~~~~~~~~~~~~~~~~~~~~~~
  3808. User-specific requirements drive the Multilib feature. Consequently,
  3809. there is no one "out-of-the-box" configuration that likely exists to
  3810. meet your needs.
  3811. In order to enable Multilib, you first need to ensure your recipe is
  3812. extended to support multiple libraries. Many standard recipes are
  3813. already extended and support multiple libraries. You can check in the
  3814. ``meta/conf/multilib.conf`` configuration file in the
  3815. :term:`Source Directory` to see how this is
  3816. done using the
  3817. :term:`BBCLASSEXTEND` variable.
  3818. Eventually, all recipes will be covered and this list will not be
  3819. needed.
  3820. For the most part, the Multilib class extension works automatically to
  3821. extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where
  3822. ``MLPREFIX`` is the particular multilib (e.g. "lib32-" or "lib64-").
  3823. Standard variables such as
  3824. :term:`DEPENDS`,
  3825. :term:`RDEPENDS`,
  3826. :term:`RPROVIDES`,
  3827. :term:`RRECOMMENDS`,
  3828. :term:`PACKAGES`, and
  3829. :term:`PACKAGES_DYNAMIC` are
  3830. automatically extended by the system. If you are extending any manual
  3831. code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure
  3832. those names are extended correctly. This automatic extension code
  3833. resides in ``multilib.bbclass``.
  3834. Using Multilib
  3835. ~~~~~~~~~~~~~~
  3836. After you have set up the recipes, you need to define the actual
  3837. combination of multiple libraries you want to build. You accomplish this
  3838. through your ``local.conf`` configuration file in the
  3839. :term:`Build Directory`. An example
  3840. configuration would be as follows:
  3841. ::
  3842. MACHINE = "qemux86-64"
  3843. require conf/multilib.conf
  3844. MULTILIBS = "multilib:lib32"
  3845. DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
  3846. IMAGE_INSTALL_append = " lib32-glib-2.0"
  3847. This example enables an additional library named
  3848. ``lib32`` alongside the normal target packages. When combining these
  3849. "lib32" alternatives, the example uses "x86" for tuning. For information
  3850. on this particular tuning, see
  3851. ``meta/conf/machine/include/ia32/arch-ia32.inc``.
  3852. The example then includes ``lib32-glib-2.0`` in all the images, which
  3853. illustrates one method of including a multiple library dependency. You
  3854. can use a normal image build to include this dependency, for example:
  3855. ::
  3856. $ bitbake core-image-sato
  3857. You can also build Multilib packages
  3858. specifically with a command like this:
  3859. ::
  3860. $ bitbake lib32-glib-2.0
  3861. Additional Implementation Details
  3862. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3863. Generic implementation details as well as details that are specific to
  3864. package management systems exist. Following are implementation details
  3865. that exist regardless of the package management system:
  3866. - The typical convention used for the class extension code as used by
  3867. Multilib assumes that all package names specified in
  3868. :term:`PACKAGES` that contain
  3869. ``${PN}`` have ``${PN}`` at the start of the name. When that
  3870. convention is not followed and ``${PN}`` appears at the middle or the
  3871. end of a name, problems occur.
  3872. - The :term:`TARGET_VENDOR`
  3873. value under Multilib will be extended to "-vendormlmultilib" (e.g.
  3874. "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this
  3875. slightly unwieldy contraction is that any "-" characters in the
  3876. vendor string presently break Autoconf's ``config.sub``, and other
  3877. separators are problematic for different reasons.
  3878. For the RPM Package Management System, the following implementation
  3879. details exist:
  3880. - A unique architecture is defined for the Multilib packages, along
  3881. with creating a unique deploy folder under ``tmp/deploy/rpm`` in the
  3882. :term:`Build Directory`. For
  3883. example, consider ``lib32`` in a ``qemux86-64`` image. The possible
  3884. architectures in the system are "all", "qemux86_64",
  3885. "lib32_qemux86_64", and "lib32_x86".
  3886. - The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM
  3887. packaging. The naming for a normal RPM package and a Multilib RPM
  3888. package in a ``qemux86-64`` system resolves to something similar to
  3889. ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``,
  3890. respectively.
  3891. - When installing a Multilib image, the RPM backend first installs the
  3892. base image and then installs the Multilib libraries.
  3893. - The build system relies on RPM to resolve the identical files in the
  3894. two (or more) Multilib packages.
  3895. For the IPK Package Management System, the following implementation
  3896. details exist:
  3897. - The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK
  3898. packaging. The naming for a normal RPM package and a Multilib IPK
  3899. package in a ``qemux86-64`` system resolves to something like
  3900. ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw_x86.ipk``,
  3901. respectively.
  3902. - The IPK deploy folder is not modified with ``${MLPREFIX}`` because
  3903. packages with and without the Multilib feature can exist in the same
  3904. folder due to the ``${PN}`` differences.
  3905. - IPK defines a sanity check for Multilib installation using certain
  3906. rules for file comparison, overridden, etc.
  3907. Installing Multiple Versions of the Same Library
  3908. ------------------------------------------------
  3909. Situations can exist where you need to install and use multiple versions
  3910. of the same library on the same system at the same time. These
  3911. situations almost always exist when a library API changes and you have
  3912. multiple pieces of software that depend on the separate versions of the
  3913. library. To accommodate these situations, you can install multiple
  3914. versions of the same library in parallel on the same system.
  3915. The process is straightforward as long as the libraries use proper
  3916. versioning. With properly versioned libraries, all you need to do to
  3917. individually specify the libraries is create separate, appropriately
  3918. named recipes where the :term:`PN` part of
  3919. the name includes a portion that differentiates each library version
  3920. (e.g. the major part of the version number). Thus, instead of having a
  3921. single recipe that loads one version of a library (e.g. ``clutter``),
  3922. you provide multiple recipes that result in different versions of the
  3923. libraries you want. As an example, the following two recipes would allow
  3924. the two separate versions of the ``clutter`` library to co-exist on the
  3925. same system:
  3926. .. code-block:: none
  3927. clutter-1.6_1.6.20.bb
  3928. clutter-1.8_1.8.4.bb
  3929. Additionally, if
  3930. you have other recipes that depend on a given library, you need to use
  3931. the :term:`DEPENDS` variable to
  3932. create the dependency. Continuing with the same example, if you want to
  3933. have a recipe depend on the 1.8 version of the ``clutter`` library, use
  3934. the following in your recipe:
  3935. ::
  3936. DEPENDS = "clutter-1.8"
  3937. Using x32 psABI
  3938. ===============
  3939. x32 processor-specific Application Binary Interface (`x32
  3940. psABI <https://software.intel.com/en-us/node/628948>`__) is a native
  3941. 32-bit processor-specific ABI for Intel 64 (x86-64) architectures. An
  3942. ABI defines the calling conventions between functions in a processing
  3943. environment. The interface determines what registers are used and what
  3944. the sizes are for various C data types.
  3945. Some processing environments prefer using 32-bit applications even when
  3946. running on Intel 64-bit platforms. Consider the i386 psABI, which is a
  3947. very old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not
  3948. provide efficient use and access of the Intel 64-bit processor
  3949. resources, leaving the system underutilized. Now consider the x86_64
  3950. psABI. This ABI is newer and uses 64-bits for data sizes and program
  3951. pointers. The extra bits increase the footprint size of the programs,
  3952. libraries, and also increases the memory and file system size
  3953. requirements. Executing under the x32 psABI enables user programs to
  3954. utilize CPU and system resources more efficiently while keeping the
  3955. memory footprint of the applications low. Extra bits are used for
  3956. registers but not for addressing mechanisms.
  3957. The Yocto Project supports the final specifications of x32 psABI as
  3958. follows:
  3959. - You can create packages and images in x32 psABI format on x86_64
  3960. architecture targets.
  3961. - You can successfully build recipes with the x32 toolchain.
  3962. - You can create and boot ``core-image-minimal`` and
  3963. ``core-image-sato`` images.
  3964. - RPM Package Manager (RPM) support exists for x32 binaries.
  3965. - Support for large images exists.
  3966. To use the x32 psABI, you need to edit your ``conf/local.conf``
  3967. configuration file as follows:
  3968. ::
  3969. MACHINE = "qemux86-64"
  3970. DEFAULTTUNE = "x86-64-x32"
  3971. baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \
  3972. or 'INVALID')) or 'lib'}"
  3973. Once you have set
  3974. up your configuration file, use BitBake to build an image that supports
  3975. the x32 psABI. Here is an example:
  3976. ::
  3977. $ bitbake core-image-sato
  3978. Enabling GObject Introspection Support
  3979. ======================================
  3980. `GObject
  3981. introspection <https://wiki.gnome.org/Projects/GObjectIntrospection>`__
  3982. is the standard mechanism for accessing GObject-based software from
  3983. runtime environments. GObject is a feature of the GLib library that
  3984. provides an object framework for the GNOME desktop and related software.
  3985. GObject Introspection adds information to GObject that allows objects
  3986. created within it to be represented across different programming
  3987. languages. If you want to construct GStreamer pipelines using Python, or
  3988. control UPnP infrastructure using Javascript and GUPnP, GObject
  3989. introspection is the only way to do it.
  3990. This section describes the Yocto Project support for generating and
  3991. packaging GObject introspection data. GObject introspection data is a
  3992. description of the API provided by libraries built on top of GLib
  3993. framework, and, in particular, that framework's GObject mechanism.
  3994. GObject Introspection Repository (GIR) files go to ``-dev`` packages,
  3995. ``typelib`` files go to main packages as they are packaged together with
  3996. libraries that are introspected.
  3997. The data is generated when building such a library, by linking the
  3998. library with a small executable binary that asks the library to describe
  3999. itself, and then executing the binary and processing its output.
  4000. Generating this data in a cross-compilation environment is difficult
  4001. because the library is produced for the target architecture, but its
  4002. code needs to be executed on the build host. This problem is solved with
  4003. the OpenEmbedded build system by running the code through QEMU, which
  4004. allows precisely that. Unfortunately, QEMU does not always work
  4005. perfectly as mentioned in the "`Known Issues <#known-issues>`__"
  4006. section.
  4007. Enabling the Generation of Introspection Data
  4008. ---------------------------------------------
  4009. Enabling the generation of introspection data (GIR files) in your
  4010. library package involves the following:
  4011. 1. Inherit the
  4012. :ref:`gobject-introspection <ref-classes-gobject-introspection>`
  4013. class.
  4014. 2. Make sure introspection is not disabled anywhere in the recipe or
  4015. from anything the recipe includes. Also, make sure that
  4016. "gobject-introspection-data" is not in
  4017. :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
  4018. and that "qemu-usermode" is not in
  4019. :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
  4020. If either of these conditions exist, nothing will happen.
  4021. 3. Try to build the recipe. If you encounter build errors that look like
  4022. something is unable to find ``.so`` libraries, check where these
  4023. libraries are located in the source tree and add the following to the
  4024. recipe:
  4025. ::
  4026. GIR_EXTRA_LIBS_PATH = "${B}/something/.libs"
  4027. .. note::
  4028. See recipes in the ``oe-core`` repository that use that
  4029. ``GIR_EXTRA_LIBS_PATH`` variable as an example.
  4030. 4. Look for any other errors, which probably mean that introspection
  4031. support in a package is not entirely standard, and thus breaks down
  4032. in a cross-compilation environment. For such cases, custom-made fixes
  4033. are needed. A good place to ask and receive help in these cases is
  4034. the :ref:`Yocto Project mailing
  4035. lists <resources-mailinglist>`.
  4036. .. note::
  4037. Using a library that no longer builds against the latest Yocto
  4038. Project release and prints introspection related errors is a good
  4039. candidate for the previous procedure.
  4040. Disabling the Generation of Introspection Data
  4041. ----------------------------------------------
  4042. You might find that you do not want to generate introspection data. Or,
  4043. perhaps QEMU does not work on your build host and target architecture
  4044. combination. If so, you can use either of the following methods to
  4045. disable GIR file generations:
  4046. - Add the following to your distro configuration:
  4047. ::
  4048. DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
  4049. Adding this statement disables generating introspection data using
  4050. QEMU but will still enable building introspection tools and libraries
  4051. (i.e. building them does not require the use of QEMU).
  4052. - Add the following to your machine configuration:
  4053. ::
  4054. MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
  4055. Adding this statement disables the use of QEMU when building packages for your
  4056. machine. Currently, this feature is used only by introspection
  4057. recipes and has the same effect as the previously described option.
  4058. .. note::
  4059. Future releases of the Yocto Project might have other features
  4060. affected by this option.
  4061. If you disable introspection data, you can still obtain it through other
  4062. means such as copying the data from a suitable sysroot, or by generating
  4063. it on the target hardware. The OpenEmbedded build system does not
  4064. currently provide specific support for these techniques.
  4065. Testing that Introspection Works in an Image
  4066. --------------------------------------------
  4067. Use the following procedure to test if generating introspection data is
  4068. working in an image:
  4069. 1. Make sure that "gobject-introspection-data" is not in
  4070. :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
  4071. and that "qemu-usermode" is not in
  4072. :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
  4073. 2. Build ``core-image-sato``.
  4074. 3. Launch a Terminal and then start Python in the terminal.
  4075. 4. Enter the following in the terminal:
  4076. ::
  4077. >>> from gi.repository import GLib
  4078. >>> GLib.get_host_name()
  4079. 5. For something a little more advanced, enter the following see:
  4080. https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html
  4081. Known Issues
  4082. ------------
  4083. The following know issues exist for GObject Introspection Support:
  4084. - ``qemu-ppc64`` immediately crashes. Consequently, you cannot build
  4085. introspection data on that architecture.
  4086. - x32 is not supported by QEMU. Consequently, introspection data is
  4087. disabled.
  4088. - musl causes transient GLib binaries to crash on assertion failures.
  4089. Consequently, generating introspection data is disabled.
  4090. - Because QEMU is not able to run the binaries correctly, introspection
  4091. is disabled for some specific packages under specific architectures
  4092. (e.g. ``gcr``, ``libsecret``, and ``webkit``).
  4093. - QEMU usermode might not work properly when running 64-bit binaries
  4094. under 32-bit host machines. In particular, "qemumips64" is known to
  4095. not work under i686.
  4096. .. _dev-optionally-using-an-external-toolchain:
  4097. Optionally Using an External Toolchain
  4098. ======================================
  4099. You might want to use an external toolchain as part of your development.
  4100. If this is the case, the fundamental steps you need to accomplish are as
  4101. follows:
  4102. - Understand where the installed toolchain resides. For cases where you
  4103. need to build the external toolchain, you would need to take separate
  4104. steps to build and install the toolchain.
  4105. - Make sure you add the layer that contains the toolchain to your
  4106. ``bblayers.conf`` file through the
  4107. :term:`BBLAYERS` variable.
  4108. - Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file
  4109. to the location in which you installed the toolchain.
  4110. A good example of an external toolchain used with the Yocto Project is
  4111. Mentor Graphics Sourcery G++ Toolchain. You can see information on how
  4112. to use that particular layer in the ``README`` file at
  4113. https://github.com/MentorEmbedded/meta-sourcery/. You can find
  4114. further information by reading about the
  4115. :term:`TCMODE` variable in the Yocto
  4116. Project Reference Manual's variable glossary.
  4117. Creating Partitioned Images Using Wic
  4118. =====================================
  4119. Creating an image for a particular hardware target using the
  4120. OpenEmbedded build system does not necessarily mean you can boot that
  4121. image as is on your device. Physical devices accept and boot images in
  4122. various ways depending on the specifics of the device. Usually,
  4123. information about the hardware can tell you what image format the device
  4124. requires. Should your device require multiple partitions on an SD card,
  4125. flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to
  4126. create the properly partitioned image.
  4127. The ``wic`` command generates partitioned images from existing
  4128. OpenEmbedded build artifacts. Image generation is driven by partitioning
  4129. commands contained in an Openembedded kickstart file (``.wks``)
  4130. specified either directly on the command line or as one of a selection
  4131. of canned kickstart files as shown with the ``wic list images`` command
  4132. in the "`Using an Existing Kickstart
  4133. File <#using-a-provided-kickstart-file>`__" section. When you apply the
  4134. command to a given set of build artifacts, the result is an image or set
  4135. of images that can be directly written onto media and used on a
  4136. particular system.
  4137. .. note::
  4138. For a kickstart file reference, see the
  4139. ":ref:`ref-manual/ref-kickstart:openembedded kickstart (\`\`.wks\`\`) reference`"
  4140. Chapter in the Yocto Project Reference Manual.
  4141. The ``wic`` command and the infrastructure it is based on is by
  4142. definition incomplete. The purpose of the command is to allow the
  4143. generation of customized images, and as such, was designed to be
  4144. completely extensible through a plugin interface. See the "`Using the
  4145. Wic PlugIn Interface <#wic-using-the-wic-plugin-interface>`__" section
  4146. for information on these plugins.
  4147. This section provides some background information on Wic, describes what
  4148. you need to have in place to run the tool, provides instruction on how
  4149. to use the Wic utility, provides information on using the Wic plugins
  4150. interface, and provides several examples that show how to use Wic.
  4151. .. _wic-background:
  4152. Background
  4153. ----------
  4154. This section provides some background on the Wic utility. While none of
  4155. this information is required to use Wic, you might find it interesting.
  4156. - The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The
  4157. "oe" diphthong in "oeic" was promoted to the letter "w", because
  4158. "oeic" is both difficult to remember and to pronounce.
  4159. - Wic is loosely based on the Meego Image Creator (``mic``) framework.
  4160. The Wic implementation has been heavily modified to make direct use
  4161. of OpenEmbedded build artifacts instead of package installation and
  4162. configuration, which are already incorporated within the OpenEmbedded
  4163. artifacts.
  4164. - Wic is a completely independent standalone utility that initially
  4165. provides easier-to-use and more flexible replacements for an existing
  4166. functionality in OE-Core's
  4167. :ref:`image-live <ref-classes-image-live>`
  4168. class. The difference between Wic and those examples is that with Wic
  4169. the functionality of those scripts is implemented by a
  4170. general-purpose partitioning language, which is based on Redhat
  4171. kickstart syntax.
  4172. .. _wic-requirements:
  4173. Requirements
  4174. ------------
  4175. In order to use the Wic utility with the OpenEmbedded Build system, your
  4176. system needs to meet the following requirements:
  4177. - The Linux distribution on your development host must support the
  4178. Yocto Project. See the ":ref:`detailed-supported-distros`"
  4179. section in the Yocto Project Reference Manual for the list of
  4180. distributions that support the Yocto Project.
  4181. - The standard system utilities, such as ``cp``, must be installed on
  4182. your development host system.
  4183. - You must have sourced the build environment setup script (i.e.
  4184. :ref:`structure-core-script`) found in the
  4185. :term:`Build Directory`.
  4186. - You need to have the build artifacts already available, which
  4187. typically means that you must have already created an image using the
  4188. Openembedded build system (e.g. ``core-image-minimal``). While it
  4189. might seem redundant to generate an image in order to create an image
  4190. using Wic, the current version of Wic requires the artifacts in the
  4191. form generated by the OpenEmbedded build system.
  4192. - You must build several native tools, which are built to run on the
  4193. build system:
  4194. ::
  4195. $ bitbake parted-native dosfstools-native mtools-native
  4196. - Include "wic" as part of the
  4197. :term:`IMAGE_FSTYPES`
  4198. variable.
  4199. - Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>`
  4200. as part of the :term:`WKS_FILE` variable
  4201. .. _wic-getting-help:
  4202. Getting Help
  4203. ------------
  4204. You can get general help for the ``wic`` command by entering the ``wic``
  4205. command by itself or by entering the command with a help argument as
  4206. follows:
  4207. ::
  4208. $ wic -h
  4209. $ wic --help
  4210. $ wic help
  4211. Currently, Wic supports seven commands: ``cp``, ``create``, ``help``,
  4212. ``list``, ``ls``, ``rm``, and ``write``. You can get help for all these
  4213. commands except "help" by using the following form:
  4214. ::
  4215. $ wic help command
  4216. For example, the following command returns help for the ``write``
  4217. command:
  4218. ::
  4219. $ wic help write
  4220. Wic supports help for three topics: ``overview``, ``plugins``, and
  4221. ``kickstart``. You can get help for any topic using the following form:
  4222. ::
  4223. $ wic help topic
  4224. For example, the following returns overview help for Wic:
  4225. ::
  4226. $ wic help overview
  4227. One additional level of help exists for Wic. You can get help on
  4228. individual images through the ``list`` command. You can use the ``list``
  4229. command to return the available Wic images as follows:
  4230. ::
  4231. $ wic list images
  4232. genericx86 Create an EFI disk image for genericx86*
  4233. beaglebone-yocto Create SD card image for Beaglebone
  4234. edgerouter Create SD card image for Edgerouter
  4235. qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
  4236. directdisk-gpt Create a 'pcbios' direct disk image
  4237. mkefidisk Create an EFI disk image
  4238. directdisk Create a 'pcbios' direct disk image
  4239. systemd-bootdisk Create an EFI disk image with systemd-boot
  4240. mkhybridiso Create a hybrid ISO image
  4241. sdimage-bootpart Create SD card image with a boot partition
  4242. directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
  4243. directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
  4244. Once you know the list of available
  4245. Wic images, you can use ``help`` with the command to get help on a
  4246. particular image. For example, the following command returns help on the
  4247. "beaglebone-yocto" image:
  4248. ::
  4249. $ wic list beaglebone-yocto help
  4250. Creates a partitioned SD card image for Beaglebone.
  4251. Boot files are located in the first vfat partition.
  4252. Operational Modes
  4253. -----------------
  4254. You can use Wic in two different modes, depending on how much control
  4255. you need for specifying the Openembedded build artifacts that are used
  4256. for creating the image: Raw and Cooked:
  4257. - *Raw Mode:* You explicitly specify build artifacts through Wic
  4258. command-line arguments.
  4259. - *Cooked Mode:* The current
  4260. :term:`MACHINE` setting and image
  4261. name are used to automatically locate and provide the build
  4262. artifacts. You just supply a kickstart file and the name of the image
  4263. from which to use artifacts.
  4264. Regardless of the mode you use, you need to have the build artifacts
  4265. ready and available.
  4266. Raw Mode
  4267. ~~~~~~~~
  4268. Running Wic in raw mode allows you to specify all the partitions through
  4269. the ``wic`` command line. The primary use for raw mode is if you have
  4270. built your kernel outside of the Yocto Project
  4271. :term:`Build Directory`. In other words, you
  4272. can point to arbitrary kernel, root filesystem locations, and so forth.
  4273. Contrast this behavior with cooked mode where Wic looks in the Build
  4274. Directory (e.g. ``tmp/deploy/images/``\ machine).
  4275. The general form of the ``wic`` command in raw mode is:
  4276. ::
  4277. $ wic create wks_file options ...
  4278. Where:
  4279. wks_file:
  4280. An OpenEmbedded kickstart file. You can provide
  4281. your own custom file or use a file from a set of
  4282. existing files as described by further options.
  4283. optional arguments:
  4284. -h, --help show this help message and exit
  4285. -o OUTDIR, --outdir OUTDIR
  4286. name of directory to create image in
  4287. -e IMAGE_NAME, --image-name IMAGE_NAME
  4288. name of the image to use the artifacts from e.g. core-
  4289. image-sato
  4290. -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR
  4291. path to the /rootfs dir to use as the .wks rootfs
  4292. source
  4293. -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR
  4294. path to the dir containing the boot artifacts (e.g.
  4295. /EFI or /syslinux dirs) to use as the .wks bootimg
  4296. source
  4297. -k KERNEL_DIR, --kernel-dir KERNEL_DIR
  4298. path to the dir containing the kernel to use in the
  4299. .wks bootimg
  4300. -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT
  4301. path to the native sysroot containing the tools to use
  4302. to build the image
  4303. -s, --skip-build-check
  4304. skip the build check
  4305. -f, --build-rootfs build rootfs
  4306. -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
  4307. compress image with specified compressor
  4308. -m, --bmap generate .bmap
  4309. --no-fstab-update Do not change fstab file.
  4310. -v VARS_DIR, --vars VARS_DIR
  4311. directory with <image>.env files that store bitbake
  4312. variables
  4313. -D, --debug output debug information
  4314. .. note::
  4315. You do not need root privileges to run Wic. In fact, you should not
  4316. run as root when using the utility.
  4317. Cooked Mode
  4318. ~~~~~~~~~~~
  4319. Running Wic in cooked mode leverages off artifacts in the Build
  4320. Directory. In other words, you do not have to specify kernel or root
  4321. filesystem locations as part of the command. All you need to provide is
  4322. a kickstart file and the name of the image from which to use artifacts
  4323. by using the "-e" option. Wic looks in the Build Directory (e.g.
  4324. ``tmp/deploy/images/``\ machine) for artifacts.
  4325. The general form of the ``wic`` command using Cooked Mode is as follows:
  4326. ::
  4327. $ wic create wks_file -e IMAGE_NAME
  4328. Where:
  4329. wks_file:
  4330. An OpenEmbedded kickstart file. You can provide
  4331. your own custom file or use a file from a set of
  4332. existing files provided with the Yocto Project
  4333. release.
  4334. required argument:
  4335. -e IMAGE_NAME, --image-name IMAGE_NAME
  4336. name of the image to use the artifacts from e.g. core-
  4337. image-sato
  4338. .. _using-a-provided-kickstart-file:
  4339. Using an Existing Kickstart File
  4340. --------------------------------
  4341. If you do not want to create your own kickstart file, you can use an
  4342. existing file provided by the Wic installation. As shipped, kickstart
  4343. files can be found in the :ref:`overview-manual/overview-manual-development-environment:yocto project source repositories` in the
  4344. following two locations:
  4345. ::
  4346. poky/meta-yocto-bsp/wic
  4347. poky/scripts/lib/wic/canned-wks
  4348. Use the following command to list the available kickstart files:
  4349. ::
  4350. $ wic list images
  4351. genericx86 Create an EFI disk image for genericx86*
  4352. beaglebone-yocto Create SD card image for Beaglebone
  4353. edgerouter Create SD card image for Edgerouter
  4354. qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
  4355. directdisk-gpt Create a 'pcbios' direct disk image
  4356. mkefidisk Create an EFI disk image
  4357. directdisk Create a 'pcbios' direct disk image
  4358. systemd-bootdisk Create an EFI disk image with systemd-boot
  4359. mkhybridiso Create a hybrid ISO image
  4360. sdimage-bootpart Create SD card image with a boot partition
  4361. directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
  4362. directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
  4363. When you use an existing file, you
  4364. do not have to use the ``.wks`` extension. Here is an example in Raw
  4365. Mode that uses the ``directdisk`` file:
  4366. ::
  4367. $ wic create directdisk -r rootfs_dir -b bootimg_dir \
  4368. -k kernel_dir -n native_sysroot
  4369. Here are the actual partition language commands used in the
  4370. ``genericx86.wks`` file to generate an image:
  4371. ::
  4372. # short-description: Create an EFI disk image for genericx86*
  4373. # long-description: Creates a partitioned EFI disk image for genericx86* machines
  4374. part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
  4375. part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
  4376. part swap --ondisk sda --size 44 --label swap1 --fstype=swap
  4377. bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
  4378. .. _wic-using-the-wic-plugin-interface:
  4379. Using the Wic Plugin Interface
  4380. ------------------------------
  4381. You can extend and specialize Wic functionality by using Wic plugins.
  4382. This section explains the Wic plugin interface.
  4383. .. note::
  4384. Wic plugins consist of "source" and "imager" plugins. Imager plugins
  4385. are beyond the scope of this section.
  4386. Source plugins provide a mechanism to customize partition content during
  4387. the Wic image generation process. You can use source plugins to map
  4388. values that you specify using ``--source`` commands in kickstart files
  4389. (i.e. ``*.wks``) to a plugin implementation used to populate a given
  4390. partition.
  4391. .. note::
  4392. If you use plugins that have build-time dependencies (e.g. native
  4393. tools, bootloaders, and so forth) when building a Wic image, you need
  4394. to specify those dependencies using the :term:`WKS_FILE_DEPENDS`
  4395. variable.
  4396. Source plugins are subclasses defined in plugin files. As shipped, the
  4397. Yocto Project provides several plugin files. You can see the source
  4398. plugin files that ship with the Yocto Project
  4399. :yocto_git:`here </cgit/cgit.cgi/poky/tree/scripts/lib/wic/plugins/source>`.
  4400. Each of these plugin files contains source plugins that are designed to
  4401. populate a specific Wic image partition.
  4402. Source plugins are subclasses of the ``SourcePlugin`` class, which is
  4403. defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example,
  4404. the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py``
  4405. file is a subclass of the ``SourcePlugin`` class, which is found in the
  4406. ``pluginbase.py`` file.
  4407. You can also implement source plugins in a layer outside of the Source
  4408. Repositories (external layer). To do so, be sure that your plugin files
  4409. are located in a directory whose path is
  4410. ``scripts/lib/wic/plugins/source/`` within your external layer. When the
  4411. plugin files are located there, the source plugins they contain are made
  4412. available to Wic.
  4413. When the Wic implementation needs to invoke a partition-specific
  4414. implementation, it looks for the plugin with the same name as the
  4415. ``--source`` parameter used in the kickstart file given to that
  4416. partition. For example, if the partition is set up using the following
  4417. command in a kickstart file:
  4418. ::
  4419. part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
  4420. The methods defined as class
  4421. members of the matching source plugin (i.e. ``bootimg-pcbios``) in the
  4422. ``bootimg-pcbios.py`` plugin file are used.
  4423. To be more concrete, here is the corresponding plugin definition from
  4424. the ``bootimg-pcbios.py`` file for the previous command along with an
  4425. example method called by the Wic implementation when it needs to prepare
  4426. a partition using an implementation-specific function:
  4427. ::
  4428. .
  4429. .
  4430. .
  4431. class BootimgPcbiosPlugin(SourcePlugin):
  4432. """
  4433. Create MBR boot partition and install syslinux on it.
  4434. """
  4435. name = 'bootimg-pcbios'
  4436. .
  4437. .
  4438. .
  4439. @classmethod
  4440. def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
  4441. oe_builddir, bootimg_dir, kernel_dir,
  4442. rootfs_dir, native_sysroot):
  4443. """
  4444. Called to do the actual content population for a partition i.e. it
  4445. 'prepares' the partition to be incorporated into the image.
  4446. In this case, prepare content for legacy bios boot partition.
  4447. """
  4448. .
  4449. .
  4450. .
  4451. If a
  4452. subclass (plugin) itself does not implement a particular function, Wic
  4453. locates and uses the default version in the superclass. It is for this
  4454. reason that all source plugins are derived from the ``SourcePlugin``
  4455. class.
  4456. The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines
  4457. a set of methods that source plugins can implement or override. Any
  4458. plugins (subclass of ``SourcePlugin``) that do not implement a
  4459. particular method inherit the implementation of the method from the
  4460. ``SourcePlugin`` class. For more information, see the ``SourcePlugin``
  4461. class in the ``pluginbase.py`` file for details:
  4462. The following list describes the methods implemented in the
  4463. ``SourcePlugin`` class:
  4464. - ``do_prepare_partition()``: Called to populate a partition with
  4465. actual content. In other words, the method prepares the final
  4466. partition image that is incorporated into the disk image.
  4467. - ``do_configure_partition()``: Called before
  4468. ``do_prepare_partition()`` to create custom configuration files for a
  4469. partition (e.g. syslinux or grub configuration files).
  4470. - ``do_install_disk()``: Called after all partitions have been
  4471. prepared and assembled into a disk image. This method provides a hook
  4472. to allow finalization of a disk image (e.g. writing an MBR).
  4473. - ``do_stage_partition()``: Special content-staging hook called
  4474. before ``do_prepare_partition()``. This method is normally empty.
  4475. Typically, a partition just uses the passed-in parameters (e.g. the
  4476. unmodified value of ``bootimg_dir``). However, in some cases, things
  4477. might need to be more tailored. As an example, certain files might
  4478. additionally need to be taken from ``bootimg_dir + /boot``. This hook
  4479. allows those files to be staged in a customized fashion.
  4480. .. note::
  4481. ``get_bitbake_var()`` allows you to access non-standard variables that
  4482. you might want to use for this behavior.
  4483. You can extend the source plugin mechanism. To add more hooks, create
  4484. more source plugin methods within ``SourcePlugin`` and the corresponding
  4485. derived subclasses. The code that calls the plugin methods uses the
  4486. ``plugin.get_source_plugin_methods()`` function to find the method or
  4487. methods needed by the call. Retrieval of those methods is accomplished
  4488. by filling up a dict with keys that contain the method names of
  4489. interest. On success, these will be filled in with the actual methods.
  4490. See the Wic implementation for examples and details.
  4491. .. _wic-usage-examples:
  4492. Wic Examples
  4493. ------------
  4494. This section provides several examples that show how to use the Wic
  4495. utility. All the examples assume the list of requirements in the
  4496. "`Requirements <#wic-requirements>`__" section have been met. The
  4497. examples assume the previously generated image is
  4498. ``core-image-minimal``.
  4499. .. _generate-an-image-using-a-provided-kickstart-file:
  4500. Generate an Image using an Existing Kickstart File
  4501. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4502. This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart
  4503. file:
  4504. ::
  4505. $ wic create mkefidisk -e core-image-minimal
  4506. INFO: Building wic-tools...
  4507. .
  4508. .
  4509. .
  4510. INFO: The new image(s) can be found here:
  4511. ./mkefidisk-201804191017-sda.direct
  4512. The following build artifacts were used to create the image(s):
  4513. ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
  4514. BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
  4515. KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
  4516. NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4517. INFO: The image(s) were created using OE kickstart file:
  4518. /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
  4519. The previous example shows the easiest way to create an image by running
  4520. in cooked mode and supplying a kickstart file and the "-e" option to
  4521. point to the existing build artifacts. Your ``local.conf`` file needs to
  4522. have the :term:`MACHINE` variable set
  4523. to the machine you are using, which is "qemux86" in this example.
  4524. Once the image builds, the output provides image location, artifact use,
  4525. and kickstart file information.
  4526. .. note::
  4527. You should always verify the details provided in the output to make
  4528. sure that the image was indeed created exactly as expected.
  4529. Continuing with the example, you can now write the image from the Build
  4530. Directory onto a USB stick, or whatever media for which you built your
  4531. image, and boot from the media. You can write the image by using
  4532. ``bmaptool`` or ``dd``:
  4533. ::
  4534. $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX
  4535. or ::
  4536. $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX
  4537. .. note::
  4538. For more information on how to use the ``bmaptool``
  4539. to flash a device with an image, see the
  4540. ":ref:`dev-manual/dev-manual-common-tasks:flashing images using \`\`bmaptool\`\``"
  4541. section.
  4542. Using a Modified Kickstart File
  4543. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4544. Because partitioned image creation is driven by the kickstart file, it
  4545. is easy to affect image creation by changing the parameters in the file.
  4546. This next example demonstrates that through modification of the
  4547. ``directdisk-gpt`` kickstart file.
  4548. As mentioned earlier, you can use the command ``wic list images`` to
  4549. show the list of existing kickstart files. The directory in which the
  4550. ``directdisk-gpt.wks`` file resides is
  4551. ``scripts/lib/image/canned-wks/``, which is located in the
  4552. :term:`Source Directory` (e.g. ``poky``).
  4553. Because available files reside in this directory, you can create and add
  4554. your own custom files to the directory. Subsequent use of the
  4555. ``wic list images`` command would then include your kickstart files.
  4556. In this example, the existing ``directdisk-gpt`` file already does most
  4557. of what is needed. However, for the hardware in this example, the image
  4558. will need to boot from ``sdb`` instead of ``sda``, which is what the
  4559. ``directdisk-gpt`` kickstart file uses.
  4560. The example begins by making a copy of the ``directdisk-gpt.wks`` file
  4561. in the ``scripts/lib/image/canned-wks`` directory and then by changing
  4562. the lines that specify the target disk from which to boot.
  4563. ::
  4564. $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
  4565. /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
  4566. Next, the example modifies the ``directdisksdb-gpt.wks`` file and
  4567. changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The
  4568. example changes the following two lines and leaves the remaining lines
  4569. untouched:
  4570. ::
  4571. part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
  4572. part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
  4573. Once the lines are changed, the
  4574. example generates the ``directdisksdb-gpt`` image. The command points
  4575. the process at the ``core-image-minimal`` artifacts for the Next Unit of
  4576. Computing (nuc) :term:`MACHINE` the
  4577. ``local.conf``.
  4578. ::
  4579. $ wic create directdisksdb-gpt -e core-image-minimal
  4580. INFO: Building wic-tools...
  4581. .
  4582. .
  4583. .
  4584. Initialising tasks: 100% |#######################################| Time: 0:00:01
  4585. NOTE: Executing SetScene Tasks
  4586. NOTE: Executing RunQueue Tasks
  4587. NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
  4588. INFO: Creating image(s)...
  4589. INFO: The new image(s) can be found here:
  4590. ./directdisksdb-gpt-201710090938-sdb.direct
  4591. The following build artifacts were used to create the image(s):
  4592. ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
  4593. BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
  4594. KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
  4595. NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4596. INFO: The image(s) were created using OE kickstart file:
  4597. /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
  4598. Continuing with the example, you can now directly ``dd`` the image to a
  4599. USB stick, or whatever media for which you built your image, and boot
  4600. the resulting media:
  4601. ::
  4602. $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
  4603. 140966+0 records in
  4604. 140966+0 records out
  4605. 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
  4606. $ sudo eject /dev/sdb
  4607. Using a Modified Kickstart File and Running in Raw Mode
  4608. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4609. This next example manually specifies each build artifact (runs in Raw
  4610. Mode) and uses a modified kickstart file. The example also uses the
  4611. ``-o`` option to cause Wic to create the output somewhere other than the
  4612. default output directory, which is the current directory:
  4613. ::
  4614. $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
  4615. --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
  4616. --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
  4617. --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
  4618. --native-sysroot /home/stephano/build/master/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4619. INFO: Creating image(s)...
  4620. INFO: The new image(s) can be found here:
  4621. /home/stephano/testwic/test-201710091445-sdb.direct
  4622. The following build artifacts were used to create the image(s):
  4623. ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
  4624. BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
  4625. KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
  4626. NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4627. INFO: The image(s) were created using OE kickstart file:
  4628. /home/stephano/my_yocto/test.wks
  4629. For this example,
  4630. :term:`MACHINE` did not have to be
  4631. specified in the ``local.conf`` file since the artifact is manually
  4632. specified.
  4633. Using Wic to Manipulate an Image
  4634. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4635. Wic image manipulation allows you to shorten turnaround time during
  4636. image development. For example, you can use Wic to delete the kernel
  4637. partition of a Wic image and then insert a newly built kernel. This
  4638. saves you time from having to rebuild the entire image each time you
  4639. modify the kernel.
  4640. .. note::
  4641. In order to use Wic to manipulate a Wic image as in this example,
  4642. your development machine must have the ``mtools`` package installed.
  4643. The following example examines the contents of the Wic image, deletes
  4644. the existing kernel, and then inserts a new kernel:
  4645. 1. *List the Partitions:* Use the ``wic ls`` command to list all the
  4646. partitions in the Wic image:
  4647. ::
  4648. $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
  4649. Num Start End Size Fstype
  4650. 1 1048576 25041919 23993344 fat16
  4651. 2 25165824 72157183 46991360 ext4
  4652. The previous output shows two partitions in the
  4653. ``core-image-minimal-qemux86.wic`` image.
  4654. 2. *Examine a Particular Partition:* Use the ``wic ls`` command again
  4655. but in a different form to examine a particular partition.
  4656. .. note::
  4657. You can get command usage on any Wic command using the following
  4658. form:
  4659. ::
  4660. $ wic help command
  4661. For example, the following command shows you the various ways to
  4662. use the
  4663. wic ls
  4664. command:
  4665. ::
  4666. $ wic help ls
  4667. The following command shows what is in Partition one:
  4668. ::
  4669. $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
  4670. Volume in drive : is boot
  4671. Volume Serial Number is E894-1809
  4672. Directory for ::/
  4673. libcom32 c32 186500 2017-10-09 16:06
  4674. libutil c32 24148 2017-10-09 16:06
  4675. syslinux cfg 220 2017-10-09 16:06
  4676. vesamenu c32 27104 2017-10-09 16:06
  4677. vmlinuz 6904608 2017-10-09 16:06
  4678. 5 files 7 142 580 bytes
  4679. 16 582 656 bytes free
  4680. The previous output shows five files, with the
  4681. ``vmlinuz`` being the kernel.
  4682. .. note::
  4683. If you see the following error, you need to update or create a
  4684. ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1"
  4685. in the file. Then, run the Wic command again:
  4686. ::
  4687. ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
  4688. output: Total number of sectors (47824) not a multiple of sectors per track (32)!
  4689. Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
  4690. 3. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the
  4691. ``vmlinuz`` file (kernel):
  4692. ::
  4693. $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
  4694. 4. *Add In the New Kernel:* Use the ``wic cp`` command to add the
  4695. updated kernel to the Wic image. Depending on how you built your
  4696. kernel, it could be in different places. If you used ``devtool`` and
  4697. an SDK to build your kernel, it resides in the ``tmp/work`` directory
  4698. of the extensible SDK. If you used ``make`` to build the kernel, the
  4699. kernel will be in the ``workspace/sources`` area.
  4700. The following example assumes ``devtool`` was used to build the
  4701. kernel:
  4702. ::
  4703. cp ~/poky_sdk/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+git999-r0/linux-yocto-4.12.12+git999/arch/x86/boot/bzImage \
  4704. ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
  4705. Once the new kernel is added back into the image, you can use the
  4706. ``dd`` command or :ref:`bmaptool
  4707. <dev-manual/dev-manual-common-tasks:flashing images using \`\`bmaptool\`\`>`
  4708. to flash your wic image onto an SD card or USB stick and test your
  4709. target.
  4710. .. note::
  4711. Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``.
  4712. Flashing Images Using ``bmaptool``
  4713. ==================================
  4714. A fast and easy way to flash an image to a bootable device is to use
  4715. Bmaptool, which is integrated into the OpenEmbedded build system.
  4716. Bmaptool is a generic tool that creates a file's block map (bmap) and
  4717. then uses that map to copy the file. As compared to traditional tools
  4718. such as dd or cp, Bmaptool can copy (or flash) large files like raw
  4719. system image files much faster.
  4720. .. note::
  4721. - If you are using Ubuntu or Debian distributions, you can install
  4722. the ``bmap-tools`` package using the following command and then
  4723. use the tool without specifying ``PATH`` even from the root
  4724. account:
  4725. ::
  4726. $ sudo apt-get install bmap-tools
  4727. - If you are unable to install the ``bmap-tools`` package, you will
  4728. need to build Bmaptool before using it. Use the following command:
  4729. ::
  4730. $ bitbake bmap-tools-native
  4731. Following, is an example that shows how to flash a Wic image. Realize
  4732. that while this example uses a Wic image, you can use Bmaptool to flash
  4733. any type of image. Use these steps to flash an image using Bmaptool:
  4734. 1. *Update your local.conf File:* You need to have the following set
  4735. in your ``local.conf`` file before building your image:
  4736. ::
  4737. IMAGE_FSTYPES += "wic wic.bmap"
  4738. 2. *Get Your Image:* Either have your image ready (pre-built with the
  4739. :term:`IMAGE_FSTYPES`
  4740. setting previously mentioned) or take the step to build the image:
  4741. ::
  4742. $ bitbake image
  4743. 3. *Flash the Device:* Flash the device with the image by using Bmaptool
  4744. depending on your particular setup. The following commands assume the
  4745. image resides in the Build Directory's ``deploy/images/`` area:
  4746. - If you have write access to the media, use this command form:
  4747. ::
  4748. $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
  4749. - If you do not have write access to the media, set your permissions
  4750. first and then use the same command form:
  4751. ::
  4752. $ sudo chmod 666 /dev/sdX
  4753. $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
  4754. For help on the ``bmaptool`` command, use the following command:
  4755. ::
  4756. $ bmaptool --help
  4757. Making Images More Secure
  4758. =========================
  4759. Security is of increasing concern for embedded devices. Consider the
  4760. issues and problems discussed in just this sampling of work found across
  4761. the Internet:
  4762. - *"*\ `Security Risks of Embedded
  4763. Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"*
  4764. by Bruce Schneier
  4765. - *"*\ `Internet Census
  4766. 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna
  4767. Botnet
  4768. - *"*\ `Security Issues for Embedded
  4769. Devices <http://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"*
  4770. by Jake Edge
  4771. When securing your image is of concern, there are steps, tools, and
  4772. variables that you can consider to help you reach the security goals you
  4773. need for your particular device. Not all situations are identical when
  4774. it comes to making an image secure. Consequently, this section provides
  4775. some guidance and suggestions for consideration when you want to make
  4776. your image more secure.
  4777. .. note::
  4778. Because the security requirements and risks are different for every
  4779. type of device, this section cannot provide a complete reference on
  4780. securing your custom OS. It is strongly recommended that you also
  4781. consult other sources of information on embedded Linux system
  4782. hardening and on security.
  4783. General Considerations
  4784. ----------------------
  4785. General considerations exist that help you create more secure images.
  4786. You should consider the following suggestions to help make your device
  4787. more secure:
  4788. - Scan additional code you are adding to the system (e.g. application
  4789. code) by using static analysis tools. Look for buffer overflows and
  4790. other potential security problems.
  4791. - Pay particular attention to the security for any web-based
  4792. administration interface.
  4793. Web interfaces typically need to perform administrative functions and
  4794. tend to need to run with elevated privileges. Thus, the consequences
  4795. resulting from the interface's security becoming compromised can be
  4796. serious. Look for common web vulnerabilities such as
  4797. cross-site-scripting (XSS), unvalidated inputs, and so forth.
  4798. As with system passwords, the default credentials for accessing a
  4799. web-based interface should not be the same across all devices. This
  4800. is particularly true if the interface is enabled by default as it can
  4801. be assumed that many end-users will not change the credentials.
  4802. - Ensure you can update the software on the device to mitigate
  4803. vulnerabilities discovered in the future. This consideration
  4804. especially applies when your device is network-enabled.
  4805. - Ensure you remove or disable debugging functionality before producing
  4806. the final image. For information on how to do this, see the
  4807. "`Considerations Specific to the OpenEmbedded Build
  4808. System <#considerations-specific-to-the-openembedded-build-system>`__"
  4809. section.
  4810. - Ensure you have no network services listening that are not needed.
  4811. - Remove any software from the image that is not needed.
  4812. - Enable hardware support for secure boot functionality when your
  4813. device supports this functionality.
  4814. Security Flags
  4815. --------------
  4816. The Yocto Project has security flags that you can enable that help make
  4817. your build output more secure. The security flags are in the
  4818. ``meta/conf/distro/include/security_flags.inc`` file in your
  4819. :term:`Source Directory` (e.g. ``poky``).
  4820. .. note::
  4821. Depending on the recipe, certain security flags are enabled and
  4822. disabled by default.
  4823. Use the following line in your ``local.conf`` file or in your custom
  4824. distribution configuration file to enable the security compiler and
  4825. linker flags for your build:
  4826. ::
  4827. require conf/distro/include/security_flags.inc
  4828. Considerations Specific to the OpenEmbedded Build System
  4829. --------------------------------------------------------
  4830. You can take some steps that are specific to the OpenEmbedded build
  4831. system to make your images more secure:
  4832. - Ensure "debug-tweaks" is not one of your selected
  4833. :term:`IMAGE_FEATURES`.
  4834. When creating a new project, the default is to provide you with an
  4835. initial ``local.conf`` file that enables this feature using the
  4836. :term:`EXTRA_IMAGE_FEATURES`
  4837. variable with the line:
  4838. ::
  4839. EXTRA_IMAGE_FEATURES = "debug-tweaks"
  4840. To disable that feature, simply comment out that line in your
  4841. ``local.conf`` file, or make sure ``IMAGE_FEATURES`` does not contain
  4842. "debug-tweaks" before producing your final image. Among other things,
  4843. leaving this in place sets the root password as blank, which makes
  4844. logging in for debugging or inspection easy during development but
  4845. also means anyone can easily log in during production.
  4846. - It is possible to set a root password for the image and also to set
  4847. passwords for any extra users you might add (e.g. administrative or
  4848. service type users). When you set up passwords for multiple images or
  4849. users, you should not duplicate passwords.
  4850. To set up passwords, use the
  4851. :ref:`extrausers <ref-classes-extrausers>`
  4852. class, which is the preferred method. For an example on how to set up
  4853. both root and user passwords, see the
  4854. ":ref:`extrausers.bbclass <ref-classes-extrausers>`"
  4855. section.
  4856. .. note::
  4857. When adding extra user accounts or setting a root password, be
  4858. cautious about setting the same password on every device. If you
  4859. do this, and the password you have set is exposed, then every
  4860. device is now potentially compromised. If you need this access but
  4861. want to ensure security, consider setting a different, random
  4862. password for each device. Typically, you do this as a separate
  4863. step after you deploy the image onto the device.
  4864. - Consider enabling a Mandatory Access Control (MAC) framework such as
  4865. SMACK or SELinux and tuning it appropriately for your device's usage.
  4866. You can find more information in the
  4867. :yocto_git:`meta-selinux </cgit/cgit.cgi/meta-selinux/>` layer.
  4868. Tools for Hardening Your Image
  4869. ------------------------------
  4870. The Yocto Project provides tools for making your image more secure. You
  4871. can find these tools in the ``meta-security`` layer of the
  4872. :yocto_git:`Yocto Project Source Repositories <>`.
  4873. Creating Your Own Distribution
  4874. ==============================
  4875. When you build an image using the Yocto Project and do not alter any
  4876. distribution :term:`Metadata`, you are
  4877. creating a Poky distribution. If you wish to gain more control over
  4878. package alternative selections, compile-time options, and other
  4879. low-level configurations, you can create your own distribution.
  4880. To create your own distribution, the basic steps consist of creating
  4881. your own distribution layer, creating your own distribution
  4882. configuration file, and then adding any needed code and Metadata to the
  4883. layer. The following steps provide some more detail:
  4884. - *Create a layer for your new distro:* Create your distribution layer
  4885. so that you can keep your Metadata and code for the distribution
  4886. separate. It is strongly recommended that you create and use your own
  4887. layer for configuration and code. Using your own layer as compared to
  4888. just placing configurations in a ``local.conf`` configuration file
  4889. makes it easier to reproduce the same build configuration when using
  4890. multiple build machines. See the
  4891. ":ref:`dev-manual/dev-manual-common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
  4892. section for information on how to quickly set up a layer.
  4893. - *Create the distribution configuration file:* The distribution
  4894. configuration file needs to be created in the ``conf/distro``
  4895. directory of your layer. You need to name it using your distribution
  4896. name (e.g. ``mydistro.conf``).
  4897. .. note::
  4898. The :term:`DISTRO` variable in your ``local.conf`` file determines the
  4899. name of your distribution.
  4900. You can split out parts of your configuration file into include files
  4901. and then "require" them from within your distribution configuration
  4902. file. Be sure to place the include files in the
  4903. ``conf/distro/include`` directory of your layer. A common example
  4904. usage of include files would be to separate out the selection of
  4905. desired version and revisions for individual recipes.
  4906. Your configuration file needs to set the following required
  4907. variables:
  4908. - :term:`DISTRO_NAME`
  4909. - :term:`DISTRO_VERSION`
  4910. These following variables are optional and you typically set them
  4911. from the distribution configuration file:
  4912. - :term:`DISTRO_FEATURES`
  4913. - :term:`DISTRO_EXTRA_RDEPENDS`
  4914. - :term:`DISTRO_EXTRA_RRECOMMENDS`
  4915. - :term:`TCLIBC`
  4916. .. tip::
  4917. If you want to base your distribution configuration file on the
  4918. very basic configuration from OE-Core, you can use
  4919. ``conf/distro/defaultsetup.conf`` as a reference and just include
  4920. variables that differ as compared to ``defaultsetup.conf``.
  4921. Alternatively, you can create a distribution configuration file
  4922. from scratch using the ``defaultsetup.conf`` file or configuration files
  4923. from other distributions such as Poky or Angstrom as references.
  4924. - *Provide miscellaneous variables:* Be sure to define any other
  4925. variables for which you want to create a default or enforce as part
  4926. of the distribution configuration. You can include nearly any
  4927. variable from the ``local.conf`` file. The variables you use are not
  4928. limited to the list in the previous bulleted item.
  4929. - *Point to Your distribution configuration file:* In your
  4930. ``local.conf`` file in the :term:`Build Directory`,
  4931. set your
  4932. :term:`DISTRO` variable to point to
  4933. your distribution's configuration file. For example, if your
  4934. distribution's configuration file is named ``mydistro.conf``, then
  4935. you point to it as follows:
  4936. ::
  4937. DISTRO = "mydistro"
  4938. - *Add more to the layer if necessary:* Use your layer to hold other
  4939. information needed for the distribution:
  4940. - Add recipes for installing distro-specific configuration files
  4941. that are not already installed by another recipe. If you have
  4942. distro-specific configuration files that are included by an
  4943. existing recipe, you should add an append file (``.bbappend``) for
  4944. those. For general information and recommendations on how to add
  4945. recipes to your layer, see the "`Creating Your Own
  4946. Layer <#creating-your-own-layer>`__" and "`Following Best
  4947. Practices When Creating
  4948. Layers <#best-practices-to-follow-when-creating-layers>`__"
  4949. sections.
  4950. - Add any image recipes that are specific to your distribution.
  4951. - Add a ``psplash`` append file for a branded splash screen. For
  4952. information on append files, see the "`Using .bbappend Files in
  4953. Your Layer <#using-bbappend-files>`__" section.
  4954. - Add any other append files to make custom changes that are
  4955. specific to individual recipes.
  4956. Creating a Custom Template Configuration Directory
  4957. ==================================================
  4958. If you are producing your own customized version of the build system for
  4959. use by other users, you might want to customize the message shown by the
  4960. setup script or you might want to change the template configuration
  4961. files (i.e. ``local.conf`` and ``bblayers.conf``) that are created in a
  4962. new build directory.
  4963. The OpenEmbedded build system uses the environment variable
  4964. ``TEMPLATECONF`` to locate the directory from which it gathers
  4965. configuration information that ultimately ends up in the
  4966. :term:`Build Directory` ``conf`` directory.
  4967. By default, ``TEMPLATECONF`` is set as follows in the ``poky``
  4968. repository:
  4969. ::
  4970. TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
  4971. This is the
  4972. directory used by the build system to find templates from which to build
  4973. some key configuration files. If you look at this directory, you will
  4974. see the ``bblayers.conf.sample``, ``local.conf.sample``, and
  4975. ``conf-notes.txt`` files. The build system uses these files to form the
  4976. respective ``bblayers.conf`` file, ``local.conf`` file, and display the
  4977. list of BitBake targets when running the setup script.
  4978. To override these default configuration files with configurations you
  4979. want used within every new Build Directory, simply set the
  4980. ``TEMPLATECONF`` variable to your directory. The ``TEMPLATECONF``
  4981. variable is set in the ``.templateconf`` file, which is in the top-level
  4982. :term:`Source Directory` folder
  4983. (e.g. ``poky``). Edit the ``.templateconf`` so that it can locate your
  4984. directory.
  4985. Best practices dictate that you should keep your template configuration
  4986. directory in your custom distribution layer. For example, suppose you
  4987. have a layer named ``meta-mylayer`` located in your home directory and
  4988. you want your template configuration directory named ``myconf``.
  4989. Changing the ``.templateconf`` as follows causes the OpenEmbedded build
  4990. system to look in your directory and base its configuration files on the
  4991. ``*.sample`` configuration files it finds. The final configuration files
  4992. (i.e. ``local.conf`` and ``bblayers.conf`` ultimately still end up in
  4993. your Build Directory, but they are based on your ``*.sample`` files.
  4994. ::
  4995. TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
  4996. Aside from the ``*.sample`` configuration files, the ``conf-notes.txt``
  4997. also resides in the default ``meta-poky/conf`` directory. The script
  4998. that sets up the build environment (i.e.
  4999. :ref:`structure-core-script`) uses this file to
  5000. display BitBake targets as part of the script output. Customizing this
  5001. ``conf-notes.txt`` file is a good way to make sure your list of custom
  5002. targets appears as part of the script's output.
  5003. Here is the default list of targets displayed as a result of running
  5004. either of the setup scripts:
  5005. ::
  5006. You can now run 'bitbake <target>'
  5007. Common targets are:
  5008. core-image-minimal
  5009. core-image-sato
  5010. meta-toolchain
  5011. meta-ide-support
  5012. Changing the listed common targets is as easy as editing your version of
  5013. ``conf-notes.txt`` in your custom template configuration directory and
  5014. making sure you have ``TEMPLATECONF`` set to your directory.
  5015. .. _dev-saving-memory-during-a-build:
  5016. Conserving Disk Space During Builds
  5017. ===================================
  5018. To help conserve disk space during builds, you can add the following
  5019. statement to your project's ``local.conf`` configuration file found in
  5020. the :term:`Build Directory`:
  5021. ::
  5022. INHERIT += "rm_work"
  5023. Adding this statement deletes the work directory used for
  5024. building a recipe once the recipe is built. For more information on
  5025. "rm_work", see the
  5026. :ref:`rm_work <ref-classes-rm-work>` class in the
  5027. Yocto Project Reference Manual.
  5028. Working with Packages
  5029. =====================
  5030. This section describes a few tasks that involve packages:
  5031. - `Excluding packages from an
  5032. image <#excluding-packages-from-an-image>`__
  5033. - `Incrementing a binary package
  5034. version <#incrementing-a-binary-package-version>`__
  5035. - `Handling optional module
  5036. packaging <#handling-optional-module-packaging>`__
  5037. - `Using runtime package
  5038. management <#using-runtime-package-management>`__
  5039. - `Generating and using signed
  5040. packages <#generating-and-using-signed-packages>`__
  5041. - `Setting up and running package test
  5042. (ptest) <#testing-packages-with-ptest>`__
  5043. - `Creating node package manager (NPM)
  5044. packages <#creating-node-package-manager-npm-packages>`__
  5045. - `Adding custom metadata to
  5046. packages <#adding-custom-metadata-to-packages>`__
  5047. Excluding Packages from an Image
  5048. --------------------------------
  5049. You might find it necessary to prevent specific packages from being
  5050. installed into an image. If so, you can use several variables to direct
  5051. the build system to essentially ignore installing recommended packages
  5052. or to not install a package at all.
  5053. The following list introduces variables you can use to prevent packages
  5054. from being installed into your image. Each of these variables only works
  5055. with IPK and RPM package types. Support for Debian packages does not
  5056. exist. Also, you can use these variables from your ``local.conf`` file
  5057. or attach them to a specific image recipe by using a recipe name
  5058. override. For more detail on the variables, see the descriptions in the
  5059. Yocto Project Reference Manual's glossary chapter.
  5060. - :term:`BAD_RECOMMENDATIONS`:
  5061. Use this variable to specify "recommended-only" packages that you do
  5062. not want installed.
  5063. - :term:`NO_RECOMMENDATIONS`:
  5064. Use this variable to prevent all "recommended-only" packages from
  5065. being installed.
  5066. - :term:`PACKAGE_EXCLUDE`:
  5067. Use this variable to prevent specific packages from being installed
  5068. regardless of whether they are "recommended-only" or not. You need to
  5069. realize that the build process could fail with an error when you
  5070. prevent the installation of a package whose presence is required by
  5071. an installed package.
  5072. .. _incrementing-a-binary-package-version:
  5073. Incrementing a Package Version
  5074. ------------------------------
  5075. This section provides some background on how binary package versioning
  5076. is accomplished and presents some of the services, variables, and
  5077. terminology involved.
  5078. In order to understand binary package versioning, you need to consider
  5079. the following:
  5080. - Binary Package: The binary package that is eventually built and
  5081. installed into an image.
  5082. - Binary Package Version: The binary package version is composed of two
  5083. components - a version and a revision.
  5084. .. note::
  5085. Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved
  5086. but this discussion for the most part ignores ``PE``.
  5087. The version and revision are taken from the
  5088. :term:`PV` and
  5089. :term:`PR` variables, respectively.
  5090. - ``PV``: The recipe version. ``PV`` represents the version of the
  5091. software being packaged. Do not confuse ``PV`` with the binary
  5092. package version.
  5093. - ``PR``: The recipe revision.
  5094. - :term:`SRCPV`: The OpenEmbedded
  5095. build system uses this string to help define the value of ``PV`` when
  5096. the source code revision needs to be included in it.
  5097. - :yocto_wiki:`PR Service </wiki/PR_Service>`: A
  5098. network-based service that helps automate keeping package feeds
  5099. compatible with existing package manager applications such as RPM,
  5100. APT, and OPKG.
  5101. Whenever the binary package content changes, the binary package version
  5102. must change. Changing the binary package version is accomplished by
  5103. changing or "bumping" the ``PR`` and/or ``PV`` values. Increasing these
  5104. values occurs one of two ways:
  5105. - Automatically using a Package Revision Service (PR Service).
  5106. - Manually incrementing the ``PR`` and/or ``PV`` variables.
  5107. Given a primary challenge of any build system and its users is how to
  5108. maintain a package feed that is compatible with existing package manager
  5109. applications such as RPM, APT, and OPKG, using an automated system is
  5110. much preferred over a manual system. In either system, the main
  5111. requirement is that binary package version numbering increases in a
  5112. linear fashion and that a number of version components exist that
  5113. support that linear progression. For information on how to ensure
  5114. package revisioning remains linear, see the "`Automatically Incrementing
  5115. a Binary Package Revision
  5116. Number <#automatically-incrementing-a-binary-package-revision-number>`__"
  5117. section.
  5118. The following three sections provide related information on the PR
  5119. Service, the manual method for "bumping" ``PR`` and/or ``PV``, and on
  5120. how to ensure binary package revisioning remains linear.
  5121. Working With a PR Service
  5122. ~~~~~~~~~~~~~~~~~~~~~~~~~
  5123. As mentioned, attempting to maintain revision numbers in the
  5124. :term:`Metadata` is error prone, inaccurate,
  5125. and causes problems for people submitting recipes. Conversely, the PR
  5126. Service automatically generates increasing numbers, particularly the
  5127. revision field, which removes the human element.
  5128. .. note::
  5129. For additional information on using a PR Service, you can see the
  5130. :yocto_wiki:`PR Service </wiki/PR_Service>` wiki page.
  5131. The Yocto Project uses variables in order of decreasing priority to
  5132. facilitate revision numbering (i.e.
  5133. :term:`PE`,
  5134. :term:`PV`, and
  5135. :term:`PR` for epoch, version, and
  5136. revision, respectively). The values are highly dependent on the policies
  5137. and procedures of a given distribution and package feed.
  5138. Because the OpenEmbedded build system uses
  5139. ":ref:`signatures <overview-checksums>`", which are
  5140. unique to a given build, the build system knows when to rebuild
  5141. packages. All the inputs into a given task are represented by a
  5142. signature, which can trigger a rebuild when different. Thus, the build
  5143. system itself does not rely on the ``PR``, ``PV``, and ``PE`` numbers to
  5144. trigger a rebuild. The signatures, however, can be used to generate
  5145. these values.
  5146. The PR Service works with both ``OEBasic`` and ``OEBasicHash``
  5147. generators. The value of ``PR`` bumps when the checksum changes and the
  5148. different generator mechanisms change signatures under different
  5149. circumstances.
  5150. As implemented, the build system includes values from the PR Service
  5151. into the ``PR`` field as an addition using the form "``.x``" so ``r0``
  5152. becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing
  5153. ``PR`` values to be used for whatever reasons, which include manual
  5154. ``PR`` bumps, should it be necessary.
  5155. By default, the PR Service is not enabled or running. Thus, the packages
  5156. generated are just "self consistent". The build system adds and removes
  5157. packages and there are no guarantees about upgrade paths but images will
  5158. be consistent and correct with the latest changes.
  5159. The simplest form for a PR Service is for it to exist for a single host
  5160. development system that builds the package feed (building system). For
  5161. this scenario, you can enable a local PR Service by setting
  5162. :term:`PRSERV_HOST` in your
  5163. ``local.conf`` file in the :term:`Build Directory`:
  5164. ::
  5165. PRSERV_HOST = "localhost:0"
  5166. Once the service is started, packages will automatically
  5167. get increasing ``PR`` values and BitBake takes care of starting and
  5168. stopping the server.
  5169. If you have a more complex setup where multiple host development systems
  5170. work against a common, shared package feed, you have a single PR Service
  5171. running and it is connected to each building system. For this scenario,
  5172. you need to start the PR Service using the ``bitbake-prserv`` command:
  5173. ::
  5174. bitbake-prserv --host ip --port port --start
  5175. In addition to
  5176. hand-starting the service, you need to update the ``local.conf`` file of
  5177. each building system as described earlier so each system points to the
  5178. server and port.
  5179. It is also recommended you use build history, which adds some sanity
  5180. checks to binary package versions, in conjunction with the server that
  5181. is running the PR Service. To enable build history, add the following to
  5182. each building system's ``local.conf`` file:
  5183. ::
  5184. # It is recommended to activate "buildhistory" for testing the PR service
  5185. INHERIT += "buildhistory"
  5186. BUILDHISTORY_COMMIT = "1"
  5187. For information on build
  5188. history, see the "`Maintaining Build Output
  5189. Quality <#maintaining-build-output-quality>`__" section.
  5190. .. note::
  5191. The OpenEmbedded build system does not maintain ``PR`` information as
  5192. part of the shared state (sstate) packages. If you maintain an sstate
  5193. feed, its expected that either all your building systems that
  5194. contribute to the sstate feed use a shared PR Service, or you do not
  5195. run a PR Service on any of your building systems. Having some systems
  5196. use a PR Service while others do not leads to obvious problems.
  5197. For more information on shared state, see the
  5198. ":ref:`overview-manual/overview-manual-concepts:shared state cache`"
  5199. section in the Yocto Project Overview and Concepts Manual.
  5200. Manually Bumping PR
  5201. ~~~~~~~~~~~~~~~~~~~
  5202. The alternative to setting up a PR Service is to manually "bump" the
  5203. :term:`PR` variable.
  5204. If a committed change results in changing the package output, then the
  5205. value of the PR variable needs to be increased (or "bumped") as part of
  5206. that commit. For new recipes you should add the ``PR`` variable and set
  5207. its initial value equal to "r0", which is the default. Even though the
  5208. default value is "r0", the practice of adding it to a new recipe makes
  5209. it harder to forget to bump the variable when you make changes to the
  5210. recipe in future.
  5211. If you are sharing a common ``.inc`` file with multiple recipes, you can
  5212. also use the ``INC_PR`` variable to ensure that the recipes sharing the
  5213. ``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The
  5214. ``.inc`` file must set ``INC_PR`` (initially to "r0"), and all recipes
  5215. referring to it should set ``PR`` to "${INC_PR}.0" initially,
  5216. incrementing the last number when the recipe is changed. If the ``.inc``
  5217. file is changed then its ``INC_PR`` should be incremented.
  5218. When upgrading the version of a binary package, assuming the ``PV``
  5219. changes, the ``PR`` variable should be reset to "r0" (or "${INC_PR}.0"
  5220. if you are using ``INC_PR``).
  5221. Usually, version increases occur only to binary packages. However, if
  5222. for some reason ``PV`` changes but does not increase, you can increase
  5223. the ``PE`` variable (Package Epoch). The ``PE`` variable defaults to
  5224. "0".
  5225. Binary package version numbering strives to follow the `Debian Version
  5226. Field Policy
  5227. Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__.
  5228. These guidelines define how versions are compared and what "increasing"
  5229. a version means.
  5230. .. _automatically-incrementing-a-binary-package-revision-number:
  5231. Automatically Incrementing a Package Version Number
  5232. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5233. When fetching a repository, BitBake uses the
  5234. :term:`SRCREV` variable to determine
  5235. the specific source code revision from which to build. You set the
  5236. ``SRCREV`` variable to
  5237. :term:`AUTOREV` to cause the
  5238. OpenEmbedded build system to automatically use the latest revision of
  5239. the software:
  5240. ::
  5241. SRCREV = "${AUTOREV}"
  5242. Furthermore, you need to reference ``SRCPV`` in ``PV`` in order to
  5243. automatically update the version whenever the revision of the source
  5244. code changes. Here is an example:
  5245. ::
  5246. PV = "1.0+git${SRCPV}"
  5247. The OpenEmbedded build system substitutes ``SRCPV`` with the following:
  5248. .. code-block:: none
  5249. AUTOINC+source_code_revision
  5250. The build system replaces the ``AUTOINC``
  5251. with a number. The number used depends on the state of the PR Service:
  5252. - If PR Service is enabled, the build system increments the number,
  5253. which is similar to the behavior of
  5254. :term:`PR`. This behavior results in
  5255. linearly increasing package versions, which is desirable. Here is an
  5256. example:
  5257. .. code-block:: none
  5258. hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
  5259. hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
  5260. - If PR Service is not enabled, the build system replaces the
  5261. ``AUTOINC`` placeholder with zero (i.e. "0"). This results in
  5262. changing the package version since the source revision is included.
  5263. However, package versions are not increased linearly. Here is an
  5264. example:
  5265. .. code-block:: none
  5266. hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
  5267. hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
  5268. In summary, the OpenEmbedded build system does not track the history of
  5269. binary package versions for this purpose. ``AUTOINC``, in this case, is
  5270. comparable to ``PR``. If PR server is not enabled, ``AUTOINC`` in the
  5271. package version is simply replaced by "0". If PR server is enabled, the
  5272. build system keeps track of the package versions and bumps the number
  5273. when the package revision changes.
  5274. Handling Optional Module Packaging
  5275. ----------------------------------
  5276. Many pieces of software split functionality into optional modules (or
  5277. plugins) and the plugins that are built might depend on configuration
  5278. options. To avoid having to duplicate the logic that determines what
  5279. modules are available in your recipe or to avoid having to package each
  5280. module by hand, the OpenEmbedded build system provides functionality to
  5281. handle module packaging dynamically.
  5282. To handle optional module packaging, you need to do two things:
  5283. - Ensure the module packaging is actually done.
  5284. - Ensure that any dependencies on optional modules from other recipes
  5285. are satisfied by your recipe.
  5286. Making Sure the Packaging is Done
  5287. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5288. To ensure the module packaging actually gets done, you use the
  5289. ``do_split_packages`` function within the ``populate_packages`` Python
  5290. function in your recipe. The ``do_split_packages`` function searches for
  5291. a pattern of files or directories under a specified path and creates a
  5292. package for each one it finds by appending to the
  5293. :term:`PACKAGES` variable and
  5294. setting the appropriate values for ``FILES_packagename``,
  5295. ``RDEPENDS_packagename``, ``DESCRIPTION_packagename``, and so forth.
  5296. Here is an example from the ``lighttpd`` recipe:
  5297. ::
  5298. python populate_packages_prepend () {
  5299. lighttpd_libdir = d.expand('${libdir}')
  5300. do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$',
  5301. 'lighttpd-module-%s', 'Lighttpd module for %s',
  5302. extra_depends='')
  5303. }
  5304. The previous example specifies a number of things in the call to
  5305. ``do_split_packages``.
  5306. - A directory within the files installed by your recipe through
  5307. ``do_install`` in which to search.
  5308. - A regular expression used to match module files in that directory. In
  5309. the example, note the parentheses () that mark the part of the
  5310. expression from which the module name should be derived.
  5311. - A pattern to use for the package names.
  5312. - A description for each package.
  5313. - An empty string for ``extra_depends``, which disables the default
  5314. dependency on the main ``lighttpd`` package. Thus, if a file in
  5315. ``${libdir}`` called ``mod_alias.so`` is found, a package called
  5316. ``lighttpd-module-alias`` is created for it and the
  5317. :term:`DESCRIPTION` is set to
  5318. "Lighttpd module for alias".
  5319. Often, packaging modules is as simple as the previous example. However,
  5320. more advanced options exist that you can use within
  5321. ``do_split_packages`` to modify its behavior. And, if you need to, you
  5322. can add more logic by specifying a hook function that is called for each
  5323. package. It is also perfectly acceptable to call ``do_split_packages``
  5324. multiple times if you have more than one set of modules to package.
  5325. For more examples that show how to use ``do_split_packages``, see the
  5326. ``connman.inc`` file in the ``meta/recipes-connectivity/connman/``
  5327. directory of the ``poky`` :ref:`source repository <yocto-project-repositories>`. You can
  5328. also find examples in ``meta/classes/kernel.bbclass``.
  5329. Following is a reference that shows ``do_split_packages`` mandatory and
  5330. optional arguments:
  5331. ::
  5332. Mandatory arguments
  5333. root
  5334. The path in which to search
  5335. file_regex
  5336. Regular expression to match searched files.
  5337. Use parentheses () to mark the part of this
  5338. expression that should be used to derive the
  5339. module name (to be substituted where %s is
  5340. used in other function arguments as noted below)
  5341. output_pattern
  5342. Pattern to use for the package names. Must
  5343. include %s.
  5344. description
  5345. Description to set for each package. Must
  5346. include %s.
  5347. Optional arguments
  5348. postinst
  5349. Postinstall script to use for all packages
  5350. (as a string)
  5351. recursive
  5352. True to perform a recursive search - default
  5353. False
  5354. hook
  5355. A hook function to be called for every match.
  5356. The function will be called with the following
  5357. arguments (in the order listed):
  5358. f
  5359. Full path to the file/directory match
  5360. pkg
  5361. The package name
  5362. file_regex
  5363. As above
  5364. output_pattern
  5365. As above
  5366. modulename
  5367. The module name derived using file_regex
  5368. extra_depends
  5369. Extra runtime dependencies (RDEPENDS) to be
  5370. set for all packages. The default value of None
  5371. causes a dependency on the main package
  5372. (${PN}) - if you do not want this, pass empty
  5373. string '' for this parameter.
  5374. aux_files_pattern
  5375. Extra item(s) to be added to FILES for each
  5376. package. Can be a single string item or a list
  5377. of strings for multiple items. Must include %s.
  5378. postrm
  5379. postrm script to use for all packages (as a
  5380. string)
  5381. allow_dirs
  5382. True to allow directories to be matched -
  5383. default False
  5384. prepend
  5385. If True, prepend created packages to PACKAGES
  5386. instead of the default False which appends them
  5387. match_path
  5388. match file_regex on the whole relative path to
  5389. the root rather than just the file name
  5390. aux_files_pattern_verbatim
  5391. Extra item(s) to be added to FILES for each
  5392. package, using the actual derived module name
  5393. rather than converting it to something legal
  5394. for a package name. Can be a single string item
  5395. or a list of strings for multiple items. Must
  5396. include %s.
  5397. allow_links
  5398. True to allow symlinks to be matched - default
  5399. False
  5400. summary
  5401. Summary to set for each package. Must include %s;
  5402. defaults to description if not set.
  5403. Satisfying Dependencies
  5404. ~~~~~~~~~~~~~~~~~~~~~~~
  5405. The second part for handling optional module packaging is to ensure that
  5406. any dependencies on optional modules from other recipes are satisfied by
  5407. your recipe. You can be sure these dependencies are satisfied by using
  5408. the :term:`PACKAGES_DYNAMIC`
  5409. variable. Here is an example that continues with the ``lighttpd`` recipe
  5410. shown earlier:
  5411. ::
  5412. PACKAGES_DYNAMIC = "lighttpd-module-.*"
  5413. The name
  5414. specified in the regular expression can of course be anything. In this
  5415. example, it is ``lighttpd-module-`` and is specified as the prefix to
  5416. ensure that any :term:`RDEPENDS` and
  5417. :term:`RRECOMMENDS` on a package
  5418. name starting with the prefix are satisfied during build time. If you
  5419. are using ``do_split_packages`` as described in the previous section,
  5420. the value you put in ``PACKAGES_DYNAMIC`` should correspond to the name
  5421. pattern specified in the call to ``do_split_packages``.
  5422. Using Runtime Package Management
  5423. --------------------------------
  5424. During a build, BitBake always transforms a recipe into one or more
  5425. packages. For example, BitBake takes the ``bash`` recipe and produces a
  5426. number of packages (e.g. ``bash``, ``bash-bashbug``,
  5427. ``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``,
  5428. ``bash-completion-extra``, ``bash-dbg``, and so forth). Not all
  5429. generated packages are included in an image.
  5430. In several situations, you might need to update, add, remove, or query
  5431. the packages on a target device at runtime (i.e. without having to
  5432. generate a new image). Examples of such situations include:
  5433. - You want to provide in-the-field updates to deployed devices (e.g.
  5434. security updates).
  5435. - You want to have a fast turn-around development cycle for one or more
  5436. applications that run on your device.
  5437. - You want to temporarily install the "debug" packages of various
  5438. applications on your device so that debugging can be greatly improved
  5439. by allowing access to symbols and source debugging.
  5440. - You want to deploy a more minimal package selection of your device
  5441. but allow in-the-field updates to add a larger selection for
  5442. customization.
  5443. In all these situations, you have something similar to a more
  5444. traditional Linux distribution in that in-field devices are able to
  5445. receive pre-compiled packages from a server for installation or update.
  5446. Being able to install these packages on a running, in-field device is
  5447. what is termed "runtime package management".
  5448. In order to use runtime package management, you need a host or server
  5449. machine that serves up the pre-compiled packages plus the required
  5450. metadata. You also need package manipulation tools on the target. The
  5451. build machine is a likely candidate to act as the server. However, that
  5452. machine does not necessarily have to be the package server. The build
  5453. machine could push its artifacts to another machine that acts as the
  5454. server (e.g. Internet-facing). In fact, doing so is advantageous for a
  5455. production environment as getting the packages away from the development
  5456. system's build directory prevents accidental overwrites.
  5457. A simple build that targets just one device produces more than one
  5458. package database. In other words, the packages produced by a build are
  5459. separated out into a couple of different package groupings based on
  5460. criteria such as the target's CPU architecture, the target board, or the
  5461. C library used on the target. For example, a build targeting the
  5462. ``qemux86`` device produces the following three package databases:
  5463. ``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86``
  5464. device to be aware of all the packages that were available to it, you
  5465. would need to point it to each of these databases individually. In a
  5466. similar way, a traditional Linux distribution usually is configured to
  5467. be aware of a number of software repositories from which it retrieves
  5468. packages.
  5469. Using runtime package management is completely optional and not required
  5470. for a successful build or deployment in any way. But if you want to make
  5471. use of runtime package management, you need to do a couple things above
  5472. and beyond the basics. The remainder of this section describes what you
  5473. need to do.
  5474. .. _runtime-package-management-build:
  5475. Build Considerations
  5476. ~~~~~~~~~~~~~~~~~~~~
  5477. This section describes build considerations of which you need to be
  5478. aware in order to provide support for runtime package management.
  5479. When BitBake generates packages, it needs to know what format or formats
  5480. to use. In your configuration, you use the
  5481. :term:`PACKAGE_CLASSES`
  5482. variable to specify the format:
  5483. 1. Open the ``local.conf`` file inside your
  5484. :term:`Build Directory` (e.g.
  5485. ``~/poky/build/conf/local.conf``).
  5486. 2. Select the desired package format as follows:
  5487. ::
  5488. PACKAGE_CLASSES ?= "package_packageformat"
  5489. where packageformat can be "ipk", "rpm",
  5490. "deb", or "tar" which are the supported package formats.
  5491. .. note::
  5492. Because the Yocto Project supports four different package formats,
  5493. you can set the variable with more than one argument. However, the
  5494. OpenEmbedded build system only uses the first argument when
  5495. creating an image or Software Development Kit (SDK).
  5496. If you would like your image to start off with a basic package database
  5497. containing the packages in your current build as well as to have the
  5498. relevant tools available on the target for runtime package management,
  5499. you can include "package-management" in the
  5500. :term:`IMAGE_FEATURES`
  5501. variable. Including "package-management" in this configuration variable
  5502. ensures that when the image is assembled for your target, the image
  5503. includes the currently-known package databases as well as the
  5504. target-specific tools required for runtime package management to be
  5505. performed on the target. However, this is not strictly necessary. You
  5506. could start your image off without any databases but only include the
  5507. required on-target package tool(s). As an example, you could include
  5508. "opkg" in your
  5509. :term:`IMAGE_INSTALL` variable
  5510. if you are using the IPK package format. You can then initialize your
  5511. target's package database(s) later once your image is up and running.
  5512. Whenever you perform any sort of build step that can potentially
  5513. generate a package or modify existing package, it is always a good idea
  5514. to re-generate the package index after the build by using the following
  5515. command:
  5516. ::
  5517. $ bitbake package-index
  5518. It might be tempting to build the
  5519. package and the package index at the same time with a command such as
  5520. the following:
  5521. ::
  5522. $ bitbake some-package package-index
  5523. Do not do this as
  5524. BitBake does not schedule the package index for after the completion of
  5525. the package you are building. Consequently, you cannot be sure of the
  5526. package index including information for the package you just built.
  5527. Thus, be sure to run the package update step separately after building
  5528. any packages.
  5529. You can use the
  5530. :term:`PACKAGE_FEED_ARCHS`,
  5531. :term:`PACKAGE_FEED_BASE_PATHS`,
  5532. and
  5533. :term:`PACKAGE_FEED_URIS`
  5534. variables to pre-configure target images to use a package feed. If you
  5535. do not define these variables, then manual steps as described in the
  5536. subsequent sections are necessary to configure the target. You should
  5537. set these variables before building the image in order to produce a
  5538. correctly configured image.
  5539. When your build is complete, your packages reside in the
  5540. ``${TMPDIR}/deploy/packageformat`` directory. For example, if
  5541. ``${``\ :term:`TMPDIR`\ ``}`` is
  5542. ``tmp`` and your selected package type is RPM, then your RPM packages
  5543. are available in ``tmp/deploy/rpm``.
  5544. .. _runtime-package-management-server:
  5545. Host or Server Machine Setup
  5546. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5547. Although other protocols are possible, a server using HTTP typically
  5548. serves packages. If you want to use HTTP, then set up and configure a
  5549. web server such as Apache 2, lighttpd, or Python web server on the
  5550. machine serving the packages.
  5551. To keep things simple, this section describes how to set up a
  5552. Python web server to share package feeds from the developer's
  5553. machine. Although this server might not be the best for a production
  5554. environment, the setup is simple and straight forward. Should you want
  5555. to use a different server more suited for production (e.g. Apache 2,
  5556. Lighttpd, or Nginx), take the appropriate steps to do so.
  5557. From within the build directory where you have built an image based on
  5558. your packaging choice (i.e. the
  5559. :term:`PACKAGE_CLASSES`
  5560. setting), simply start the server. The following example assumes a build
  5561. directory of ``~/poky/build/tmp/deploy/rpm`` and a ``PACKAGE_CLASSES``
  5562. setting of "package_rpm":
  5563. ::
  5564. $ cd ~/poky/build/tmp/deploy/rpm
  5565. $ python3 -m http.server
  5566. .. _runtime-package-management-target:
  5567. Target Setup
  5568. ~~~~~~~~~~~~
  5569. Setting up the target differs depending on the package management
  5570. system. This section provides information for RPM, IPK, and DEB.
  5571. .. _runtime-package-management-target-rpm:
  5572. Using RPM
  5573. ^^^^^^^^^
  5574. The `Dandified Packaging
  5575. Tool <https://en.wikipedia.org/wiki/DNF_(software)>`__ (DNF) performs
  5576. runtime package management of RPM packages. In order to use DNF for
  5577. runtime package management, you must perform an initial setup on the
  5578. target machine for cases where the ``PACKAGE_FEED_*`` variables were not
  5579. set as part of the image that is running on the target. This means if
  5580. you built your image and did not not use these variables as part of the
  5581. build and your image is now running on the target, you need to perform
  5582. the steps in this section if you want to use runtime package management.
  5583. .. note::
  5584. For information on the ``PACKAGE_FEED_*`` variables, see
  5585. :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and
  5586. :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables
  5587. glossary.
  5588. On the target, you must inform DNF that package databases are available.
  5589. You do this by creating a file named
  5590. ``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``.
  5591. As an example, assume the target is able to use the following package
  5592. databases: ``all``, ``i586``, and ``qemux86`` from a server named
  5593. ``my.server``. The specifics for setting up the web server are up to
  5594. you. The critical requirement is that the URIs in the target repository
  5595. configuration point to the correct remote location for the feeds.
  5596. .. note::
  5597. For development purposes, you can point the web server to the build
  5598. system's ``deploy`` directory. However, for production use, it is better to
  5599. copy the package directories to a location outside of the build area and use
  5600. that location. Doing so avoids situations where the build system
  5601. overwrites or changes the ``deploy`` directory.
  5602. When telling DNF where to look for the package databases, you must
  5603. declare individual locations per architecture or a single location used
  5604. for all architectures. You cannot do both:
  5605. - *Create an Explicit List of Architectures:* Define individual base
  5606. URLs to identify where each package database is located:
  5607. .. code-block:: none
  5608. [oe-packages]
  5609. baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
  5610. This example
  5611. informs DNF about individual package databases for all three
  5612. architectures.
  5613. - *Create a Single (Full) Package Index:* Define a single base URL that
  5614. identifies where a full package database is located:
  5615. ::
  5616. [oe-packages]
  5617. baseurl=http://my.server/rpm
  5618. This example informs DNF about a single
  5619. package database that contains all the package index information for
  5620. all supported architectures.
  5621. Once you have informed DNF where to find the package databases, you need
  5622. to fetch them:
  5623. .. code-block:: none
  5624. # dnf makecache
  5625. DNF is now able to find, install, and
  5626. upgrade packages from the specified repository or repositories.
  5627. .. note::
  5628. See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for
  5629. additional information.
  5630. .. _runtime-package-management-target-ipk:
  5631. Using IPK
  5632. ^^^^^^^^^
  5633. The ``opkg`` application performs runtime package management of IPK
  5634. packages. You must perform an initial setup for ``opkg`` on the target
  5635. machine if the
  5636. :term:`PACKAGE_FEED_ARCHS`,
  5637. :term:`PACKAGE_FEED_BASE_PATHS`,
  5638. and
  5639. :term:`PACKAGE_FEED_URIS`
  5640. variables have not been set or the target image was built before the
  5641. variables were set.
  5642. The ``opkg`` application uses configuration files to find available
  5643. package databases. Thus, you need to create a configuration file inside
  5644. the ``/etc/opkg/`` direction, which informs ``opkg`` of any repository
  5645. you want to use.
  5646. As an example, suppose you are serving packages from a ``ipk/``
  5647. directory containing the ``i586``, ``all``, and ``qemux86`` databases
  5648. through an HTTP server named ``my.server``. On the target, create a
  5649. configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/``
  5650. directory containing the following:
  5651. .. code-block:: none
  5652. src/gz all http://my.server/ipk/all
  5653. src/gz i586 http://my.server/ipk/i586
  5654. src/gz qemux86 http://my.server/ipk/qemux86
  5655. Next, instruct ``opkg`` to fetch the
  5656. repository information:
  5657. .. code-block:: none
  5658. # opkg update
  5659. The ``opkg`` application is now able to find, install, and upgrade packages
  5660. from the specified repository.
  5661. .. _runtime-package-management-target-deb:
  5662. Using DEB
  5663. ^^^^^^^^^
  5664. The ``apt`` application performs runtime package management of DEB
  5665. packages. This application uses a source list file to find available
  5666. package databases. You must perform an initial setup for ``apt`` on the
  5667. target machine if the
  5668. :term:`PACKAGE_FEED_ARCHS`,
  5669. :term:`PACKAGE_FEED_BASE_PATHS`,
  5670. and
  5671. :term:`PACKAGE_FEED_URIS`
  5672. variables have not been set or the target image was built before the
  5673. variables were set.
  5674. To inform ``apt`` of the repository you want to use, you might create a
  5675. list file (e.g. ``my_repo.list``) inside the
  5676. ``/etc/apt/sources.list.d/`` directory. As an example, suppose you are
  5677. serving packages from a ``deb/`` directory containing the ``i586``,
  5678. ``all``, and ``qemux86`` databases through an HTTP server named
  5679. ``my.server``. The list file should contain:
  5680. .. code-block:: none
  5681. deb http://my.server/deb/all ./
  5682. deb http://my.server/deb/i586 ./
  5683. deb http://my.server/deb/qemux86 ./
  5684. Next, instruct the ``apt`` application
  5685. to fetch the repository information:
  5686. .. code-block:: none
  5687. # apt-get update
  5688. After this step,
  5689. ``apt`` is able to find, install, and upgrade packages from the
  5690. specified repository.
  5691. Generating and Using Signed Packages
  5692. ------------------------------------
  5693. In order to add security to RPM packages used during a build, you can
  5694. take steps to securely sign them. Once a signature is verified, the
  5695. OpenEmbedded build system can use the package in the build. If security
  5696. fails for a signed package, the build system aborts the build.
  5697. This section describes how to sign RPM packages during a build and how
  5698. to use signed package feeds (repositories) when doing a build.
  5699. Signing RPM Packages
  5700. ~~~~~~~~~~~~~~~~~~~~
  5701. To enable signing RPM packages, you must set up the following
  5702. configurations in either your ``local.config`` or ``distro.config``
  5703. file:
  5704. ::
  5705. # Inherit sign_rpm.bbclass to enable signing functionality
  5706. INHERIT += " sign_rpm"
  5707. # Define the GPG key that will be used for signing.
  5708. RPM_GPG_NAME = "key_name"
  5709. # Provide passphrase for the key
  5710. RPM_GPG_PASSPHRASE = "passphrase"
  5711. .. note::
  5712. Be sure to supply appropriate values for both `key_name` and
  5713. `passphrase`.
  5714. Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in
  5715. the previous example, two optional variables related to signing exist:
  5716. - *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed
  5717. when the package is signed.
  5718. - *GPG_PATH:* Specifies the ``gpg`` home directory used when the
  5719. package is signed.
  5720. Processing Package Feeds
  5721. ~~~~~~~~~~~~~~~~~~~~~~~~
  5722. In addition to being able to sign RPM packages, you can also enable
  5723. signed package feeds for IPK and RPM packages.
  5724. The steps you need to take to enable signed package feed use are similar
  5725. to the steps used to sign RPM packages. You must define the following in
  5726. your ``local.config`` or ``distro.config`` file:
  5727. ::
  5728. INHERIT += "sign_package_feed"
  5729. PACKAGE_FEED_GPG_NAME = "key_name"
  5730. PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase"
  5731. For signed package feeds, the passphrase must exist in a separate file,
  5732. which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE``
  5733. variable. Regarding security, keeping a plain text passphrase out of the
  5734. configuration is more secure.
  5735. Aside from the ``PACKAGE_FEED_GPG_NAME`` and
  5736. ``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables
  5737. related to signed package feeds exist:
  5738. - *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed
  5739. when the package is signed.
  5740. - *GPG_PATH:* Specifies the ``gpg`` home directory used when the
  5741. package is signed.
  5742. - *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg``
  5743. signature. This variable applies only to RPM and IPK package feeds.
  5744. Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are
  5745. "ASC", which is the default and specifies ascii armored, and "BIN",
  5746. which specifies binary.
  5747. Testing Packages With ptest
  5748. ---------------------------
  5749. A Package Test (ptest) runs tests against packages built by the
  5750. OpenEmbedded build system on the target machine. A ptest contains at
  5751. least two items: the actual test, and a shell script (``run-ptest``)
  5752. that starts the test. The shell script that starts the test must not
  5753. contain the actual test - the script only starts the test. On the other
  5754. hand, the test can be anything from a simple shell script that runs a
  5755. binary and checks the output to an elaborate system of test binaries and
  5756. data files.
  5757. The test generates output in the format used by Automake:
  5758. ::
  5759. result: testname
  5760. where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and
  5761. the testname can be any identifying string.
  5762. For a list of Yocto Project recipes that are already enabled with ptest,
  5763. see the :yocto_wiki:`Ptest </wiki/Ptest>` wiki page.
  5764. .. note::
  5765. A recipe is "ptest-enabled" if it inherits the
  5766. :ref:`ptest <ref-classes-ptest>` class.
  5767. Adding ptest to Your Build
  5768. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  5769. To add package testing to your build, add the
  5770. :term:`DISTRO_FEATURES` and
  5771. :term:`EXTRA_IMAGE_FEATURES`
  5772. variables to your ``local.conf`` file, which is found in the
  5773. :term:`Build Directory`:
  5774. ::
  5775. DISTRO_FEATURES_append = " ptest"
  5776. EXTRA_IMAGE_FEATURES += "ptest-pkgs"
  5777. Once your build is complete, the ptest files are installed into the
  5778. ``/usr/lib/package/ptest`` directory within the image, where ``package``
  5779. is the name of the package.
  5780. Running ptest
  5781. ~~~~~~~~~~~~~
  5782. The ``ptest-runner`` package installs a shell script that loops through
  5783. all installed ptest test suites and runs them in sequence. Consequently,
  5784. you might want to add this package to your image.
  5785. Getting Your Package Ready
  5786. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  5787. In order to enable a recipe to run installed ptests on target hardware,
  5788. you need to prepare the recipes that build the packages you want to
  5789. test. Here is what you have to do for each recipe:
  5790. - *Be sure the recipe inherits
  5791. the* :ref:`ptest <ref-classes-ptest>` *class:*
  5792. Include the following line in each recipe:
  5793. ::
  5794. inherit ptest
  5795. - *Create run-ptest:* This script starts your test. Locate the
  5796. script where you will refer to it using
  5797. :term:`SRC_URI`. Here is an
  5798. example that starts a test for ``dbus``:
  5799. ::
  5800. #!/bin/sh
  5801. cd test
  5802. make -k runtest-TESTS
  5803. - *Ensure dependencies are met:* If the test adds build or runtime
  5804. dependencies that normally do not exist for the package (such as
  5805. requiring "make" to run the test suite), use the
  5806. :term:`DEPENDS` and
  5807. :term:`RDEPENDS` variables in
  5808. your recipe in order for the package to meet the dependencies. Here
  5809. is an example where the package has a runtime dependency on "make":
  5810. ::
  5811. RDEPENDS_${PN}-ptest += "make"
  5812. - *Add a function to build the test suite:* Not many packages support
  5813. cross-compilation of their test suites. Consequently, you usually
  5814. need to add a cross-compilation function to the package.
  5815. Many packages based on Automake compile and run the test suite by
  5816. using a single command such as ``make check``. However, the host
  5817. ``make check`` builds and runs on the same computer, while
  5818. cross-compiling requires that the package is built on the host but
  5819. executed for the target architecture (though often, as in the case
  5820. for ptest, the execution occurs on the host). The built version of
  5821. Automake that ships with the Yocto Project includes a patch that
  5822. separates building and execution. Consequently, packages that use the
  5823. unaltered, patched version of ``make check`` automatically
  5824. cross-compiles.
  5825. Regardless, you still must add a ``do_compile_ptest`` function to
  5826. build the test suite. Add a function similar to the following to your
  5827. recipe:
  5828. ::
  5829. do_compile_ptest() {
  5830. oe_runmake buildtest-TESTS
  5831. }
  5832. - *Ensure special configurations are set:* If the package requires
  5833. special configurations prior to compiling the test code, you must
  5834. insert a ``do_configure_ptest`` function into the recipe.
  5835. - *Install the test suite:* The ``ptest`` class automatically copies
  5836. the file ``run-ptest`` to the target and then runs make
  5837. ``install-ptest`` to run the tests. If this is not enough, you need
  5838. to create a ``do_install_ptest`` function and make sure it gets
  5839. called after the "make install-ptest" completes.
  5840. Creating Node Package Manager (NPM) Packages
  5841. --------------------------------------------
  5842. `NPM <https://en.wikipedia.org/wiki/Npm_(software)>`__ is a package
  5843. manager for the JavaScript programming language. The Yocto Project
  5844. supports the NPM :ref:`fetcher <bitbake:bb-fetchers>`. You can
  5845. use this fetcher in combination with
  5846. :doc:`devtool <../ref-manual/ref-devtool-reference>` to create
  5847. recipes that produce NPM packages.
  5848. Two workflows exist that allow you to create NPM packages using
  5849. ``devtool``: the NPM registry modules method and the NPM project code
  5850. method.
  5851. .. note::
  5852. While it is possible to create NPM recipes manually, using
  5853. ``devtool`` is far simpler.
  5854. Additionally, some requirements and caveats exist.
  5855. .. _npm-package-creation-requirements:
  5856. Requirements and Caveats
  5857. ~~~~~~~~~~~~~~~~~~~~~~~~
  5858. You need to be aware of the following before using ``devtool`` to create
  5859. NPM packages:
  5860. - Of the two methods that you can use ``devtool`` to create NPM
  5861. packages, the registry approach is slightly simpler. However, you
  5862. might consider the project approach because you do not have to
  5863. publish your module in the NPM registry
  5864. (`npm-registry <https://docs.npmjs.com/misc/registry>`_), which
  5865. is NPM's public registry.
  5866. - Be familiar with
  5867. :doc:`devtool <../ref-manual/ref-devtool-reference>`.
  5868. - The NPM host tools need the native ``nodejs-npm`` package, which is
  5869. part of the OpenEmbedded environment. You need to get the package by
  5870. cloning the https://github.com/openembedded/meta-openembedded
  5871. repository out of GitHub. Be sure to add the path to your local copy
  5872. to your ``bblayers.conf`` file.
  5873. - ``devtool`` cannot detect native libraries in module dependencies.
  5874. Consequently, you must manually add packages to your recipe.
  5875. - While deploying NPM packages, ``devtool`` cannot determine which
  5876. dependent packages are missing on the target (e.g. the node runtime
  5877. ``nodejs``). Consequently, you need to find out what files are
  5878. missing and be sure they are on the target.
  5879. - Although you might not need NPM to run your node package, it is
  5880. useful to have NPM on your target. The NPM package name is
  5881. ``nodejs-npm``.
  5882. .. _npm-using-the-registry-modules-method:
  5883. Using the Registry Modules Method
  5884. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5885. This section presents an example that uses the ``cute-files`` module,
  5886. which is a file browser web application.
  5887. .. note::
  5888. You must know the ``cute-files`` module version.
  5889. The first thing you need to do is use ``devtool`` and the NPM fetcher to
  5890. create the recipe:
  5891. ::
  5892. $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2"
  5893. The
  5894. ``devtool add`` command runs ``recipetool create`` and uses the same
  5895. fetch URI to download each dependency and capture license details where
  5896. possible. The result is a generated recipe.
  5897. The recipe file is fairly simple and contains every license that
  5898. ``recipetool`` finds and includes the licenses in the recipe's
  5899. :term:`LIC_FILES_CHKSUM`
  5900. variables. You need to examine the variables and look for those with
  5901. "unknown" in the :term:`LICENSE`
  5902. field. You need to track down the license information for "unknown"
  5903. modules and manually add the information to the recipe.
  5904. ``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap
  5905. files capture the version of all dependent modules. Many packages do not
  5906. provide shrinkwrap files. ``recipetool`` create a shrinkwrap file as it
  5907. runs.
  5908. .. note::
  5909. A package is created for each sub-module. This policy is the only
  5910. practical way to have the licenses for all of the dependencies
  5911. represented in the license manifest of the image.
  5912. The ``devtool edit-recipe`` command lets you take a look at the recipe:
  5913. ::
  5914. $ devtool edit-recipe cute-files
  5915. SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
  5916. LICENSE = "MIT & ISC & Unknown"
  5917. LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
  5918. file://node_modules/toidentifier/LICENSE;md5=1a261071a044d02eb6f2bb47f51a3502 \
  5919. file://node_modules/debug/LICENSE;md5=ddd815a475e7338b0be7a14d8ee35a99 \
  5920. ...
  5921. SRC_URI = " \
  5922. npm://registry.npmjs.org/;package=cute-files;version=${PV} \
  5923. npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
  5924. "
  5925. S = "${WORKDIR}/npm"
  5926. inherit npm LICENSE_${PN} = "MIT"
  5927. LICENSE_${PN}-accepts = "MIT"
  5928. LICENSE_${PN}-array-flatten = "MIT"
  5929. ...
  5930. LICENSE_${PN}-vary = "MIT"
  5931. Three key points exist in the previous example:
  5932. - :term:`SRC_URI` uses the NPM
  5933. scheme so that the NPM fetcher is used.
  5934. - ``recipetool`` collects all the license information. If a
  5935. sub-module's license is unavailable, the sub-module's name appears in
  5936. the comments.
  5937. - The ``inherit npm`` statement causes the
  5938. :ref:`npm <ref-classes-npm>` class to package
  5939. up all the modules.
  5940. You can run the following command to build the ``cute-files`` package:
  5941. ::
  5942. $ devtool build cute-files
  5943. Remember that ``nodejs`` must be installed on
  5944. the target before your package.
  5945. Assuming 192.168.7.2 for the target's IP address, use the following
  5946. command to deploy your package:
  5947. ::
  5948. $ devtool deploy-target -s cute-files root@192.168.7.2
  5949. Once the package is installed on the target, you can
  5950. test the application:
  5951. .. note::
  5952. Because of a known issue, you cannot simply run ``cute-files`` as you would
  5953. if you had run ``npm install``.
  5954. ::
  5955. $ cd /usr/lib/node_modules/cute-files
  5956. $ node cute-files.js
  5957. On a browser,
  5958. go to ``http://192.168.7.2:3000`` and you see the following:
  5959. .. image:: figures/cute-files-npm-example.png
  5960. :align: center
  5961. You can find the recipe in ``workspace/recipes/cute-files``. You can use
  5962. the recipe in any layer you choose.
  5963. .. _npm-using-the-npm-projects-method:
  5964. Using the NPM Projects Code Method
  5965. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5966. Although it is useful to package modules already in the NPM registry,
  5967. adding ``node.js`` projects under development is a more common developer
  5968. use case.
  5969. This section covers the NPM projects code method, which is very similar
  5970. to the "registry" approach described in the previous section. In the NPM
  5971. projects method, you provide ``devtool`` with an URL that points to the
  5972. source files.
  5973. Replicating the same example, (i.e. ``cute-files``) use the following
  5974. command:
  5975. ::
  5976. $ devtool add https://github.com/martinaglv/cute-files.git
  5977. The
  5978. recipe this command generates is very similar to the recipe created in
  5979. the previous section. However, the ``SRC_URI`` looks like the following:
  5980. ::
  5981. SRC_URI = " \
  5982. git://github.com/martinaglv/cute-files.git;protocol=https \
  5983. npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
  5984. "
  5985. In this example,
  5986. the main module is taken from the Git repository and dependencies are
  5987. taken from the NPM registry. Other than those differences, the recipe is
  5988. basically the same between the two methods. You can build and deploy the
  5989. package exactly as described in the previous section that uses the
  5990. registry modules method.
  5991. Adding custom metadata to packages
  5992. ----------------------------------
  5993. The variable
  5994. :term:`PACKAGE_ADD_METADATA`
  5995. can be used to add additional metadata to packages. This is reflected in
  5996. the package control/spec file. To take the ipk format for example, the
  5997. CONTROL file stored inside would contain the additional metadata as
  5998. additional lines.
  5999. The variable can be used in multiple ways, including using suffixes to
  6000. set it for a specific package type and/or package. Note that the order
  6001. of precedence is the same as this list:
  6002. - ``PACKAGE_ADD_METADATA_<PKGTYPE>_<PN>``
  6003. - ``PACKAGE_ADD_METADATA_<PKGTYPE>``
  6004. - ``PACKAGE_ADD_METADATA_<PN>``
  6005. - ``PACKAGE_ADD_METADATA``
  6006. `<PKGTYPE>` is a parameter and expected to be a distinct name of specific
  6007. package type:
  6008. - IPK for .ipk packages
  6009. - DEB for .deb packages
  6010. - RPM for .rpm packages
  6011. `<PN>` is a parameter and expected to be a package name.
  6012. The variable can contain multiple [one-line] metadata fields separated
  6013. by the literal sequence '\\n'. The separator can be redefined using the
  6014. variable flag ``separator``.
  6015. The following is an example that adds two custom fields for ipk
  6016. packages:
  6017. ::
  6018. PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets"
  6019. Efficiently Fetching Source Files During a Build
  6020. ================================================
  6021. The OpenEmbedded build system works with source files located through
  6022. the :term:`SRC_URI` variable. When
  6023. you build something using BitBake, a big part of the operation is
  6024. locating and downloading all the source tarballs. For images,
  6025. downloading all the source for various packages can take a significant
  6026. amount of time.
  6027. This section shows you how you can use mirrors to speed up fetching
  6028. source files and how you can pre-fetch files all of which leads to more
  6029. efficient use of resources and time.
  6030. Setting up Effective Mirrors
  6031. ----------------------------
  6032. A good deal that goes into a Yocto Project build is simply downloading
  6033. all of the source tarballs. Maybe you have been working with another
  6034. build system (OpenEmbedded or Angstrom) for which you have built up a
  6035. sizable directory of source tarballs. Or, perhaps someone else has such
  6036. a directory for which you have read access. If so, you can save time by
  6037. adding statements to your configuration file so that the build process
  6038. checks local directories first for existing tarballs before checking the
  6039. Internet.
  6040. Here is an efficient way to set it up in your ``local.conf`` file:
  6041. ::
  6042. SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
  6043. INHERIT += "own-mirrors"
  6044. BB_GENERATE_MIRROR_TARBALLS = "1"
  6045. # BB_NO_NETWORK = "1"
  6046. In the previous example, the
  6047. :term:`BB_GENERATE_MIRROR_TARBALLS`
  6048. variable causes the OpenEmbedded build system to generate tarballs of
  6049. the Git repositories and store them in the
  6050. :term:`DL_DIR` directory. Due to
  6051. performance reasons, generating and storing these tarballs is not the
  6052. build system's default behavior.
  6053. You can also use the
  6054. :term:`PREMIRRORS` variable. For
  6055. an example, see the variable's glossary entry in the Yocto Project
  6056. Reference Manual.
  6057. Getting Source Files and Suppressing the Build
  6058. ----------------------------------------------
  6059. Another technique you can use to ready yourself for a successive string
  6060. of build operations, is to pre-fetch all the source files without
  6061. actually starting a build. This technique lets you work through any
  6062. download issues and ultimately gathers all the source files into your
  6063. download directory :ref:`structure-build-downloads`,
  6064. which is located with :term:`DL_DIR`.
  6065. Use the following BitBake command form to fetch all the necessary
  6066. sources without starting the build:
  6067. ::
  6068. $ bitbake target --runall=fetch
  6069. This
  6070. variation of the BitBake command guarantees that you have all the
  6071. sources for that BitBake target should you disconnect from the Internet
  6072. and want to do the build later offline.
  6073. Selecting an Initialization Manager
  6074. ===================================
  6075. By default, the Yocto Project uses SysVinit as the initialization
  6076. manager. However, support also exists for systemd, which is a full
  6077. replacement for init with parallel starting of services, reduced shell
  6078. overhead and other features that are used by many distributions.
  6079. Within the system, SysVinit treats system components as services. These
  6080. services are maintained as shell scripts stored in the ``/etc/init.d/``
  6081. directory. Services organize into different run levels. This
  6082. organization is maintained by putting links to the services in the
  6083. ``/etc/rcN.d/`` directories, where `N/` is one of the following options:
  6084. "S", "0", "1", "2", "3", "4", "5", or "6".
  6085. .. note::
  6086. Each runlevel has a dependency on the previous runlevel. This
  6087. dependency allows the services to work properly.
  6088. In comparison, systemd treats components as units. Using units is a
  6089. broader concept as compared to using a service. A unit includes several
  6090. different types of entities. Service is one of the types of entities.
  6091. The runlevel concept in SysVinit corresponds to the concept of a target
  6092. in systemd, where target is also a type of supported unit.
  6093. In a SysVinit-based system, services load sequentially (i.e. one by one)
  6094. during init and parallelization is not supported. With systemd, services
  6095. start in parallel. Needless to say, the method can have an impact on
  6096. system startup performance.
  6097. If you want to use SysVinit, you do not have to do anything. But, if you
  6098. want to use systemd, you must take some steps as described in the
  6099. following sections.
  6100. Using systemd Exclusively
  6101. -------------------------
  6102. Set these variables in your distribution configuration file as follows:
  6103. ::
  6104. DISTRO_FEATURES_append = " systemd"
  6105. VIRTUAL-RUNTIME_init_manager = "systemd"
  6106. You can also prevent the SysVinit distribution feature from
  6107. being automatically enabled as follows:
  6108. ::
  6109. DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
  6110. Doing so removes any
  6111. redundant SysVinit scripts.
  6112. To remove initscripts from your image altogether, set this variable
  6113. also:
  6114. ::
  6115. VIRTUAL-RUNTIME_initscripts = ""
  6116. For information on the backfill variable, see
  6117. :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`.
  6118. Using systemd for the Main Image and Using SysVinit for the Rescue Image
  6119. ------------------------------------------------------------------------
  6120. Set these variables in your distribution configuration file as follows:
  6121. ::
  6122. DISTRO_FEATURES_append = " systemd"
  6123. VIRTUAL-RUNTIME_init_manager = "systemd"
  6124. Doing so causes your main image to use the
  6125. ``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal
  6126. image cannot use this package group. However, it can install SysVinit
  6127. and the appropriate packages will have support for both systemd and
  6128. SysVinit.
  6129. .. _selecting-dev-manager:
  6130. Selecting a Device Manager
  6131. ==========================
  6132. The Yocto Project provides multiple ways to manage the device manager
  6133. (``/dev``):
  6134. - Persistent and Pre-Populated\ ``/dev``: For this case, the ``/dev``
  6135. directory is persistent and the required device nodes are created
  6136. during the build.
  6137. - Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev``
  6138. directory is provided by the kernel as an in-memory file system and
  6139. is automatically populated by the kernel at runtime. Additional
  6140. configuration of device nodes is done in user space by a device
  6141. manager like ``udev`` or ``busybox-mdev``.
  6142. .. _static-dev-management:
  6143. Using Persistent and Pre-Populated\ ``/dev``
  6144. --------------------------------------------
  6145. To use the static method for device population, you need to set the
  6146. :term:`USE_DEVFS` variable to "0"
  6147. as follows:
  6148. ::
  6149. USE_DEVFS = "0"
  6150. The content of the resulting ``/dev`` directory is defined in a Device
  6151. Table file. The
  6152. :term:`IMAGE_DEVICE_TABLES`
  6153. variable defines the Device Table to use and should be set in the
  6154. machine or distro configuration file. Alternatively, you can set this
  6155. variable in your ``local.conf`` configuration file.
  6156. If you do not define the ``IMAGE_DEVICE_TABLES`` variable, the default
  6157. ``device_table-minimal.txt`` is used:
  6158. ::
  6159. IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
  6160. The population is handled by the ``makedevs`` utility during image
  6161. creation:
  6162. .. _devtmpfs-dev-management:
  6163. Using ``devtmpfs`` and a Device Manager
  6164. ---------------------------------------
  6165. To use the dynamic method for device population, you need to use (or be
  6166. sure to set) the :term:`USE_DEVFS`
  6167. variable to "1", which is the default:
  6168. ::
  6169. USE_DEVFS = "1"
  6170. With this
  6171. setting, the resulting ``/dev`` directory is populated by the kernel
  6172. using ``devtmpfs``. Make sure the corresponding kernel configuration
  6173. variable ``CONFIG_DEVTMPFS`` is set when building you build a Linux
  6174. kernel.
  6175. All devices created by ``devtmpfs`` will be owned by ``root`` and have
  6176. permissions ``0600``.
  6177. To have more control over the device nodes, you can use a device manager
  6178. like ``udev`` or ``busybox-mdev``. You choose the device manager by
  6179. defining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or
  6180. distro configuration file. Alternatively, you can set this variable in
  6181. your ``local.conf`` configuration file:
  6182. ::
  6183. VIRTUAL-RUNTIME_dev_manager = "udev"
  6184. # Some alternative values
  6185. # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
  6186. # VIRTUAL-RUNTIME_dev_manager = "systemd"
  6187. .. _platdev-appdev-srcrev:
  6188. Using an External SCM
  6189. =====================
  6190. If you're working on a recipe that pulls from an external Source Code
  6191. Manager (SCM), it is possible to have the OpenEmbedded build system
  6192. notice new recipe changes added to the SCM and then build the resulting
  6193. packages that depend on the new recipes by using the latest versions.
  6194. This only works for SCMs from which it is possible to get a sensible
  6195. revision number for changes. Currently, you can do this with Apache
  6196. Subversion (SVN), Git, and Bazaar (BZR) repositories.
  6197. To enable this behavior, the :term:`PV` of
  6198. the recipe needs to reference
  6199. :term:`SRCPV`. Here is an example:
  6200. ::
  6201. PV = "1.2.3+git${SRCPV}"
  6202. Then, you can add the following to your
  6203. ``local.conf``:
  6204. ::
  6205. SRCREV_pn-PN = "${AUTOREV}"
  6206. :term:`PN` is the name of the recipe for
  6207. which you want to enable automatic source revision updating.
  6208. If you do not want to update your local configuration file, you can add
  6209. the following directly to the recipe to finish enabling the feature:
  6210. ::
  6211. SRCREV = "${AUTOREV}"
  6212. The Yocto Project provides a distribution named ``poky-bleeding``, whose
  6213. configuration file contains the line:
  6214. ::
  6215. require conf/distro/include/poky-floating-revisions.inc
  6216. This line pulls in the
  6217. listed include file that contains numerous lines of exactly that form:
  6218. ::
  6219. #SRCREV_pn-opkg-native ?= "${AUTOREV}"
  6220. #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
  6221. #SRCREV_pn-opkg ?= "${AUTOREV}"
  6222. #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
  6223. #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
  6224. SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
  6225. SRCREV_pn-matchbox-common ?= "${AUTOREV}"
  6226. SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
  6227. SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
  6228. SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
  6229. SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
  6230. SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
  6231. SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
  6232. SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
  6233. SRCREV_pn-settings-daemon ?= "${AUTOREV}"
  6234. SRCREV_pn-screenshot ?= "${AUTOREV}"
  6235. . . .
  6236. These lines allow you to
  6237. experiment with building a distribution that tracks the latest
  6238. development source for numerous packages.
  6239. .. note::
  6240. The ``poky-bleeding`` distribution is not tested on a regular basis. Keep
  6241. this in mind if you use it.
  6242. Creating a Read-Only Root Filesystem
  6243. ====================================
  6244. Suppose, for security reasons, you need to disable your target device's
  6245. root filesystem's write permissions (i.e. you need a read-only root
  6246. filesystem). Or, perhaps you are running the device's operating system
  6247. from a read-only storage device. For either case, you can customize your
  6248. image for that behavior.
  6249. .. note::
  6250. Supporting a read-only root filesystem requires that the system and
  6251. applications do not try to write to the root filesystem. You must
  6252. configure all parts of the target system to write elsewhere, or to
  6253. gracefully fail in the event of attempting to write to the root
  6254. filesystem.
  6255. Creating the Root Filesystem
  6256. ----------------------------
  6257. To create the read-only root filesystem, simply add the
  6258. "read-only-rootfs" feature to your image, normally in one of two ways.
  6259. The first way is to add the "read-only-rootfs" image feature in the
  6260. image's recipe file via the ``IMAGE_FEATURES`` variable:
  6261. ::
  6262. IMAGE_FEATURES += "read-only-rootfs"
  6263. As an alternative, you can add the same feature
  6264. from within your build directory's ``local.conf`` file with the
  6265. associated ``EXTRA_IMAGE_FEATURES`` variable, as in:
  6266. ::
  6267. EXTRA_IMAGE_FEATURES = "read-only-rootfs"
  6268. For more information on how to use these variables, see the
  6269. ":ref:`usingpoky-extend-customimage-imagefeatures`"
  6270. section. For information on the variables, see
  6271. :term:`IMAGE_FEATURES` and
  6272. :term:`EXTRA_IMAGE_FEATURES`.
  6273. Post-Installation Scripts and Read-Only Root Filesystem
  6274. -------------------------------------------------------
  6275. It is very important that you make sure all post-Installation
  6276. (``pkg_postinst``) scripts for packages that are installed into the
  6277. image can be run at the time when the root filesystem is created during
  6278. the build on the host system. These scripts cannot attempt to run during
  6279. first-boot on the target device. With the "read-only-rootfs" feature
  6280. enabled, the build system checks during root filesystem creation to make
  6281. sure all post-installation scripts succeed. If any of these scripts
  6282. still need to be run after the root filesystem is created, the build
  6283. immediately fails. These build-time checks ensure that the build fails
  6284. rather than the target device fails later during its initial boot
  6285. operation.
  6286. Most of the common post-installation scripts generated by the build
  6287. system for the out-of-the-box Yocto Project are engineered so that they
  6288. can run during root filesystem creation (e.g. post-installation scripts
  6289. for caching fonts). However, if you create and add custom scripts, you
  6290. need to be sure they can be run during this file system creation.
  6291. Here are some common problems that prevent post-installation scripts
  6292. from running during root filesystem creation:
  6293. - *Not using $D in front of absolute paths:* The build system defines
  6294. ``$``\ :term:`D` when the root
  6295. filesystem is created. Furthermore, ``$D`` is blank when the script
  6296. is run on the target device. This implies two purposes for ``$D``:
  6297. ensuring paths are valid in both the host and target environments,
  6298. and checking to determine which environment is being used as a method
  6299. for taking appropriate actions.
  6300. - *Attempting to run processes that are specific to or dependent on the
  6301. target architecture:* You can work around these attempts by using
  6302. native tools, which run on the host system, to accomplish the same
  6303. tasks, or by alternatively running the processes under QEMU, which
  6304. has the ``qemu_run_binary`` function. For more information, see the
  6305. :ref:`qemu <ref-classes-qemu>` class.
  6306. Areas With Write Access
  6307. -----------------------
  6308. With the "read-only-rootfs" feature enabled, any attempt by the target
  6309. to write to the root filesystem at runtime fails. Consequently, you must
  6310. make sure that you configure processes and applications that attempt
  6311. these types of writes do so to directories with write access (e.g.
  6312. ``/tmp`` or ``/var/run``).
  6313. Maintaining Build Output Quality
  6314. ================================
  6315. Many factors can influence the quality of a build. For example, if you
  6316. upgrade a recipe to use a new version of an upstream software package or
  6317. you experiment with some new configuration options, subtle changes can
  6318. occur that you might not detect until later. Consider the case where
  6319. your recipe is using a newer version of an upstream package. In this
  6320. case, a new version of a piece of software might introduce an optional
  6321. dependency on another library, which is auto-detected. If that library
  6322. has already been built when the software is building, the software will
  6323. link to the built library and that library will be pulled into your
  6324. image along with the new software even if you did not want the library.
  6325. The :ref:`buildhistory <ref-classes-buildhistory>`
  6326. class exists to help you maintain the quality of your build output. You
  6327. can use the class to highlight unexpected and possibly unwanted changes
  6328. in the build output. When you enable build history, it records
  6329. information about the contents of each package and image and then
  6330. commits that information to a local Git repository where you can examine
  6331. the information.
  6332. The remainder of this section describes the following:
  6333. - :ref:`How you can enable and disable build history <dev-manual/dev-manual-common-tasks:enabling and disabling build history>`
  6334. - :ref:`How to understand what the build history contains <dev-manual/dev-manual-common-tasks:understanding what the build history contains>`
  6335. - :ref:`How to limit the information used for build history <dev-manual/dev-manual-common-tasks:using build history to gather image information only>`
  6336. - :ref:`How to examine the build history from both a command-line and web interface <dev-manual/dev-manual-common-tasks:examining build history information>`
  6337. Enabling and Disabling Build History
  6338. ------------------------------------
  6339. Build history is disabled by default. To enable it, add the following
  6340. ``INHERIT`` statement and set the
  6341. :term:`BUILDHISTORY_COMMIT`
  6342. variable to "1" at the end of your ``conf/local.conf`` file found in the
  6343. :term:`Build Directory`:
  6344. ::
  6345. INHERIT += "buildhistory"
  6346. BUILDHISTORY_COMMIT = "1"
  6347. Enabling build history as
  6348. previously described causes the OpenEmbedded build system to collect
  6349. build output information and commit it as a single commit to a local
  6350. :ref:`overview-manual/overview-manual-development-environment:git` repository.
  6351. .. note::
  6352. Enabling build history increases your build times slightly,
  6353. particularly for images, and increases the amount of disk space used
  6354. during the build.
  6355. You can disable build history by removing the previous statements from
  6356. your ``conf/local.conf`` file.
  6357. Understanding What the Build History Contains
  6358. ---------------------------------------------
  6359. Build history information is kept in
  6360. ``${``\ :term:`TOPDIR`\ ``}/buildhistory``
  6361. in the Build Directory as defined by the
  6362. :term:`BUILDHISTORY_DIR`
  6363. variable. The following is an example abbreviated listing:
  6364. .. image:: figures/buildhistory.png
  6365. :align: center
  6366. At the top level, a ``metadata-revs`` file exists that lists the
  6367. revisions of the repositories for the enabled layers when the build was
  6368. produced. The rest of the data splits into separate ``packages``,
  6369. ``images`` and ``sdk`` directories, the contents of which are described
  6370. as follows.
  6371. Build History Package Information
  6372. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6373. The history for each package contains a text file that has name-value
  6374. pairs with information about the package. For example,
  6375. ``buildhistory/packages/i586-poky-linux/busybox/busybox/latest``
  6376. contains the following:
  6377. .. code-block:: none
  6378. PV = 1.22.1
  6379. PR = r32
  6380. RPROVIDES =
  6381. RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
  6382. RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
  6383. PKGSIZE = 540168
  6384. FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
  6385. /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
  6386. /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
  6387. /usr/share/pixmaps /usr/share/applications /usr/share/idl \
  6388. /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
  6389. FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
  6390. /etc/busybox.links.nosuid /etc/busybox.links.suid
  6391. Most of these
  6392. name-value pairs correspond to variables used to produce the package.
  6393. The exceptions are ``FILELIST``, which is the actual list of files in
  6394. the package, and ``PKGSIZE``, which is the total size of files in the
  6395. package in bytes.
  6396. A file also exists that corresponds to the recipe from which the package
  6397. came (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``):
  6398. .. code-block:: none
  6399. PV = 1.22.1
  6400. PR = r32
  6401. DEPENDS = initscripts kern-tools-native update-rc.d-native \
  6402. virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
  6403. virtual/libc virtual/update-alternatives
  6404. PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
  6405. busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
  6406. busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
  6407. Finally, for those recipes fetched from a version control system (e.g.,
  6408. Git), a file exists that lists source revisions that are specified in
  6409. the recipe and lists the actual revisions used during the build. Listed
  6410. and actual revisions might differ when
  6411. :term:`SRCREV` is set to
  6412. ${:term:`AUTOREV`}. Here is an
  6413. example assuming
  6414. ``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``):
  6415. ::
  6416. # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
  6417. SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
  6418. # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
  6419. SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f"
  6420. You can use the
  6421. ``buildhistory-collect-srcrevs`` command with the ``-a`` option to
  6422. collect the stored ``SRCREV`` values from build history and report them
  6423. in a format suitable for use in global configuration (e.g.,
  6424. ``local.conf`` or a distro include file) to override floating
  6425. ``AUTOREV`` values to a fixed set of revisions. Here is some example
  6426. output from this command:
  6427. ::
  6428. $ buildhistory-collect-srcrevs -a
  6429. # i586-poky-linux
  6430. SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
  6431. SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
  6432. SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
  6433. SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
  6434. # x86_64-linux
  6435. SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
  6436. SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
  6437. SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
  6438. SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
  6439. SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
  6440. SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
  6441. SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
  6442. SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
  6443. SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
  6444. # qemux86-poky-linux
  6445. SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
  6446. SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
  6447. # all-poky-linux
  6448. SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
  6449. .. note::
  6450. Here are some notes on using the ``buildhistory-collect-srcrevs`` command:
  6451. - By default, only values where the ``SRCREV`` was not hardcoded
  6452. (usually when ``AUTOREV`` is used) are reported. Use the ``-a``
  6453. option to see all ``SRCREV`` values.
  6454. - The output statements might not have any effect if overrides are
  6455. applied elsewhere in the build system configuration. Use the
  6456. ``-f`` option to add the ``forcevariable`` override to each output
  6457. line if you need to work around this restriction.
  6458. - The script does apply special handling when building for multiple
  6459. machines. However, the script does place a comment before each set
  6460. of values that specifies which triplet to which they belong as
  6461. previously shown (e.g., ``i586-poky-linux``).
  6462. Build History Image Information
  6463. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6464. The files produced for each image are as follows:
  6465. - ``image-files:`` A directory containing selected files from the root
  6466. filesystem. The files are defined by
  6467. :term:`BUILDHISTORY_IMAGE_FILES`.
  6468. - ``build-id.txt:`` Human-readable information about the build
  6469. configuration and metadata source revisions. This file contains the
  6470. full build header as printed by BitBake.
  6471. - ``*.dot:`` Dependency graphs for the image that are compatible with
  6472. ``graphviz``.
  6473. - ``files-in-image.txt:`` A list of files in the image with
  6474. permissions, owner, group, size, and symlink information.
  6475. - ``image-info.txt:`` A text file containing name-value pairs with
  6476. information about the image. See the following listing example for
  6477. more information.
  6478. - ``installed-package-names.txt:`` A list of installed packages by name
  6479. only.
  6480. - ``installed-package-sizes.txt:`` A list of installed packages ordered
  6481. by size.
  6482. - ``installed-packages.txt:`` A list of installed packages with full
  6483. package filenames.
  6484. .. note::
  6485. Installed package information is able to be gathered and produced
  6486. even if package management is disabled for the final image.
  6487. Here is an example of ``image-info.txt``:
  6488. .. code-block:: none
  6489. DISTRO = poky
  6490. DISTRO_VERSION = 1.7
  6491. USER_CLASSES = buildstats image-mklibs image-prelink
  6492. IMAGE_CLASSES = image_types
  6493. IMAGE_FEATURES = debug-tweaks
  6494. IMAGE_LINGUAS =
  6495. IMAGE_INSTALL = packagegroup-core-boot run-postinsts
  6496. BAD_RECOMMENDATIONS =
  6497. NO_RECOMMENDATIONS =
  6498. PACKAGE_EXCLUDE =
  6499. ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
  6500. write_image_manifest ; buildhistory_list_installed_image ; \
  6501. buildhistory_get_image_installed ; ssh_allow_empty_password; \
  6502. postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
  6503. IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
  6504. IMAGESIZE = 6900
  6505. Other than ``IMAGESIZE``,
  6506. which is the total size of the files in the image in Kbytes, the
  6507. name-value pairs are variables that may have influenced the content of
  6508. the image. This information is often useful when you are trying to
  6509. determine why a change in the package or file listings has occurred.
  6510. Using Build History to Gather Image Information Only
  6511. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6512. As you can see, build history produces image information, including
  6513. dependency graphs, so you can see why something was pulled into the
  6514. image. If you are just interested in this information and not interested
  6515. in collecting specific package or SDK information, you can enable
  6516. writing only image information without any history by adding the
  6517. following to your ``conf/local.conf`` file found in the
  6518. :term:`Build Directory`:
  6519. ::
  6520. INHERIT += "buildhistory"
  6521. BUILDHISTORY_COMMIT = "0"
  6522. BUILDHISTORY_FEATURES = "image"
  6523. Here, you set the
  6524. :term:`BUILDHISTORY_FEATURES`
  6525. variable to use the image feature only.
  6526. Build History SDK Information
  6527. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6528. Build history collects similar information on the contents of SDKs (e.g.
  6529. ``bitbake -c populate_sdk imagename``) as compared to information it
  6530. collects for images. Furthermore, this information differs depending on
  6531. whether an extensible or standard SDK is being produced.
  6532. The following list shows the files produced for SDKs:
  6533. - ``files-in-sdk.txt:`` A list of files in the SDK with permissions,
  6534. owner, group, size, and symlink information. This list includes both
  6535. the host and target parts of the SDK.
  6536. - ``sdk-info.txt:`` A text file containing name-value pairs with
  6537. information about the SDK. See the following listing example for more
  6538. information.
  6539. - ``sstate-task-sizes.txt:`` A text file containing name-value pairs
  6540. with information about task group sizes (e.g. ``do_populate_sysroot``
  6541. tasks have a total size). The ``sstate-task-sizes.txt`` file exists
  6542. only when an extensible SDK is created.
  6543. - ``sstate-package-sizes.txt:`` A text file containing name-value pairs
  6544. with information for the shared-state packages and sizes in the SDK.
  6545. The ``sstate-package-sizes.txt`` file exists only when an extensible
  6546. SDK is created.
  6547. - ``sdk-files:`` A folder that contains copies of the files mentioned
  6548. in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output.
  6549. Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is
  6550. specific to the extensible SDK although you can set it differently if
  6551. you would like to pull in specific files from the standard SDK.
  6552. The default files are ``conf/local.conf``, ``conf/bblayers.conf``,
  6553. ``conf/auto.conf``, ``conf/locked-sigs.inc``, and
  6554. ``conf/devtool.conf``. Thus, for an extensible SDK, these files get
  6555. copied into the ``sdk-files`` directory.
  6556. - The following information appears under each of the ``host`` and
  6557. ``target`` directories for the portions of the SDK that run on the
  6558. host and on the target, respectively:
  6559. .. note::
  6560. The following files for the most part are empty when producing an
  6561. extensible SDK because this type of SDK is not constructed from
  6562. packages as is the standard SDK.
  6563. - ``depends.dot:`` Dependency graph for the SDK that is compatible
  6564. with ``graphviz``.
  6565. - ``installed-package-names.txt:`` A list of installed packages by
  6566. name only.
  6567. - ``installed-package-sizes.txt:`` A list of installed packages
  6568. ordered by size.
  6569. - ``installed-packages.txt:`` A list of installed packages with full
  6570. package filenames.
  6571. Here is an example of ``sdk-info.txt``:
  6572. .. code-block:: none
  6573. DISTRO = poky
  6574. DISTRO_VERSION = 1.3+snapshot-20130327
  6575. SDK_NAME = poky-glibc-i686-arm
  6576. SDK_VERSION = 1.3+snapshot
  6577. SDKMACHINE =
  6578. SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
  6579. BAD_RECOMMENDATIONS =
  6580. SDKSIZE = 352712
  6581. Other than ``SDKSIZE``, which is
  6582. the total size of the files in the SDK in Kbytes, the name-value pairs
  6583. are variables that might have influenced the content of the SDK. This
  6584. information is often useful when you are trying to determine why a
  6585. change in the package or file listings has occurred.
  6586. Examining Build History Information
  6587. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6588. You can examine build history output from the command line or from a web
  6589. interface.
  6590. To see any changes that have occurred (assuming you have
  6591. :term:`BUILDHISTORY_COMMIT` = "1"),
  6592. you can simply use any Git command that allows you to view the history
  6593. of a repository. Here is one method:
  6594. ::
  6595. $ git log -p
  6596. You need to realize,
  6597. however, that this method does show changes that are not significant
  6598. (e.g. a package's size changing by a few bytes).
  6599. A command-line tool called ``buildhistory-diff`` does exist, though,
  6600. that queries the Git repository and prints just the differences that
  6601. might be significant in human-readable form. Here is an example:
  6602. ::
  6603. $ ~/poky/poky/scripts/buildhistory-diff . HEAD^
  6604. Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
  6605. /etc/anotherpkg.conf was added
  6606. /sbin/anotherpkg was added
  6607. * (installed-package-names.txt):
  6608. * anotherpkg was added
  6609. Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
  6610. anotherpkg was added
  6611. packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
  6612. * PR changed from "r0" to "r1"
  6613. * PV changed from "0.1.10" to "0.1.12"
  6614. packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
  6615. * PR changed from "r0" to "r1"
  6616. * PV changed from "0.1.10" to "0.1.12"
  6617. .. note::
  6618. The ``buildhistory-diff`` tool requires the ``GitPython``
  6619. package. Be sure to install it using Pip3 as follows:
  6620. ::
  6621. $ pip3 install GitPython --user
  6622. Alternatively, you can install ``python3-git`` using the appropriate
  6623. distribution package manager (e.g. ``apt-get``, ``dnf``, or ``zipper``).
  6624. To see changes to the build history using a web interface, follow the
  6625. instruction in the ``README`` file
  6626. :yocto_git:`here </cgit/cgit.cgi/buildhistory-web/>`.
  6627. Here is a sample screenshot of the interface:
  6628. .. image:: figures/buildhistory-web.png
  6629. :align: center
  6630. Performing Automated Runtime Testing
  6631. ====================================
  6632. The OpenEmbedded build system makes available a series of automated
  6633. tests for images to verify runtime functionality. You can run these
  6634. tests on either QEMU or actual target hardware. Tests are written in
  6635. Python making use of the ``unittest`` module, and the majority of them
  6636. run commands on the target system over SSH. This section describes how
  6637. you set up the environment to use these tests, run available tests, and
  6638. write and add your own tests.
  6639. For information on the test and QA infrastructure available within the
  6640. Yocto Project, see the ":ref:`ref-manual/ref-release-process:testing and quality assurance`"
  6641. section in the Yocto Project Reference Manual.
  6642. Enabling Tests
  6643. --------------
  6644. Depending on whether you are planning to run tests using QEMU or on the
  6645. hardware, you have to take different steps to enable the tests. See the
  6646. following subsections for information on how to enable both types of
  6647. tests.
  6648. .. _qemu-image-enabling-tests:
  6649. Enabling Runtime Tests on QEMU
  6650. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6651. In order to run tests, you need to do the following:
  6652. - *Set up to avoid interaction with sudo for networking:* To
  6653. accomplish this, you must do one of the following:
  6654. - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all
  6655. commands or just for ``runqemu-ifup``. You must provide the full
  6656. path as that can change if you are using multiple clones of the
  6657. source repository.
  6658. .. note::
  6659. On some distributions, you also need to comment out "Defaults
  6660. requiretty" in ``/etc/sudoers``.
  6661. - Manually configure a tap interface for your system.
  6662. - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which
  6663. should generate a list of tap devices. This is the option
  6664. typically chosen for Autobuilder-type environments.
  6665. .. note::
  6666. - Be sure to use an absolute path when calling this script
  6667. with sudo.
  6668. - Ensure that your host has the package ``iptables`` installed.
  6669. - The package recipe ``qemu-helper-native`` is required to run
  6670. this script. Build the package using the following command:
  6671. ::
  6672. $ bitbake qemu-helper-native
  6673. - *Set the DISPLAY variable:* You need to set this variable so that
  6674. you have an X server available (e.g. start ``vncserver`` for a
  6675. headless machine).
  6676. - *Be sure your host's firewall accepts incoming connections from
  6677. 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an
  6678. HTTP server on a random high number port, which is used to serve
  6679. files to the target. The DNF module serves
  6680. ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands.
  6681. That means your host's firewall must accept incoming connections from
  6682. 192.168.7.0/24, which is the default IP range used for tap devices by
  6683. ``runqemu``.
  6684. - *Be sure your host has the correct packages installed:* Depending
  6685. your host's distribution, you need to have the following packages
  6686. installed:
  6687. - Ubuntu and Debian: ``sysstat`` and ``iproute2``
  6688. - OpenSUSE: ``sysstat`` and ``iproute2``
  6689. - Fedora: ``sysstat`` and ``iproute``
  6690. - CentOS: ``sysstat`` and ``iproute``
  6691. Once you start running the tests, the following happens:
  6692. 1. A copy of the root filesystem is written to ``${WORKDIR}/testimage``.
  6693. 2. The image is booted under QEMU using the standard ``runqemu`` script.
  6694. 3. A default timeout of 500 seconds occurs to allow for the boot process
  6695. to reach the login prompt. You can change the timeout period by
  6696. setting
  6697. :term:`TEST_QEMUBOOT_TIMEOUT`
  6698. in the ``local.conf`` file.
  6699. 4. Once the boot process is reached and the login prompt appears, the
  6700. tests run. The full boot log is written to
  6701. ``${WORKDIR}/testimage/qemu_boot_log``.
  6702. 5. Each test module loads in the order found in ``TEST_SUITES``. You can
  6703. find the full output of the commands run over SSH in
  6704. ``${WORKDIR}/testimgage/ssh_target_log``.
  6705. 6. If no failures occur, the task running the tests ends successfully.
  6706. You can find the output from the ``unittest`` in the task log at
  6707. ``${WORKDIR}/temp/log.do_testimage``.
  6708. .. _hardware-image-enabling-tests:
  6709. Enabling Runtime Tests on Hardware
  6710. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6711. The OpenEmbedded build system can run tests on real hardware, and for
  6712. certain devices it can also deploy the image to be tested onto the
  6713. device beforehand.
  6714. For automated deployment, a "master image" is installed onto the
  6715. hardware once as part of setup. Then, each time tests are to be run, the
  6716. following occurs:
  6717. 1. The master image is booted into and used to write the image to be
  6718. tested to a second partition.
  6719. 2. The device is then rebooted using an external script that you need to
  6720. provide.
  6721. 3. The device boots into the image to be tested.
  6722. When running tests (independent of whether the image has been deployed
  6723. automatically or not), the device is expected to be connected to a
  6724. network on a pre-determined IP address. You can either use static IP
  6725. addresses written into the image, or set the image to use DHCP and have
  6726. your DHCP server on the test network assign a known IP address based on
  6727. the MAC address of the device.
  6728. In order to run tests on hardware, you need to set ``TEST_TARGET`` to an
  6729. appropriate value. For QEMU, you do not have to change anything, the
  6730. default value is "qemu". For running tests on hardware, the following
  6731. options exist:
  6732. - *"simpleremote":* Choose "simpleremote" if you are going to run tests
  6733. on a target system that is already running the image to be tested and
  6734. is available on the network. You can use "simpleremote" in
  6735. conjunction with either real hardware or an image running within a
  6736. separately started QEMU or any other virtual machine manager.
  6737. - *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is
  6738. an EFI-based machine with ``systemd-boot`` as bootloader and
  6739. ``core-image-testmaster`` (or something similar) is installed. Also,
  6740. your hardware under test must be in a DHCP-enabled network that gives
  6741. it the same IP address for each reboot.
  6742. If you choose "SystemdbootTarget", there are additional requirements
  6743. and considerations. See the "`Selecting
  6744. SystemdbootTarget <#selecting-systemdboottarget>`__" section, which
  6745. follows, for more information.
  6746. - *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying
  6747. images and running tests on the BeagleBone "Black" or original
  6748. "White" hardware. For information on how to use these tests, see the
  6749. comments at the top of the BeagleBoneTarget
  6750. ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file.
  6751. - *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying
  6752. images and running tests on the Ubiquiti Networks EdgeRouter Lite.
  6753. For information on how to use these tests, see the comments at the
  6754. top of the EdgeRouterTarget
  6755. ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file.
  6756. - *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running
  6757. tests on any generic PC that boots using GRUB. For information on how
  6758. to use these tests, see the comments at the top of the GrubTarget
  6759. ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file.
  6760. - *"your-target":* Create your own custom target if you want to run
  6761. tests when you are deploying images and running tests on a custom
  6762. machine within your BSP layer. To do this, you need to add a Python
  6763. unit that defines the target class under ``lib/oeqa/controllers/``
  6764. within your layer. You must also provide an empty ``__init__.py``.
  6765. For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``.
  6766. Selecting SystemdbootTarget
  6767. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6768. If you did not set ``TEST_TARGET`` to "SystemdbootTarget", then you do
  6769. not need any information in this section. You can skip down to the
  6770. "`Running Tests <#qemu-image-running-tests>`__" section.
  6771. If you did set ``TEST_TARGET`` to "SystemdbootTarget", you also need to
  6772. perform a one-time setup of your master image by doing the following:
  6773. 1. *Set EFI_PROVIDER:* Be sure that ``EFI_PROVIDER`` is as follows:
  6774. ::
  6775. EFI_PROVIDER = "systemd-boot"
  6776. 2. *Build the master image:* Build the ``core-image-testmaster`` image.
  6777. The ``core-image-testmaster`` recipe is provided as an example for a
  6778. "master" image and you can customize the image recipe as you would
  6779. any other recipe.
  6780. Here are the image recipe requirements:
  6781. - Inherits ``core-image`` so that kernel modules are installed.
  6782. - Installs normal linux utilities not busybox ones (e.g. ``bash``,
  6783. ``coreutils``, ``tar``, ``gzip``, and ``kmod``).
  6784. - Uses a custom Initial RAM Disk (initramfs) image with a custom
  6785. installer. A normal image that you can install usually creates a
  6786. single rootfs partition. This image uses another installer that
  6787. creates a specific partition layout. Not all Board Support
  6788. Packages (BSPs) can use an installer. For such cases, you need to
  6789. manually create the following partition layout on the target:
  6790. - First partition mounted under ``/boot``, labeled "boot".
  6791. - The main rootfs partition where this image gets installed,
  6792. which is mounted under ``/``.
  6793. - Another partition labeled "testrootfs" where test images get
  6794. deployed.
  6795. 3. *Install image:* Install the image that you just built on the target
  6796. system.
  6797. The final thing you need to do when setting ``TEST_TARGET`` to
  6798. "SystemdbootTarget" is to set up the test image:
  6799. 1. *Set up your local.conf file:* Make sure you have the following
  6800. statements in your ``local.conf`` file:
  6801. ::
  6802. IMAGE_FSTYPES += "tar.gz"
  6803. INHERIT += "testimage"
  6804. TEST_TARGET = "SystemdbootTarget"
  6805. TEST_TARGET_IP = "192.168.2.3"
  6806. 2. *Build your test image:* Use BitBake to build the image:
  6807. ::
  6808. $ bitbake core-image-sato
  6809. Power Control
  6810. ~~~~~~~~~~~~~
  6811. For most hardware targets other than "simpleremote", you can control
  6812. power:
  6813. - You can use ``TEST_POWERCONTROL_CMD`` together with
  6814. ``TEST_POWERCONTROL_EXTRA_ARGS`` as a command that runs on the host
  6815. and does power cycling. The test code passes one argument to that
  6816. command: off, on or cycle (off then on). Here is an example that
  6817. could appear in your ``local.conf`` file:
  6818. ::
  6819. TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
  6820. In this example, the expect
  6821. script does the following:
  6822. .. code-block:: shell
  6823. ssh test@10.11.12.1 "pyctl nuc1 arg"
  6824. It then runs a Python script that controls power for a label called
  6825. ``nuc1``.
  6826. .. note::
  6827. You need to customize ``TEST_POWERCONTROL_CMD`` and
  6828. ``TEST_POWERCONTROL_EXTRA_ARGS`` for your own setup. The one requirement
  6829. is that it accepts "on", "off", and "cycle" as the last argument.
  6830. - When no command is defined, it connects to the device over SSH and
  6831. uses the classic reboot command to reboot the device. Classic reboot
  6832. is fine as long as the machine actually reboots (i.e. the SSH test
  6833. has not failed). It is useful for scenarios where you have a simple
  6834. setup, typically with a single board, and where some manual
  6835. interaction is okay from time to time.
  6836. If you have no hardware to automatically perform power control but still
  6837. wish to experiment with automated hardware testing, you can use the
  6838. ``dialog-power-control`` script that shows a dialog prompting you to perform
  6839. the required power action. This script requires either KDialog or Zenity
  6840. to be installed. To use this script, set the
  6841. :term:`TEST_POWERCONTROL_CMD`
  6842. variable as follows:
  6843. ::
  6844. TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
  6845. Serial Console Connection
  6846. ~~~~~~~~~~~~~~~~~~~~~~~~~
  6847. For test target classes requiring a serial console to interact with the
  6848. bootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget),
  6849. you need to specify a command to use to connect to the serial console of
  6850. the target machine by using the
  6851. :term:`TEST_SERIALCONTROL_CMD`
  6852. variable and optionally the
  6853. :term:`TEST_SERIALCONTROL_EXTRA_ARGS`
  6854. variable.
  6855. These cases could be a serial terminal program if the machine is
  6856. connected to a local serial port, or a ``telnet`` or ``ssh`` command
  6857. connecting to a remote console server. Regardless of the case, the
  6858. command simply needs to connect to the serial console and forward that
  6859. connection to standard input and output as any normal terminal program
  6860. does. For example, to use the picocom terminal program on serial device
  6861. ``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows:
  6862. ::
  6863. TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
  6864. For local
  6865. devices where the serial port device disappears when the device reboots,
  6866. an additional "serdevtry" wrapper script is provided. To use this
  6867. wrapper, simply prefix the terminal command with
  6868. ``${COREBASE}/scripts/contrib/serdevtry``:
  6869. ::
  6870. TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0"
  6871. .. _qemu-image-running-tests:
  6872. Running Tests
  6873. -------------
  6874. You can start the tests automatically or manually:
  6875. - *Automatically running tests:* To run the tests automatically after
  6876. the OpenEmbedded build system successfully creates an image, first
  6877. set the
  6878. :term:`TESTIMAGE_AUTO`
  6879. variable to "1" in your ``local.conf`` file in the
  6880. :term:`Build Directory`:
  6881. ::
  6882. TESTIMAGE_AUTO = "1"
  6883. Next, build your image. If the image successfully builds, the
  6884. tests run:
  6885. ::
  6886. bitbake core-image-sato
  6887. - *Manually running tests:* To manually run the tests, first globally
  6888. inherit the
  6889. :ref:`testimage <ref-classes-testimage*>` class
  6890. by editing your ``local.conf`` file:
  6891. ::
  6892. INHERIT += "testimage"
  6893. Next, use BitBake to run the tests:
  6894. ::
  6895. bitbake -c testimage image
  6896. All test files reside in ``meta/lib/oeqa/runtime`` in the
  6897. :term:`Source Directory`. A test name maps
  6898. directly to a Python module. Each test module may contain a number of
  6899. individual tests. Tests are usually grouped together by the area tested
  6900. (e.g tests for systemd reside in ``meta/lib/oeqa/runtime/systemd.py``).
  6901. You can add tests to any layer provided you place them in the proper
  6902. area and you extend :term:`BBPATH` in
  6903. the ``local.conf`` file as normal. Be sure that tests reside in
  6904. ``layer/lib/oeqa/runtime``.
  6905. .. note::
  6906. Be sure that module names do not collide with module names used in
  6907. the default set of test modules in ``meta/lib/oeqa/runtime``.
  6908. You can change the set of tests run by appending or overriding
  6909. :term:`TEST_SUITES` variable in
  6910. ``local.conf``. Each name in ``TEST_SUITES`` represents a required test
  6911. for the image. Test modules named within ``TEST_SUITES`` cannot be
  6912. skipped even if a test is not suitable for an image (e.g. running the
  6913. RPM tests on an image without ``rpm``). Appending "auto" to
  6914. ``TEST_SUITES`` causes the build system to try to run all tests that are
  6915. suitable for the image (i.e. each test module may elect to skip itself).
  6916. The order you list tests in ``TEST_SUITES`` is important and influences
  6917. test dependencies. Consequently, tests that depend on other tests should
  6918. be added after the test on which they depend. For example, since the
  6919. ``ssh`` test depends on the ``ping`` test, "ssh" needs to come after
  6920. "ping" in the list. The test class provides no re-ordering or dependency
  6921. handling.
  6922. .. note::
  6923. Each module can have multiple classes with multiple test methods.
  6924. And, Python ``unittest`` rules apply.
  6925. Here are some things to keep in mind when running tests:
  6926. - The default tests for the image are defined as:
  6927. ::
  6928. DEFAULT_TEST_SUITES_pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg"
  6929. - Add your own test to the list of the by using the following:
  6930. ::
  6931. TEST_SUITES_append = " mytest"
  6932. - Run a specific list of tests as follows:
  6933. ::
  6934. TEST_SUITES = "test1 test2 test3"
  6935. Remember, order is important. Be sure to place a test that is
  6936. dependent on another test later in the order.
  6937. Exporting Tests
  6938. ---------------
  6939. You can export tests so that they can run independently of the build
  6940. system. Exporting tests is required if you want to be able to hand the
  6941. test execution off to a scheduler. You can only export tests that are
  6942. defined in :term:`TEST_SUITES`.
  6943. If your image is already built, make sure the following are set in your
  6944. ``local.conf`` file:
  6945. ::
  6946. INHERIT += "testexport"
  6947. TEST_TARGET_IP = "IP-address-for-the-test-target"
  6948. TEST_SERVER_IP = "IP-address-for-the-test-server"
  6949. You can then export the tests with the
  6950. following BitBake command form:
  6951. ::
  6952. $ bitbake image -c testexport
  6953. Exporting the tests places them in the
  6954. :term:`Build Directory` in
  6955. ``tmp/testexport/``\ image, which is controlled by the
  6956. ``TEST_EXPORT_DIR`` variable.
  6957. You can now run the tests outside of the build environment:
  6958. ::
  6959. $ cd tmp/testexport/image
  6960. $ ./runexported.py testdata.json
  6961. Here is a complete example that shows IP addresses and uses the
  6962. ``core-image-sato`` image:
  6963. ::
  6964. INHERIT += "testexport"
  6965. TEST_TARGET_IP = "192.168.7.2"
  6966. TEST_SERVER_IP = "192.168.7.1"
  6967. Use BitBake to export the tests:
  6968. ::
  6969. $ bitbake core-image-sato -c testexport
  6970. Run the tests outside of
  6971. the build environment using the following:
  6972. ::
  6973. $ cd tmp/testexport/core-image-sato
  6974. $ ./runexported.py testdata.json
  6975. .. _qemu-image-writing-new-tests:
  6976. Writing New Tests
  6977. -----------------
  6978. As mentioned previously, all new test files need to be in the proper
  6979. place for the build system to find them. New tests for additional
  6980. functionality outside of the core should be added to the layer that adds
  6981. the functionality, in ``layer/lib/oeqa/runtime`` (as long as
  6982. :term:`BBPATH` is extended in the
  6983. layer's ``layer.conf`` file as normal). Just remember the following:
  6984. - Filenames need to map directly to test (module) names.
  6985. - Do not use module names that collide with existing core tests.
  6986. - Minimally, an empty ``__init__.py`` file must exist in the runtime
  6987. directory.
  6988. To create a new test, start by copying an existing module (e.g.
  6989. ``syslog.py`` or ``gcc.py`` are good ones to use). Test modules can use
  6990. code from ``meta/lib/oeqa/utils``, which are helper classes.
  6991. .. note::
  6992. Structure shell commands such that you rely on them and they return a
  6993. single code for success. Be aware that sometimes you will need to
  6994. parse the output. See the ``df.py`` and ``date.py`` modules for examples.
  6995. You will notice that all test classes inherit ``oeRuntimeTest``, which
  6996. is found in ``meta/lib/oetest.py``. This base class offers some helper
  6997. attributes, which are described in the following sections:
  6998. .. _qemu-image-writing-tests-class-methods:
  6999. Class Methods
  7000. ~~~~~~~~~~~~~
  7001. Class methods are as follows:
  7002. - *hasPackage(pkg):* Returns "True" if ``pkg`` is in the installed
  7003. package list of the image, which is based on the manifest file that
  7004. is generated during the ``do_rootfs`` task.
  7005. - *hasFeature(feature):* Returns "True" if the feature is in
  7006. :term:`IMAGE_FEATURES` or
  7007. :term:`DISTRO_FEATURES`.
  7008. .. _qemu-image-writing-tests-class-attributes:
  7009. Class Attributes
  7010. ~~~~~~~~~~~~~~~~
  7011. Class attributes are as follows:
  7012. - *pscmd:* Equals "ps -ef" if ``procps`` is installed in the image.
  7013. Otherwise, ``pscmd`` equals "ps" (busybox).
  7014. - *tc:* The called test context, which gives access to the
  7015. following attributes:
  7016. - *d:* The BitBake datastore, which allows you to use stuff such
  7017. as ``oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")``.
  7018. - *testslist and testsrequired:* Used internally. The tests
  7019. do not need these.
  7020. - *filesdir:* The absolute path to
  7021. ``meta/lib/oeqa/runtime/files``, which contains helper files for
  7022. tests meant for copying on the target such as small files written
  7023. in C for compilation.
  7024. - *target:* The target controller object used to deploy and
  7025. start an image on a particular target (e.g. Qemu, SimpleRemote,
  7026. and SystemdbootTarget). Tests usually use the following:
  7027. - *ip:* The target's IP address.
  7028. - *server_ip:* The host's IP address, which is usually used
  7029. by the DNF test suite.
  7030. - *run(cmd, timeout=None):* The single, most used method.
  7031. This command is a wrapper for: ``ssh root@host "cmd"``. The
  7032. command returns a tuple: (status, output), which are what their
  7033. names imply - the return code of "cmd" and whatever output it
  7034. produces. The optional timeout argument represents the number
  7035. of seconds the test should wait for "cmd" to return. If the
  7036. argument is "None", the test uses the default instance's
  7037. timeout period, which is 300 seconds. If the argument is "0",
  7038. the test runs until the command returns.
  7039. - *copy_to(localpath, remotepath):*
  7040. ``scp localpath root@ip:remotepath``.
  7041. - *copy_from(remotepath, localpath):*
  7042. ``scp root@host:remotepath localpath``.
  7043. .. _qemu-image-writing-tests-instance-attributes:
  7044. Instance Attributes
  7045. ~~~~~~~~~~~~~~~~~~~
  7046. A single instance attribute exists, which is ``target``. The ``target``
  7047. instance attribute is identical to the class attribute of the same name,
  7048. which is described in the previous section. This attribute exists as
  7049. both an instance and class attribute so tests can use
  7050. ``self.target.run(cmd)`` in instance methods instead of
  7051. ``oeRuntimeTest.tc.target.run(cmd)``.
  7052. Installing Packages in the DUT Without the Package Manager
  7053. ----------------------------------------------------------
  7054. When a test requires a package built by BitBake, it is possible to
  7055. install that package. Installing the package does not require a package
  7056. manager be installed in the device under test (DUT). It does, however,
  7057. require an SSH connection and the target must be using the
  7058. ``sshcontrol`` class.
  7059. .. note::
  7060. This method uses ``scp`` to copy files from the host to the target, which
  7061. causes permissions and special attributes to be lost.
  7062. A JSON file is used to define the packages needed by a test. This file
  7063. must be in the same path as the file used to define the tests.
  7064. Furthermore, the filename must map directly to the test module name with
  7065. a ``.json`` extension.
  7066. The JSON file must include an object with the test name as keys of an
  7067. object or an array. This object (or array of objects) uses the following
  7068. data:
  7069. - "pkg" - A mandatory string that is the name of the package to be
  7070. installed.
  7071. - "rm" - An optional boolean, which defaults to "false", that specifies
  7072. to remove the package after the test.
  7073. - "extract" - An optional boolean, which defaults to "false", that
  7074. specifies if the package must be extracted from the package format.
  7075. When set to "true", the package is not automatically installed into
  7076. the DUT.
  7077. Following is an example JSON file that handles test "foo" installing
  7078. package "bar" and test "foobar" installing packages "foo" and "bar".
  7079. Once the test is complete, the packages are removed from the DUT.
  7080. ::
  7081. {
  7082. "foo": {
  7083. "pkg": "bar"
  7084. },
  7085. "foobar": [
  7086. {
  7087. "pkg": "foo",
  7088. "rm": true
  7089. },
  7090. {
  7091. "pkg": "bar",
  7092. "rm": true
  7093. }
  7094. ]
  7095. }
  7096. .. _usingpoky-debugging-tools-and-techniques:
  7097. Debugging Tools and Techniques
  7098. ==============================
  7099. The exact method for debugging build failures depends on the nature of
  7100. the problem and on the system's area from which the bug originates.
  7101. Standard debugging practices such as comparison against the last known
  7102. working version with examination of the changes and the re-application
  7103. of steps to identify the one causing the problem are valid for the Yocto
  7104. Project just as they are for any other system. Even though it is
  7105. impossible to detail every possible potential failure, this section
  7106. provides some general tips to aid in debugging given a variety of
  7107. situations.
  7108. .. note::
  7109. A useful feature for debugging is the error reporting tool.
  7110. Configuring the Yocto Project to use this tool causes the
  7111. OpenEmbedded build system to produce error reporting commands as part
  7112. of the console output. You can enter the commands after the build
  7113. completes to log error information into a common database, that can
  7114. help you figure out what might be going wrong. For information on how
  7115. to enable and use this feature, see the
  7116. ":ref:`dev-manual/dev-manual-common-tasks:using the error reporting tool`"
  7117. section.
  7118. The following list shows the debugging topics in the remainder of this
  7119. section:
  7120. - "`Viewing Logs from Failed
  7121. Tasks <#dev-debugging-viewing-logs-from-failed-tasks>`__" describes
  7122. how to find and view logs from tasks that failed during the build
  7123. process.
  7124. - "`Viewing Variable
  7125. Values <#dev-debugging-viewing-variable-values>`__" describes how to
  7126. use the BitBake ``-e`` option to examine variable values after a
  7127. recipe has been parsed.
  7128. - ":ref:`dev-manual/dev-manual-common-tasks:viewing package information with \`\`oe-pkgdata-util\`\``"
  7129. describes how to use the ``oe-pkgdata-util`` utility to query
  7130. :term:`PKGDATA_DIR` and
  7131. display package-related information for built packages.
  7132. - "`Viewing Dependencies Between Recipes and
  7133. Tasks <#dev-viewing-dependencies-between-recipes-and-tasks>`__"
  7134. describes how to use the BitBake ``-g`` option to display recipe
  7135. dependency information used during the build.
  7136. - "`Viewing Task Variable
  7137. Dependencies <#dev-viewing-task-variable-dependencies>`__" describes
  7138. how to use the ``bitbake-dumpsig`` command in conjunction with key
  7139. subdirectories in the
  7140. :term:`Build Directory` to determine
  7141. variable dependencies.
  7142. - "`Running Specific Tasks <#dev-debugging-taskrunning>`__" describes
  7143. how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``)
  7144. to run specific tasks in the build chain. It can be useful to run
  7145. tasks "out-of-order" when trying isolate build issues.
  7146. - "`General BitBake Problems <#dev-debugging-bitbake>`__" describes how
  7147. to use BitBake's ``-D`` debug output option to reveal more about what
  7148. BitBake is doing during the build.
  7149. - "`Building with No Dependencies <#dev-debugging-buildfile>`__"
  7150. describes how to use the BitBake ``-b`` option to build a recipe
  7151. while ignoring dependencies.
  7152. - "`Recipe Logging Mechanisms <#recipe-logging-mechanisms>`__"
  7153. describes how to use the many recipe logging functions to produce
  7154. debugging output and report errors and warnings.
  7155. - "`Debugging Parallel Make Races <#debugging-parallel-make-races>`__"
  7156. describes how to debug situations where the build consists of several
  7157. parts that are run simultaneously and when the output or result of
  7158. one part is not ready for use with a different part of the build that
  7159. depends on that output.
  7160. - "`Debugging With the GNU Project Debugger (GDB)
  7161. Remotely <#platdev-gdb-remotedebug>`__" describes how to use GDB to
  7162. allow you to examine running programs, which can help you fix
  7163. problems.
  7164. - "`Debugging with the GNU Project Debugger (GDB) on the
  7165. Target <#debugging-with-the-gnu-project-debugger-gdb-on-the-target>`__"
  7166. describes how to use GDB directly on target hardware for debugging.
  7167. - "`Other Debugging Tips <#dev-other-debugging-others>`__" describes
  7168. miscellaneous debugging tips that can be useful.
  7169. .. _dev-debugging-viewing-logs-from-failed-tasks:
  7170. Viewing Logs from Failed Tasks
  7171. ------------------------------
  7172. You can find the log for a task in the file
  7173. ``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`.
  7174. For example, the log for the
  7175. :ref:`ref-tasks-compile` task of the
  7176. QEMU minimal image for the x86 machine (``qemux86``) might be in
  7177. ``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``.
  7178. To see the commands :term:`BitBake` ran
  7179. to generate a log, look at the corresponding ``run.do_``\ `taskname` file
  7180. in the same directory.
  7181. ``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic
  7182. links to ``log.do_``\ `taskname`\ ``.``\ `pid` and
  7183. ``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had
  7184. when it ran. The symlinks always point to the files corresponding to the
  7185. most recent run.
  7186. .. _dev-debugging-viewing-variable-values:
  7187. Viewing Variable Values
  7188. -----------------------
  7189. Sometimes you need to know the value of a variable as a result of
  7190. BitBake's parsing step. This could be because some unexpected behavior
  7191. occurred in your project. Perhaps an attempt to :ref:`modify a variable
  7192. <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing
  7193. variables>` did not work out as expected.
  7194. BitBake's ``-e`` option is used to display variable values after
  7195. parsing. The following command displays the variable values after the
  7196. configuration files (i.e. ``local.conf``, ``bblayers.conf``,
  7197. ``bitbake.conf`` and so forth) have been parsed:
  7198. ::
  7199. $ bitbake -e
  7200. The following command displays variable values after a specific recipe has
  7201. been parsed. The variables include those from the configuration as well:
  7202. ::
  7203. $ bitbake -e recipename
  7204. .. note::
  7205. Each recipe has its own private set of variables (datastore).
  7206. Internally, after parsing the configuration, a copy of the resulting
  7207. datastore is made prior to parsing each recipe. This copying implies
  7208. that variables set in one recipe will not be visible to other
  7209. recipes.
  7210. Likewise, each task within a recipe gets a private datastore based on
  7211. the recipe datastore, which means that variables set within one task
  7212. will not be visible to other tasks.
  7213. In the output of ``bitbake -e``, each variable is preceded by a
  7214. description of how the variable got its value, including temporary
  7215. values that were later overridden. This description also includes
  7216. variable flags (varflags) set on the variable. The output can be very
  7217. helpful during debugging.
  7218. Variables that are exported to the environment are preceded by
  7219. ``export`` in the output of ``bitbake -e``. See the following example:
  7220. ::
  7221. export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
  7222. In addition to variable values, the output of the ``bitbake -e`` and
  7223. ``bitbake -e`` recipe commands includes the following information:
  7224. - The output starts with a tree listing all configuration files and
  7225. classes included globally, recursively listing the files they include
  7226. or inherit in turn. Much of the behavior of the OpenEmbedded build
  7227. system (including the behavior of the :ref:`ref-manual/ref-tasks:normal recipe build tasks`) is
  7228. implemented in the
  7229. :ref:`base <ref-classes-base>` class and the
  7230. classes it inherits, rather than being built into BitBake itself.
  7231. - After the variable values, all functions appear in the output. For
  7232. shell functions, variables referenced within the function body are
  7233. expanded. If a function has been modified using overrides or using
  7234. override-style operators like ``_append`` and ``_prepend``, then the
  7235. final assembled function body appears in the output.
  7236. Viewing Package Information with ``oe-pkgdata-util``
  7237. ----------------------------------------------------
  7238. You can use the ``oe-pkgdata-util`` command-line utility to query
  7239. :term:`PKGDATA_DIR` and display
  7240. various package-related information. When you use the utility, you must
  7241. use it to view information on packages that have already been built.
  7242. Following are a few of the available ``oe-pkgdata-util`` subcommands.
  7243. .. note::
  7244. You can use the standard \* and ? globbing wildcards as part of
  7245. package names and paths.
  7246. - ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages
  7247. that have been built, optionally limiting the match to packages that
  7248. match pattern.
  7249. - ``oe-pkgdata-util list-pkg-files package ...``: Lists the
  7250. files and directories contained in the given packages.
  7251. .. note::
  7252. A different way to view the contents of a package is to look at
  7253. the
  7254. ``${``\ :term:`WORKDIR`\ ``}/packages-split``
  7255. directory of the recipe that generates the package. This directory
  7256. is created by the
  7257. :ref:`ref-tasks-package` task
  7258. and has one subdirectory for each package the recipe generates,
  7259. which contains the files stored in that package.
  7260. If you want to inspect the ``${WORKDIR}/packages-split``
  7261. directory, make sure that
  7262. :ref:`rm_work <ref-classes-rm-work>` is not
  7263. enabled when you build the recipe.
  7264. - ``oe-pkgdata-util find-path path ...``: Lists the names of
  7265. the packages that contain the given paths. For example, the following
  7266. tells us that ``/usr/share/man/man1/make.1`` is contained in the
  7267. ``make-doc`` package:
  7268. ::
  7269. $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
  7270. make-doc: /usr/share/man/man1/make.1
  7271. - ``oe-pkgdata-util lookup-recipe package ...``: Lists the name
  7272. of the recipes that produce the given packages.
  7273. For more information on the ``oe-pkgdata-util`` command, use the help
  7274. facility:
  7275. ::
  7276. $ oe-pkgdata-util --help
  7277. $ oe-pkgdata-util subcommand --help
  7278. .. _dev-viewing-dependencies-between-recipes-and-tasks:
  7279. Viewing Dependencies Between Recipes and Tasks
  7280. ----------------------------------------------
  7281. Sometimes it can be hard to see why BitBake wants to build other recipes
  7282. before the one you have specified. Dependency information can help you
  7283. understand why a recipe is built.
  7284. To generate dependency information for a recipe, run the following
  7285. command:
  7286. ::
  7287. $ bitbake -g recipename
  7288. This command writes the following files in the current directory:
  7289. - ``pn-buildlist``: A list of recipes/targets involved in building
  7290. `recipename`. "Involved" here means that at least one task from the
  7291. recipe needs to run when building `recipename` from scratch. Targets
  7292. that are in
  7293. :term:`ASSUME_PROVIDED`
  7294. are not listed.
  7295. - ``task-depends.dot``: A graph showing dependencies between tasks.
  7296. The graphs are in
  7297. `DOT <https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29>`__
  7298. format and can be converted to images (e.g. using the ``dot`` tool from
  7299. `Graphviz <https://www.graphviz.org/>`__).
  7300. .. note::
  7301. - DOT files use a plain text format. The graphs generated using the
  7302. ``bitbake -g`` command are often so large as to be difficult to
  7303. read without special pruning (e.g. with Bitbake's ``-I`` option)
  7304. and processing. Despite the form and size of the graphs, the
  7305. corresponding ``.dot`` files can still be possible to read and
  7306. provide useful information.
  7307. As an example, the ``task-depends.dot`` file contains lines such
  7308. as the following:
  7309. ::
  7310. "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
  7311. The above example line reveals that the
  7312. :ref:`ref-tasks-configure`
  7313. task in ``libxslt`` depends on the
  7314. :ref:`ref-tasks-populate_sysroot`
  7315. task in ``libxml2``, which is a normal
  7316. :term:`DEPENDS` dependency
  7317. between the two recipes.
  7318. - For an example of how ``.dot`` files can be processed, see the
  7319. ``scripts/contrib/graph-tool`` Python script, which finds and
  7320. displays paths between graph nodes.
  7321. You can use a different method to view dependency information by using
  7322. the following command:
  7323. ::
  7324. $ bitbake -g -u taskexp recipename
  7325. This command
  7326. displays a GUI window from which you can view build-time and runtime
  7327. dependencies for the recipes involved in building recipename.
  7328. .. _dev-viewing-task-variable-dependencies:
  7329. Viewing Task Variable Dependencies
  7330. ----------------------------------
  7331. As mentioned in the
  7332. ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake
  7333. User Manual, BitBake tries to automatically determine what variables a
  7334. task depends on so that it can rerun the task if any values of the
  7335. variables change. This determination is usually reliable. However, if
  7336. you do things like construct variable names at runtime, then you might
  7337. have to manually declare dependencies on those variables using
  7338. ``vardeps`` as described in the
  7339. ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake
  7340. User Manual.
  7341. If you are unsure whether a variable dependency is being picked up
  7342. automatically for a given task, you can list the variable dependencies
  7343. BitBake has determined by doing the following:
  7344. 1. Build the recipe containing the task:
  7345. ::
  7346. $ bitbake recipename
  7347. 2. Inside the :term:`STAMPS_DIR`
  7348. directory, find the signature data (``sigdata``) file that
  7349. corresponds to the task. The ``sigdata`` files contain a pickled
  7350. Python database of all the metadata that went into creating the input
  7351. checksum for the task. As an example, for the
  7352. :ref:`ref-tasks-fetch` task of the
  7353. ``db`` recipe, the ``sigdata`` file might be found in the following
  7354. location:
  7355. ::
  7356. ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
  7357. For tasks that are accelerated through the shared state
  7358. (:ref:`sstate <overview-manual/overview-manual-concepts:shared state cache>`) cache, an
  7359. additional ``siginfo`` file is written into
  7360. :term:`SSTATE_DIR` along with
  7361. the cached task output. The ``siginfo`` files contain exactly the
  7362. same information as ``sigdata`` files.
  7363. 3. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here
  7364. is an example:
  7365. ::
  7366. $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
  7367. In the output of the above command, you will find a line like the
  7368. following, which lists all the (inferred) variable dependencies for
  7369. the task. This list also includes indirect dependencies from
  7370. variables depending on other variables, recursively.
  7371. ::
  7372. Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
  7373. .. note::
  7374. Functions (e.g. ``base_do_fetch``) also count as variable dependencies.
  7375. These functions in turn depend on the variables they reference.
  7376. The output of ``bitbake-dumpsig`` also includes the value each
  7377. variable had, a list of dependencies for each variable, and
  7378. :term:`bitbake:BB_HASHBASE_WHITELIST`
  7379. information.
  7380. There is also a ``bitbake-diffsigs`` command for comparing two
  7381. ``siginfo`` or ``sigdata`` files. This command can be helpful when
  7382. trying to figure out what changed between two versions of a task. If you
  7383. call ``bitbake-diffsigs`` with just one file, the command behaves like
  7384. ``bitbake-dumpsig``.
  7385. You can also use BitBake to dump out the signature construction
  7386. information without executing tasks by using either of the following
  7387. BitBake command-line options:
  7388. ::
  7389. ‐‐dump-signatures=SIGNATURE_HANDLER
  7390. -S SIGNATURE_HANDLER
  7391. .. note::
  7392. Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which
  7393. dump only the signature or compare the dumped signature with the cached one,
  7394. respectively.
  7395. Using BitBake with either of these options causes BitBake to dump out
  7396. ``sigdata`` files in the ``stamps`` directory for every task it would
  7397. have executed instead of building the specified target package.
  7398. .. _dev-viewing-metadata-used-to-create-the-input-signature-of-a-shared-state-task:
  7399. Viewing Metadata Used to Create the Input Signature of a Shared State Task
  7400. --------------------------------------------------------------------------
  7401. Seeing what metadata went into creating the input signature of a shared
  7402. state (sstate) task can be a useful debugging aid. This information is
  7403. available in signature information (``siginfo``) files in
  7404. :term:`SSTATE_DIR`. For
  7405. information on how to view and interpret information in ``siginfo``
  7406. files, see the "`Viewing Task Variable
  7407. Dependencies <#dev-viewing-task-variable-dependencies>`__" section.
  7408. For conceptual information on shared state, see the
  7409. ":ref:`overview-manual/overview-manual-concepts:shared state`"
  7410. section in the Yocto Project Overview and Concepts Manual.
  7411. .. _dev-invalidating-shared-state-to-force-a-task-to-run:
  7412. Invalidating Shared State to Force a Task to Run
  7413. ------------------------------------------------
  7414. The OpenEmbedded build system uses
  7415. :ref:`checksums <overview-checksums>` and
  7416. :ref:`overview-manual/overview-manual-concepts:shared state` cache to avoid unnecessarily
  7417. rebuilding tasks. Collectively, this scheme is known as "shared state
  7418. code".
  7419. As with all schemes, this one has some drawbacks. It is possible that
  7420. you could make implicit changes to your code that the checksum
  7421. calculations do not take into account. These implicit changes affect a
  7422. task's output but do not trigger the shared state code into rebuilding a
  7423. recipe. Consider an example during which a tool changes its output.
  7424. Assume that the output of ``rpmdeps`` changes. The result of the change
  7425. should be that all the ``package`` and ``package_write_rpm`` shared
  7426. state cache items become invalid. However, because the change to the
  7427. output is external to the code and therefore implicit, the associated
  7428. shared state cache items do not become invalidated. In this case, the
  7429. build process uses the cached items rather than running the task again.
  7430. Obviously, these types of implicit changes can cause problems.
  7431. To avoid these problems during the build, you need to understand the
  7432. effects of any changes you make. Realize that changes you make directly
  7433. to a function are automatically factored into the checksum calculation.
  7434. Thus, these explicit changes invalidate the associated area of shared
  7435. state cache. However, you need to be aware of any implicit changes that
  7436. are not obvious changes to the code and could affect the output of a
  7437. given task.
  7438. When you identify an implicit change, you can easily take steps to
  7439. invalidate the cache and force the tasks to run. The steps you can take
  7440. are as simple as changing a function's comments in the source code. For
  7441. example, to invalidate package shared state files, change the comment
  7442. statements of
  7443. :ref:`ref-tasks-package` or the
  7444. comments of one of the functions it calls. Even though the change is
  7445. purely cosmetic, it causes the checksum to be recalculated and forces
  7446. the build system to run the task again.
  7447. .. note::
  7448. For an example of a commit that makes a cosmetic change to invalidate
  7449. shared state, see this
  7450. :yocto_git:`commit </cgit.cgi/poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`.
  7451. .. _dev-debugging-taskrunning:
  7452. Running Specific Tasks
  7453. ----------------------
  7454. Any given recipe consists of a set of tasks. The standard BitBake
  7455. behavior in most cases is: ``do_fetch``, ``do_unpack``, ``do_patch``,
  7456. ``do_configure``, ``do_compile``, ``do_install``, ``do_package``,
  7457. ``do_package_write_*``, and ``do_build``. The default task is
  7458. ``do_build`` and any tasks on which it depends build first. Some tasks,
  7459. such as ``do_devshell``, are not part of the default build chain. If you
  7460. wish to run a task that is not part of the default build chain, you can
  7461. use the ``-c`` option in BitBake. Here is an example:
  7462. ::
  7463. $ bitbake matchbox-desktop -c devshell
  7464. The ``-c`` option respects task dependencies, which means that all other
  7465. tasks (including tasks from other recipes) that the specified task
  7466. depends on will be run before the task. Even when you manually specify a
  7467. task to run with ``-c``, BitBake will only run the task if it considers
  7468. it "out of date". See the
  7469. ":ref:`overview-manual/overview-manual-concepts:stamp files and the rerunning of tasks`"
  7470. section in the Yocto Project Overview and Concepts Manual for how
  7471. BitBake determines whether a task is "out of date".
  7472. If you want to force an up-to-date task to be rerun (e.g. because you
  7473. made manual modifications to the recipe's
  7474. :term:`WORKDIR` that you want to try
  7475. out), then you can use the ``-f`` option.
  7476. .. note::
  7477. The reason ``-f`` is never required when running the
  7478. :ref:`ref-tasks-devshell` task is because the
  7479. [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ]
  7480. variable flag is already set for the task.
  7481. The following example shows one way you can use the ``-f`` option:
  7482. ::
  7483. $ bitbake matchbox-desktop
  7484. .
  7485. .
  7486. make some changes to the source code in the work directory
  7487. .
  7488. .
  7489. $ bitbake matchbox-desktop -c compile -f
  7490. $ bitbake matchbox-desktop
  7491. This sequence first builds and then recompiles ``matchbox-desktop``. The
  7492. last command reruns all tasks (basically the packaging tasks) after the
  7493. compile. BitBake recognizes that the ``do_compile`` task was rerun and
  7494. therefore understands that the other tasks also need to be run again.
  7495. Another, shorter way to rerun a task and all
  7496. :ref:`ref-manual/ref-tasks:normal recipe build tasks`
  7497. that depend on it is to use the ``-C`` option.
  7498. .. note::
  7499. This option is upper-cased and is separate from the ``-c``
  7500. option, which is lower-cased.
  7501. Using this option invalidates the given task and then runs the
  7502. :ref:`ref-tasks-build` task, which is
  7503. the default task if no task is given, and the tasks on which it depends.
  7504. You could replace the final two commands in the previous example with
  7505. the following single command:
  7506. ::
  7507. $ bitbake matchbox-desktop -C compile
  7508. Internally, the ``-f`` and ``-C`` options work by tainting (modifying)
  7509. the input checksum of the specified task. This tainting indirectly
  7510. causes the task and its dependent tasks to be rerun through the normal
  7511. task dependency mechanisms.
  7512. .. note::
  7513. BitBake explicitly keeps track of which tasks have been tainted in
  7514. this fashion, and will print warnings such as the following for
  7515. builds involving such tasks:
  7516. .. code-block:: none
  7517. WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
  7518. The purpose of the warning is to let you know that the work directory
  7519. and build output might not be in the clean state they would be in for
  7520. a "normal" build, depending on what actions you took. To get rid of
  7521. such warnings, you can remove the work directory and rebuild the
  7522. recipe, as follows:
  7523. ::
  7524. $ bitbake matchbox-desktop -c clean
  7525. $ bitbake matchbox-desktop
  7526. You can view a list of tasks in a given package by running the
  7527. ``do_listtasks`` task as follows:
  7528. ::
  7529. $ bitbake matchbox-desktop -c listtasks
  7530. The results appear as output to the console and are also in
  7531. the file ``${WORKDIR}/temp/log.do_listtasks``.
  7532. .. _dev-debugging-bitbake:
  7533. General BitBake Problems
  7534. ------------------------
  7535. You can see debug output from BitBake by using the ``-D`` option. The
  7536. debug output gives more information about what BitBake is doing and the
  7537. reason behind it. Each ``-D`` option you use increases the logging
  7538. level. The most common usage is ``-DDD``.
  7539. The output from ``bitbake -DDD -v targetname`` can reveal why BitBake
  7540. chose a certain version of a package or why BitBake picked a certain
  7541. provider. This command could also help you in a situation where you
  7542. think BitBake did something unexpected.
  7543. .. _dev-debugging-buildfile:
  7544. Building with No Dependencies
  7545. -----------------------------
  7546. To build a specific recipe (``.bb`` file), you can use the following
  7547. command form:
  7548. ::
  7549. $ bitbake -b somepath/somerecipe.bb
  7550. This command form does
  7551. not check for dependencies. Consequently, you should use it only when
  7552. you know existing dependencies have been met.
  7553. .. note::
  7554. You can also specify fragments of the filename. In this case, BitBake
  7555. checks for a unique match.
  7556. Recipe Logging Mechanisms
  7557. -------------------------
  7558. The Yocto Project provides several logging functions for producing
  7559. debugging output and reporting errors and warnings. For Python
  7560. functions, the following logging functions exist. All of these functions
  7561. log to ``${T}/log.do_``\ `task`, and can also log to standard output
  7562. (stdout) with the right settings:
  7563. - ``bb.plain(msg)``: Writes msg as is to the log while also
  7564. logging to stdout.
  7565. - ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to
  7566. stdout if BitBake is called with "-v".
  7567. - ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the
  7568. log. Also logs to stdout if the log level is greater than or equal to
  7569. level. See the ":ref:`-D <bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax>`" option
  7570. in the BitBake User Manual for more information.
  7571. - ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also
  7572. logging to stdout.
  7573. - ``bb.error(msg)``: Writes "ERROR: msg" to the log while also
  7574. logging to standard out (stdout).
  7575. .. note::
  7576. Calling this function does not cause the task to fail.
  7577. - ``bb.fatal(``\ msg\ ``)``: This logging function is similar to
  7578. ``bb.error(``\ msg\ ``)`` but also causes the calling task to fail.
  7579. .. note::
  7580. ``bb.fatal()`` raises an exception, which means you do not need to put a
  7581. "return" statement after the function.
  7582. The same logging functions are also available in shell functions, under
  7583. the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``,
  7584. and ``bbfatal``. The
  7585. :ref:`logging <ref-classes-logging>` class
  7586. implements these functions. See that class in the ``meta/classes``
  7587. folder of the :term:`Source Directory` for information.
  7588. Logging With Python
  7589. ~~~~~~~~~~~~~~~~~~~
  7590. When creating recipes using Python and inserting code that handles build
  7591. logs, keep in mind the goal is to have informative logs while keeping
  7592. the console as "silent" as possible. Also, if you want status messages
  7593. in the log, use the "debug" loglevel.
  7594. Following is an example written in Python. The code handles logging for
  7595. a function that determines the number of tasks needed to be run. See the
  7596. ":ref:`ref-tasks-listtasks`"
  7597. section for additional information:
  7598. ::
  7599. python do_listtasks() {
  7600. bb.debug(2, "Starting to figure out the task list")
  7601. if noteworthy_condition:
  7602. bb.note("There are 47 tasks to run")
  7603. bb.debug(2, "Got to point xyz")
  7604. if warning_trigger:
  7605. bb.warn("Detected warning_trigger, this might be a problem later.")
  7606. if recoverable_error:
  7607. bb.error("Hit recoverable_error, you really need to fix this!")
  7608. if fatal_error:
  7609. bb.fatal("fatal_error detected, unable to print the task list")
  7610. bb.plain("The tasks present are abc")
  7611. bb.debug(2, "Finished figuring out the tasklist")
  7612. }
  7613. Logging With Bash
  7614. ~~~~~~~~~~~~~~~~~
  7615. When creating recipes using Bash and inserting code that handles build
  7616. logs, you have the same goals - informative with minimal console output.
  7617. The syntax you use for recipes written in Bash is similar to that of
  7618. recipes written in Python described in the previous section.
  7619. Following is an example written in Bash. The code logs the progress of
  7620. the ``do_my_function`` function.
  7621. ::
  7622. do_my_function() {
  7623. bbdebug 2 "Running do_my_function"
  7624. if [ exceptional_condition ]; then
  7625. bbnote "Hit exceptional_condition"
  7626. fi
  7627. bbdebug 2 "Got to point xyz"
  7628. if [ warning_trigger ]; then
  7629. bbwarn "Detected warning_trigger, this might cause a problem later."
  7630. fi
  7631. if [ recoverable_error ]; then
  7632. bberror "Hit recoverable_error, correcting"
  7633. fi
  7634. if [ fatal_error ]; then
  7635. bbfatal "fatal_error detected"
  7636. fi
  7637. bbdebug 2 "Completed do_my_function"
  7638. }
  7639. Debugging Parallel Make Races
  7640. -----------------------------
  7641. A parallel ``make`` race occurs when the build consists of several parts
  7642. that are run simultaneously and a situation occurs when the output or
  7643. result of one part is not ready for use with a different part of the
  7644. build that depends on that output. Parallel make races are annoying and
  7645. can sometimes be difficult to reproduce and fix. However, some simple
  7646. tips and tricks exist that can help you debug and fix them. This section
  7647. presents a real-world example of an error encountered on the Yocto
  7648. Project autobuilder and the process used to fix it.
  7649. .. note::
  7650. If you cannot properly fix a ``make`` race condition, you can work around it
  7651. by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST`
  7652. variables.
  7653. The Failure
  7654. ~~~~~~~~~~~
  7655. For this example, assume that you are building an image that depends on
  7656. the "neard" package. And, during the build, BitBake runs into problems
  7657. and creates the following output.
  7658. .. note::
  7659. This example log file has longer lines artificially broken to make
  7660. the listing easier to read.
  7661. If you examine the output or the log file, you see the failure during
  7662. ``make``:
  7663. .. code-block:: none
  7664. | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
  7665. | DEBUG: Executing shell function do_compile
  7666. | NOTE: make -j 16
  7667. | make --no-print-directory all-am
  7668. | /bin/mkdir -p include/near
  7669. | /bin/mkdir -p include/near
  7670. | /bin/mkdir -p include/near
  7671. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7672. 0.14-r0/neard-0.14/include/types.h include/near/types.h
  7673. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7674. 0.14-r0/neard-0.14/include/log.h include/near/log.h
  7675. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7676. 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
  7677. | /bin/mkdir -p include/near
  7678. | /bin/mkdir -p include/near
  7679. | /bin/mkdir -p include/near
  7680. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7681. 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
  7682. | /bin/mkdir -p include/near
  7683. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7684. 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
  7685. | /bin/mkdir -p include/near
  7686. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7687. 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
  7688. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7689. 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
  7690. | /bin/mkdir -p include/near
  7691. | /bin/mkdir -p include/near
  7692. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7693. 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
  7694. | /bin/mkdir -p include/near
  7695. | /bin/mkdir -p include/near
  7696. | /bin/mkdir -p include/near
  7697. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7698. 0.14-r0/neard-0.14/include/device.h include/near/device.h
  7699. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7700. 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
  7701. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7702. 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
  7703. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7704. 0.14-r0/neard-0.14/include/version.h include/near/version.h
  7705. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7706. 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
  7707. | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
  7708. | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
  7709. build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
  7710. yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
  7711. -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
  7712. lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
  7713. tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
  7714. nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
  7715. yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
  7716. -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
  7717. -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
  7718. -o tools/snep-send.o tools/snep-send.c
  7719. | In file included from tools/snep-send.c:16:0:
  7720. | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
  7721. | #include <near/dbus.h>
  7722. | ^
  7723. | compilation terminated.
  7724. | make[1]: *** [tools/snep-send.o] Error 1
  7725. | make[1]: *** Waiting for unfinished jobs....
  7726. | make: *** [all] Error 2
  7727. | ERROR: oe_runmake failed
  7728. Reproducing the Error
  7729. ~~~~~~~~~~~~~~~~~~~~~
  7730. Because race conditions are intermittent, they do not manifest
  7731. themselves every time you do the build. In fact, most times the build
  7732. will complete without problems even though the potential race condition
  7733. exists. Thus, once the error surfaces, you need a way to reproduce it.
  7734. In this example, compiling the "neard" package is causing the problem.
  7735. So the first thing to do is build "neard" locally. Before you start the
  7736. build, set the
  7737. :term:`PARALLEL_MAKE` variable
  7738. in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a
  7739. high value for ``PARALLEL_MAKE`` increases the chances of the race
  7740. condition showing up:
  7741. ::
  7742. $ bitbake neard
  7743. Once the local build for "neard" completes, start a ``devshell`` build:
  7744. ::
  7745. $ bitbake neard -c devshell
  7746. For information on how to use a
  7747. ``devshell``, see the "`Using a Development
  7748. Shell <#platdev-appdev-devshell>`__" section.
  7749. In the ``devshell``, do the following:
  7750. ::
  7751. $ make clean
  7752. $ make tools/snep-send.o
  7753. The ``devshell`` commands cause the failure to clearly
  7754. be visible. In this case, a missing dependency exists for the "neard"
  7755. Makefile target. Here is some abbreviated, sample output with the
  7756. missing dependency clearly visible at the end:
  7757. ::
  7758. i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
  7759. .
  7760. .
  7761. .
  7762. tools/snep-send.c
  7763. In file included from tools/snep-send.c:16:0:
  7764. tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
  7765. #include <near/dbus.h>
  7766. ^
  7767. compilation terminated.
  7768. make: *** [tools/snep-send.o] Error 1
  7769. $
  7770. Creating a Patch for the Fix
  7771. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7772. Because there is a missing dependency for the Makefile target, you need
  7773. to patch the ``Makefile.am`` file, which is generated from
  7774. ``Makefile.in``. You can use Quilt to create the patch:
  7775. ::
  7776. $ quilt new parallelmake.patch
  7777. Patch patches/parallelmake.patch is now on top
  7778. $ quilt add Makefile.am
  7779. File Makefile.am added to patch patches/parallelmake.patch
  7780. For more information on using Quilt, see the
  7781. "`Using Quilt in Your Workflow <#using-a-quilt-workflow>`__" section.
  7782. At this point you need to make the edits to ``Makefile.am`` to add the
  7783. missing dependency. For our example, you have to add the following line
  7784. to the file:
  7785. ::
  7786. tools/snep-send.$(OBJEXT): include/near/dbus.h
  7787. Once you have edited the file, use the ``refresh`` command to create the
  7788. patch:
  7789. ::
  7790. $ quilt refresh
  7791. Refreshed patch patches/parallelmake.patch
  7792. Once
  7793. the patch file exists, you need to add it back to the originating recipe
  7794. folder. Here is an example assuming a top-level
  7795. :term:`Source Directory` named ``poky``:
  7796. ::
  7797. $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
  7798. The final thing you need to do to implement the fix in the build is to
  7799. update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the
  7800. :term:`SRC_URI` statement includes
  7801. the patch file. The recipe file is in the folder above the patch. Here
  7802. is what the edited ``SRC_URI`` statement would look like:
  7803. ::
  7804. SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
  7805. file://neard.in \
  7806. file://neard.service.in \
  7807. file://parallelmake.patch \
  7808. "
  7809. With the patch complete and moved to the correct folder and the
  7810. ``SRC_URI`` statement updated, you can exit the ``devshell``:
  7811. ::
  7812. $ exit
  7813. Testing the Build
  7814. ~~~~~~~~~~~~~~~~~
  7815. With everything in place, you can get back to trying the build again
  7816. locally:
  7817. ::
  7818. $ bitbake neard
  7819. This build should succeed.
  7820. Now you can open up a ``devshell`` again and repeat the clean and make
  7821. operations as follows:
  7822. ::
  7823. $ bitbake neard -c devshell
  7824. $ make clean
  7825. $ make tools/snep-send.o
  7826. The build should work without issue.
  7827. As with all solved problems, if they originated upstream, you need to
  7828. submit the fix for the recipe in OE-Core and upstream so that the
  7829. problem is taken care of at its source. See the "`Submitting a Change to
  7830. the Yocto Project <#how-to-submit-a-change>`__" section for more
  7831. information.
  7832. .. _platdev-gdb-remotedebug:
  7833. Debugging With the GNU Project Debugger (GDB) Remotely
  7834. ------------------------------------------------------
  7835. GDB allows you to examine running programs, which in turn helps you to
  7836. understand and fix problems. It also allows you to perform post-mortem
  7837. style analysis of program crashes. GDB is available as a package within
  7838. the Yocto Project and is installed in SDK images by default. See the
  7839. ":ref:`ref-manual/ref-images:Images`" chapter in the Yocto
  7840. Project Reference Manual for a description of these images. You can find
  7841. information on GDB at https://sourceware.org/gdb/.
  7842. .. note::
  7843. For best results, install debug (``-dbg``) packages for the applications you
  7844. are going to debug. Doing so makes extra debug symbols available that give
  7845. you more meaningful output.
  7846. Sometimes, due to memory or disk space constraints, it is not possible
  7847. to use GDB directly on the remote target to debug applications. These
  7848. constraints arise because GDB needs to load the debugging information
  7849. and the binaries of the process being debugged. Additionally, GDB needs
  7850. to perform many computations to locate information such as function
  7851. names, variable names and values, stack traces and so forth - even
  7852. before starting the debugging process. These extra computations place
  7853. more load on the target system and can alter the characteristics of the
  7854. program being debugged.
  7855. To help get past the previously mentioned constraints, you can use
  7856. gdbserver, which runs on the remote target and does not load any
  7857. debugging information from the debugged process. Instead, a GDB instance
  7858. processes the debugging information that is run on a remote computer -
  7859. the host GDB. The host GDB then sends control commands to gdbserver to
  7860. make it stop or start the debugged program, as well as read or write
  7861. memory regions of that debugged program. All the debugging information
  7862. loaded and processed as well as all the heavy debugging is done by the
  7863. host GDB. Offloading these processes gives the gdbserver running on the
  7864. target a chance to remain small and fast.
  7865. Because the host GDB is responsible for loading the debugging
  7866. information and for doing the necessary processing to make actual
  7867. debugging happen, you have to make sure the host can access the
  7868. unstripped binaries complete with their debugging information and also
  7869. be sure the target is compiled with no optimizations. The host GDB must
  7870. also have local access to all the libraries used by the debugged
  7871. program. Because gdbserver does not need any local debugging
  7872. information, the binaries on the remote target can remain stripped.
  7873. However, the binaries must also be compiled without optimization so they
  7874. match the host's binaries.
  7875. To remain consistent with GDB documentation and terminology, the binary
  7876. being debugged on the remote target machine is referred to as the
  7877. "inferior" binary. For documentation on GDB see the `GDB
  7878. site <https://sourceware.org/gdb/documentation/>`__.
  7879. The following steps show you how to debug using the GNU project
  7880. debugger.
  7881. 1. *Configure your build system to construct the companion debug
  7882. filesystem:*
  7883. In your ``local.conf`` file, set the following:
  7884. ::
  7885. IMAGE_GEN_DEBUGFS = "1"
  7886. IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
  7887. These options cause the
  7888. OpenEmbedded build system to generate a special companion filesystem
  7889. fragment, which contains the matching source and debug symbols to
  7890. your deployable filesystem. The build system does this by looking at
  7891. what is in the deployed filesystem, and pulling the corresponding
  7892. ``-dbg`` packages.
  7893. The companion debug filesystem is not a complete filesystem, but only
  7894. contains the debug fragments. This filesystem must be combined with
  7895. the full filesystem for debugging. Subsequent steps in this procedure
  7896. show how to combine the partial filesystem with the full filesystem.
  7897. 2. *Configure the system to include gdbserver in the target filesystem:*
  7898. Make the following addition in either your ``local.conf`` file or in
  7899. an image recipe:
  7900. ::
  7901. IMAGE_INSTALL_append = " gdbserver"
  7902. The change makes
  7903. sure the ``gdbserver`` package is included.
  7904. 3. *Build the environment:*
  7905. Use the following command to construct the image and the companion
  7906. Debug Filesystem:
  7907. ::
  7908. $ bitbake image
  7909. Build the cross GDB component and
  7910. make it available for debugging. Build the SDK that matches the
  7911. image. Building the SDK is best for a production build that can be
  7912. used later for debugging, especially during long term maintenance:
  7913. ::
  7914. $ bitbake -c populate_sdk image
  7915. Alternatively, you can build the minimal toolchain components that
  7916. match the target. Doing so creates a smaller than typical SDK and
  7917. only contains a minimal set of components with which to build simple
  7918. test applications, as well as run the debugger:
  7919. ::
  7920. $ bitbake meta-toolchain
  7921. A final method is to build Gdb itself within the build system:
  7922. ::
  7923. $ bitbake gdb-cross-<architecture>
  7924. Doing so produces a temporary copy of
  7925. ``cross-gdb`` you can use for debugging during development. While
  7926. this is the quickest approach, the two previous methods in this step
  7927. are better when considering long-term maintenance strategies.
  7928. .. note::
  7929. If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests
  7930. the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the
  7931. actual name you want to use.
  7932. 4. *Set up the* ``debugfs``\ *:*
  7933. Run the following commands to set up the ``debugfs``:
  7934. ::
  7935. $ mkdir debugfs
  7936. $ cd debugfs
  7937. $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image.rootfs.tar.bz2
  7938. $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image-dbg.rootfs.tar.bz2
  7939. 5. *Set up GDB:*
  7940. Install the SDK (if you built one) and then source the correct
  7941. environment file. Sourcing the environment file puts the SDK in your
  7942. ``PATH`` environment variable.
  7943. If you are using the build system, Gdb is located in
  7944. `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb``
  7945. 6. *Boot the target:*
  7946. For information on how to run QEMU, see the `QEMU
  7947. Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__.
  7948. .. note::
  7949. Be sure to verify that your host can access the target via TCP.
  7950. 7. *Debug a program:*
  7951. Debugging a program involves running gdbserver on the target and then
  7952. running Gdb on the host. The example in this step debugs ``gzip``:
  7953. .. code-block:: shell
  7954. root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
  7955. For
  7956. additional gdbserver options, see the `GDB Server
  7957. Documentation <https://www.gnu.org/software/gdb/documentation/>`__.
  7958. After running gdbserver on the target, you need to run Gdb on the
  7959. host and configure it and connect to the target. Use these commands:
  7960. ::
  7961. $ cd directory-holding-the-debugfs-directory
  7962. $ arch-gdb
  7963. (gdb) set sysroot debugfs
  7964. (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
  7965. (gdb) target remote IP-of-target:1234
  7966. At this
  7967. point, everything should automatically load (i.e. matching binaries,
  7968. symbols and headers).
  7969. .. note::
  7970. The Gdb ``set`` commands in the previous example can be placed into the
  7971. users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever
  7972. commands are in that file.
  7973. 8. *Deploying without a full image rebuild:*
  7974. In many cases, during development you want a quick method to deploy a
  7975. new binary to the target and debug it, without waiting for a full
  7976. image build.
  7977. One approach to solving this situation is to just build the component
  7978. you want to debug. Once you have built the component, copy the
  7979. executable directly to both the target and the host ``debugfs``.
  7980. If the binary is processed through the debug splitting in
  7981. OpenEmbedded, you should also copy the debug items (i.e. ``.debug``
  7982. contents and corresponding ``/usr/src/debug`` files) from the work
  7983. directory. Here is an example:
  7984. ::
  7985. $ bitbake bash
  7986. $ bitbake -c devshell bash
  7987. $ cd ..
  7988. $ scp packages-split/bash/bin/bash target:/bin/bash
  7989. $ cp -a packages-split/bash-dbg/\* path/debugfs
  7990. Debugging with the GNU Project Debugger (GDB) on the Target
  7991. -----------------------------------------------------------
  7992. The previous section addressed using GDB remotely for debugging
  7993. purposes, which is the most usual case due to the inherent hardware
  7994. limitations on many embedded devices. However, debugging in the target
  7995. hardware itself is also possible with more powerful devices. This
  7996. section describes what you need to do in order to support using GDB to
  7997. debug on the target hardware.
  7998. To support this kind of debugging, you need do the following:
  7999. - Ensure that GDB is on the target. You can do this by adding "gdb" to
  8000. :term:`IMAGE_INSTALL`:
  8001. ::
  8002. IMAGE_INSTALL_append = " gdb"
  8003. Alternatively, you can add "tools-debug" to :term:`IMAGE_FEATURES`:
  8004. ::
  8005. IMAGE_FEATURES_append = " tools-debug"
  8006. - Ensure that debug symbols are present. You can make sure these
  8007. symbols are present by installing ``-dbg``:
  8008. ::
  8009. IMAGE_INSTALL_append = "packagename-dbg"
  8010. Alternatively, you can do the following to include
  8011. all the debug symbols:
  8012. ::
  8013. IMAGE_FEATURES_append = " dbg-pkgs"
  8014. .. note::
  8015. To improve the debug information accuracy, you can reduce the level
  8016. of optimization used by the compiler. For example, when adding the
  8017. following line to your ``local.conf`` file, you will reduce optimization
  8018. from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION`
  8019. of "-O -fno-omit-frame-pointer":
  8020. ::
  8021. DEBUG_BUILD = "1"
  8022. Consider that this will reduce the application's performance and is
  8023. recommended only for debugging purposes.
  8024. .. _dev-other-debugging-others:
  8025. Other Debugging Tips
  8026. --------------------
  8027. Here are some other tips that you might find useful:
  8028. - When adding new packages, it is worth watching for undesirable items
  8029. making their way into compiler command lines. For example, you do not
  8030. want references to local system files like ``/usr/lib/`` or
  8031. ``/usr/include/``.
  8032. - If you want to remove the ``psplash`` boot splashscreen, add
  8033. ``psplash=false`` to the kernel command line. Doing so prevents
  8034. ``psplash`` from loading and thus allows you to see the console. It
  8035. is also possible to switch out of the splashscreen by switching the
  8036. virtual console (e.g. Fn+Left or Fn+Right on a Zaurus).
  8037. - Removing :term:`TMPDIR` (usually
  8038. ``tmp/``, within the
  8039. :term:`Build Directory`) can often fix
  8040. temporary build issues. Removing ``TMPDIR`` is usually a relatively
  8041. cheap operation, because task output will be cached in
  8042. :term:`SSTATE_DIR` (usually
  8043. ``sstate-cache/``, which is also in the Build Directory).
  8044. .. note::
  8045. Removing ``TMPDIR`` might be a workaround rather than a fix.
  8046. Consequently, trying to determine the underlying cause of an issue before
  8047. removing the directory is a good idea.
  8048. - Understanding how a feature is used in practice within existing
  8049. recipes can be very helpful. It is recommended that you configure
  8050. some method that allows you to quickly search through files.
  8051. Using GNU Grep, you can use the following shell function to
  8052. recursively search through common recipe-related files, skipping
  8053. binary files, ``.git`` directories, and the Build Directory (assuming
  8054. its name starts with "build"):
  8055. ::
  8056. g() {
  8057. grep -Ir \
  8058. --exclude-dir=.git \
  8059. --exclude-dir='build*' \
  8060. --include='*.bb*' \
  8061. --include='*.inc*' \
  8062. --include='*.conf*' \
  8063. --include='*.py*' \
  8064. "$@"
  8065. }
  8066. Following are some usage examples:
  8067. ::
  8068. $ g FOO # Search recursively for "FOO"
  8069. $ g -i foo # Search recursively for "foo", ignoring case
  8070. $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
  8071. If figuring
  8072. out how some feature works requires a lot of searching, it might
  8073. indicate that the documentation should be extended or improved. In
  8074. such cases, consider filing a documentation bug using the Yocto
  8075. Project implementation of
  8076. :yocto_bugs:`Bugzilla <>`. For information on
  8077. how to submit a bug against the Yocto Project, see the Yocto Project
  8078. Bugzilla :yocto_wiki:`wiki page </wiki/Bugzilla_Configuration_and_Bug_Tracking>`
  8079. and the "`Submitting a Defect Against the Yocto
  8080. Project <#submitting-a-defect-against-the-yocto-project>`__" section.
  8081. .. note::
  8082. The manuals might not be the right place to document variables
  8083. that are purely internal and have a limited scope (e.g. internal
  8084. variables used to implement a single ``.bbclass`` file).
  8085. Making Changes to the Yocto Project
  8086. ===================================
  8087. Because the Yocto Project is an open-source, community-based project,
  8088. you can effect changes to the project. This section presents procedures
  8089. that show you how to submit a defect against the project and how to
  8090. submit a change.
  8091. Submitting a Defect Against the Yocto Project
  8092. ---------------------------------------------
  8093. Use the Yocto Project implementation of
  8094. `Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug)
  8095. against the Yocto Project. For additional information on this
  8096. implementation of Bugzilla see the ":ref:`Yocto Project
  8097. Bugzilla <resources-bugtracker>`" section in the
  8098. Yocto Project Reference Manual. For more detail on any of the following
  8099. steps, see the Yocto Project
  8100. :yocto_wiki:`Bugzilla wiki page </wiki/Bugzilla_Configuration_and_Bug_Tracking>`.
  8101. Use the following general steps to submit a bug:
  8102. 1. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`.
  8103. 2. Click "File a Bug" to enter a new bug.
  8104. 3. Choose the appropriate "Classification", "Product", and "Component"
  8105. for which the bug was found. Bugs for the Yocto Project fall into
  8106. one of several classifications, which in turn break down into
  8107. several products and components. For example, for a bug against the
  8108. ``meta-intel`` layer, you would choose "Build System, Metadata &
  8109. Runtime", "BSPs", and "bsps-meta-intel", respectively.
  8110. 4. Choose the "Version" of the Yocto Project for which you found the
  8111. bug (e.g. &DISTRO;).
  8112. 5. Determine and select the "Severity" of the bug. The severity
  8113. indicates how the bug impacted your work.
  8114. 6. Choose the "Hardware" that the bug impacts.
  8115. 7. Choose the "Architecture" that the bug impacts.
  8116. 8. Choose a "Documentation change" item for the bug. Fixing a bug might
  8117. or might not affect the Yocto Project documentation. If you are
  8118. unsure of the impact to the documentation, select "Don't Know".
  8119. 9. Provide a brief "Summary" of the bug. Try to limit your summary to
  8120. just a line or two and be sure to capture the essence of the bug.
  8121. 10. Provide a detailed "Description" of the bug. You should provide as
  8122. much detail as you can about the context, behavior, output, and so
  8123. forth that surrounds the bug. You can even attach supporting files
  8124. for output from logs by using the "Add an attachment" button.
  8125. 11. Click the "Submit Bug" button submit the bug. A new Bugzilla number
  8126. is assigned to the bug and the defect is logged in the bug tracking
  8127. system.
  8128. Once you file a bug, the bug is processed by the Yocto Project Bug
  8129. Triage Team and further details concerning the bug are assigned (e.g.
  8130. priority and owner). You are the "Submitter" of the bug and any further
  8131. categorization, progress, or comments on the bug result in Bugzilla
  8132. sending you an automated email concerning the particular change or
  8133. progress to the bug.
  8134. .. _how-to-submit-a-change:
  8135. Submitting a Change to the Yocto Project
  8136. ----------------------------------------
  8137. Contributions to the Yocto Project and OpenEmbedded are very welcome.
  8138. Because the system is extremely configurable and flexible, we recognize
  8139. that developers will want to extend, configure or optimize it for their
  8140. specific uses.
  8141. The Yocto Project uses a mailing list and a patch-based workflow that is
  8142. similar to the Linux kernel but contains important differences. In
  8143. general, a mailing list exists through which you can submit patches. You
  8144. should send patches to the appropriate mailing list so that they can be
  8145. reviewed and merged by the appropriate maintainer. The specific mailing
  8146. list you need to use depends on the location of the code you are
  8147. changing. Each component (e.g. layer) should have a ``README`` file that
  8148. indicates where to send the changes and which process to follow.
  8149. You can send the patch to the mailing list using whichever approach you
  8150. feel comfortable with to generate the patch. Once sent, the patch is
  8151. usually reviewed by the community at large. If somebody has concerns
  8152. with the patch, they will usually voice their concern over the mailing
  8153. list. If a patch does not receive any negative reviews, the maintainer
  8154. of the affected layer typically takes the patch, tests it, and then
  8155. based on successful testing, merges the patch.
  8156. The "poky" repository, which is the Yocto Project's reference build
  8157. environment, is a hybrid repository that contains several individual
  8158. pieces (e.g. BitBake, Metadata, documentation, and so forth) built using
  8159. the combo-layer tool. The upstream location used for submitting changes
  8160. varies by component:
  8161. - *Core Metadata:* Send your patch to the
  8162. :oe_lists:`openembedded-core </g/openembedded-core>`
  8163. mailing list. For example, a change to anything under the ``meta`` or
  8164. ``scripts`` directories should be sent to this mailing list.
  8165. - *BitBake:* For changes to BitBake (i.e. anything under the
  8166. ``bitbake`` directory), send your patch to the
  8167. :oe_lists:`bitbake-devel </g/bitbake-devel>`
  8168. mailing list.
  8169. - *"meta-\*" trees:* These trees contain Metadata. Use the
  8170. :yocto_lists:`poky </g/poky>` mailing list.
  8171. - *Documentation*: For changes to the Yocto Project documentation, use the
  8172. :yocto_lists:`docs </g/docs>` mailing list.
  8173. For changes to other layers hosted in the Yocto Project source
  8174. repositories (i.e. ``yoctoproject.org``) and tools use the
  8175. :yocto_lists:`Yocto Project </g/yocto/>` general mailing list.
  8176. .. note::
  8177. Sometimes a layer's documentation specifies to use a particular
  8178. mailing list. If so, use that list.
  8179. For additional recipes that do not fit into the core Metadata, you
  8180. should determine which layer the recipe should go into and submit the
  8181. change in the manner recommended by the documentation (e.g. the
  8182. ``README`` file) supplied with the layer. If in doubt, please ask on the
  8183. Yocto general mailing list or on the openembedded-devel mailing list.
  8184. You can also push a change upstream and request a maintainer to pull the
  8185. change into the component's upstream repository. You do this by pushing
  8186. to a contribution repository that is upstream. See the ":ref:`gs-git-workflows-and-the-yocto-project`"
  8187. section in the Yocto Project Overview and Concepts Manual for additional
  8188. concepts on working in the Yocto Project development environment.
  8189. Two commonly used testing repositories exist for OpenEmbedded-Core:
  8190. - *"ross/mut" branch:* The "mut" (master-under-test) tree exists in the
  8191. ``poky-contrib`` repository in the
  8192. :yocto_git:`Yocto Project source repositories <>`.
  8193. - *"master-next" branch:* This branch is part of the main "poky"
  8194. repository in the Yocto Project source repositories.
  8195. Maintainers use these branches to test submissions prior to merging
  8196. patches. Thus, you can get an idea of the status of a patch based on
  8197. whether the patch has been merged into one of these branches.
  8198. .. note::
  8199. This system is imperfect and changes can sometimes get lost in the
  8200. flow. Asking about the status of a patch or change is reasonable if
  8201. the change has been idle for a while with no feedback. The Yocto
  8202. Project does have plans to use
  8203. `Patchwork <https://en.wikipedia.org/wiki/Patchwork_(software)>`__
  8204. to track the status of patches and also to automatically preview
  8205. patches.
  8206. The following sections provide procedures for submitting a change.
  8207. .. _pushing-a-change-upstream:
  8208. Using Scripts to Push a Change Upstream and Request a Pull
  8209. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8210. Follow this procedure to push a change to an upstream "contrib" Git
  8211. repository:
  8212. .. note::
  8213. You can find general Git information on how to push a change upstream
  8214. in the
  8215. `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__.
  8216. 1. *Make Your Changes Locally:* Make your changes in your local Git
  8217. repository. You should make small, controlled, isolated changes.
  8218. Keeping changes small and isolated aids review, makes
  8219. merging/rebasing easier and keeps the change history clean should
  8220. anyone need to refer to it in future.
  8221. 2. *Stage Your Changes:* Stage your changes by using the ``git add``
  8222. command on each file you changed.
  8223. 3. *Commit Your Changes:* Commit the change by using the ``git commit``
  8224. command. Make sure your commit information follows standards by
  8225. following these accepted conventions:
  8226. - Be sure to include a "Signed-off-by:" line in the same style as
  8227. required by the Linux kernel. Adding this line signifies that you,
  8228. the submitter, have agreed to the Developer's Certificate of
  8229. Origin 1.1 as follows:
  8230. .. code-block:: none
  8231. Developer's Certificate of Origin 1.1
  8232. By making a contribution to this project, I certify that:
  8233. (a) The contribution was created in whole or in part by me and I
  8234. have the right to submit it under the open source license
  8235. indicated in the file; or
  8236. (b) The contribution is based upon previous work that, to the best
  8237. of my knowledge, is covered under an appropriate open source
  8238. license and I have the right under that license to submit that
  8239. work with modifications, whether created in whole or in part
  8240. by me, under the same open source license (unless I am
  8241. permitted to submit under a different license), as indicated
  8242. in the file; or
  8243. (c) The contribution was provided directly to me by some other
  8244. person who certified (a), (b) or (c) and I have not modified
  8245. it.
  8246. (d) I understand and agree that this project and the contribution
  8247. are public and that a record of the contribution (including all
  8248. personal information I submit with it, including my sign-off) is
  8249. maintained indefinitely and may be redistributed consistent with
  8250. this project or the open source license(s) involved.
  8251. - Provide a single-line summary of the change and, if more
  8252. explanation is needed, provide more detail in the body of the
  8253. commit. This summary is typically viewable in the "shortlist" of
  8254. changes. Thus, providing something short and descriptive that
  8255. gives the reader a summary of the change is useful when viewing a
  8256. list of many commits. You should prefix this short description
  8257. with the recipe name (if changing a recipe), or else with the
  8258. short form path to the file being changed.
  8259. - For the body of the commit message, provide detailed information
  8260. that describes what you changed, why you made the change, and the
  8261. approach you used. It might also be helpful if you mention how you
  8262. tested the change. Provide as much detail as you can in the body
  8263. of the commit message.
  8264. .. note::
  8265. You do not need to provide a more detailed explanation of a
  8266. change if the change is minor to the point of the single line
  8267. summary providing all the information.
  8268. - If the change addresses a specific bug or issue that is associated
  8269. with a bug-tracking ID, include a reference to that ID in your
  8270. detailed description. For example, the Yocto Project uses a
  8271. specific convention for bug references - any commit that addresses
  8272. a specific bug should use the following form for the detailed
  8273. description. Be sure to use the actual bug-tracking ID from
  8274. Bugzilla for bug-id:
  8275. ::
  8276. Fixes [YOCTO #bug-id]
  8277. detailed description of change
  8278. 4. *Push Your Commits to a "Contrib" Upstream:* If you have arranged for
  8279. permissions to push to an upstream contrib repository, push the
  8280. change to that repository:
  8281. ::
  8282. $ git push upstream_remote_repo local_branch_name
  8283. For example, suppose you have permissions to push
  8284. into the upstream ``meta-intel-contrib`` repository and you are
  8285. working in a local branch named `your_name`\ ``/README``. The following
  8286. command pushes your local commits to the ``meta-intel-contrib``
  8287. upstream repository and puts the commit in a branch named
  8288. `your_name`\ ``/README``:
  8289. ::
  8290. $ git push meta-intel-contrib your_name/README
  8291. 5. *Determine Who to Notify:* Determine the maintainer or the mailing
  8292. list that you need to notify for the change.
  8293. Before submitting any change, you need to be sure who the maintainer
  8294. is or what mailing list that you need to notify. Use either these
  8295. methods to find out:
  8296. - *Maintenance File:* Examine the ``maintainers.inc`` file, which is
  8297. located in the :term:`Source Directory` at
  8298. ``meta/conf/distro/include``, to see who is responsible for code.
  8299. - *Search by File:* Using :ref:`overview-manual/overview-manual-development-environment:git`, you can
  8300. enter the following command to bring up a short list of all
  8301. commits against a specific file:
  8302. ::
  8303. git shortlog -- filename
  8304. Just provide the name of the file for which you are interested. The
  8305. information returned is not ordered by history but does include a
  8306. list of everyone who has committed grouped by name. From the list,
  8307. you can see who is responsible for the bulk of the changes against
  8308. the file.
  8309. - *Examine the List of Mailing Lists:* For a list of the Yocto
  8310. Project and related mailing lists, see the ":ref:`Mailing
  8311. lists <resources-mailinglist>`" section in
  8312. the Yocto Project Reference Manual.
  8313. 6. *Make a Pull Request:* Notify the maintainer or the mailing list that
  8314. you have pushed a change by making a pull request.
  8315. The Yocto Project provides two scripts that conveniently let you
  8316. generate and send pull requests to the Yocto Project. These scripts
  8317. are ``create-pull-request`` and ``send-pull-request``. You can find
  8318. these scripts in the ``scripts`` directory within the
  8319. :term:`Source Directory` (e.g.
  8320. ``~/poky/scripts``).
  8321. Using these scripts correctly formats the requests without
  8322. introducing any whitespace or HTML formatting. The maintainer that
  8323. receives your patches either directly or through the mailing list
  8324. needs to be able to save and apply them directly from your emails.
  8325. Using these scripts is the preferred method for sending patches.
  8326. First, create the pull request. For example, the following command
  8327. runs the script, specifies the upstream repository in the contrib
  8328. directory into which you pushed the change, and provides a subject
  8329. line in the created patch files:
  8330. ::
  8331. $ ~/poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
  8332. Running this script forms ``*.patch`` files in a folder named
  8333. ``pull-``\ `PID` in the current directory. One of the patch files is a
  8334. cover letter.
  8335. Before running the ``send-pull-request`` script, you must edit the
  8336. cover letter patch to insert information about your change. After
  8337. editing the cover letter, send the pull request. For example, the
  8338. following command runs the script and specifies the patch directory
  8339. and email address. In this example, the email address is a mailing
  8340. list:
  8341. ::
  8342. $ ~/poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
  8343. You need to follow the prompts as the script is interactive.
  8344. .. note::
  8345. For help on using these scripts, simply provide the ``-h``
  8346. argument as follows:
  8347. ::
  8348. $ poky/scripts/create-pull-request -h
  8349. $ poky/scripts/send-pull-request -h
  8350. .. _submitting-a-patch:
  8351. Using Email to Submit a Patch
  8352. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8353. You can submit patches without using the ``create-pull-request`` and
  8354. ``send-pull-request`` scripts described in the previous section.
  8355. However, keep in mind, the preferred method is to use the scripts.
  8356. Depending on the components changed, you need to submit the email to a
  8357. specific mailing list. For some guidance on which mailing list to use,
  8358. see the `list <#figuring-out-the-mailing-list-to-use>`__ at the
  8359. beginning of this section. For a description of all the available
  8360. mailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the
  8361. Yocto Project Reference Manual.
  8362. Here is the general procedure on how to submit a patch through email
  8363. without using the scripts:
  8364. 1. *Make Your Changes Locally:* Make your changes in your local Git
  8365. repository. You should make small, controlled, isolated changes.
  8366. Keeping changes small and isolated aids review, makes
  8367. merging/rebasing easier and keeps the change history clean should
  8368. anyone need to refer to it in future.
  8369. 2. *Stage Your Changes:* Stage your changes by using the ``git add``
  8370. command on each file you changed.
  8371. 3. *Commit Your Changes:* Commit the change by using the
  8372. ``git commit --signoff`` command. Using the ``--signoff`` option
  8373. identifies you as the person making the change and also satisfies the
  8374. Developer's Certificate of Origin (DCO) shown earlier.
  8375. When you form a commit, you must follow certain standards established
  8376. by the Yocto Project development team. See :ref:`Step 3
  8377. <dev-manual/dev-manual-common-tasks:using scripts to push a change upstream and request a pull>`
  8378. in the previous section for information on how to provide commit information
  8379. that meets Yocto Project commit message standards.
  8380. 4. *Format the Commit:* Format the commit into an email message. To
  8381. format commits, use the ``git format-patch`` command. When you
  8382. provide the command, you must include a revision list or a number of
  8383. patches as part of the command. For example, either of these two
  8384. commands takes your most recent single commit and formats it as an
  8385. email message in the current directory:
  8386. ::
  8387. $ git format-patch -1
  8388. or ::
  8389. $ git format-patch HEAD~
  8390. After the command is run, the current directory contains a numbered
  8391. ``.patch`` file for the commit.
  8392. If you provide several commits as part of the command, the
  8393. ``git format-patch`` command produces a series of numbered files in
  8394. the current directory – one for each commit. If you have more than
  8395. one patch, you should also use the ``--cover`` option with the
  8396. command, which generates a cover letter as the first "patch" in the
  8397. series. You can then edit the cover letter to provide a description
  8398. for the series of patches. For information on the
  8399. ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed
  8400. using the ``man git-format-patch`` command.
  8401. .. note::
  8402. If you are or will be a frequent contributor to the Yocto Project
  8403. or to OpenEmbedded, you might consider requesting a contrib area
  8404. and the necessary associated rights.
  8405. 5. *Import the Files Into Your Mail Client:* Import the files into your
  8406. mail client by using the ``git send-email`` command.
  8407. .. note::
  8408. In order to use ``git send-email``, you must have the proper Git packages
  8409. installed on your host.
  8410. For Ubuntu, Debian, and Fedora the package is ``git-email``.
  8411. The ``git send-email`` command sends email by using a local or remote
  8412. Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or
  8413. through a direct ``smtp`` configuration in your Git ``~/.gitconfig``
  8414. file. If you are submitting patches through email only, it is very
  8415. important that you submit them without any whitespace or HTML
  8416. formatting that either you or your mailer introduces. The maintainer
  8417. that receives your patches needs to be able to save and apply them
  8418. directly from your emails. A good way to verify that what you are
  8419. sending will be applicable by the maintainer is to do a dry run and
  8420. send them to yourself and then save and apply them as the maintainer
  8421. would.
  8422. The ``git send-email`` command is the preferred method for sending
  8423. your patches using email since there is no risk of compromising
  8424. whitespace in the body of the message, which can occur when you use
  8425. your own mail client. The command also has several options that let
  8426. you specify recipients and perform further editing of the email
  8427. message. For information on how to use the ``git send-email``
  8428. command, see ``GIT-SEND-EMAIL(1)`` displayed using the
  8429. ``man git-send-email`` command.
  8430. Working With Licenses
  8431. =====================
  8432. As mentioned in the ":ref:`overview-manual/overview-manual-development-environment:licensing`"
  8433. section in the Yocto Project Overview and Concepts Manual, open source
  8434. projects are open to the public and they consequently have different
  8435. licensing structures in place. This section describes the mechanism by
  8436. which the :term:`OpenEmbedded Build System`
  8437. tracks changes to
  8438. licensing text and covers how to maintain open source license compliance
  8439. during your project's lifecycle. The section also describes how to
  8440. enable commercially licensed recipes, which by default are disabled.
  8441. .. _usingpoky-configuring-LIC_FILES_CHKSUM:
  8442. Tracking License Changes
  8443. ------------------------
  8444. The license of an upstream project might change in the future. In order
  8445. to prevent these changes going unnoticed, the
  8446. :term:`LIC_FILES_CHKSUM`
  8447. variable tracks changes to the license text. The checksums are validated
  8448. at the end of the configure step, and if the checksums do not match, the
  8449. build will fail.
  8450. .. _usingpoky-specifying-LIC_FILES_CHKSUM:
  8451. Specifying the ``LIC_FILES_CHKSUM`` Variable
  8452. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8453. The ``LIC_FILES_CHKSUM`` variable contains checksums of the license text
  8454. in the source code for the recipe. Following is an example of how to
  8455. specify ``LIC_FILES_CHKSUM``:
  8456. ::
  8457. LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
  8458. file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
  8459. file://licfile2.txt;endline=50;md5=zzzz \
  8460. ..."
  8461. .. note::
  8462. - When using "beginline" and "endline", realize that line numbering
  8463. begins with one and not zero. Also, the included lines are
  8464. inclusive (i.e. lines five through and including 29 in the
  8465. previous example for ``licfile1.txt``).
  8466. - When a license check fails, the selected license text is included
  8467. as part of the QA message. Using this output, you can determine
  8468. the exact start and finish for the needed license text.
  8469. The build system uses the :term:`S`
  8470. variable as the default directory when searching files listed in
  8471. ``LIC_FILES_CHKSUM``. The previous example employs the default
  8472. directory.
  8473. Consider this next example:
  8474. ::
  8475. LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
  8476. md5=bb14ed3c4cda583abc85401304b5cd4e"
  8477. LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
  8478. The first line locates a file in ``${S}/src/ls.c`` and isolates lines
  8479. five through 16 as license text. The second line refers to a file in
  8480. :term:`WORKDIR`.
  8481. Note that ``LIC_FILES_CHKSUM`` variable is mandatory for all recipes,
  8482. unless the ``LICENSE`` variable is set to "CLOSED".
  8483. .. _usingpoky-LIC_FILES_CHKSUM-explanation-of-syntax:
  8484. Explanation of Syntax
  8485. ~~~~~~~~~~~~~~~~~~~~~
  8486. As mentioned in the previous section, the ``LIC_FILES_CHKSUM`` variable
  8487. lists all the important files that contain the license text for the
  8488. source code. It is possible to specify a checksum for an entire file, or
  8489. a specific section of a file (specified by beginning and ending line
  8490. numbers with the "beginline" and "endline" parameters, respectively).
  8491. The latter is useful for source files with a license notice header,
  8492. README documents, and so forth. If you do not use the "beginline"
  8493. parameter, then it is assumed that the text begins on the first line of
  8494. the file. Similarly, if you do not use the "endline" parameter, it is
  8495. assumed that the license text ends with the last line of the file.
  8496. The "md5" parameter stores the md5 checksum of the license text. If the
  8497. license text changes in any way as compared to this parameter then a
  8498. mismatch occurs. This mismatch triggers a build failure and notifies the
  8499. developer. Notification allows the developer to review and address the
  8500. license text changes. Also note that if a mismatch occurs during the
  8501. build, the correct md5 checksum is placed in the build log and can be
  8502. easily copied to the recipe.
  8503. There is no limit to how many files you can specify using the
  8504. ``LIC_FILES_CHKSUM`` variable. Generally, however, every project
  8505. requires a few specifications for license tracking. Many projects have a
  8506. "COPYING" file that stores the license information for all the source
  8507. code files. This practice allows you to just track the "COPYING" file as
  8508. long as it is kept up to date.
  8509. .. note::
  8510. - If you specify an empty or invalid "md5" parameter,
  8511. :term:`BitBake` returns an md5
  8512. mis-match error and displays the correct "md5" parameter value
  8513. during the build. The correct parameter is also captured in the
  8514. build log.
  8515. - If the whole file contains only license text, you do not need to
  8516. use the "beginline" and "endline" parameters.
  8517. Enabling Commercially Licensed Recipes
  8518. --------------------------------------
  8519. By default, the OpenEmbedded build system disables components that have
  8520. commercial or other special licensing requirements. Such requirements
  8521. are defined on a recipe-by-recipe basis through the
  8522. :term:`LICENSE_FLAGS` variable
  8523. definition in the affected recipe. For instance, the
  8524. ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe
  8525. contains the following statement:
  8526. ::
  8527. LICENSE_FLAGS = "commercial"
  8528. Here is a
  8529. slightly more complicated example that contains both an explicit recipe
  8530. name and version (after variable expansion):
  8531. ::
  8532. LICENSE_FLAGS = "license_${PN}_${PV}"
  8533. In order for a component restricted by a
  8534. ``LICENSE_FLAGS`` definition to be enabled and included in an image, it
  8535. needs to have a matching entry in the global
  8536. :term:`LICENSE_FLAGS_WHITELIST`
  8537. variable, which is a variable typically defined in your ``local.conf``
  8538. file. For example, to enable the
  8539. ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you
  8540. could add either the string "commercial_gst-plugins-ugly" or the more
  8541. general string "commercial" to ``LICENSE_FLAGS_WHITELIST``. See the
  8542. "`License Flag Matching <#license-flag-matching>`__" section for a full
  8543. explanation of how ``LICENSE_FLAGS`` matching works. Here is the
  8544. example:
  8545. ::
  8546. LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
  8547. Likewise, to additionally enable the package built from the recipe
  8548. containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that
  8549. the actual recipe name was ``emgd_1.10.bb``, the following string would
  8550. enable that package as well as the original ``gst-plugins-ugly``
  8551. package:
  8552. ::
  8553. LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
  8554. As a convenience, you do not need to specify the
  8555. complete license string in the whitelist for every package. You can use
  8556. an abbreviated form, which consists of just the first portion or
  8557. portions of the license string before the initial underscore character
  8558. or characters. A partial string will match any license that contains the
  8559. given string as the first portion of its license. For example, the
  8560. following whitelist string will also match both of the packages
  8561. previously mentioned as well as any other packages that have licenses
  8562. starting with "commercial" or "license".
  8563. ::
  8564. LICENSE_FLAGS_WHITELIST = "commercial license"
  8565. License Flag Matching
  8566. ~~~~~~~~~~~~~~~~~~~~~
  8567. License flag matching allows you to control what recipes the
  8568. OpenEmbedded build system includes in the build. Fundamentally, the
  8569. build system attempts to match ``LICENSE_FLAGS`` strings found in
  8570. recipes against ``LICENSE_FLAGS_WHITELIST`` strings found in the
  8571. whitelist. A match causes the build system to include a recipe in the
  8572. build, while failure to find a match causes the build system to exclude
  8573. a recipe.
  8574. In general, license flag matching is simple. However, understanding some
  8575. concepts will help you correctly and effectively use matching.
  8576. Before a flag defined by a particular recipe is tested against the
  8577. contents of the whitelist, the expanded string ``_${PN}`` is appended to
  8578. the flag. This expansion makes each ``LICENSE_FLAGS`` value
  8579. recipe-specific. After expansion, the string is then matched against the
  8580. whitelist. Thus, specifying ``LICENSE_FLAGS = "commercial"`` in recipe
  8581. "foo", for example, results in the string ``"commercial_foo"``. And, to
  8582. create a match, that string must appear in the whitelist.
  8583. Judicious use of the ``LICENSE_FLAGS`` strings and the contents of the
  8584. ``LICENSE_FLAGS_WHITELIST`` variable allows you a lot of flexibility for
  8585. including or excluding recipes based on licensing. For example, you can
  8586. broaden the matching capabilities by using license flags string subsets
  8587. in the whitelist.
  8588. .. note::
  8589. When using a string subset, be sure to use the part of the expanded
  8590. string that precedes the appended underscore character (e.g.
  8591. ``usethispart_1.3``, ``usethispart_1.4``, and so forth).
  8592. For example, simply specifying the string "commercial" in the whitelist
  8593. matches any expanded ``LICENSE_FLAGS`` definition that starts with the
  8594. string "commercial" such as "commercial_foo" and "commercial_bar", which
  8595. are the strings the build system automatically generates for
  8596. hypothetical recipes named "foo" and "bar" assuming those recipes simply
  8597. specify the following:
  8598. ::
  8599. LICENSE_FLAGS = "commercial"
  8600. Thus, you can choose
  8601. to exhaustively enumerate each license flag in the whitelist and allow
  8602. only specific recipes into the image, or you can use a string subset
  8603. that causes a broader range of matches to allow a range of recipes into
  8604. the image.
  8605. This scheme works even if the ``LICENSE_FLAGS`` string already has
  8606. ``_${PN}`` appended. For example, the build system turns the license
  8607. flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match
  8608. both the general "commercial" and the specific "commercial_1.2_foo"
  8609. strings found in the whitelist, as expected.
  8610. Here are some other scenarios:
  8611. - You can specify a versioned string in the recipe such as
  8612. "commercial_foo_1.2" in a "foo" recipe. The build system expands this
  8613. string to "commercial_foo_1.2_foo". Combine this license flag with a
  8614. whitelist that has the string "commercial" and you match the flag
  8615. along with any other flag that starts with the string "commercial".
  8616. - Under the same circumstances, you can use "commercial_foo" in the
  8617. whitelist and the build system not only matches "commercial_foo_1.2"
  8618. but also matches any license flag with the string "commercial_foo",
  8619. regardless of the version.
  8620. - You can be very specific and use both the package and version parts
  8621. in the whitelist (e.g. "commercial_foo_1.2") to specifically match a
  8622. versioned recipe.
  8623. Other Variables Related to Commercial Licenses
  8624. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8625. Other helpful variables related to commercial license handling exist and
  8626. are defined in the
  8627. ``poky/meta/conf/distro/include/default-distrovars.inc`` file:
  8628. ::
  8629. COMMERCIAL_AUDIO_PLUGINS ?= ""
  8630. COMMERCIAL_VIDEO_PLUGINS ?= ""
  8631. If you
  8632. want to enable these components, you can do so by making sure you have
  8633. statements similar to the following in your ``local.conf`` configuration
  8634. file:
  8635. ::
  8636. COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
  8637. gst-plugins-ugly-mpegaudioparse"
  8638. COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
  8639. gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
  8640. LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
  8641. Of course, you could also create a matching whitelist for those
  8642. components using the more general "commercial" in the whitelist, but
  8643. that would also enable all the other packages with ``LICENSE_FLAGS``
  8644. containing "commercial", which you may or may not want:
  8645. ::
  8646. LICENSE_FLAGS_WHITELIST = "commercial"
  8647. Specifying audio and video plugins as part of the
  8648. ``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements
  8649. (along with the enabling ``LICENSE_FLAGS_WHITELIST``) includes the
  8650. plugins or components into built images, thus adding support for media
  8651. formats or components.
  8652. Maintaining Open Source License Compliance During Your Product's Lifecycle
  8653. --------------------------------------------------------------------------
  8654. One of the concerns for a development organization using open source
  8655. software is how to maintain compliance with various open source
  8656. licensing during the lifecycle of the product. While this section does
  8657. not provide legal advice or comprehensively cover all scenarios, it does
  8658. present methods that you can use to assist you in meeting the compliance
  8659. requirements during a software release.
  8660. With hundreds of different open source licenses that the Yocto Project
  8661. tracks, it is difficult to know the requirements of each and every
  8662. license. However, the requirements of the major FLOSS licenses can begin
  8663. to be covered by assuming that three main areas of concern exist:
  8664. - Source code must be provided.
  8665. - License text for the software must be provided.
  8666. - Compilation scripts and modifications to the source code must be
  8667. provided.
  8668. There are other requirements beyond the scope of these three and the
  8669. methods described in this section (e.g. the mechanism through which
  8670. source code is distributed).
  8671. As different organizations have different methods of complying with open
  8672. source licensing, this section is not meant to imply that there is only
  8673. one single way to meet your compliance obligations, but rather to
  8674. describe one method of achieving compliance. The remainder of this
  8675. section describes methods supported to meet the previously mentioned
  8676. three requirements. Once you take steps to meet these requirements, and
  8677. prior to releasing images, sources, and the build system, you should
  8678. audit all artifacts to ensure completeness.
  8679. .. note::
  8680. The Yocto Project generates a license manifest during image creation
  8681. that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp`
  8682. to assist with any audits.
  8683. Providing the Source Code
  8684. ~~~~~~~~~~~~~~~~~~~~~~~~~
  8685. Compliance activities should begin before you generate the final image.
  8686. The first thing you should look at is the requirement that tops the list
  8687. for most compliance groups - providing the source. The Yocto Project has
  8688. a few ways of meeting this requirement.
  8689. One of the easiest ways to meet this requirement is to provide the
  8690. entire :term:`DL_DIR` used by the
  8691. build. This method, however, has a few issues. The most obvious is the
  8692. size of the directory since it includes all sources used in the build
  8693. and not just the source used in the released image. It will include
  8694. toolchain source, and other artifacts, which you would not generally
  8695. release. However, the more serious issue for most companies is
  8696. accidental release of proprietary software. The Yocto Project provides
  8697. an :ref:`archiver <ref-classes-archiver>` class to
  8698. help avoid some of these concerns.
  8699. Before you employ ``DL_DIR`` or the ``archiver`` class, you need to
  8700. decide how you choose to provide source. The source ``archiver`` class
  8701. can generate tarballs and SRPMs and can create them with various levels
  8702. of compliance in mind.
  8703. One way of doing this (but certainly not the only way) is to release
  8704. just the source as a tarball. You can do this by adding the following to
  8705. the ``local.conf`` file found in the
  8706. :term:`Build Directory`:
  8707. ::
  8708. INHERIT += "archiver"
  8709. ARCHIVER_MODE[src] = "original"
  8710. During the creation of your
  8711. image, the source from all recipes that deploy packages to the image is
  8712. placed within subdirectories of ``DEPLOY_DIR/sources`` based on the
  8713. :term:`LICENSE` for each recipe.
  8714. Releasing the entire directory enables you to comply with requirements
  8715. concerning providing the unmodified source. It is important to note that
  8716. the size of the directory can get large.
  8717. A way to help mitigate the size issue is to only release tarballs for
  8718. licenses that require the release of source. Let us assume you are only
  8719. concerned with GPL code as identified by running the following script:
  8720. .. code-block:: shell
  8721. # Script to archive a subset of packages matching specific license(s)
  8722. # Source and license files are copied into sub folders of package folder
  8723. # Must be run from build folder
  8724. #!/bin/bash
  8725. src_release_dir="source-release"
  8726. mkdir -p $src_release_dir
  8727. for a in tmp/deploy/sources/*; do
  8728. for d in $a/*; do
  8729. # Get package name from path
  8730. p=`basename $d`
  8731. p=${p%-*}
  8732. p=${p%-*}
  8733. # Only archive GPL packages (update *GPL* regex for your license check)
  8734. numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
  8735. if [ $numfiles -gt 1 ]; then
  8736. echo Archiving $p
  8737. mkdir -p $src_release_dir/$p/source
  8738. cp $d/* $src_release_dir/$p/source 2> /dev/null
  8739. mkdir -p $src_release_dir/$p/license
  8740. cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
  8741. fi
  8742. done
  8743. done
  8744. At this point, you
  8745. could create a tarball from the ``gpl_source_release`` directory and
  8746. provide that to the end user. This method would be a step toward
  8747. achieving compliance with section 3a of GPLv2 and with section 6 of
  8748. GPLv3.
  8749. Providing License Text
  8750. ~~~~~~~~~~~~~~~~~~~~~~
  8751. One requirement that is often overlooked is inclusion of license text.
  8752. This requirement also needs to be dealt with prior to generating the
  8753. final image. Some licenses require the license text to accompany the
  8754. binary. You can achieve this by adding the following to your
  8755. ``local.conf`` file:
  8756. ::
  8757. COPY_LIC_MANIFEST = "1"
  8758. COPY_LIC_DIRS = "1"
  8759. LICENSE_CREATE_PACKAGE = "1"
  8760. Adding these statements to the
  8761. configuration file ensures that the licenses collected during package
  8762. generation are included on your image.
  8763. .. note::
  8764. Setting all three variables to "1" results in the image having two
  8765. copies of the same license file. One copy resides in
  8766. ``/usr/share/common-licenses`` and the other resides in
  8767. ``/usr/share/license``.
  8768. The reason for this behavior is because
  8769. :term:`COPY_LIC_DIRS` and
  8770. :term:`COPY_LIC_MANIFEST`
  8771. add a copy of the license when the image is built but do not offer a
  8772. path for adding licenses for newly installed packages to an image.
  8773. :term:`LICENSE_CREATE_PACKAGE`
  8774. adds a separate package and an upgrade path for adding licenses to an
  8775. image.
  8776. As the source ``archiver`` class has already archived the original
  8777. unmodified source that contains the license files, you would have
  8778. already met the requirements for inclusion of the license information
  8779. with source as defined by the GPL and other open source licenses.
  8780. Providing Compilation Scripts and Source Code Modifications
  8781. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8782. At this point, we have addressed all we need to prior to generating the
  8783. image. The next two requirements are addressed during the final
  8784. packaging of the release.
  8785. By releasing the version of the OpenEmbedded build system and the layers
  8786. used during the build, you will be providing both compilation scripts
  8787. and the source code modifications in one step.
  8788. If the deployment team has a :ref:`overview-manual/overview-manual-concepts:bsp layer`
  8789. and a distro layer, and those
  8790. those layers are used to patch, compile, package, or modify (in any way)
  8791. any open source software included in your released images, you might be
  8792. required to release those layers under section 3 of GPLv2 or section 1
  8793. of GPLv3. One way of doing that is with a clean checkout of the version
  8794. of the Yocto Project and layers used during your build. Here is an
  8795. example:
  8796. .. code-block:: shell
  8797. # We built using the dunfell branch of the poky repo
  8798. $ git clone -b dunfell git://git.yoctoproject.org/poky
  8799. $ cd poky
  8800. # We built using the release_branch for our layers
  8801. $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
  8802. $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
  8803. # clean up the .git repos
  8804. $ find . -name ".git" -type d -exec rm -rf {} \;
  8805. One
  8806. thing a development organization might want to consider for end-user
  8807. convenience is to modify ``meta-poky/conf/bblayers.conf.sample`` to
  8808. ensure that when the end user utilizes the released build system to
  8809. build an image, the development organization's layers are included in
  8810. the ``bblayers.conf`` file automatically:
  8811. ::
  8812. # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
  8813. # changes incompatibly
  8814. POKY_BBLAYERS_CONF_VERSION = "2"
  8815. BBPATH = "${TOPDIR}"
  8816. BBFILES ?= ""
  8817. BBLAYERS ?= " \
  8818. ##OEROOT##/meta \
  8819. ##OEROOT##/meta-poky \
  8820. ##OEROOT##/meta-yocto-bsp \
  8821. ##OEROOT##/meta-mylayer \
  8822. "
  8823. Creating and
  8824. providing an archive of the :term:`Metadata`
  8825. layers (recipes, configuration files, and so forth) enables you to meet
  8826. your requirements to include the scripts to control compilation as well
  8827. as any modifications to the original source.
  8828. Copying Licenses that Do Not Exist
  8829. ----------------------------------
  8830. Some packages, such as the linux-firmware package, have many licenses
  8831. that are not in any way common. You can avoid adding a lot of these
  8832. types of common license files, which are only applicable to a specific
  8833. package, by using the
  8834. :term:`NO_GENERIC_LICENSE`
  8835. variable. Using this variable also avoids QA errors when you use a
  8836. non-common, non-CLOSED license in a recipe.
  8837. The following is an example that uses the ``LICENSE.Abilis.txt`` file as
  8838. the license from the fetched source:
  8839. ::
  8840. NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
  8841. Using the Error Reporting Tool
  8842. ==============================
  8843. The error reporting tool allows you to submit errors encountered during
  8844. builds to a central database. Outside of the build environment, you can
  8845. use a web interface to browse errors, view statistics, and query for
  8846. errors. The tool works using a client-server system where the client
  8847. portion is integrated with the installed Yocto Project
  8848. :term:`Source Directory` (e.g. ``poky``).
  8849. The server receives the information collected and saves it in a
  8850. database.
  8851. A live instance of the error reporting server exists at
  8852. https://errors.yoctoproject.org. This server exists so that when
  8853. you want to get help with build failures, you can submit all of the
  8854. information on the failure easily and then point to the URL in your bug
  8855. report or send an email to the mailing list.
  8856. .. note::
  8857. If you send error reports to this server, the reports become publicly
  8858. visible.
  8859. Enabling and Using the Tool
  8860. ---------------------------
  8861. By default, the error reporting tool is disabled. You can enable it by
  8862. inheriting the
  8863. :ref:`report-error <ref-classes-report-error>`
  8864. class by adding the following statement to the end of your
  8865. ``local.conf`` file in your
  8866. :term:`Build Directory`.
  8867. ::
  8868. INHERIT += "report-error"
  8869. By default, the error reporting feature stores information in
  8870. ``${``\ :term:`LOG_DIR`\ ``}/error-report``.
  8871. However, you can specify a directory to use by adding the following to
  8872. your ``local.conf`` file:
  8873. ::
  8874. ERR_REPORT_DIR = "path"
  8875. Enabling error
  8876. reporting causes the build process to collect the errors and store them
  8877. in a file as previously described. When the build system encounters an
  8878. error, it includes a command as part of the console output. You can run
  8879. the command to send the error file to the server. For example, the
  8880. following command sends the errors to an upstream server:
  8881. ::
  8882. $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
  8883. In the previous example, the errors are sent to a public database
  8884. available at https://errors.yoctoproject.org, which is used by the
  8885. entire community. If you specify a particular server, you can send the
  8886. errors to a different database. Use the following command for more
  8887. information on available options:
  8888. ::
  8889. $ send-error-report --help
  8890. When sending the error file, you are prompted to review the data being
  8891. sent as well as to provide a name and optional email address. Once you
  8892. satisfy these prompts, the command returns a link from the server that
  8893. corresponds to your entry in the database. For example, here is a
  8894. typical link: https://errors.yoctoproject.org/Errors/Details/9522/
  8895. Following the link takes you to a web interface where you can browse,
  8896. query the errors, and view statistics.
  8897. Disabling the Tool
  8898. ------------------
  8899. To disable the error reporting feature, simply remove or comment out the
  8900. following statement from the end of your ``local.conf`` file in your
  8901. :term:`Build Directory`.
  8902. ::
  8903. INHERIT += "report-error"
  8904. Setting Up Your Own Error Reporting Server
  8905. ------------------------------------------
  8906. If you want to set up your own error reporting server, you can obtain
  8907. the code from the Git repository at :yocto_git:`/cgit/cgit.cgi/error-report-web/`.
  8908. Instructions on how to set it up are in the README document.
  8909. .. _dev-using-wayland-and-weston:
  8910. Using Wayland and Weston
  8911. ========================
  8912. `Wayland <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)>`__
  8913. is a computer display server protocol that provides a method for
  8914. compositing window managers to communicate directly with applications
  8915. and video hardware and expects them to communicate with input hardware
  8916. using other libraries. Using Wayland with supporting targets can result
  8917. in better control over graphics frame rendering than an application
  8918. might otherwise achieve.
  8919. The Yocto Project provides the Wayland protocol libraries and the
  8920. reference
  8921. `Weston <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston>`__
  8922. compositor as part of its release. You can find the integrated packages
  8923. in the ``meta`` layer of the :term:`Source Directory`.
  8924. Specifically, you
  8925. can find the recipes that build both Wayland and Weston at
  8926. ``meta/recipes-graphics/wayland``.
  8927. You can build both the Wayland and Weston packages for use only with
  8928. targets that accept the `Mesa 3D and Direct Rendering
  8929. Infrastructure <https://en.wikipedia.org/wiki/Mesa_(computer_graphics)>`__,
  8930. which is also known as Mesa DRI. This implies that you cannot build and
  8931. use the packages if your target uses, for example, the Intel Embedded
  8932. Media and Graphics Driver (Intel EMGD) that overrides Mesa DRI.
  8933. .. note::
  8934. Due to lack of EGL support, Weston 1.0.3 will not run directly on the
  8935. emulated QEMU hardware. However, this version of Weston will run
  8936. under X emulation without issues.
  8937. This section describes what you need to do to implement Wayland and use
  8938. the Weston compositor when building an image for a supporting target.
  8939. Enabling Wayland in an Image
  8940. ----------------------------
  8941. To enable Wayland, you need to enable it to be built and enable it to be
  8942. included (installed) in the image.
  8943. .. _enable-building:
  8944. Building Wayland
  8945. ~~~~~~~~~~~~~~~~
  8946. To cause Mesa to build the ``wayland-egl`` platform and Weston to build
  8947. Wayland with Kernel Mode Setting
  8948. (`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__)
  8949. support, include the "wayland" flag in the
  8950. :term:`DISTRO_FEATURES`
  8951. statement in your ``local.conf`` file:
  8952. ::
  8953. DISTRO_FEATURES_append = " wayland"
  8954. .. note::
  8955. If X11 has been enabled elsewhere, Weston will build Wayland with X11
  8956. support
  8957. .. _enable-installation-in-an-image:
  8958. Installing Wayland and Weston
  8959. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8960. To install the Wayland feature into an image, you must include the
  8961. following
  8962. :term:`CORE_IMAGE_EXTRA_INSTALL`
  8963. statement in your ``local.conf`` file:
  8964. ::
  8965. CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
  8966. Running Weston
  8967. --------------
  8968. To run Weston inside X11, enabling it as described earlier and building
  8969. a Sato image is sufficient. If you are running your image under Sato, a
  8970. Weston Launcher appears in the "Utility" category.
  8971. Alternatively, you can run Weston through the command-line interpretor
  8972. (CLI), which is better suited for development work. To run Weston under
  8973. the CLI, you need to do the following after your image is built:
  8974. 1. Run these commands to export ``XDG_RUNTIME_DIR``:
  8975. ::
  8976. mkdir -p /tmp/$USER-weston
  8977. chmod 0700 /tmp/$USER-weston
  8978. export XDG_RUNTIME_DIR=/tmp/$USER-weston
  8979. 2. Launch Weston in the shell:
  8980. ::
  8981. weston