common-tasks.rst 454 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581
  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/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/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 :oe_layerindex:`OpenEmbedded Metadata Index <>`
  34. for a list of layers from the OpenEmbedded community that can be used in
  35. the Yocto Project. You could find a layer that is identical or close
  36. to what you need.
  37. 2. *Create a Directory:* Create the directory for your layer. When you
  38. create the layer, be sure to create the directory in an area not
  39. associated with the Yocto Project :term:`Source Directory`
  40. (e.g. the cloned ``poky`` repository).
  41. While not strictly required, prepend the name of the directory with
  42. the string "meta-". For example:
  43. ::
  44. meta-mylayer
  45. meta-GUI_xyz
  46. meta-mymachine
  47. With rare exceptions, a layer's name follows this form:
  48. ::
  49. meta-root_name
  50. Following this layer naming convention can save
  51. you trouble later when tools, components, or variables "assume" your
  52. layer name begins with "meta-". A notable example is in configuration
  53. files as shown in the following step where layer names without the
  54. "meta-" string are appended to several variables used in the
  55. configuration.
  56. 3. *Create a Layer Configuration File:* Inside your new layer folder,
  57. you need to create a ``conf/layer.conf`` file. It is easiest to take
  58. an existing layer configuration file and copy that to your layer's
  59. ``conf`` directory and then modify the file as needed.
  60. The ``meta-yocto-bsp/conf/layer.conf`` file in the Yocto Project
  61. :yocto_git:`Source Repositories </poky/tree/meta-yocto-bsp/conf>`
  62. demonstrates the required syntax. For your layer, you need to replace
  63. "yoctobsp" with a unique identifier for your layer (e.g. "machinexyz"
  64. for a layer named "meta-machinexyz"):
  65. ::
  66. # We have a conf and classes directory, add to BBPATH
  67. BBPATH .= ":${LAYERDIR}"
  68. # We have recipes-* directories, add to BBFILES
  69. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  70. ${LAYERDIR}/recipes-*/*/*.bbappend"
  71. BBFILE_COLLECTIONS += "yoctobsp"
  72. BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
  73. BBFILE_PRIORITY_yoctobsp = "5"
  74. LAYERVERSION_yoctobsp = "4"
  75. LAYERSERIES_COMPAT_yoctobsp = "dunfell"
  76. Following is an explanation of the layer configuration file:
  77. - :term:`BBPATH`: Adds the layer's
  78. root directory to BitBake's search path. Through the use of the
  79. ``BBPATH`` variable, BitBake locates class files (``.bbclass``),
  80. configuration files, and files that are included with ``include``
  81. and ``require`` statements. For these cases, BitBake uses the
  82. first file that matches the name found in ``BBPATH``. This is
  83. similar to the way the ``PATH`` variable is used for binaries. It
  84. is recommended, therefore, that you use unique class and
  85. configuration filenames in your custom layer.
  86. - :term:`BBFILES`: Defines the
  87. location for all recipes in the layer.
  88. - :term:`BBFILE_COLLECTIONS`:
  89. Establishes the current layer through a unique identifier that is
  90. used throughout the OpenEmbedded build system to refer to the
  91. layer. In this example, the identifier "yoctobsp" is the
  92. representation for the container layer named "meta-yocto-bsp".
  93. - :term:`BBFILE_PATTERN`:
  94. Expands immediately during parsing to provide the directory of the
  95. layer.
  96. - :term:`BBFILE_PRIORITY`:
  97. Establishes a priority to use for recipes in the layer when the
  98. OpenEmbedded build finds recipes of the same name in different
  99. layers.
  100. - :term:`LAYERVERSION`:
  101. Establishes a version number for the layer. You can use this
  102. version number to specify this exact version of the layer as a
  103. dependency when using the
  104. :term:`LAYERDEPENDS`
  105. variable.
  106. - :term:`LAYERDEPENDS`:
  107. Lists all layers on which this layer depends (if any).
  108. - :term:`LAYERSERIES_COMPAT`:
  109. Lists the :yocto_wiki:`Yocto Project </Releases>`
  110. releases for which the current version is compatible. This
  111. variable is a good way to indicate if your particular layer is
  112. current.
  113. 4. *Add Content:* Depending on the type of layer, add the content. If
  114. the layer adds support for a machine, add the machine configuration
  115. in a ``conf/machine/`` file within the layer. If the layer adds
  116. distro policy, add the distro configuration in a ``conf/distro/``
  117. file within the layer. If the layer introduces new recipes, put the
  118. recipes you need in ``recipes-*`` subdirectories within the layer.
  119. .. note::
  120. For an explanation of layer hierarchy that is compliant with the
  121. Yocto Project, see the ":ref:`bsp-guide/bsp:example filesystem layout`"
  122. section in the Yocto Project Board Support Package (BSP) Developer's Guide.
  123. 5. *Optionally Test for Compatibility:* If you want permission to use
  124. the Yocto Project Compatibility logo with your layer or application
  125. that uses your layer, perform the steps to apply for compatibility.
  126. See the "`Making Sure Your Layer is Compatible With Yocto
  127. Project <#making-sure-your-layer-is-compatible-with-yocto-project>`__"
  128. section for more information.
  129. Following Best Practices When Creating Layers
  130. ---------------------------------------------
  131. To create layers that are easier to maintain and that will not impact
  132. builds for other machines, you should consider the information in the
  133. following list:
  134. - *Avoid "Overlaying" Entire Recipes from Other Layers in Your
  135. Configuration:* In other words, do not copy an entire recipe into
  136. your layer and then modify it. Rather, use an append file
  137. (``.bbappend``) to override only those parts of the original recipe
  138. you need to modify.
  139. - *Avoid Duplicating Include Files:* Use append files (``.bbappend``)
  140. for each recipe that uses an include file. Or, if you are introducing
  141. a new recipe that requires the included file, use the path relative
  142. to the original layer directory to refer to the file. For example,
  143. use ``require recipes-core/``\ `package`\ ``/``\ `file`\ ``.inc`` instead
  144. of ``require`` `file`\ ``.inc``. If you're finding you have to overlay
  145. the include file, it could indicate a deficiency in the include file
  146. in the layer to which it originally belongs. If this is the case, you
  147. should try to address that deficiency instead of overlaying the
  148. include file. For example, you could address this by getting the
  149. maintainer of the include file to add a variable or variables to make
  150. it easy to override the parts needing to be overridden.
  151. - *Structure Your Layers:* Proper use of overrides within append files
  152. and placement of machine-specific files within your layer can ensure
  153. that a build is not using the wrong Metadata and negatively impacting
  154. a build for a different machine. Following are some examples:
  155. - *Modify Variables to Support a Different Machine:* Suppose you
  156. have a layer named ``meta-one`` that adds support for building
  157. machine "one". To do so, you use an append file named
  158. ``base-files.bbappend`` and create a dependency on "foo" by
  159. altering the :term:`DEPENDS`
  160. variable:
  161. ::
  162. DEPENDS = "foo"
  163. The dependency is created during any
  164. build that includes the layer ``meta-one``. However, you might not
  165. want this dependency for all machines. For example, suppose you
  166. are building for machine "two" but your ``bblayers.conf`` file has
  167. the ``meta-one`` layer included. During the build, the
  168. ``base-files`` for machine "two" will also have the dependency on
  169. ``foo``.
  170. To make sure your changes apply only when building machine "one",
  171. use a machine override with the ``DEPENDS`` statement:
  172. ::
  173. DEPENDS_one = "foo"
  174. You should follow the same strategy when using ``_append``
  175. and ``_prepend`` operations:
  176. ::
  177. DEPENDS_append_one = " foo"
  178. DEPENDS_prepend_one = "foo "
  179. As an actual example, here's a
  180. snippet from the generic kernel include file ``linux-yocto.inc``,
  181. wherein the kernel compile and link options are adjusted in the
  182. case of a subset of the supported architectures:
  183. ::
  184. DEPENDS_append_aarch64 = " libgcc"
  185. KERNEL_CC_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
  186. KERNEL_LD_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
  187. DEPENDS_append_nios2 = " libgcc"
  188. KERNEL_CC_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
  189. KERNEL_LD_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
  190. DEPENDS_append_arc = " libgcc"
  191. KERNEL_CC_append_arc = " ${TOOLCHAIN_OPTIONS}"
  192. KERNEL_LD_append_arc = " ${TOOLCHAIN_OPTIONS}"
  193. KERNEL_FEATURES_append_qemuall=" features/debug/printk.scc"
  194. .. note::
  195. Avoiding "+=" and "=+" and using machine-specific ``_append``
  196. and ``_prepend`` operations is recommended as well.
  197. - *Place Machine-Specific Files in Machine-Specific Locations:* When
  198. you have a base recipe, such as ``base-files.bb``, that contains a
  199. :term:`SRC_URI` statement to a
  200. file, you can use an append file to cause the build to use your
  201. own version of the file. For example, an append file in your layer
  202. at ``meta-one/recipes-core/base-files/base-files.bbappend`` could
  203. extend :term:`FILESPATH` using :term:`FILESEXTRAPATHS` as follows:
  204. ::
  205. FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
  206. The build for machine "one" will pick up your machine-specific file as
  207. long as you have the file in
  208. ``meta-one/recipes-core/base-files/base-files/``. However, if you
  209. are building for a different machine and the ``bblayers.conf``
  210. file includes the ``meta-one`` layer and the location of your
  211. machine-specific file is the first location where that file is
  212. found according to ``FILESPATH``, builds for all machines will
  213. also use that machine-specific file.
  214. You can make sure that a machine-specific file is used for a
  215. particular machine by putting the file in a subdirectory specific
  216. to the machine. For example, rather than placing the file in
  217. ``meta-one/recipes-core/base-files/base-files/`` as shown above,
  218. put it in ``meta-one/recipes-core/base-files/base-files/one/``.
  219. Not only does this make sure the file is used only when building
  220. for machine "one", but the build process locates the file more
  221. quickly.
  222. In summary, you need to place all files referenced from
  223. ``SRC_URI`` in a machine-specific subdirectory within the layer in
  224. order to restrict those files to machine-specific builds.
  225. - *Perform Steps to Apply for Yocto Project Compatibility:* If you want
  226. permission to use the Yocto Project Compatibility logo with your
  227. layer or application that uses your layer, perform the steps to apply
  228. for compatibility. See the "`Making Sure Your Layer is Compatible
  229. With Yocto
  230. Project <#making-sure-your-layer-is-compatible-with-yocto-project>`__"
  231. section for more information.
  232. - *Follow the Layer Naming Convention:* Store custom layers in a Git
  233. repository that use the ``meta-layer_name`` format.
  234. - *Group Your Layers Locally:* Clone your repository alongside other
  235. cloned ``meta`` directories from the :term:`Source Directory`.
  236. Making Sure Your Layer is Compatible With Yocto Project
  237. -------------------------------------------------------
  238. When you create a layer used with the Yocto Project, it is advantageous
  239. to make sure that the layer interacts well with existing Yocto Project
  240. layers (i.e. the layer is compatible with the Yocto Project). Ensuring
  241. compatibility makes the layer easy to be consumed by others in the Yocto
  242. Project community and could allow you permission to use the Yocto
  243. Project Compatible Logo.
  244. .. note::
  245. Only Yocto Project member organizations are permitted to use the
  246. Yocto Project Compatible Logo. The logo is not available for general
  247. use. For information on how to become a Yocto Project member
  248. organization, see the :yocto_home:`Yocto Project Website <>`.
  249. The Yocto Project Compatibility Program consists of a layer application
  250. process that requests permission to use the Yocto Project Compatibility
  251. Logo for your layer and application. The process consists of two parts:
  252. 1. Successfully passing a script (``yocto-check-layer``) that when run
  253. against your layer, tests it against constraints based on experiences
  254. of how layers have worked in the real world and where pitfalls have
  255. been found. Getting a "PASS" result from the script is required for
  256. successful compatibility registration.
  257. 2. Completion of an application acceptance form, which you can find at
  258. :yocto_home:`/webform/yocto-project-compatible-registration`.
  259. To be granted permission to use the logo, you need to satisfy the
  260. following:
  261. - Be able to check the box indicating that you got a "PASS" when
  262. running the script against your layer.
  263. - Answer "Yes" to the questions on the form or have an acceptable
  264. explanation for any questions answered "No".
  265. - Be a Yocto Project Member Organization.
  266. The remainder of this section presents information on the registration
  267. form and on the ``yocto-check-layer`` script.
  268. Yocto Project Compatible Program Application
  269. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  270. Use the form to apply for your layer's approval. Upon successful
  271. application, you can use the Yocto Project Compatibility Logo with your
  272. layer and the application that uses your layer.
  273. To access the form, use this link:
  274. :yocto_home:`/webform/yocto-project-compatible-registration`.
  275. Follow the instructions on the form to complete your application.
  276. The application consists of the following sections:
  277. - *Contact Information:* Provide your contact information as the fields
  278. require. Along with your information, provide the released versions
  279. of the Yocto Project for which your layer is compatible.
  280. - *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the
  281. items in the checklist. Space exists at the bottom of the form for
  282. any explanations for items for which you answered "No".
  283. - *Recommendations:* Provide answers for the questions regarding Linux
  284. kernel use and build success.
  285. ``yocto-check-layer`` Script
  286. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  287. The ``yocto-check-layer`` script provides you a way to assess how
  288. compatible your layer is with the Yocto Project. You should run this
  289. script prior to using the form to apply for compatibility as described
  290. in the previous section. You need to achieve a "PASS" result in order to
  291. have your application form successfully processed.
  292. The script divides tests into three areas: COMMON, BSP, and DISTRO. For
  293. example, given a distribution layer (DISTRO), the layer must pass both
  294. the COMMON and DISTRO related tests. Furthermore, if your layer is a BSP
  295. layer, the layer must pass the COMMON and BSP set of tests.
  296. To execute the script, enter the following commands from your build
  297. directory:
  298. ::
  299. $ source oe-init-build-env
  300. $ yocto-check-layer your_layer_directory
  301. Be sure to provide the actual directory for your
  302. layer as part of the command.
  303. Entering the command causes the script to determine the type of layer
  304. and then to execute a set of specific tests against the layer. The
  305. following list overviews the test:
  306. - ``common.test_readme``: Tests if a ``README`` file exists in the
  307. layer and the file is not empty.
  308. - ``common.test_parse``: Tests to make sure that BitBake can parse the
  309. files without error (i.e. ``bitbake -p``).
  310. - ``common.test_show_environment``: Tests that the global or per-recipe
  311. environment is in order without errors (i.e. ``bitbake -e``).
  312. - ``common.test_world``: Verifies that ``bitbake world`` works.
  313. - ``common.test_signatures``: Tests to be sure that BSP and DISTRO
  314. layers do not come with recipes that change signatures.
  315. - ``common.test_layerseries_compat``: Verifies layer compatibility is
  316. set properly.
  317. - ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine
  318. configurations.
  319. - ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not
  320. set the machine when the layer is added.
  321. - ``bsp.test_machine_world``: Verifies that ``bitbake world`` works
  322. regardless of which machine is selected.
  323. - ``bsp.test_machine_signatures``: Verifies that building for a
  324. particular machine affects only the signature of tasks specific to
  325. that machine.
  326. - ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has
  327. distro configurations.
  328. - ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer
  329. does not set the distribution when the layer is added.
  330. Enabling Your Layer
  331. -------------------
  332. Before the OpenEmbedded build system can use your new layer, you need to
  333. enable it. To enable your layer, simply add your layer's path to the
  334. ``BBLAYERS`` variable in your ``conf/bblayers.conf`` file, which is
  335. found in the :term:`Build Directory`.
  336. The following example shows how to enable a layer named
  337. ``meta-mylayer``:
  338. ::
  339. # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
  340. # changes incompatibly
  341. POKY_BBLAYERS_CONF_VERSION = "2"
  342. BBPATH = "${TOPDIR}"
  343. BBFILES ?= ""
  344. BBLAYERS ?= " \
  345. /home/user/poky/meta \
  346. /home/user/poky/meta-poky \
  347. /home/user/poky/meta-yocto-bsp \
  348. /home/user/poky/meta-mylayer \
  349. "
  350. BitBake parses each ``conf/layer.conf`` file from the top down as
  351. specified in the ``BBLAYERS`` variable within the ``conf/bblayers.conf``
  352. file. During the processing of each ``conf/layer.conf`` file, BitBake
  353. adds the recipes, classes and configurations contained within the
  354. particular layer to the source directory.
  355. Using .bbappend Files in Your Layer
  356. -----------------------------------
  357. A recipe that appends Metadata to another recipe is called a BitBake
  358. append file. A BitBake append file uses the ``.bbappend`` file type
  359. suffix, while the corresponding recipe to which Metadata is being
  360. appended uses the ``.bb`` file type suffix.
  361. You can use a ``.bbappend`` file in your layer to make additions or
  362. changes to the content of another layer's recipe without having to copy
  363. the other layer's recipe into your layer. Your ``.bbappend`` file
  364. resides in your layer, while the main ``.bb`` recipe file to which you
  365. are appending Metadata resides in a different layer.
  366. Being able to append information to an existing recipe not only avoids
  367. duplication, but also automatically applies recipe changes from a
  368. different layer into your layer. If you were copying recipes, you would
  369. have to manually merge changes as they occur.
  370. When you create an append file, you must use the same root name as the
  371. corresponding recipe file. For example, the append file
  372. ``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This
  373. means the original recipe and append file names are version
  374. number-specific. If the corresponding recipe is renamed to update to a
  375. newer version, you must also rename and possibly update the
  376. corresponding ``.bbappend`` as well. During the build process, BitBake
  377. displays an error on starting if it detects a ``.bbappend`` file that
  378. does not have a corresponding recipe with a matching name. See the
  379. :term:`BB_DANGLINGAPPENDS_WARNONLY`
  380. variable for information on how to handle this error.
  381. As an example, consider the main formfactor recipe and a corresponding
  382. formfactor append file both from the :term:`Source Directory`.
  383. Here is the main
  384. formfactor recipe, which is named ``formfactor_0.0.bb`` and located in
  385. the "meta" layer at ``meta/recipes-bsp/formfactor``:
  386. ::
  387. SUMMARY = "Device formfactor information"
  388. DESCRIPTION = "A formfactor configuration file provides information about the \
  389. target hardware for which the image is being built and information that the \
  390. build system cannot obtain from other sources such as the kernel."
  391. SECTION = "base"
  392. LICENSE = "MIT"
  393. LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
  394. PR = "r45"
  395. SRC_URI = "file://config file://machconfig"
  396. S = "${WORKDIR}"
  397. PACKAGE_ARCH = "${MACHINE_ARCH}"
  398. INHIBIT_DEFAULT_DEPS = "1"
  399. do_install() {
  400. # Install file only if it has contents
  401. install -d ${D}${sysconfdir}/formfactor/
  402. install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
  403. if [ -s "${S}/machconfig" ]; then
  404. install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
  405. fi
  406. }
  407. In the main recipe, note the :term:`SRC_URI`
  408. variable, which tells the OpenEmbedded build system where to find files
  409. during the build.
  410. Following is the append file, which is named ``formfactor_0.0.bbappend``
  411. and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The
  412. file is in the layer at ``recipes-bsp/formfactor``:
  413. ::
  414. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
  415. By default, the build system uses the
  416. :term:`FILESPATH` variable to
  417. locate files. This append file extends the locations by setting the
  418. :term:`FILESEXTRAPATHS`
  419. variable. Setting this variable in the ``.bbappend`` file is the most
  420. reliable and recommended method for adding directories to the search
  421. path used by the build system to find files.
  422. The statement in this example extends the directories to include
  423. ``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``,
  424. which resolves to a directory named ``formfactor`` in the same directory
  425. in which the append file resides (i.e.
  426. ``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must
  427. have the supporting directory structure set up that will contain any
  428. files or patches you will be including from the layer.
  429. Using the immediate expansion assignment operator ``:=`` is important
  430. because of the reference to ``THISDIR``. The trailing colon character is
  431. important as it ensures that items in the list remain colon-separated.
  432. .. note::
  433. BitBake automatically defines the ``THISDIR`` variable. You should
  434. never set this variable yourself. Using "_prepend" as part of the
  435. ``FILESEXTRAPATHS`` ensures your path will be searched prior to other
  436. paths in the final list.
  437. Also, not all append files add extra files. Many append files simply
  438. exist to add build options (e.g. ``systemd``). For these cases, your
  439. append file would not even use the ``FILESEXTRAPATHS`` statement.
  440. Prioritizing Your Layer
  441. -----------------------
  442. Each layer is assigned a priority value. Priority values control which
  443. layer takes precedence if there are recipe files with the same name in
  444. multiple layers. For these cases, the recipe file from the layer with a
  445. higher priority number takes precedence. Priority values also affect the
  446. order in which multiple ``.bbappend`` files for the same recipe are
  447. applied. You can either specify the priority manually, or allow the
  448. build system to calculate it based on the layer's dependencies.
  449. To specify the layer's priority manually, use the
  450. :term:`BBFILE_PRIORITY`
  451. variable and append the layer's root name:
  452. ::
  453. BBFILE_PRIORITY_mylayer = "1"
  454. .. note::
  455. It is possible for a recipe with a lower version number
  456. :term:`PV` in a layer that has a higher
  457. priority to take precedence.
  458. Also, the layer priority does not currently affect the precedence
  459. order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake
  460. might address this.
  461. Managing Layers
  462. ---------------
  463. You can use the BitBake layer management tool ``bitbake-layers`` to
  464. provide a view into the structure of recipes across a multi-layer
  465. project. Being able to generate output that reports on configured layers
  466. with their paths and priorities and on ``.bbappend`` files and their
  467. applicable recipes can help to reveal potential problems.
  468. For help on the BitBake layer management tool, use the following
  469. command:
  470. ::
  471. $ bitbake-layers --help
  472. NOTE: Starting bitbake server...
  473. usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] <subcommand> ...
  474. BitBake layers utility
  475. optional arguments:
  476. -d, --debug Enable debug output
  477. -q, --quiet Print only errors
  478. -F, --force Force add without recipe parse verification
  479. --color COLOR Colorize output (where COLOR is auto, always, never)
  480. -h, --help show this help message and exit
  481. subcommands:
  482. <subcommand>
  483. layerindex-fetch Fetches a layer from a layer index along with its
  484. dependent layers, and adds them to conf/bblayers.conf.
  485. layerindex-show-depends
  486. Find layer dependencies from layer index.
  487. add-layer Add one or more layers to bblayers.conf.
  488. remove-layer Remove one or more layers from bblayers.conf.
  489. flatten flatten layer configuration into a separate output
  490. directory.
  491. show-layers show current configured layers.
  492. show-overlayed list overlayed recipes (where the same recipe exists
  493. in another layer)
  494. show-recipes list available recipes, showing the layer they are
  495. provided by
  496. show-appends list bbappend files and recipe files they apply to
  497. show-cross-depends Show dependencies between recipes that cross layer
  498. boundaries.
  499. create-layer Create a basic layer
  500. Use bitbake-layers <subcommand> --help to get help on a specific command
  501. The following list describes the available commands:
  502. - ``help:`` Displays general help or help on a specified command.
  503. - ``show-layers:`` Shows the current configured layers.
  504. - ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed
  505. when a recipe with the same name exists in another layer that has a
  506. higher layer priority.
  507. - ``show-recipes:`` Lists available recipes and the layers that
  508. provide them.
  509. - ``show-appends:`` Lists ``.bbappend`` files and the recipe files to
  510. which they apply.
  511. - ``show-cross-depends:`` Lists dependency relationships between
  512. recipes that cross layer boundaries.
  513. - ``add-layer:`` Adds a layer to ``bblayers.conf``.
  514. - ``remove-layer:`` Removes a layer from ``bblayers.conf``
  515. - ``flatten:`` Flattens the layer configuration into a separate
  516. output directory. Flattening your layer configuration builds a
  517. "flattened" directory that contains the contents of all layers, with
  518. any overlayed recipes removed and any ``.bbappend`` files appended to
  519. the corresponding recipes. You might have to perform some manual
  520. cleanup of the flattened layer as follows:
  521. - Non-recipe files (such as patches) are overwritten. The flatten
  522. command shows a warning for these files.
  523. - Anything beyond the normal layer setup has been added to the
  524. ``layer.conf`` file. Only the lowest priority layer's
  525. ``layer.conf`` is used.
  526. - Overridden and appended items from ``.bbappend`` files need to be
  527. cleaned up. The contents of each ``.bbappend`` end up in the
  528. flattened recipe. However, if there are appended or changed
  529. variable values, you need to tidy these up yourself. Consider the
  530. following example. Here, the ``bitbake-layers`` command adds the
  531. line ``#### bbappended ...`` so that you know where the following
  532. lines originate:
  533. ::
  534. ...
  535. DESCRIPTION = "A useful utility"
  536. ...
  537. EXTRA_OECONF = "--enable-something"
  538. ...
  539. #### bbappended from meta-anotherlayer ####
  540. DESCRIPTION = "Customized utility"
  541. EXTRA_OECONF += "--enable-somethingelse"
  542. Ideally, you would tidy up these utilities as follows:
  543. ::
  544. ...
  545. DESCRIPTION = "Customized utility"
  546. ...
  547. EXTRA_OECONF = "--enable-something --enable-somethingelse"
  548. ...
  549. - ``layerindex-fetch``: Fetches a layer from a layer index, along
  550. with its dependent layers, and adds the layers to the
  551. ``conf/bblayers.conf`` file.
  552. - ``layerindex-show-depends``: Finds layer dependencies from the
  553. layer index.
  554. - ``create-layer``: Creates a basic layer.
  555. Creating a General Layer Using the ``bitbake-layers`` Script
  556. ------------------------------------------------------------
  557. The ``bitbake-layers`` script with the ``create-layer`` subcommand
  558. simplifies creating a new general layer.
  559. .. note::
  560. - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`"
  561. section in the Yocto
  562. Project Board Specific (BSP) Developer's Guide.
  563. - In order to use a layer with the OpenEmbedded build system, you
  564. need to add the layer to your ``bblayers.conf`` configuration
  565. file. See the ":ref:`dev-manual/common-tasks:adding a layer using the \`\`bitbake-layers\`\` script`"
  566. section for more information.
  567. The default mode of the script's operation with this subcommand is to
  568. create a layer with the following:
  569. - A layer priority of 6.
  570. - A ``conf`` subdirectory that contains a ``layer.conf`` file.
  571. - A ``recipes-example`` subdirectory that contains a further
  572. subdirectory named ``example``, which contains an ``example.bb``
  573. recipe file.
  574. - A ``COPYING.MIT``, which is the license statement for the layer. The
  575. script assumes you want to use the MIT license, which is typical for
  576. most layers, for the contents of the layer itself.
  577. - A ``README`` file, which is a file describing the contents of your
  578. new layer.
  579. In its simplest form, you can use the following command form to create a
  580. layer. The command creates a layer whose name corresponds to
  581. "your_layer_name" in the current directory:
  582. ::
  583. $ bitbake-layers create-layer your_layer_name
  584. As an example, the following command creates a layer named ``meta-scottrif``
  585. in your home directory:
  586. ::
  587. $ cd /usr/home
  588. $ bitbake-layers create-layer meta-scottrif
  589. NOTE: Starting bitbake server...
  590. Add your new layer with 'bitbake-layers add-layer meta-scottrif'
  591. If you want to set the priority of the layer to other than the default
  592. value of "6", you can either use the ``--priority`` option or you
  593. can edit the
  594. :term:`BBFILE_PRIORITY` value
  595. in the ``conf/layer.conf`` after the script creates it. Furthermore, if
  596. you want to give the example recipe file some name other than the
  597. default, you can use the ``--example-recipe-name`` option.
  598. The easiest way to see how the ``bitbake-layers create-layer`` command
  599. works is to experiment with the script. You can also read the usage
  600. information by entering the following:
  601. ::
  602. $ bitbake-layers create-layer --help
  603. NOTE: Starting bitbake server...
  604. usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
  605. [--example-recipe-name EXAMPLERECIPE]
  606. layerdir
  607. Create a basic layer
  608. positional arguments:
  609. layerdir Layer directory to create
  610. optional arguments:
  611. -h, --help show this help message and exit
  612. --priority PRIORITY, -p PRIORITY
  613. Layer directory to create
  614. --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
  615. Filename of the example recipe
  616. Adding a Layer Using the ``bitbake-layers`` Script
  617. --------------------------------------------------
  618. Once you create your general layer, you must add it to your
  619. ``bblayers.conf`` file. Adding the layer to this configuration file
  620. makes the OpenEmbedded build system aware of your layer so that it can
  621. search it for metadata.
  622. Add your layer by using the ``bitbake-layers add-layer`` command:
  623. ::
  624. $ bitbake-layers add-layer your_layer_name
  625. Here is an example that adds a
  626. layer named ``meta-scottrif`` to the configuration file. Following the
  627. command that adds the layer is another ``bitbake-layers`` command that
  628. shows the layers that are in your ``bblayers.conf`` file:
  629. ::
  630. $ bitbake-layers add-layer meta-scottrif
  631. NOTE: Starting bitbake server...
  632. Parsing recipes: 100% |##########################################################| Time: 0:00:49
  633. Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
  634. $ bitbake-layers show-layers
  635. NOTE: Starting bitbake server...
  636. layer path priority
  637. ==========================================================================
  638. meta /home/scottrif/poky/meta 5
  639. meta-poky /home/scottrif/poky/meta-poky 5
  640. meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
  641. workspace /home/scottrif/poky/build/workspace 99
  642. meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
  643. Adding the layer to this file
  644. enables the build system to locate the layer during the build.
  645. .. note::
  646. During a build, the OpenEmbedded build system looks in the layers
  647. from the top of the list down to the bottom in that order.
  648. Customizing Images
  649. ==================
  650. You can customize images to satisfy particular requirements. This
  651. section describes several methods and provides guidelines for each.
  652. Customizing Images Using ``local.conf``
  653. ---------------------------------------
  654. Probably the easiest way to customize an image is to add a package by
  655. way of the ``local.conf`` configuration file. Because it is limited to
  656. local use, this method generally only allows you to add packages and is
  657. not as flexible as creating your own customized image. When you add
  658. packages using local variables this way, you need to realize that these
  659. variable changes are in effect for every build and consequently affect
  660. all images, which might not be what you require.
  661. To add a package to your image using the local configuration file, use
  662. the ``IMAGE_INSTALL`` variable with the ``_append`` operator:
  663. ::
  664. IMAGE_INSTALL_append = " strace"
  665. Use of the syntax is important -
  666. specifically, the space between the quote and the package name, which is
  667. ``strace`` in this example. This space is required since the ``_append``
  668. operator does not add the space.
  669. Furthermore, you must use ``_append`` instead of the ``+=`` operator if
  670. you want to avoid ordering issues. The reason for this is because doing
  671. so unconditionally appends to the variable and avoids ordering problems
  672. due to the variable being set in image recipes and ``.bbclass`` files
  673. with operators like ``?=``. Using ``_append`` ensures the operation
  674. takes effect.
  675. As shown in its simplest use, ``IMAGE_INSTALL_append`` affects all
  676. images. It is possible to extend the syntax so that the variable applies
  677. to a specific image only. Here is an example:
  678. ::
  679. IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
  680. This example adds ``strace`` to the ``core-image-minimal`` image only.
  681. You can add packages using a similar approach through the
  682. ``CORE_IMAGE_EXTRA_INSTALL`` variable. If you use this variable, only
  683. ``core-image-*`` images are affected.
  684. Customizing Images Using Custom ``IMAGE_FEATURES`` and ``EXTRA_IMAGE_FEATURES``
  685. -------------------------------------------------------------------------------
  686. Another method for customizing your image is to enable or disable
  687. high-level image features by using the
  688. :term:`IMAGE_FEATURES` and
  689. :term:`EXTRA_IMAGE_FEATURES`
  690. variables. Although the functions for both variables are nearly
  691. equivalent, best practices dictate using ``IMAGE_FEATURES`` from within
  692. a recipe and using ``EXTRA_IMAGE_FEATURES`` from within your
  693. ``local.conf`` file, which is found in the
  694. :term:`Build Directory`.
  695. To understand how these features work, the best reference is
  696. ``meta/classes/core-image.bbclass``. This class lists out the available
  697. ``IMAGE_FEATURES`` of which most map to package groups while some, such
  698. as ``debug-tweaks`` and ``read-only-rootfs``, resolve as general
  699. configuration settings.
  700. In summary, the file looks at the contents of the ``IMAGE_FEATURES``
  701. variable and then maps or configures the feature accordingly. Based on
  702. this information, the build system automatically adds the appropriate
  703. packages or configurations to the
  704. :term:`IMAGE_INSTALL` variable.
  705. Effectively, you are enabling extra features by extending the class or
  706. creating a custom class for use with specialized image ``.bb`` files.
  707. Use the ``EXTRA_IMAGE_FEATURES`` variable from within your local
  708. configuration file. Using a separate area from which to enable features
  709. with this variable helps you avoid overwriting the features in the image
  710. recipe that are enabled with ``IMAGE_FEATURES``. The value of
  711. ``EXTRA_IMAGE_FEATURES`` is added to ``IMAGE_FEATURES`` within
  712. ``meta/conf/bitbake.conf``.
  713. To illustrate how you can use these variables to modify your image,
  714. consider an example that selects the SSH server. The Yocto Project ships
  715. with two SSH servers you can use with your images: Dropbear and OpenSSH.
  716. Dropbear is a minimal SSH server appropriate for resource-constrained
  717. environments, while OpenSSH is a well-known standard SSH server
  718. implementation. By default, the ``core-image-sato`` image is configured
  719. to use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb``
  720. images both include OpenSSH. The ``core-image-minimal`` image does not
  721. contain an SSH server.
  722. You can customize your image and change these defaults. Edit the
  723. ``IMAGE_FEATURES`` variable in your recipe or use the
  724. ``EXTRA_IMAGE_FEATURES`` in your ``local.conf`` file so that it
  725. configures the image you are working with to include
  726. ``ssh-server-dropbear`` or ``ssh-server-openssh``.
  727. .. note::
  728. See the ":ref:`ref-manual/features:image features`" section in the Yocto
  729. Project Reference Manual for a complete list of image features that ship
  730. with the Yocto Project.
  731. Customizing Images Using Custom .bb Files
  732. -----------------------------------------
  733. You can also customize an image by creating a custom recipe that defines
  734. additional software as part of the image. The following example shows
  735. the form for the two lines you need:
  736. ::
  737. IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
  738. inherit core-image
  739. Defining the software using a custom recipe gives you total control over
  740. the contents of the image. It is important to use the correct names of
  741. packages in the ``IMAGE_INSTALL`` variable. You must use the
  742. OpenEmbedded notation and not the Debian notation for the names (e.g.
  743. ``glibc-dev`` instead of ``libc6-dev``).
  744. The other method for creating a custom image is to base it on an
  745. existing image. For example, if you want to create an image based on
  746. ``core-image-sato`` but add the additional package ``strace`` to the
  747. image, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new
  748. ``.bb`` and add the following line to the end of the copy:
  749. ::
  750. IMAGE_INSTALL += "strace"
  751. Customizing Images Using Custom Package Groups
  752. ----------------------------------------------
  753. For complex custom images, the best approach for customizing an image is
  754. to create a custom package group recipe that is used to build the image
  755. or images. A good example of a package group recipe is
  756. ``meta/recipes-core/packagegroups/packagegroup-base.bb``.
  757. If you examine that recipe, you see that the ``PACKAGES`` variable lists
  758. the package group packages to produce. The ``inherit packagegroup``
  759. statement sets appropriate default values and automatically adds
  760. ``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each
  761. package specified in the ``PACKAGES`` statement.
  762. .. note::
  763. The ``inherit packagegroup`` line should be located near the top of the
  764. recipe, certainly before the ``PACKAGES`` statement.
  765. For each package you specify in ``PACKAGES``, you can use ``RDEPENDS``
  766. and ``RRECOMMENDS`` entries to provide a list of packages the parent
  767. task package should contain. You can see examples of these further down
  768. in the ``packagegroup-base.bb`` recipe.
  769. Here is a short, fabricated example showing the same basic pieces for a
  770. hypothetical packagegroup defined in ``packagegroup-custom.bb``, where
  771. the variable ``PN`` is the standard way to abbreviate the reference to
  772. the full packagegroup name ``packagegroup-custom``:
  773. ::
  774. DESCRIPTION = "My Custom Package Groups"
  775. inherit packagegroup
  776. PACKAGES = "\
  777. ${PN}-apps \
  778. ${PN}-tools \
  779. "
  780. RDEPENDS_${PN}-apps = "\
  781. dropbear \
  782. portmap \
  783. psplash"
  784. RDEPENDS_${PN}-tools = "\
  785. oprofile \
  786. oprofileui-server \
  787. lttng-tools"
  788. RRECOMMENDS_${PN}-tools = "\
  789. kernel-module-oprofile"
  790. In the previous example, two package group packages are created with
  791. their dependencies and their recommended package dependencies listed:
  792. ``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To
  793. build an image using these package group packages, you need to add
  794. ``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to
  795. ``IMAGE_INSTALL``. For other forms of image dependencies see the other
  796. areas of this section.
  797. Customizing an Image Hostname
  798. -----------------------------
  799. By default, the configured hostname (i.e. ``/etc/hostname``) in an image
  800. is the same as the machine name. For example, if
  801. :term:`MACHINE` equals "qemux86", the
  802. configured hostname written to ``/etc/hostname`` is "qemux86".
  803. You can customize this name by altering the value of the "hostname"
  804. variable in the ``base-files`` recipe using either an append file or a
  805. configuration file. Use the following in an append file:
  806. ::
  807. hostname = "myhostname"
  808. Use the following in a configuration file:
  809. ::
  810. hostname_pn-base-files = "myhostname"
  811. Changing the default value of the variable "hostname" can be useful in
  812. certain situations. For example, suppose you need to do extensive
  813. testing on an image and you would like to easily identify the image
  814. under test from existing images with typical default hostnames. In this
  815. situation, you could change the default hostname to "testme", which
  816. results in all the images using the name "testme". Once testing is
  817. complete and you do not need to rebuild the image for test any longer,
  818. you can easily reset the default hostname.
  819. Another point of interest is that if you unset the variable, the image
  820. will have no default hostname in the filesystem. Here is an example that
  821. unsets the variable in a configuration file:
  822. ::
  823. hostname_pn-base-files = ""
  824. Having no default hostname in the filesystem is suitable for
  825. environments that use dynamic hostnames such as virtual machines.
  826. Writing a New Recipe
  827. ====================
  828. Recipes (``.bb`` files) are fundamental components in the Yocto Project
  829. environment. Each software component built by the OpenEmbedded build
  830. system requires a recipe to define the component. This section describes
  831. how to create, write, and test a new recipe.
  832. .. note::
  833. For information on variables that are useful for recipes and for
  834. information about recipe naming issues, see the
  835. ":ref:`ref-manual/varlocality:recipes`" section of the Yocto Project
  836. Reference Manual.
  837. Overview
  838. --------
  839. The following figure shows the basic process for creating a new recipe.
  840. The remainder of the section provides details for the steps.
  841. .. image:: figures/recipe-workflow.png
  842. :align: center
  843. Locate or Automatically Create a Base Recipe
  844. --------------------------------------------
  845. You can always write a recipe from scratch. However, three choices exist
  846. that can help you quickly get a start on a new recipe:
  847. - ``devtool add``: A command that assists in creating a recipe and an
  848. environment conducive to development.
  849. - ``recipetool create``: A command provided by the Yocto Project that
  850. automates creation of a base recipe based on the source files.
  851. - *Existing Recipes:* Location and modification of an existing recipe
  852. that is similar in function to the recipe you need.
  853. .. note::
  854. For information on recipe syntax, see the
  855. ":ref:`dev-manual/common-tasks:recipe syntax`" section.
  856. Creating the Base Recipe Using ``devtool add``
  857. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  858. The ``devtool add`` command uses the same logic for auto-creating the
  859. recipe as ``recipetool create``, which is listed below. Additionally,
  860. however, ``devtool add`` sets up an environment that makes it easy for
  861. you to patch the source and to make changes to the recipe as is often
  862. necessary when adding a recipe to build a new piece of software to be
  863. included in a build.
  864. You can find a complete description of the ``devtool add`` command in
  865. the ":ref:`sdk-manual/extensible:a closer look at \`\`devtool add\`\``" section
  866. in the Yocto Project Application Development and the Extensible Software
  867. Development Kit (eSDK) manual.
  868. Creating the Base Recipe Using ``recipetool create``
  869. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  870. ``recipetool create`` automates creation of a base recipe given a set of
  871. source code files. As long as you can extract or point to the source
  872. files, the tool will construct a recipe and automatically configure all
  873. pre-build information into the recipe. For example, suppose you have an
  874. application that builds using Autotools. Creating the base recipe using
  875. ``recipetool`` results in a recipe that has the pre-build dependencies,
  876. license requirements, and checksums configured.
  877. To run the tool, you just need to be in your
  878. :term:`Build Directory` and have sourced the
  879. build environment setup script (i.e.
  880. :ref:`structure-core-script`).
  881. To get help on the tool, use the following command:
  882. ::
  883. $ recipetool -h
  884. NOTE: Starting bitbake server...
  885. usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ...
  886. OpenEmbedded recipe tool
  887. options:
  888. -d, --debug Enable debug output
  889. -q, --quiet Print only errors
  890. --color COLOR Colorize output (where COLOR is auto, always, never)
  891. -h, --help show this help message and exit
  892. subcommands:
  893. create Create a new recipe
  894. newappend Create a bbappend for the specified target in the specified
  895. layer
  896. setvar Set a variable within a recipe
  897. appendfile Create/update a bbappend to replace a target file
  898. appendsrcfiles Create/update a bbappend to add or replace source files
  899. appendsrcfile Create/update a bbappend to add or replace a source file
  900. Use recipetool <subcommand> --help to get help on a specific command
  901. Running ``recipetool create -o OUTFILE`` creates the base recipe and
  902. locates it properly in the layer that contains your source files.
  903. Following are some syntax examples:
  904. - Use this syntax to generate a recipe based on source. Once generated,
  905. the recipe resides in the existing source code layer:
  906. ::
  907. recipetool create -o OUTFILE source
  908. - Use this syntax to generate a recipe using code that
  909. you extract from source. The extracted code is placed in its own layer
  910. defined by ``EXTERNALSRC``.
  911. ::
  912. recipetool create -o OUTFILE -x EXTERNALSRC source
  913. - Use this syntax to generate a recipe based on source. The options
  914. direct ``recipetool`` to generate debugging information. Once generated,
  915. the recipe resides in the existing source code layer:
  916. ::
  917. recipetool create -d -o OUTFILE source
  918. Locating and Using a Similar Recipe
  919. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  920. Before writing a recipe from scratch, it is often useful to discover
  921. whether someone else has already written one that meets (or comes close
  922. to meeting) your needs. The Yocto Project and OpenEmbedded communities
  923. maintain many recipes that might be candidates for what you are doing.
  924. You can find a good central index of these recipes in the
  925. :oe_layerindex:`OpenEmbedded Layer Index <>`.
  926. Working from an existing recipe or a skeleton recipe is the best way to
  927. get started. Here are some points on both methods:
  928. - *Locate and modify a recipe that is close to what you want to do:*
  929. This method works when you are familiar with the current recipe
  930. space. The method does not work so well for those new to the Yocto
  931. Project or writing recipes.
  932. Some risks associated with this method are using a recipe that has
  933. areas totally unrelated to what you are trying to accomplish with
  934. your recipe, not recognizing areas of the recipe that you might have
  935. to add from scratch, and so forth. All these risks stem from
  936. unfamiliarity with the existing recipe space.
  937. - *Use and modify the following skeleton recipe:* If for some reason
  938. you do not want to use ``recipetool`` and you cannot find an existing
  939. recipe that is close to meeting your needs, you can use the following
  940. structure to provide the fundamental areas of a new recipe.
  941. ::
  942. DESCRIPTION = ""
  943. HOMEPAGE = ""
  944. LICENSE = ""
  945. SECTION = ""
  946. DEPENDS = ""
  947. LIC_FILES_CHKSUM = ""
  948. SRC_URI = ""
  949. Storing and Naming the Recipe
  950. -----------------------------
  951. Once you have your base recipe, you should put it in your own layer and
  952. name it appropriately. Locating it correctly ensures that the
  953. OpenEmbedded build system can find it when you use BitBake to process
  954. the recipe.
  955. - *Storing Your Recipe:* The OpenEmbedded build system locates your
  956. recipe through the layer's ``conf/layer.conf`` file and the
  957. :term:`BBFILES` variable. This
  958. variable sets up a path from which the build system can locate
  959. recipes. Here is the typical use:
  960. ::
  961. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  962. ${LAYERDIR}/recipes-*/*/*.bbappend"
  963. Consequently, you need to be sure you locate your new recipe inside
  964. your layer such that it can be found.
  965. You can find more information on how layers are structured in the
  966. "`Understanding and Creating
  967. Layers <#understanding-and-creating-layers>`__" section.
  968. - *Naming Your Recipe:* When you name your recipe, you need to follow
  969. this naming convention:
  970. ::
  971. basename_version.bb
  972. Use lower-cased characters and do not include the reserved suffixes
  973. ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use
  974. them as part of your recipe name unless the string applies). Here are some
  975. examples:
  976. .. code-block:: none
  977. cups_1.7.0.bb
  978. gawk_4.0.2.bb
  979. irssi_0.8.16-rc1.bb
  980. Running a Build on the Recipe
  981. -----------------------------
  982. Creating a new recipe is usually an iterative process that requires
  983. using BitBake to process the recipe multiple times in order to
  984. progressively discover and add information to the recipe file.
  985. Assuming you have sourced the build environment setup script (i.e.
  986. :ref:`structure-core-script`) and you are in
  987. the :term:`Build Directory`, use
  988. BitBake to process your recipe. All you need to provide is the
  989. ``basename`` of the recipe as described in the previous section:
  990. ::
  991. $ bitbake basename
  992. During the build, the OpenEmbedded build system creates a temporary work
  993. directory for each recipe
  994. (``${``\ :term:`WORKDIR`\ ``}``)
  995. where it keeps extracted source files, log files, intermediate
  996. compilation and packaging files, and so forth.
  997. The path to the per-recipe temporary work directory depends on the
  998. context in which it is being built. The quickest way to find this path
  999. is to have BitBake return it by running the following:
  1000. ::
  1001. $ bitbake -e basename | grep ^WORKDIR=
  1002. As an example, assume a Source Directory
  1003. top-level folder named ``poky``, a default Build Directory at
  1004. ``poky/build``, and a ``qemux86-poky-linux`` machine target system.
  1005. Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this
  1006. case, the work directory the build system uses to build the package
  1007. would be as follows:
  1008. ::
  1009. poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
  1010. Inside this directory you can find sub-directories such as ``image``,
  1011. ``packages-split``, and ``temp``. After the build, you can examine these
  1012. to determine how well the build went.
  1013. .. note::
  1014. You can find log files for each task in the recipe's ``temp``
  1015. directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``).
  1016. Log files are named ``log.taskname`` (e.g. ``log.do_configure``,
  1017. ``log.do_fetch``, and ``log.do_compile``).
  1018. You can find more information about the build process in
  1019. ":doc:`/overview-manual/development-environment`"
  1020. chapter of the Yocto Project Overview and Concepts Manual.
  1021. Fetching Code
  1022. -------------
  1023. The first thing your recipe must do is specify how to fetch the source
  1024. files. Fetching is controlled mainly through the
  1025. :term:`SRC_URI` variable. Your recipe
  1026. must have a ``SRC_URI`` variable that points to where the source is
  1027. located. For a graphical representation of source locations, see the
  1028. ":ref:`overview-manual/concepts:sources`" section in
  1029. the Yocto Project Overview and Concepts Manual.
  1030. The :ref:`ref-tasks-fetch` task uses
  1031. the prefix of each entry in the ``SRC_URI`` variable value to determine
  1032. which :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>` to use to get your
  1033. source files. It is the ``SRC_URI`` variable that triggers the fetcher.
  1034. The :ref:`ref-tasks-patch` task uses
  1035. the variable after source is fetched to apply patches. The OpenEmbedded
  1036. build system uses
  1037. :term:`FILESOVERRIDES` for
  1038. scanning directory locations for local files in ``SRC_URI``.
  1039. The ``SRC_URI`` variable in your recipe must define each unique location
  1040. for your source files. It is good practice to not hard-code version
  1041. numbers in a URL used in ``SRC_URI``. Rather than hard-code these
  1042. values, use ``${``\ :term:`PV`\ ``}``,
  1043. which causes the fetch process to use the version specified in the
  1044. recipe filename. Specifying the version in this manner means that
  1045. upgrading the recipe to a future version is as simple as renaming the
  1046. recipe to match the new version.
  1047. Here is a simple example from the
  1048. ``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source
  1049. comes from a single tarball. Notice the use of the
  1050. :term:`PV` variable:
  1051. ::
  1052. SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \
  1053. Files mentioned in ``SRC_URI`` whose names end in a typical archive
  1054. extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so
  1055. forth), are automatically extracted during the
  1056. :ref:`ref-tasks-unpack` task. For
  1057. another example that specifies these types of files, see the
  1058. "`Autotooled Package <#new-recipe-autotooled-package>`__" section.
  1059. Another way of specifying source is from an SCM. For Git repositories,
  1060. you must specify :term:`SRCREV` and
  1061. you should specify :term:`PV` to include
  1062. the revision with :term:`SRCPV`. Here
  1063. is an example from the recipe
  1064. ``meta/recipes-kernel/blktrace/blktrace_git.bb``:
  1065. ::
  1066. SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
  1067. PR = "r6"
  1068. PV = "1.0.5+git${SRCPV}"
  1069. SRC_URI = "git://git.kernel.dk/blktrace.git \
  1070. file://ldflags.patch"
  1071. If your ``SRC_URI`` statement includes URLs pointing to individual files
  1072. fetched from a remote server other than a version control system,
  1073. BitBake attempts to verify the files against checksums defined in your
  1074. recipe to ensure they have not been tampered with or otherwise modified
  1075. since the recipe was written. Two checksums are used:
  1076. ``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``.
  1077. If your ``SRC_URI`` variable points to more than a single URL (excluding
  1078. SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for
  1079. each URL. For these cases, you provide a name for each URL as part of
  1080. the ``SRC_URI`` and then reference that name in the subsequent checksum
  1081. statements. Here is an example combining lines from the files
  1082. ``git.inc`` and ``git_2.24.1.bb``:
  1083. ::
  1084. SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
  1085. ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages"
  1086. SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b"
  1087. SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02"
  1088. SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d"
  1089. SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230"
  1090. Proper values for ``md5`` and ``sha256`` checksums might be available
  1091. with other signatures on the download page for the upstream source (e.g.
  1092. ``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the
  1093. OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``,
  1094. you should verify all the signatures you find by hand.
  1095. If no ``SRC_URI`` checksums are specified when you attempt to build the
  1096. recipe, or you provide an incorrect checksum, the build will produce an
  1097. error for each missing or incorrect checksum. As part of the error
  1098. message, the build system provides the checksum string corresponding to
  1099. the fetched file. Once you have the correct checksums, you can copy and
  1100. paste them into your recipe and then run the build again to continue.
  1101. .. note::
  1102. As mentioned, if the upstream source provides signatures for
  1103. verifying the downloaded source code, you should verify those
  1104. manually before setting the checksum values in the recipe and
  1105. continuing with the build.
  1106. This final example is a bit more complicated and is from the
  1107. ``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The
  1108. example's ``SRC_URI`` statement identifies multiple files as the source
  1109. files for the recipe: a tarball, a patch file, a desktop file, and an
  1110. icon.
  1111. ::
  1112. SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
  1113. file://xwc.patch \
  1114. file://rxvt.desktop \
  1115. file://rxvt.png"
  1116. When you specify local files using the ``file://`` URI protocol, the
  1117. build system fetches files from the local machine. The path is relative
  1118. to the :term:`FILESPATH` variable
  1119. and searches specific directories in a certain order:
  1120. ``${``\ :term:`BP`\ ``}``,
  1121. ``${``\ :term:`BPN`\ ``}``, and
  1122. ``files``. The directories are assumed to be subdirectories of the
  1123. directory in which the recipe or append file resides. For another
  1124. example that specifies these types of files, see the "`Single .c File
  1125. Package (Hello
  1126. World!) <#new-recipe-single-c-file-package-hello-world>`__" section.
  1127. The previous example also specifies a patch file. Patch files are files
  1128. whose names usually end in ``.patch`` or ``.diff`` but can end with
  1129. compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example.
  1130. The build system automatically applies patches as described in the
  1131. "`Patching Code <#new-recipe-patching-code>`__" section.
  1132. Unpacking Code
  1133. --------------
  1134. During the build, the
  1135. :ref:`ref-tasks-unpack` task unpacks
  1136. the source with ``${``\ :term:`S`\ ``}``
  1137. pointing to where it is unpacked.
  1138. If you are fetching your source files from an upstream source archived
  1139. tarball and the tarball's internal structure matches the common
  1140. convention of a top-level subdirectory named
  1141. ``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``,
  1142. then you do not need to set ``S``. However, if ``SRC_URI`` specifies to
  1143. fetch source from an archive that does not use this convention, or from
  1144. an SCM like Git or Subversion, your recipe needs to define ``S``.
  1145. If processing your recipe using BitBake successfully unpacks the source
  1146. files, you need to be sure that the directory pointed to by ``${S}``
  1147. matches the structure of the source.
  1148. Patching Code
  1149. -------------
  1150. Sometimes it is necessary to patch code after it has been fetched. Any
  1151. files mentioned in ``SRC_URI`` whose names end in ``.patch`` or
  1152. ``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are
  1153. treated as patches. The
  1154. :ref:`ref-tasks-patch` task
  1155. automatically applies these patches.
  1156. The build system should be able to apply patches with the "-p1" option
  1157. (i.e. one directory level in the path will be stripped off). If your
  1158. patch needs to have more directory levels stripped off, specify the
  1159. number of levels using the "striplevel" option in the ``SRC_URI`` entry
  1160. for the patch. Alternatively, if your patch needs to be applied in a
  1161. specific subdirectory that is not specified in the patch file, use the
  1162. "patchdir" option in the entry.
  1163. As with all local files referenced in
  1164. :term:`SRC_URI` using ``file://``,
  1165. you should place patch files in a directory next to the recipe either
  1166. named the same as the base name of the recipe
  1167. (:term:`BP` and
  1168. :term:`BPN`) or "files".
  1169. Licensing
  1170. ---------
  1171. Your recipe needs to have both the
  1172. :term:`LICENSE` and
  1173. :term:`LIC_FILES_CHKSUM`
  1174. variables:
  1175. - ``LICENSE``: This variable specifies the license for the software.
  1176. If you do not know the license under which the software you are
  1177. building is distributed, you should go to the source code and look
  1178. for that information. Typical files containing this information
  1179. include ``COPYING``, ``LICENSE``, and ``README`` files. You could
  1180. also find the information near the top of a source file. For example,
  1181. given a piece of software licensed under the GNU General Public
  1182. License version 2, you would set ``LICENSE`` as follows:
  1183. ::
  1184. LICENSE = "GPLv2"
  1185. The licenses you specify within ``LICENSE`` can have any name as long
  1186. as you do not use spaces, since spaces are used as separators between
  1187. license names. For standard licenses, use the names of the files in
  1188. ``meta/files/common-licenses/`` or the ``SPDXLICENSEMAP`` flag names
  1189. defined in ``meta/conf/licenses.conf``.
  1190. - ``LIC_FILES_CHKSUM``: The OpenEmbedded build system uses this
  1191. variable to make sure the license text has not changed. If it has,
  1192. the build produces an error and it affords you the chance to figure
  1193. it out and correct the problem.
  1194. You need to specify all applicable licensing files for the software.
  1195. At the end of the configuration step, the build process will compare
  1196. the checksums of the files to be sure the text has not changed. Any
  1197. differences result in an error with the message containing the
  1198. current checksum. For more explanation and examples of how to set the
  1199. ``LIC_FILES_CHKSUM`` variable, see the
  1200. ":ref:`dev-manual/common-tasks:tracking license changes`" section.
  1201. To determine the correct checksum string, you can list the
  1202. appropriate files in the ``LIC_FILES_CHKSUM`` variable with incorrect
  1203. md5 strings, attempt to build the software, and then note the
  1204. resulting error messages that will report the correct md5 strings.
  1205. See the "`Fetching Code <#new-recipe-fetching-code>`__" section for
  1206. additional information.
  1207. Here is an example that assumes the software has a ``COPYING`` file:
  1208. ::
  1209. LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
  1210. When you try to build the
  1211. software, the build system will produce an error and give you the
  1212. correct string that you can substitute into the recipe file for a
  1213. subsequent build.
  1214. Dependencies
  1215. ------------
  1216. Most software packages have a short list of other packages that they
  1217. require, which are called dependencies. These dependencies fall into two
  1218. main categories: build-time dependencies, which are required when the
  1219. software is built; and runtime dependencies, which are required to be
  1220. installed on the target in order for the software to run.
  1221. Within a recipe, you specify build-time dependencies using the
  1222. :term:`DEPENDS` variable. Although
  1223. nuances exist, items specified in ``DEPENDS`` should be names of other
  1224. recipes. It is important that you specify all build-time dependencies
  1225. explicitly.
  1226. Another consideration is that configure scripts might automatically
  1227. check for optional dependencies and enable corresponding functionality
  1228. if those dependencies are found. If you wish to make a recipe that is
  1229. more generally useful (e.g. publish the recipe in a layer for others to
  1230. use), instead of hard-disabling the functionality, you can use the
  1231. :term:`PACKAGECONFIG` variable to allow functionality and the
  1232. corresponding dependencies to be enabled and disabled easily by other
  1233. users of the recipe.
  1234. Similar to build-time dependencies, you specify runtime dependencies
  1235. through a variable -
  1236. :term:`RDEPENDS`, which is
  1237. package-specific. All variables that are package-specific need to have
  1238. the name of the package added to the end as an override. Since the main
  1239. package for a recipe has the same name as the recipe, and the recipe's
  1240. name can be found through the
  1241. ``${``\ :term:`PN`\ ``}`` variable, then
  1242. you specify the dependencies for the main package by setting
  1243. ``RDEPENDS_${PN}``. If the package were named ``${PN}-tools``, then you
  1244. would set ``RDEPENDS_${PN}-tools``, and so forth.
  1245. Some runtime dependencies will be set automatically at packaging time.
  1246. These dependencies include any shared library dependencies (i.e. if a
  1247. package "example" contains "libexample" and another package "mypackage"
  1248. contains a binary that links to "libexample" then the OpenEmbedded build
  1249. system will automatically add a runtime dependency to "mypackage" on
  1250. "example"). See the
  1251. ":ref:`overview-manual/concepts:automatically added runtime dependencies`"
  1252. section in the Yocto Project Overview and Concepts Manual for further
  1253. details.
  1254. Configuring the Recipe
  1255. ----------------------
  1256. Most software provides some means of setting build-time configuration
  1257. options before compilation. Typically, setting these options is
  1258. accomplished by running a configure script with options, or by modifying
  1259. a build configuration file.
  1260. .. note::
  1261. As of Yocto Project Release 1.7, some of the core recipes that
  1262. package binary configuration scripts now disable the scripts due to
  1263. the scripts previously requiring error-prone path substitution. The
  1264. OpenEmbedded build system uses ``pkg-config`` now, which is much more
  1265. robust. You can find a list of the ``*-config`` scripts that are disabled
  1266. in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section
  1267. in the Yocto Project Reference Manual.
  1268. A major part of build-time configuration is about checking for
  1269. build-time dependencies and possibly enabling optional functionality as
  1270. a result. You need to specify any build-time dependencies for the
  1271. software you are building in your recipe's
  1272. :term:`DEPENDS` value, in terms of
  1273. other recipes that satisfy those dependencies. You can often find
  1274. build-time or runtime dependencies described in the software's
  1275. documentation.
  1276. The following list provides configuration items of note based on how
  1277. your software is built:
  1278. - *Autotools:* If your source files have a ``configure.ac`` file, then
  1279. your software is built using Autotools. If this is the case, you just
  1280. need to worry about modifying the configuration.
  1281. When using Autotools, your recipe needs to inherit the
  1282. :ref:`autotools <ref-classes-autotools>` class
  1283. and your recipe does not have to contain a
  1284. :ref:`ref-tasks-configure` task.
  1285. However, you might still want to make some adjustments. For example,
  1286. you can set
  1287. :term:`EXTRA_OECONF` or
  1288. :term:`PACKAGECONFIG_CONFARGS`
  1289. to pass any needed configure options that are specific to the recipe.
  1290. - *CMake:* If your source files have a ``CMakeLists.txt`` file, then
  1291. your software is built using CMake. If this is the case, you just
  1292. need to worry about modifying the configuration.
  1293. When you use CMake, your recipe needs to inherit the
  1294. :ref:`cmake <ref-classes-cmake>` class and your
  1295. recipe does not have to contain a
  1296. :ref:`ref-tasks-configure` task.
  1297. You can make some adjustments by setting
  1298. :term:`EXTRA_OECMAKE` to
  1299. pass any needed configure options that are specific to the recipe.
  1300. .. note::
  1301. If you need to install one or more custom CMake toolchain files
  1302. that are supplied by the application you are building, install the
  1303. files to ``${D}${datadir}/cmake/Modules`` during ``do_install``.
  1304. - *Other:* If your source files do not have a ``configure.ac`` or
  1305. ``CMakeLists.txt`` file, then your software is built using some
  1306. method other than Autotools or CMake. If this is the case, you
  1307. normally need to provide a
  1308. :ref:`ref-tasks-configure` task
  1309. in your recipe unless, of course, there is nothing to configure.
  1310. Even if your software is not being built by Autotools or CMake, you
  1311. still might not need to deal with any configuration issues. You need
  1312. to determine if configuration is even a required step. You might need
  1313. to modify a Makefile or some configuration file used for the build to
  1314. specify necessary build options. Or, perhaps you might need to run a
  1315. provided, custom configure script with the appropriate options.
  1316. For the case involving a custom configure script, you would run
  1317. ``./configure --help`` and look for the options you need to set.
  1318. Once configuration succeeds, it is always good practice to look at the
  1319. ``log.do_configure`` file to ensure that the appropriate options have
  1320. been enabled and no additional build-time dependencies need to be added
  1321. to ``DEPENDS``. For example, if the configure script reports that it
  1322. found something not mentioned in ``DEPENDS``, or that it did not find
  1323. something that it needed for some desired optional functionality, then
  1324. you would need to add those to ``DEPENDS``. Looking at the log might
  1325. also reveal items being checked for, enabled, or both that you do not
  1326. want, or items not being found that are in ``DEPENDS``, in which case
  1327. you would need to look at passing extra options to the configure script
  1328. as needed. For reference information on configure options specific to
  1329. the software you are building, you can consult the output of the
  1330. ``./configure --help`` command within ``${S}`` or consult the software's
  1331. upstream documentation.
  1332. Using Headers to Interface with Devices
  1333. ---------------------------------------
  1334. If your recipe builds an application that needs to communicate with some
  1335. device or needs an API into a custom kernel, you will need to provide
  1336. appropriate header files. Under no circumstances should you ever modify
  1337. the existing
  1338. ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file.
  1339. These headers are used to build ``libc`` and must not be compromised
  1340. with custom or machine-specific header information. If you customize
  1341. ``libc`` through modified headers all other applications that use
  1342. ``libc`` thus become affected.
  1343. .. note::
  1344. Never copy and customize the ``libc`` header file (i.e.
  1345. ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``).
  1346. The correct way to interface to a device or custom kernel is to use a
  1347. separate package that provides the additional headers for the driver or
  1348. other unique interfaces. When doing so, your application also becomes
  1349. responsible for creating a dependency on that specific provider.
  1350. Consider the following:
  1351. - Never modify ``linux-libc-headers.inc``. Consider that file to be
  1352. part of the ``libc`` system, and not something you use to access the
  1353. kernel directly. You should access ``libc`` through specific ``libc``
  1354. calls.
  1355. - Applications that must talk directly to devices should either provide
  1356. necessary headers themselves, or establish a dependency on a special
  1357. headers package that is specific to that driver.
  1358. For example, suppose you want to modify an existing header that adds I/O
  1359. control or network support. If the modifications are used by a small
  1360. number programs, providing a unique version of a header is easy and has
  1361. little impact. When doing so, bear in mind the guidelines in the
  1362. previous list.
  1363. .. note::
  1364. If for some reason your changes need to modify the behavior of the ``libc``,
  1365. and subsequently all other applications on the system, use a ``.bbappend``
  1366. to modify the ``linux-kernel-headers.inc`` file. However, take care to not
  1367. make the changes machine specific.
  1368. Consider a case where your kernel is older and you need an older
  1369. ``libc`` ABI. The headers installed by your recipe should still be a
  1370. standard mainline kernel, not your own custom one.
  1371. When you use custom kernel headers you need to get them from
  1372. :term:`STAGING_KERNEL_DIR`,
  1373. which is the directory with kernel headers that are required to build
  1374. out-of-tree modules. Your recipe will also need the following:
  1375. ::
  1376. do_configure[depends] += "virtual/kernel:do_shared_workdir"
  1377. Compilation
  1378. -----------
  1379. During a build, the ``do_compile`` task happens after source is fetched,
  1380. unpacked, and configured. If the recipe passes through ``do_compile``
  1381. successfully, nothing needs to be done.
  1382. However, if the compile step fails, you need to diagnose the failure.
  1383. Here are some common issues that cause failures.
  1384. .. note::
  1385. For cases where improper paths are detected for configuration files
  1386. or for when libraries/headers cannot be found, be sure you are using
  1387. the more robust ``pkg-config``. See the note in section
  1388. ":ref:`dev-manual/common-tasks:Configuring the Recipe`" for additional information.
  1389. - *Parallel build failures:* These failures manifest themselves as
  1390. intermittent errors, or errors reporting that a file or directory
  1391. that should be created by some other part of the build process could
  1392. not be found. This type of failure can occur even if, upon
  1393. inspection, the file or directory does exist after the build has
  1394. failed, because that part of the build process happened in the wrong
  1395. order.
  1396. To fix the problem, you need to either satisfy the missing dependency
  1397. in the Makefile or whatever script produced the Makefile, or (as a
  1398. workaround) set :term:`PARALLEL_MAKE` to an empty string:
  1399. ::
  1400. PARALLEL_MAKE = ""
  1401. For information on parallel Makefile issues, see the "`Debugging
  1402. Parallel Make Races <#debugging-parallel-make-races>`__" section.
  1403. - *Improper host path usage:* This failure applies to recipes building
  1404. for the target or ``nativesdk`` only. The failure occurs when the
  1405. compilation process uses improper headers, libraries, or other files
  1406. from the host system when cross-compiling for the target.
  1407. To fix the problem, examine the ``log.do_compile`` file to identify
  1408. the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and
  1409. so forth) and then either add configure options, apply a patch, or do
  1410. both.
  1411. - *Failure to find required libraries/headers:* If a build-time
  1412. dependency is missing because it has not been declared in
  1413. :term:`DEPENDS`, or because the
  1414. dependency exists but the path used by the build process to find the
  1415. file is incorrect and the configure step did not detect it, the
  1416. compilation process could fail. For either of these failures, the
  1417. compilation process notes that files could not be found. In these
  1418. cases, you need to go back and add additional options to the
  1419. configure script as well as possibly add additional build-time
  1420. dependencies to ``DEPENDS``.
  1421. Occasionally, it is necessary to apply a patch to the source to
  1422. ensure the correct paths are used. If you need to specify paths to
  1423. find files staged into the sysroot from other recipes, use the
  1424. variables that the OpenEmbedded build system provides (e.g.
  1425. ``STAGING_BINDIR``, ``STAGING_INCDIR``, ``STAGING_DATADIR``, and so
  1426. forth).
  1427. Installing
  1428. ----------
  1429. During ``do_install``, the task copies the built files along with their
  1430. hierarchy to locations that would mirror their locations on the target
  1431. device. The installation process copies files from the
  1432. ``${``\ :term:`S`\ ``}``,
  1433. ``${``\ :term:`B`\ ``}``, and
  1434. ``${``\ :term:`WORKDIR`\ ``}``
  1435. directories to the ``${``\ :term:`D`\ ``}``
  1436. directory to create the structure as it should appear on the target
  1437. system.
  1438. How your software is built affects what you must do to be sure your
  1439. software is installed correctly. The following list describes what you
  1440. must do for installation depending on the type of build system used by
  1441. the software being built:
  1442. - *Autotools and CMake:* If the software your recipe is building uses
  1443. Autotools or CMake, the OpenEmbedded build system understands how to
  1444. install the software. Consequently, you do not have to have a
  1445. ``do_install`` task as part of your recipe. You just need to make
  1446. sure the install portion of the build completes with no issues.
  1447. However, if you wish to install additional files not already being
  1448. installed by ``make install``, you should do this using a
  1449. ``do_install_append`` function using the install command as described
  1450. in the "Manual" bulleted item later in this list.
  1451. - *Other (using* ``make install``\ *)*: You need to define a ``do_install``
  1452. function in your recipe. The function should call
  1453. ``oe_runmake install`` and will likely need to pass in the
  1454. destination directory as well. How you pass that path is dependent on
  1455. how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``,
  1456. ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth).
  1457. For an example recipe using ``make install``, see the
  1458. "`Makefile-Based Package <#new-recipe-makefile-based-package>`__"
  1459. section.
  1460. - *Manual:* You need to define a ``do_install`` function in your
  1461. recipe. The function must first use ``install -d`` to create the
  1462. directories under
  1463. ``${``\ :term:`D`\ ``}``. Once the
  1464. directories exist, your function can use ``install`` to manually
  1465. install the built software into the directories.
  1466. You can find more information on ``install`` at
  1467. https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html.
  1468. For the scenarios that do not use Autotools or CMake, you need to track
  1469. the installation and diagnose and fix any issues until everything
  1470. installs correctly. You need to look in the default location of
  1471. ``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been
  1472. installed correctly.
  1473. .. note::
  1474. - During the installation process, you might need to modify some of
  1475. the installed files to suit the target layout. For example, you
  1476. might need to replace hard-coded paths in an initscript with
  1477. values of variables provided by the build system, such as
  1478. replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such
  1479. modifications during ``do_install``, be sure to modify the
  1480. destination file after copying rather than before copying.
  1481. Modifying after copying ensures that the build system can
  1482. re-execute ``do_install`` if needed.
  1483. - ``oe_runmake install``, which can be run directly or can be run
  1484. indirectly by the
  1485. :ref:`autotools <ref-classes-autotools>` and
  1486. :ref:`cmake <ref-classes-cmake>` classes,
  1487. runs ``make install`` in parallel. Sometimes, a Makefile can have
  1488. missing dependencies between targets that can result in race
  1489. conditions. If you experience intermittent failures during
  1490. ``do_install``, you might be able to work around them by disabling
  1491. parallel Makefile installs by adding the following to the recipe:
  1492. ::
  1493. PARALLEL_MAKEINST = ""
  1494. See :term:`PARALLEL_MAKEINST` for additional information.
  1495. - If you need to install one or more custom CMake toolchain files
  1496. that are supplied by the application you are building, install the
  1497. files to ``${D}${datadir}/cmake/Modules`` during
  1498. :ref:`ref-tasks-install`.
  1499. Enabling System Services
  1500. ------------------------
  1501. If you want to install a service, which is a process that usually starts
  1502. on boot and runs in the background, then you must include some
  1503. additional definitions in your recipe.
  1504. If you are adding services and the service initialization script or the
  1505. service file itself is not installed, you must provide for that
  1506. installation in your recipe using a ``do_install_append`` function. If
  1507. your recipe already has a ``do_install`` function, update the function
  1508. near its end rather than adding an additional ``do_install_append``
  1509. function.
  1510. When you create the installation for your services, you need to
  1511. accomplish what is normally done by ``make install``. In other words,
  1512. make sure your installation arranges the output similar to how it is
  1513. arranged on the target system.
  1514. The OpenEmbedded build system provides support for starting services two
  1515. different ways:
  1516. - *SysVinit:* SysVinit is a system and service manager that manages the
  1517. init system used to control the very basic functions of your system.
  1518. The init program is the first program started by the Linux kernel
  1519. when the system boots. Init then controls the startup, running and
  1520. shutdown of all other programs.
  1521. To enable a service using SysVinit, your recipe needs to inherit the
  1522. :ref:`update-rc.d <ref-classes-update-rc.d>`
  1523. class. The class helps facilitate safely installing the package on
  1524. the target.
  1525. You will need to set the
  1526. :term:`INITSCRIPT_PACKAGES`,
  1527. :term:`INITSCRIPT_NAME`,
  1528. and
  1529. :term:`INITSCRIPT_PARAMS`
  1530. variables within your recipe.
  1531. - *systemd:* System Management Daemon (systemd) was designed to replace
  1532. SysVinit and to provide enhanced management of services. For more
  1533. information on systemd, see the systemd homepage at
  1534. https://freedesktop.org/wiki/Software/systemd/.
  1535. To enable a service using systemd, your recipe needs to inherit the
  1536. :ref:`systemd <ref-classes-systemd>` class. See
  1537. the ``systemd.bbclass`` file located in your :term:`Source Directory`
  1538. section for
  1539. more information.
  1540. Packaging
  1541. ---------
  1542. Successful packaging is a combination of automated processes performed
  1543. by the OpenEmbedded build system and some specific steps you need to
  1544. take. The following list describes the process:
  1545. - *Splitting Files*: The ``do_package`` task splits the files produced
  1546. by the recipe into logical components. Even software that produces a
  1547. single binary might still have debug symbols, documentation, and
  1548. other logical components that should be split out. The ``do_package``
  1549. task ensures that files are split up and packaged correctly.
  1550. - *Running QA Checks*: The
  1551. :ref:`insane <ref-classes-insane>` class adds a
  1552. step to the package generation process so that output quality
  1553. assurance checks are generated by the OpenEmbedded build system. This
  1554. step performs a range of checks to be sure the build's output is free
  1555. of common problems that show up during runtime. For information on
  1556. these checks, see the
  1557. :ref:`insane <ref-classes-insane>` class and
  1558. the ":ref:`ref-manual/qa-checks:qa error and warning messages`"
  1559. chapter in the Yocto Project Reference Manual.
  1560. - *Hand-Checking Your Packages*: After you build your software, you
  1561. need to be sure your packages are correct. Examine the
  1562. ``${``\ :term:`WORKDIR`\ ``}/packages-split``
  1563. directory and make sure files are where you expect them to be. If you
  1564. discover problems, you can set
  1565. :term:`PACKAGES`,
  1566. :term:`FILES`,
  1567. ``do_install(_append)``, and so forth as needed.
  1568. - *Splitting an Application into Multiple Packages*: If you need to
  1569. split an application into several packages, see the "`Splitting an
  1570. Application into Multiple
  1571. Packages <#splitting-an-application-into-multiple-packages>`__"
  1572. section for an example.
  1573. - *Installing a Post-Installation Script*: For an example showing how
  1574. to install a post-installation script, see the "`Post-Installation
  1575. Scripts <#new-recipe-post-installation-scripts>`__" section.
  1576. - *Marking Package Architecture*: Depending on what your recipe is
  1577. building and how it is configured, it might be important to mark the
  1578. packages produced as being specific to a particular machine, or to
  1579. mark them as not being specific to a particular machine or
  1580. architecture at all.
  1581. By default, packages apply to any machine with the same architecture
  1582. as the target machine. When a recipe produces packages that are
  1583. machine-specific (e.g. the
  1584. :term:`MACHINE` value is passed
  1585. into the configure script or a patch is applied only for a particular
  1586. machine), you should mark them as such by adding the following to the
  1587. recipe:
  1588. ::
  1589. PACKAGE_ARCH = "${MACHINE_ARCH}"
  1590. On the other hand, if the recipe produces packages that do not
  1591. contain anything specific to the target machine or architecture at
  1592. all (e.g. recipes that simply package script files or configuration
  1593. files), you should use the
  1594. :ref:`allarch <ref-classes-allarch>` class to
  1595. do this for you by adding this to your recipe:
  1596. ::
  1597. inherit allarch
  1598. Ensuring that the package architecture is correct is not critical
  1599. while you are doing the first few builds of your recipe. However, it
  1600. is important in order to ensure that your recipe rebuilds (or does
  1601. not rebuild) appropriately in response to changes in configuration,
  1602. and to ensure that you get the appropriate packages installed on the
  1603. target machine, particularly if you run separate builds for more than
  1604. one target machine.
  1605. Sharing Files Between Recipes
  1606. -----------------------------
  1607. Recipes often need to use files provided by other recipes on the build
  1608. host. For example, an application linking to a common library needs
  1609. access to the library itself and its associated headers. The way this
  1610. access is accomplished is by populating a sysroot with files. Each
  1611. recipe has two sysroots in its work directory, one for target files
  1612. (``recipe-sysroot``) and one for files that are native to the build host
  1613. (``recipe-sysroot-native``).
  1614. .. note::
  1615. You could find the term "staging" used within the Yocto project
  1616. regarding files populating sysroots (e.g. the :term:`STAGING_DIR`
  1617. variable).
  1618. Recipes should never populate the sysroot directly (i.e. write files
  1619. into sysroot). Instead, files should be installed into standard
  1620. locations during the
  1621. :ref:`ref-tasks-install` task within
  1622. the ``${``\ :term:`D`\ ``}`` directory. The
  1623. reason for this limitation is that almost all files that populate the
  1624. sysroot are cataloged in manifests in order to ensure the files can be
  1625. removed later when a recipe is either modified or removed. Thus, the
  1626. sysroot is able to remain free from stale files.
  1627. A subset of the files installed by the
  1628. :ref:`ref-tasks-install` task are
  1629. used by the
  1630. :ref:`ref-tasks-populate_sysroot`
  1631. task as defined by the the
  1632. :term:`SYSROOT_DIRS` variable to
  1633. automatically populate the sysroot. It is possible to modify the list of
  1634. directories that populate the sysroot. The following example shows how
  1635. you could add the ``/opt`` directory to the list of directories within a
  1636. recipe:
  1637. ::
  1638. SYSROOT_DIRS += "/opt"
  1639. For a more complete description of the
  1640. :ref:`ref-tasks-populate_sysroot`
  1641. task and its associated functions, see the
  1642. :ref:`staging <ref-classes-staging>` class.
  1643. Using Virtual Providers
  1644. -----------------------
  1645. Prior to a build, if you know that several different recipes provide the
  1646. same functionality, you can use a virtual provider (i.e. ``virtual/*``)
  1647. as a placeholder for the actual provider. The actual provider is
  1648. determined at build-time.
  1649. A common scenario where a virtual provider is used would be for the
  1650. kernel recipe. Suppose you have three kernel recipes whose
  1651. :term:`PN` values map to ``kernel-big``,
  1652. ``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes
  1653. in some way uses a :term:`PROVIDES`
  1654. statement that essentially identifies itself as being able to provide
  1655. ``virtual/kernel``. Here is one way through the
  1656. :ref:`kernel <ref-classes-kernel>` class:
  1657. ::
  1658. PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }"
  1659. Any recipe that inherits the ``kernel`` class is
  1660. going to utilize a ``PROVIDES`` statement that identifies that recipe as
  1661. being able to provide the ``virtual/kernel`` item.
  1662. Now comes the time to actually build an image and you need a kernel
  1663. recipe, but which one? You can configure your build to call out the
  1664. kernel recipe you want by using the :term:`PREFERRED_PROVIDER` variable. As
  1665. an example, consider the :yocto_git:`x86-base.inc
  1666. </poky/tree/meta/conf/machine/include/x86-base.inc>` include file, which is a
  1667. machine (i.e. :term:`MACHINE`) configuration file. This include file is the
  1668. reason all x86-based machines use the ``linux-yocto`` kernel. Here are the
  1669. relevant lines from the include file:
  1670. ::
  1671. PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
  1672. PREFERRED_VERSION_linux-yocto ??= "4.15%"
  1673. When you use a virtual provider, you do not have to "hard code" a recipe
  1674. name as a build dependency. You can use the
  1675. :term:`DEPENDS` variable to state the
  1676. build is dependent on ``virtual/kernel`` for example:
  1677. ::
  1678. DEPENDS = "virtual/kernel"
  1679. During the build, the OpenEmbedded build system picks
  1680. the correct recipe needed for the ``virtual/kernel`` dependency based on
  1681. the ``PREFERRED_PROVIDER`` variable. If you want to use the small kernel
  1682. mentioned at the beginning of this section, configure your build as
  1683. follows:
  1684. ::
  1685. PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
  1686. .. note::
  1687. Any recipe that ``PROVIDES`` a ``virtual/*`` item that is ultimately not
  1688. selected through ``PREFERRED_PROVIDER`` does not get built. Preventing these
  1689. recipes from building is usually the desired behavior since this mechanism's
  1690. purpose is to select between mutually exclusive alternative providers.
  1691. The following lists specific examples of virtual providers:
  1692. - ``virtual/kernel``: Provides the name of the kernel recipe to use
  1693. when building a kernel image.
  1694. - ``virtual/bootloader``: Provides the name of the bootloader to use
  1695. when building an image.
  1696. - ``virtual/libgbm``: Provides ``gbm.pc``.
  1697. - ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``.
  1698. - ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL).
  1699. - ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM).
  1700. - ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2).
  1701. .. note::
  1702. Virtual providers only apply to build time dependencies specified with
  1703. :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime
  1704. dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`.
  1705. Properly Versioning Pre-Release Recipes
  1706. ---------------------------------------
  1707. Sometimes the name of a recipe can lead to versioning problems when the
  1708. recipe is upgraded to a final release. For example, consider the
  1709. ``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in
  1710. the "`Storing and Naming the
  1711. Recipe <#new-recipe-storing-and-naming-the-recipe>`__" section. This
  1712. recipe is at a release candidate stage (i.e. "rc1"). When the recipe is
  1713. released, the recipe filename becomes ``irssi_0.8.16.bb``. The version
  1714. change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the
  1715. build system and package managers, so the resulting packages will not
  1716. correctly trigger an upgrade.
  1717. In order to ensure the versions compare properly, the recommended
  1718. convention is to set :term:`PV` within the
  1719. recipe to "previous_version+current_version". You can use an additional
  1720. variable so that you can use the current version elsewhere. Here is an
  1721. example:
  1722. ::
  1723. REALPV = "0.8.16-rc1"
  1724. PV = "0.8.15+${REALPV}"
  1725. Post-Installation Scripts
  1726. -------------------------
  1727. Post-installation scripts run immediately after installing a package on
  1728. the target or during image creation when a package is included in an
  1729. image. To add a post-installation script to a package, add a
  1730. ``pkg_postinst_``\ `PACKAGENAME`\ ``()`` function to the recipe file
  1731. (``.bb``) and replace `PACKAGENAME` with the name of the package you want
  1732. to attach to the ``postinst`` script. To apply the post-installation
  1733. script to the main package for the recipe, which is usually what is
  1734. required, specify
  1735. ``${``\ :term:`PN`\ ``}`` in place of
  1736. PACKAGENAME.
  1737. A post-installation function has the following structure:
  1738. ::
  1739. pkg_postinst_PACKAGENAME() {
  1740. # Commands to carry out
  1741. }
  1742. The script defined in the post-installation function is called when the
  1743. root filesystem is created. If the script succeeds, the package is
  1744. marked as installed.
  1745. .. note::
  1746. Any RPM post-installation script that runs on the target should
  1747. return a 0 exit code. RPM does not allow non-zero exit codes for
  1748. these scripts, and the RPM package manager will cause the package to
  1749. fail installation on the target.
  1750. Sometimes it is necessary for the execution of a post-installation
  1751. script to be delayed until the first boot. For example, the script might
  1752. need to be executed on the device itself. To delay script execution
  1753. until boot time, you must explicitly mark post installs to defer to the
  1754. target. You can use ``pkg_postinst_ontarget()`` or call
  1755. ``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any
  1756. failure of a ``pkg_postinst()`` script (including exit 1) triggers an
  1757. error during the
  1758. :ref:`ref-tasks-rootfs` task.
  1759. If you have recipes that use ``pkg_postinst`` function and they require
  1760. the use of non-standard native tools that have dependencies during
  1761. rootfs construction, you need to use the
  1762. :term:`PACKAGE_WRITE_DEPS`
  1763. variable in your recipe to list these tools. If you do not use this
  1764. variable, the tools might be missing and execution of the
  1765. post-installation script is deferred until first boot. Deferring the
  1766. script to first boot is undesirable and for read-only rootfs impossible.
  1767. .. note::
  1768. Equivalent support for pre-install, pre-uninstall, and post-uninstall
  1769. scripts exist by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``,
  1770. respectively. These scrips work in exactly the same way as does
  1771. ``pkg_postinst`` with the exception that they run at different times. Also,
  1772. because of when they run, they are not applicable to being run at image
  1773. creation time like ``pkg_postinst``.
  1774. Testing
  1775. -------
  1776. The final step for completing your recipe is to be sure that the
  1777. software you built runs correctly. To accomplish runtime testing, add
  1778. the build's output packages to your image and test them on the target.
  1779. For information on how to customize your image by adding specific
  1780. packages, see the "`Customizing
  1781. Images <#usingpoky-extend-customimage>`__" section.
  1782. Examples
  1783. --------
  1784. To help summarize how to write a recipe, this section provides some
  1785. examples given various scenarios:
  1786. - Recipes that use local files
  1787. - Using an Autotooled package
  1788. - Using a Makefile-based package
  1789. - Splitting an application into multiple packages
  1790. - Adding binaries to an image
  1791. Single .c File Package (Hello World!)
  1792. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1793. Building an application from a single file that is stored locally (e.g.
  1794. under ``files``) requires a recipe that has the file listed in the
  1795. ``SRC_URI`` variable. Additionally, you need to manually write the
  1796. ``do_compile`` and ``do_install`` tasks. The ``S`` variable defines the
  1797. directory containing the source code, which is set to
  1798. :term:`WORKDIR` in this case - the
  1799. directory BitBake uses for the build.
  1800. ::
  1801. SUMMARY = "Simple helloworld application"
  1802. SECTION = "examples"
  1803. LICENSE = "MIT"
  1804. LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
  1805. SRC_URI = "file://helloworld.c"
  1806. S = "${WORKDIR}"
  1807. do_compile() {
  1808. ${CC} helloworld.c -o helloworld
  1809. }
  1810. do_install() {
  1811. install -d ${D}${bindir}
  1812. install -m 0755 helloworld ${D}${bindir}
  1813. }
  1814. By default, the ``helloworld``, ``helloworld-dbg``, and
  1815. ``helloworld-dev`` packages are built. For information on how to
  1816. customize the packaging process, see the "`Splitting an Application into
  1817. Multiple Packages <#splitting-an-application-into-multiple-packages>`__"
  1818. section.
  1819. Autotooled Package
  1820. ~~~~~~~~~~~~~~~~~~
  1821. Applications that use Autotools such as ``autoconf`` and ``automake``
  1822. require a recipe that has a source archive listed in ``SRC_URI`` and
  1823. also inherit the
  1824. :ref:`autotools <ref-classes-autotools>` class,
  1825. which contains the definitions of all the steps needed to build an
  1826. Autotool-based application. The result of the build is automatically
  1827. packaged. And, if the application uses NLS for localization, packages
  1828. with local information are generated (one package per language).
  1829. Following is one example: (``hello_2.3.bb``)
  1830. ::
  1831. SUMMARY = "GNU Helloworld application"
  1832. SECTION = "examples"
  1833. LICENSE = "GPLv2+"
  1834. LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
  1835. SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
  1836. inherit autotools gettext
  1837. The variable ``LIC_FILES_CHKSUM`` is used to track source license
  1838. changes as described in the
  1839. ":ref:`dev-manual/common-tasks:tracking license changes`" section in
  1840. the Yocto Project Overview and Concepts Manual. You can quickly create
  1841. Autotool-based recipes in a manner similar to the previous example.
  1842. Makefile-Based Package
  1843. ~~~~~~~~~~~~~~~~~~~~~~
  1844. Applications that use GNU ``make`` also require a recipe that has the
  1845. source archive listed in ``SRC_URI``. You do not need to add a
  1846. ``do_compile`` step since by default BitBake starts the ``make`` command
  1847. to compile the application. If you need additional ``make`` options, you
  1848. should store them in the
  1849. :term:`EXTRA_OEMAKE` or
  1850. :term:`PACKAGECONFIG_CONFARGS`
  1851. variables. BitBake passes these options into the GNU ``make``
  1852. invocation. Note that a ``do_install`` task is still required.
  1853. Otherwise, BitBake runs an empty ``do_install`` task by default.
  1854. Some applications might require extra parameters to be passed to the
  1855. compiler. For example, the application might need an additional header
  1856. path. You can accomplish this by adding to the ``CFLAGS`` variable. The
  1857. following example shows this:
  1858. ::
  1859. CFLAGS_prepend = "-I ${S}/include "
  1860. In the following example, ``mtd-utils`` is a makefile-based package:
  1861. ::
  1862. SUMMARY = "Tools for managing memory technology devices"
  1863. SECTION = "base"
  1864. DEPENDS = "zlib lzo e2fsprogs util-linux"
  1865. HOMEPAGE = "http://www.linux-mtd.infradead.org/"
  1866. LICENSE = "GPLv2+"
  1867. LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
  1868. file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
  1869. # Use the latest version at 26 Oct, 2013
  1870. SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
  1871. SRC_URI = "git://git.infradead.org/mtd-utils.git \
  1872. file://add-exclusion-to-mkfs-jffs2-git-2.patch \
  1873. "
  1874. PV = "1.5.1+git${SRCPV}"
  1875. S = "${WORKDIR}/git"
  1876. EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
  1877. do_install () {
  1878. oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
  1879. }
  1880. PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
  1881. FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
  1882. FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
  1883. FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image"
  1884. PARALLEL_MAKE = ""
  1885. BBCLASSEXTEND = "native"
  1886. Splitting an Application into Multiple Packages
  1887. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1888. You can use the variables ``PACKAGES`` and ``FILES`` to split an
  1889. application into multiple packages.
  1890. Following is an example that uses the ``libxpm`` recipe. By default,
  1891. this recipe generates a single package that contains the library along
  1892. with a few binaries. You can modify the recipe to split the binaries
  1893. into separate packages:
  1894. ::
  1895. require xorg-lib-common.inc
  1896. SUMMARY = "Xpm: X Pixmap extension library"
  1897. LICENSE = "BSD"
  1898. LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
  1899. DEPENDS += "libxext libsm libxt"
  1900. PE = "1"
  1901. XORG_PN = "libXpm"
  1902. PACKAGES =+ "sxpm cxpm"
  1903. FILES_cxpm = "${bindir}/cxpm"
  1904. FILES_sxpm = "${bindir}/sxpm"
  1905. In the previous example, we want to ship the ``sxpm`` and ``cxpm``
  1906. binaries in separate packages. Since ``bindir`` would be packaged into
  1907. the main ``PN`` package by default, we prepend the ``PACKAGES`` variable
  1908. so additional package names are added to the start of list. This results
  1909. in the extra ``FILES_*`` variables then containing information that
  1910. define which files and directories go into which packages. Files
  1911. included by earlier packages are skipped by latter packages. Thus, the
  1912. main ``PN`` package does not include the above listed files.
  1913. Packaging Externally Produced Binaries
  1914. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1915. Sometimes, you need to add pre-compiled binaries to an image. For
  1916. example, suppose that binaries for proprietary code exist, which are
  1917. created by a particular division of a company. Your part of the company
  1918. needs to use those binaries as part of an image that you are building
  1919. using the OpenEmbedded build system. Since you only have the binaries
  1920. and not the source code, you cannot use a typical recipe that expects to
  1921. fetch the source specified in
  1922. :term:`SRC_URI` and then compile it.
  1923. One method is to package the binaries and then install them as part of
  1924. the image. Generally, it is not a good idea to package binaries since,
  1925. among other things, it can hinder the ability to reproduce builds and
  1926. could lead to compatibility problems with ABI in the future. However,
  1927. sometimes you have no choice.
  1928. The easiest solution is to create a recipe that uses the
  1929. :ref:`bin_package <ref-classes-bin-package>` class
  1930. and to be sure that you are using default locations for build artifacts.
  1931. In most cases, the ``bin_package`` class handles "skipping" the
  1932. configure and compile steps as well as sets things up to grab packages
  1933. from the appropriate area. In particular, this class sets ``noexec`` on
  1934. both the :ref:`ref-tasks-configure`
  1935. and :ref:`ref-tasks-compile` tasks,
  1936. sets ``FILES_${PN}`` to "/" so that it picks up all files, and sets up a
  1937. :ref:`ref-tasks-install` task, which
  1938. effectively copies all files from ``${S}`` to ``${D}``. The
  1939. ``bin_package`` class works well when the files extracted into ``${S}``
  1940. are already laid out in the way they should be laid out on the target.
  1941. For more information on these variables, see the
  1942. :term:`FILES`,
  1943. :term:`PN`,
  1944. :term:`S`, and
  1945. :term:`D` variables in the Yocto Project
  1946. Reference Manual's variable glossary.
  1947. .. note::
  1948. - Using :term:`DEPENDS` is a good
  1949. idea even for components distributed in binary form, and is often
  1950. necessary for shared libraries. For a shared library, listing the
  1951. library dependencies in ``DEPENDS`` makes sure that the libraries
  1952. are available in the staging sysroot when other recipes link
  1953. against the library, which might be necessary for successful
  1954. linking.
  1955. - Using ``DEPENDS`` also allows runtime dependencies between
  1956. packages to be added automatically. See the
  1957. ":ref:`overview-manual/concepts:automatically added runtime dependencies`"
  1958. section in the Yocto Project Overview and Concepts Manual for more
  1959. information.
  1960. If you cannot use the ``bin_package`` class, you need to be sure you are
  1961. doing the following:
  1962. - Create a recipe where the
  1963. :ref:`ref-tasks-configure` and
  1964. :ref:`ref-tasks-compile` tasks do
  1965. nothing: It is usually sufficient to just not define these tasks in
  1966. the recipe, because the default implementations do nothing unless a
  1967. Makefile is found in
  1968. ``${``\ :term:`S`\ ``}``.
  1969. If ``${S}`` might contain a Makefile, or if you inherit some class
  1970. that replaces ``do_configure`` and ``do_compile`` with custom
  1971. versions, then you can use the
  1972. ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]``
  1973. flag to turn the tasks into no-ops, as follows:
  1974. ::
  1975. do_configure[noexec] = "1"
  1976. do_compile[noexec] = "1"
  1977. Unlike
  1978. :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`,
  1979. using the flag preserves the dependency chain from the
  1980. :ref:`ref-tasks-fetch`,
  1981. :ref:`ref-tasks-unpack`, and
  1982. :ref:`ref-tasks-patch` tasks to the
  1983. :ref:`ref-tasks-install` task.
  1984. - Make sure your ``do_install`` task installs the binaries
  1985. appropriately.
  1986. - Ensure that you set up :term:`FILES`
  1987. (usually
  1988. ``FILES_${``\ :term:`PN`\ ``}``) to
  1989. point to the files you have installed, which of course depends on
  1990. where you have installed them and whether those files are in
  1991. different locations than the defaults.
  1992. .. note::
  1993. If image prelinking is enabled (e.g. "image-prelink" is in :term:`USER_CLASSES`
  1994. which it is by default), prelink will change the binaries in the generated images
  1995. and this often catches people out. Remove that class to ensure binaries are
  1996. preserved exactly if that is necessary.
  1997. Following Recipe Style Guidelines
  1998. ---------------------------------
  1999. When writing recipes, it is good to conform to existing style
  2000. guidelines. The :oe_wiki:`OpenEmbedded Styleguide </Styleguide>` wiki page
  2001. provides rough guidelines for preferred recipe style.
  2002. It is common for existing recipes to deviate a bit from this style.
  2003. However, aiming for at least a consistent style is a good idea. Some
  2004. practices, such as omitting spaces around ``=`` operators in assignments
  2005. or ordering recipe components in an erratic way, are widely seen as poor
  2006. style.
  2007. Recipe Syntax
  2008. -------------
  2009. Understanding recipe file syntax is important for writing recipes. The
  2010. following list overviews the basic items that make up a BitBake recipe
  2011. file. For more complete BitBake syntax descriptions, see the
  2012. ":doc:`bitbake-user-manual/bitbake-user-manual-metadata`"
  2013. chapter of the BitBake User Manual.
  2014. - *Variable Assignments and Manipulations:* Variable assignments allow
  2015. a value to be assigned to a variable. The assignment can be static
  2016. text or might include the contents of other variables. In addition to
  2017. the assignment, appending and prepending operations are also
  2018. supported.
  2019. The following example shows some of the ways you can use variables in
  2020. recipes:
  2021. ::
  2022. S = "${WORKDIR}/postfix-${PV}"
  2023. CFLAGS += "-DNO_ASM"
  2024. SRC_URI_append = " file://fixup.patch"
  2025. - *Functions:* Functions provide a series of actions to be performed.
  2026. You usually use functions to override the default implementation of a
  2027. task function or to complement a default function (i.e. append or
  2028. prepend to an existing function). Standard functions use ``sh`` shell
  2029. syntax, although access to OpenEmbedded variables and internal
  2030. methods are also available.
  2031. The following is an example function from the ``sed`` recipe:
  2032. ::
  2033. do_install () {
  2034. autotools_do_install
  2035. install -d ${D}${base_bindir}
  2036. mv ${D}${bindir}/sed ${D}${base_bindir}/sed
  2037. rmdir ${D}${bindir}/
  2038. }
  2039. It is
  2040. also possible to implement new functions that are called between
  2041. existing tasks as long as the new functions are not replacing or
  2042. complementing the default functions. You can implement functions in
  2043. Python instead of shell. Both of these options are not seen in the
  2044. majority of recipes.
  2045. - *Keywords:* BitBake recipes use only a few keywords. You use keywords
  2046. to include common functions (``inherit``), load parts of a recipe
  2047. from other files (``include`` and ``require``) and export variables
  2048. to the environment (``export``).
  2049. The following example shows the use of some of these keywords:
  2050. ::
  2051. export POSTCONF = "${STAGING_BINDIR}/postconf"
  2052. inherit autoconf
  2053. require otherfile.inc
  2054. - *Comments (#):* Any lines that begin with the hash character (``#``)
  2055. are treated as comment lines and are ignored:
  2056. ::
  2057. # This is a comment
  2058. This next list summarizes the most important and most commonly used
  2059. parts of the recipe syntax. For more information on these parts of the
  2060. syntax, you can reference the
  2061. :doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata` chapter
  2062. in the BitBake User Manual.
  2063. - *Line Continuation (\\):* Use the backward slash (``\``) character to
  2064. split a statement over multiple lines. Place the slash character at
  2065. the end of the line that is to be continued on the next line:
  2066. ::
  2067. VAR = "A really long \
  2068. line"
  2069. .. note::
  2070. You cannot have any characters including spaces or tabs after the
  2071. slash character.
  2072. - *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to
  2073. access the contents of a variable:
  2074. ::
  2075. SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
  2076. .. note::
  2077. It is important to understand that the value of a variable
  2078. expressed in this form does not get substituted automatically. The
  2079. expansion of these expressions happens on-demand later (e.g.
  2080. usually when a function that makes reference to the variable
  2081. executes). This behavior ensures that the values are most
  2082. appropriate for the context in which they are finally used. On the
  2083. rare occasion that you do need the variable expression to be
  2084. expanded immediately, you can use the
  2085. :=
  2086. operator instead of
  2087. =
  2088. when you make the assignment, but this is not generally needed.
  2089. - *Quote All Assignments ("value"):* Use double quotes around values in
  2090. all variable assignments (e.g. ``"value"``). Following is an example:
  2091. ::
  2092. VAR1 = "${OTHERVAR}"
  2093. VAR2 = "The version is ${PV}"
  2094. - *Conditional Assignment (?=):* Conditional assignment is used to
  2095. assign a value to a variable, but only when the variable is currently
  2096. unset. Use the question mark followed by the equal sign (``?=``) to
  2097. make a "soft" assignment used for conditional assignment. Typically,
  2098. "soft" assignments are used in the ``local.conf`` file for variables
  2099. that are allowed to come through from the external environment.
  2100. Here is an example where ``VAR1`` is set to "New value" if it is
  2101. currently empty. However, if ``VAR1`` has already been set, it
  2102. remains unchanged:
  2103. ::
  2104. VAR1 ?= "New value"
  2105. In this next example, ``VAR1`` is left with the value "Original value":
  2106. ::
  2107. VAR1 = "Original value"
  2108. VAR1 ?= "New value"
  2109. - *Appending (+=):* Use the plus character followed by the equals sign
  2110. (``+=``) to append values to existing variables.
  2111. .. note::
  2112. This operator adds a space between the existing content of the
  2113. variable and the new content.
  2114. Here is an example:
  2115. ::
  2116. SRC_URI += "file://fix-makefile.patch"
  2117. - *Prepending (=+):* Use the equals sign followed by the plus character
  2118. (``=+``) to prepend values to existing variables.
  2119. .. note::
  2120. This operator adds a space between the new content and the
  2121. existing content of the variable.
  2122. Here is an example:
  2123. ::
  2124. VAR =+ "Starts"
  2125. - *Appending (_append):* Use the ``_append`` operator to append values
  2126. to existing variables. This operator does not add any additional
  2127. space. Also, the operator is applied after all the ``+=``, and ``=+``
  2128. operators have been applied and after all ``=`` assignments have
  2129. occurred.
  2130. The following example shows the space being explicitly added to the
  2131. start to ensure the appended value is not merged with the existing
  2132. value:
  2133. ::
  2134. SRC_URI_append = " file://fix-makefile.patch"
  2135. You can also use
  2136. the ``_append`` operator with overrides, which results in the actions
  2137. only being performed for the specified target or machine:
  2138. ::
  2139. SRC_URI_append_sh4 = " file://fix-makefile.patch"
  2140. - *Prepending (_prepend):* Use the ``_prepend`` operator to prepend
  2141. values to existing variables. This operator does not add any
  2142. additional space. Also, the operator is applied after all the ``+=``,
  2143. and ``=+`` operators have been applied and after all ``=``
  2144. assignments have occurred.
  2145. The following example shows the space being explicitly added to the
  2146. end to ensure the prepended value is not merged with the existing
  2147. value:
  2148. ::
  2149. CFLAGS_prepend = "-I${S}/myincludes "
  2150. You can also use the
  2151. ``_prepend`` operator with overrides, which results in the actions
  2152. only being performed for the specified target or machine:
  2153. ::
  2154. CFLAGS_prepend_sh4 = "-I${S}/myincludes "
  2155. - *Overrides:* You can use overrides to set a value conditionally,
  2156. typically based on how the recipe is being built. For example, to set
  2157. the :term:`KBRANCH` variable's
  2158. value to "standard/base" for any target
  2159. :term:`MACHINE`, except for
  2160. qemuarm where it should be set to "standard/arm-versatile-926ejs",
  2161. you would do the following:
  2162. ::
  2163. KBRANCH = "standard/base"
  2164. KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
  2165. Overrides are also used to separate
  2166. alternate values of a variable in other situations. For example, when
  2167. setting variables such as
  2168. :term:`FILES` and
  2169. :term:`RDEPENDS` that are
  2170. specific to individual packages produced by a recipe, you should
  2171. always use an override that specifies the name of the package.
  2172. - *Indentation:* Use spaces for indentation rather than tabs. For
  2173. shell functions, both currently work. However, it is a policy
  2174. decision of the Yocto Project to use tabs in shell functions. Realize
  2175. that some layers have a policy to use spaces for all indentation.
  2176. - *Using Python for Complex Operations:* For more advanced processing,
  2177. it is possible to use Python code during variable assignments (e.g.
  2178. search and replacement on a variable).
  2179. You indicate Python code using the ``${@python_code}`` syntax for the
  2180. variable assignment:
  2181. ::
  2182. SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
  2183. - *Shell Function Syntax:* Write shell functions as if you were writing
  2184. a shell script when you describe a list of actions to take. You
  2185. should ensure that your script works with a generic ``sh`` and that
  2186. it does not require any ``bash`` or other shell-specific
  2187. functionality. The same considerations apply to various system
  2188. utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you
  2189. might wish to use. If in doubt, you should check with multiple
  2190. implementations - including those from BusyBox.
  2191. Adding a New Machine
  2192. ====================
  2193. Adding a new machine to the Yocto Project is a straightforward process.
  2194. This section describes how to add machines that are similar to those
  2195. that the Yocto Project already supports.
  2196. .. note::
  2197. Although well within the capabilities of the Yocto Project, adding a
  2198. totally new architecture might require changes to ``gcc``/``glibc``
  2199. and to the site information, which is beyond the scope of this
  2200. manual.
  2201. For a complete example that shows how to add a new machine, see the
  2202. ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
  2203. section in the Yocto Project Board Support Package (BSP) Developer's
  2204. Guide.
  2205. Adding the Machine Configuration File
  2206. -------------------------------------
  2207. To add a new machine, you need to add a new machine configuration file
  2208. to the layer's ``conf/machine`` directory. This configuration file
  2209. provides details about the device you are adding.
  2210. The OpenEmbedded build system uses the root name of the machine
  2211. configuration file to reference the new machine. For example, given a
  2212. machine configuration file named ``crownbay.conf``, the build system
  2213. recognizes the machine as "crownbay".
  2214. The most important variables you must set in your machine configuration
  2215. file or include from a lower-level configuration file are as follows:
  2216. - ``TARGET_ARCH`` (e.g. "arm")
  2217. - ``PREFERRED_PROVIDER_virtual/kernel``
  2218. - ``MACHINE_FEATURES`` (e.g. "apm screen wifi")
  2219. You might also need these variables:
  2220. - ``SERIAL_CONSOLES`` (e.g. "115200;ttyS0 115200;ttyS1")
  2221. - ``KERNEL_IMAGETYPE`` (e.g. "zImage")
  2222. - ``IMAGE_FSTYPES`` (e.g. "tar.gz jffs2")
  2223. You can find full details on these variables in the reference section.
  2224. You can leverage existing machine ``.conf`` files from
  2225. ``meta-yocto-bsp/conf/machine/``.
  2226. Adding a Kernel for the Machine
  2227. -------------------------------
  2228. The OpenEmbedded build system needs to be able to build a kernel for the
  2229. machine. You need to either create a new kernel recipe for this machine,
  2230. or extend an existing kernel recipe. You can find several kernel recipe
  2231. examples in the Source Directory at ``meta/recipes-kernel/linux`` that
  2232. you can use as references.
  2233. If you are creating a new kernel recipe, normal recipe-writing rules
  2234. apply for setting up a ``SRC_URI``. Thus, you need to specify any
  2235. necessary patches and set ``S`` to point at the source code. You need to
  2236. create a ``do_configure`` task that configures the unpacked kernel with
  2237. a ``defconfig`` file. You can do this by using a ``make defconfig``
  2238. command or, more commonly, by copying in a suitable ``defconfig`` file
  2239. and then running ``make oldconfig``. By making use of ``inherit kernel``
  2240. and potentially some of the ``linux-*.inc`` files, most other
  2241. functionality is centralized and the defaults of the class normally work
  2242. well.
  2243. If you are extending an existing kernel recipe, it is usually a matter
  2244. of adding a suitable ``defconfig`` file. The file needs to be added into
  2245. a location similar to ``defconfig`` files used for other machines in a
  2246. given kernel recipe. A possible way to do this is by listing the file in
  2247. the ``SRC_URI`` and adding the machine to the expression in
  2248. ``COMPATIBLE_MACHINE``:
  2249. ::
  2250. COMPATIBLE_MACHINE = '(qemux86|qemumips)'
  2251. For more information on ``defconfig`` files, see the
  2252. ":ref:`kernel-dev/common:changing the configuration`"
  2253. section in the Yocto Project Linux Kernel Development Manual.
  2254. Adding a Formfactor Configuration File
  2255. --------------------------------------
  2256. A formfactor configuration file provides information about the target
  2257. hardware for which the image is being built and information that the
  2258. build system cannot obtain from other sources such as the kernel. Some
  2259. examples of information contained in a formfactor configuration file
  2260. include framebuffer orientation, whether or not the system has a
  2261. keyboard, the positioning of the keyboard in relation to the screen, and
  2262. the screen resolution.
  2263. The build system uses reasonable defaults in most cases. However, if
  2264. customization is necessary, you need to create a ``machconfig`` file in
  2265. the ``meta/recipes-bsp/formfactor/files`` directory. This directory
  2266. contains directories for specific machines such as ``qemuarm`` and
  2267. ``qemux86``. For information about the settings available and the
  2268. defaults, see the ``meta/recipes-bsp/formfactor/files/config`` file
  2269. found in the same area.
  2270. Following is an example for "qemuarm" machine:
  2271. ::
  2272. HAVE_TOUCHSCREEN=1
  2273. HAVE_KEYBOARD=1
  2274. DISPLAY_CAN_ROTATE=0
  2275. DISPLAY_ORIENTATION=0
  2276. #DISPLAY_WIDTH_PIXELS=640
  2277. #DISPLAY_HEIGHT_PIXELS=480
  2278. #DISPLAY_BPP=16
  2279. DISPLAY_DPI=150
  2280. DISPLAY_SUBPIXEL_ORDER=vrgb
  2281. Upgrading Recipes
  2282. =================
  2283. Over time, upstream developers publish new versions for software built
  2284. by layer recipes. It is recommended to keep recipes up-to-date with
  2285. upstream version releases.
  2286. While several methods exist that allow you upgrade a recipe, you might
  2287. consider checking on the upgrade status of a recipe first. You can do so
  2288. using the ``devtool check-upgrade-status`` command. See the
  2289. ":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`"
  2290. section in the Yocto Project Reference Manual for more information.
  2291. The remainder of this section describes three ways you can upgrade a
  2292. recipe. You can use the Automated Upgrade Helper (AUH) to set up
  2293. automatic version upgrades. Alternatively, you can use
  2294. ``devtool upgrade`` to set up semi-automatic version upgrades. Finally,
  2295. you can manually upgrade a recipe by editing the recipe itself.
  2296. Using the Auto Upgrade Helper (AUH)
  2297. -----------------------------------
  2298. The AUH utility works in conjunction with the OpenEmbedded build system
  2299. in order to automatically generate upgrades for recipes based on new
  2300. versions being published upstream. Use AUH when you want to create a
  2301. service that performs the upgrades automatically and optionally sends
  2302. you an email with the results.
  2303. AUH allows you to update several recipes with a single use. You can also
  2304. optionally perform build and integration tests using images with the
  2305. results saved to your hard drive and emails of results optionally sent
  2306. to recipe maintainers. Finally, AUH creates Git commits with appropriate
  2307. commit messages in the layer's tree for the changes made to recipes.
  2308. .. note::
  2309. Conditions do exist when you should not use AUH to upgrade recipes
  2310. and you should instead use either ``devtool upgrade`` or upgrade your
  2311. recipes manually:
  2312. - When AUH cannot complete the upgrade sequence. This situation
  2313. usually results because custom patches carried by the recipe
  2314. cannot be automatically rebased to the new version. In this case,
  2315. ``devtool upgrade`` allows you to manually resolve conflicts.
  2316. - When for any reason you want fuller control over the upgrade
  2317. process. For example, when you want special arrangements for
  2318. testing.
  2319. The following steps describe how to set up the AUH utility:
  2320. 1. *Be Sure the Development Host is Set Up:* You need to be sure that
  2321. your development host is set up to use the Yocto Project. For
  2322. information on how to set up your host, see the
  2323. ":ref:`dev-manual/start:Preparing the Build Host`" section.
  2324. 2. *Make Sure Git is Configured:* The AUH utility requires Git to be
  2325. configured because AUH uses Git to save upgrades. Thus, you must have
  2326. Git user and email configured. The following command shows your
  2327. configurations:
  2328. ::
  2329. $ git config --list
  2330. If you do not have the user and
  2331. email configured, you can use the following commands to do so:
  2332. ::
  2333. $ git config --global user.name some_name
  2334. $ git config --global user.email username@domain.com
  2335. 3. *Clone the AUH Repository:* To use AUH, you must clone the repository
  2336. onto your development host. The following command uses Git to create
  2337. a local copy of the repository on your system:
  2338. ::
  2339. $ git clone git://git.yoctoproject.org/auto-upgrade-helper
  2340. Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done.
  2341. remote: Compressing objects: 100% (300/300), done.
  2342. remote: Total 768 (delta 499), reused 703 (delta 434)
  2343. Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
  2344. Resolving deltas: 100% (499/499), done.
  2345. Checking connectivity... done.
  2346. AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or
  2347. :term:`Poky` repositories.
  2348. 4. *Create a Dedicated Build Directory:* Run the
  2349. :ref:`structure-core-script`
  2350. script to create a fresh build directory that you use exclusively for
  2351. running the AUH utility:
  2352. ::
  2353. $ cd ~/poky
  2354. $ source oe-init-build-env your_AUH_build_directory
  2355. Re-using an existing build directory and its configurations is not
  2356. recommended as existing settings could cause AUH to fail or behave
  2357. undesirably.
  2358. 5. *Make Configurations in Your Local Configuration File:* Several
  2359. settings need to exist in the ``local.conf`` file in the build
  2360. directory you just created for AUH. Make these following
  2361. configurations:
  2362. - If you want to enable :ref:`Build
  2363. History <dev-manual/common-tasks:maintaining build output quality>`,
  2364. which is optional, you need the following lines in the
  2365. ``conf/local.conf`` file:
  2366. ::
  2367. INHERIT =+ "buildhistory"
  2368. BUILDHISTORY_COMMIT = "1"
  2369. With this configuration and a successful
  2370. upgrade, a build history "diff" file appears in the
  2371. ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in
  2372. your build directory.
  2373. - If you want to enable testing through the
  2374. :ref:`testimage <ref-classes-testimage*>`
  2375. class, which is optional, you need to have the following set in
  2376. your ``conf/local.conf`` file:
  2377. ::
  2378. INHERIT += "testimage"
  2379. .. note::
  2380. If your distro does not enable by default ptest, which Poky
  2381. does, you need the following in your ``local.conf`` file:
  2382. ::
  2383. DISTRO_FEATURES_append = " ptest"
  2384. 6. *Optionally Start a vncserver:* If you are running in a server
  2385. without an X11 session, you need to start a vncserver:
  2386. ::
  2387. $ vncserver :1
  2388. $ export DISPLAY=:1
  2389. 7. *Create and Edit an AUH Configuration File:* You need to have the
  2390. ``upgrade-helper/upgrade-helper.conf`` configuration file in your
  2391. build directory. You can find a sample configuration file in the
  2392. :yocto_git:`AUH source repository </auto-upgrade-helper/tree/>`.
  2393. Read through the sample file and make configurations as needed. For
  2394. example, if you enabled build history in your ``local.conf`` as
  2395. described earlier, you must enable it in ``upgrade-helper.conf``.
  2396. Also, if you are using the default ``maintainers.inc`` file supplied
  2397. with Poky and located in ``meta-yocto`` and you do not set a
  2398. "maintainers_whitelist" or "global_maintainer_override" in the
  2399. ``upgrade-helper.conf`` configuration, and you specify "-e all" on
  2400. the AUH command-line, the utility automatically sends out emails to
  2401. all the default maintainers. Please avoid this.
  2402. This next set of examples describes how to use the AUH:
  2403. - *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the
  2404. following form:
  2405. ::
  2406. $ upgrade-helper.py recipe_name
  2407. For example, this command upgrades the ``xmodmap`` recipe:
  2408. ::
  2409. $ upgrade-helper.py xmodmap
  2410. - *Upgrading a Specific Recipe to a Particular Version:* To upgrade a
  2411. specific recipe to a particular version, use the following form:
  2412. ::
  2413. $ upgrade-helper.py recipe_name -t version
  2414. For example, this command upgrades the ``xmodmap`` recipe to version 1.2.3:
  2415. ::
  2416. $ upgrade-helper.py xmodmap -t 1.2.3
  2417. - *Upgrading all Recipes to the Latest Versions and Suppressing Email
  2418. Notifications:* To upgrade all recipes to their most recent versions
  2419. and suppress the email notifications, use the following command:
  2420. ::
  2421. $ upgrade-helper.py all
  2422. - *Upgrading all Recipes to the Latest Versions and Send Email
  2423. Notifications:* To upgrade all recipes to their most recent versions
  2424. and send email messages to maintainers for each attempted recipe as
  2425. well as a status email, use the following command:
  2426. ::
  2427. $ upgrade-helper.py -e all
  2428. Once you have run the AUH utility, you can find the results in the AUH
  2429. build directory:
  2430. ::
  2431. ${BUILDDIR}/upgrade-helper/timestamp
  2432. The AUH utility
  2433. also creates recipe update commits from successful upgrade attempts in
  2434. the layer tree.
  2435. You can easily set up to run the AUH utility on a regular basis by using
  2436. a cron job. See the
  2437. :yocto_git:`weeklyjob.sh </auto-upgrade-helper/tree/weeklyjob.sh>`
  2438. file distributed with the utility for an example.
  2439. Using ``devtool upgrade``
  2440. -------------------------
  2441. As mentioned earlier, an alternative method for upgrading recipes to
  2442. newer versions is to use
  2443. :doc:`devtool upgrade </ref-manual/devtool-reference>`.
  2444. You can read about ``devtool upgrade`` in general in the
  2445. ":ref:`sdk-manual/extensible:use \`\`devtool upgrade\`\` to create a version of the recipe that supports a newer version of the software`"
  2446. section in the Yocto Project Application Development and the Extensible
  2447. Software Development Kit (eSDK) Manual.
  2448. To see all the command-line options available with ``devtool upgrade``,
  2449. use the following help command:
  2450. ::
  2451. $ devtool upgrade -h
  2452. If you want to find out what version a recipe is currently at upstream
  2453. without any attempt to upgrade your local version of the recipe, you can
  2454. use the following command:
  2455. ::
  2456. $ devtool latest-version recipe_name
  2457. As mentioned in the previous section describing AUH, ``devtool upgrade``
  2458. works in a less-automated manner than AUH. Specifically,
  2459. ``devtool upgrade`` only works on a single recipe that you name on the
  2460. command line, cannot perform build and integration testing using images,
  2461. and does not automatically generate commits for changes in the source
  2462. tree. Despite all these "limitations", ``devtool upgrade`` updates the
  2463. recipe file to the new upstream version and attempts to rebase custom
  2464. patches contained by the recipe as needed.
  2465. .. note::
  2466. AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat
  2467. of a "wrapper" application for ``devtool upgrade``.
  2468. A typical scenario involves having used Git to clone an upstream
  2469. repository that you use during build operations. Because you have built the
  2470. recipe in the past, the layer is likely added to your
  2471. configuration already. If for some reason, the layer is not added, you
  2472. could add it easily using the
  2473. ":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`"
  2474. script. For example, suppose you use the ``nano.bb`` recipe from the
  2475. ``meta-oe`` layer in the ``meta-openembedded`` repository. For this
  2476. example, assume that the layer has been cloned into following area:
  2477. ::
  2478. /home/scottrif/meta-openembedded
  2479. The following command from your
  2480. :term:`Build Directory` adds the layer to
  2481. your build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``):
  2482. ::
  2483. $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
  2484. NOTE: Starting bitbake server...
  2485. Parsing recipes: 100% |##########################################| Time: 0:00:55
  2486. Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
  2487. Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
  2488. Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
  2489. Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
  2490. Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
  2491. For this example, assume that the ``nano.bb`` recipe that
  2492. is upstream has a 2.9.3 version number. However, the version in the
  2493. local repository is 2.7.4. The following command from your build
  2494. directory automatically upgrades the recipe for you:
  2495. .. note::
  2496. Using the ``-V`` option is not necessary. Omitting the version number causes
  2497. ``devtool upgrade`` to upgrade the recipe to the most recent version.
  2498. ::
  2499. $ devtool upgrade nano -V 2.9.3
  2500. NOTE: Starting bitbake server...
  2501. NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
  2502. Parsing recipes: 100% |##########################################| Time: 0:00:46
  2503. Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
  2504. NOTE: Extracting current version source...
  2505. NOTE: Resolving any missing task queue dependencies
  2506. .
  2507. .
  2508. .
  2509. NOTE: Executing SetScene Tasks
  2510. NOTE: Executing RunQueue Tasks
  2511. NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
  2512. Adding changed files: 100% |#####################################| Time: 0:00:00
  2513. NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
  2514. NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
  2515. Continuing with this example, you can use ``devtool build`` to build the
  2516. newly upgraded recipe:
  2517. ::
  2518. $ devtool build nano
  2519. NOTE: Starting bitbake server...
  2520. Loading cache: 100% |################################################################################################| Time: 0:00:01
  2521. Loaded 2040 entries from dependency cache.
  2522. Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
  2523. Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
  2524. NOTE: Resolving any missing task queue dependencies
  2525. .
  2526. .
  2527. .
  2528. NOTE: Executing SetScene Tasks
  2529. NOTE: Executing RunQueue Tasks
  2530. NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
  2531. NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
  2532. Within the ``devtool upgrade`` workflow, opportunity
  2533. exists to deploy and test your rebuilt software. For this example,
  2534. however, running ``devtool finish`` cleans up the workspace once the
  2535. source in your workspace is clean. This usually means using Git to stage
  2536. and submit commits for the changes generated by the upgrade process.
  2537. Once the tree is clean, you can clean things up in this example with the
  2538. following command from the ``${BUILDDIR}/workspace/sources/nano``
  2539. directory:
  2540. ::
  2541. $ devtool finish nano meta-oe
  2542. NOTE: Starting bitbake server...
  2543. Loading cache: 100% |################################################################################################| Time: 0:00:00
  2544. Loaded 2040 entries from dependency cache.
  2545. Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
  2546. Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
  2547. NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
  2548. NOTE: Updating recipe nano_2.9.3.bb
  2549. NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
  2550. NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
  2551. NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
  2552. Using the ``devtool finish`` command cleans up the workspace and creates a patch
  2553. file based on your commits. The tool puts all patch files back into the
  2554. source directory in a sub-directory named ``nano`` in this case.
  2555. Manually Upgrading a Recipe
  2556. ---------------------------
  2557. If for some reason you choose not to upgrade recipes using
  2558. :ref:`dev-manual/common-tasks:Using the Auto Upgrade Helper (AUH)` or
  2559. by :ref:`dev-manual/common-tasks:Using \`\`devtool upgrade\`\``,
  2560. you can manually edit the recipe files to upgrade the versions.
  2561. .. note::
  2562. Manually updating multiple recipes scales poorly and involves many
  2563. steps. The recommendation to upgrade recipe versions is through AUH
  2564. or ``devtool upgrade``, both of which automate some steps and provide
  2565. guidance for others needed for the manual process.
  2566. To manually upgrade recipe versions, follow these general steps:
  2567. 1. *Change the Version:* Rename the recipe such that the version (i.e.
  2568. the :term:`PV` part of the recipe name)
  2569. changes appropriately. If the version is not part of the recipe name,
  2570. change the value as it is set for ``PV`` within the recipe itself.
  2571. 2. *Update* ``SRCREV`` *if Needed*: If the source code your recipe builds
  2572. is fetched from Git or some other version control system, update
  2573. :term:`SRCREV` to point to the
  2574. commit hash that matches the new version.
  2575. 3. *Build the Software:* Try to build the recipe using BitBake. Typical
  2576. build failures include the following:
  2577. - License statements were updated for the new version. For this
  2578. case, you need to review any changes to the license and update the
  2579. values of :term:`LICENSE` and
  2580. :term:`LIC_FILES_CHKSUM`
  2581. as needed.
  2582. .. note::
  2583. License changes are often inconsequential. For example, the
  2584. license text's copyright year might have changed.
  2585. - Custom patches carried by the older version of the recipe might
  2586. fail to apply to the new version. For these cases, you need to
  2587. review the failures. Patches might not be necessary for the new
  2588. version of the software if the upgraded version has fixed those
  2589. issues. If a patch is necessary and failing, you need to rebase it
  2590. into the new version.
  2591. 4. *Optionally Attempt to Build for Several Architectures:* Once you
  2592. successfully build the new software for a given architecture, you
  2593. could test the build for other architectures by changing the
  2594. :term:`MACHINE` variable and
  2595. rebuilding the software. This optional step is especially important
  2596. if the recipe is to be released publicly.
  2597. 5. *Check the Upstream Change Log or Release Notes:* Checking both these
  2598. reveals if new features exist that could break
  2599. backwards-compatibility. If so, you need to take steps to mitigate or
  2600. eliminate that situation.
  2601. 6. *Optionally Create a Bootable Image and Test:* If you want, you can
  2602. test the new software by booting it onto actual hardware.
  2603. 7. *Create a Commit with the Change in the Layer Repository:* After all
  2604. builds work and any testing is successful, you can create commits for
  2605. any changes in the layer holding your upgraded recipe.
  2606. Finding Temporary Source Code
  2607. =============================
  2608. You might find it helpful during development to modify the temporary
  2609. source code used by recipes to build packages. For example, suppose you
  2610. are developing a patch and you need to experiment a bit to figure out
  2611. your solution. After you have initially built the package, you can
  2612. iteratively tweak the source code, which is located in the
  2613. :term:`Build Directory`, and then you can
  2614. force a re-compile and quickly test your altered code. Once you settle
  2615. on a solution, you can then preserve your changes in the form of
  2616. patches.
  2617. During a build, the unpacked temporary source code used by recipes to
  2618. build packages is available in the Build Directory as defined by the
  2619. :term:`S` variable. Below is the default
  2620. value for the ``S`` variable as defined in the
  2621. ``meta/conf/bitbake.conf`` configuration file in the
  2622. :term:`Source Directory`:
  2623. ::
  2624. S = "${WORKDIR}/${BP}"
  2625. You should be aware that many recipes override the
  2626. ``S`` variable. For example, recipes that fetch their source from Git
  2627. usually set ``S`` to ``${WORKDIR}/git``.
  2628. .. note::
  2629. The :term:`BP` represents the base recipe name, which consists of the name
  2630. and version:
  2631. ::
  2632. BP = "${BPN}-${PV}"
  2633. The path to the work directory for the recipe
  2634. (:term:`WORKDIR`) is defined as
  2635. follows:
  2636. ::
  2637. ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
  2638. The actual directory depends on several things:
  2639. - :term:`TMPDIR`: The top-level build
  2640. output directory.
  2641. - :term:`MULTIMACH_TARGET_SYS`:
  2642. The target system identifier.
  2643. - :term:`PN`: The recipe name.
  2644. - :term:`EXTENDPE`: The epoch - (if
  2645. :term:`PE` is not specified, which is
  2646. usually the case for most recipes, then ``EXTENDPE`` is blank).
  2647. - :term:`PV`: The recipe version.
  2648. - :term:`PR`: The recipe revision.
  2649. As an example, assume a Source Directory top-level folder named
  2650. ``poky``, a default Build Directory at ``poky/build``, and a
  2651. ``qemux86-poky-linux`` machine target system. Furthermore, suppose your
  2652. recipe is named ``foo_1.3.0.bb``. In this case, the work directory the
  2653. build system uses to build the package would be as follows:
  2654. ::
  2655. poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
  2656. Using Quilt in Your Workflow
  2657. ============================
  2658. `Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool
  2659. that allows you to capture source code changes without having a clean
  2660. source tree. This section outlines the typical workflow you can use to
  2661. modify source code, test changes, and then preserve the changes in the
  2662. form of a patch all using Quilt.
  2663. .. note::
  2664. With regard to preserving changes to source files, if you clean a
  2665. recipe or have ``rm_work`` enabled, the
  2666. :ref:`devtool workflow <sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow>`
  2667. as described in the Yocto Project Application Development and the
  2668. Extensible Software Development Kit (eSDK) manual is a safer
  2669. development flow than the flow that uses Quilt.
  2670. Follow these general steps:
  2671. 1. *Find the Source Code:* Temporary source code used by the
  2672. OpenEmbedded build system is kept in the
  2673. :term:`Build Directory`. See the
  2674. "`Finding Temporary Source
  2675. Code <#finding-the-temporary-source-code>`__" section to learn how to
  2676. locate the directory that has the temporary source code for a
  2677. particular package.
  2678. 2. *Change Your Working Directory:* You need to be in the directory that
  2679. has the temporary source code. That directory is defined by the
  2680. :term:`S` variable.
  2681. 3. *Create a New Patch:* Before modifying source code, you need to
  2682. create a new patch. To create a new patch file, use ``quilt new`` as
  2683. below:
  2684. ::
  2685. $ quilt new my_changes.patch
  2686. 4. *Notify Quilt and Add Files:* After creating the patch, you need to
  2687. notify Quilt about the files you plan to edit. You notify Quilt by
  2688. adding the files to the patch you just created:
  2689. ::
  2690. $ quilt add file1.c file2.c file3.c
  2691. 5. *Edit the Files:* Make your changes in the source code to the files
  2692. you added to the patch.
  2693. 6. *Test Your Changes:* Once you have modified the source code, the
  2694. easiest way to test your changes is by calling the ``do_compile``
  2695. task as shown in the following example:
  2696. ::
  2697. $ bitbake -c compile -f package
  2698. The ``-f`` or ``--force`` option forces the specified task to
  2699. execute. If you find problems with your code, you can just keep
  2700. editing and re-testing iteratively until things work as expected.
  2701. .. note::
  2702. All the modifications you make to the temporary source code disappear
  2703. once you run the ``do_clean`` or ``do_cleanall`` tasks using BitBake
  2704. (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``).
  2705. Modifications will also disappear if you use the ``rm_work`` feature as
  2706. described in the
  2707. ":ref:`dev-manual/common-tasks:conserving disk space during builds`"
  2708. section.
  2709. 7. *Generate the Patch:* Once your changes work as expected, you need to
  2710. use Quilt to generate the final patch that contains all your
  2711. modifications.
  2712. ::
  2713. $ quilt refresh
  2714. At this point, the
  2715. ``my_changes.patch`` file has all your edits made to the ``file1.c``,
  2716. ``file2.c``, and ``file3.c`` files.
  2717. You can find the resulting patch file in the ``patches/``
  2718. subdirectory of the source (``S``) directory.
  2719. 8. *Copy the Patch File:* For simplicity, copy the patch file into a
  2720. directory named ``files``, which you can create in the same directory
  2721. that holds the recipe (``.bb``) file or the append (``.bbappend``)
  2722. file. Placing the patch here guarantees that the OpenEmbedded build
  2723. system will find the patch. Next, add the patch into the ``SRC_URI``
  2724. of the recipe. Here is an example:
  2725. ::
  2726. SRC_URI += "file://my_changes.patch"
  2727. Using a Development Shell
  2728. =========================
  2729. When debugging certain commands or even when just editing packages,
  2730. ``devshell`` can be a useful tool. When you invoke ``devshell``, all
  2731. tasks up to and including
  2732. :ref:`ref-tasks-patch` are run for the
  2733. specified target. Then, a new terminal is opened and you are placed in
  2734. ``${``\ :term:`S`\ ``}``, the source
  2735. directory. In the new terminal, all the OpenEmbedded build-related
  2736. environment variables are still defined so you can use commands such as
  2737. ``configure`` and ``make``. The commands execute just as if the
  2738. OpenEmbedded build system were executing them. Consequently, working
  2739. this way can be helpful when debugging a build or preparing software to
  2740. be used with the OpenEmbedded build system.
  2741. Following is an example that uses ``devshell`` on a target named
  2742. ``matchbox-desktop``:
  2743. ::
  2744. $ bitbake matchbox-desktop -c devshell
  2745. This command spawns a terminal with a shell prompt within the
  2746. OpenEmbedded build environment. The
  2747. :term:`OE_TERMINAL` variable
  2748. controls what type of shell is opened.
  2749. For spawned terminals, the following occurs:
  2750. - The ``PATH`` variable includes the cross-toolchain.
  2751. - The ``pkgconfig`` variables find the correct ``.pc`` files.
  2752. - The ``configure`` command finds the Yocto Project site files as well
  2753. as any other necessary files.
  2754. Within this environment, you can run configure or compile commands as if
  2755. they were being run by the OpenEmbedded build system itself. As noted
  2756. earlier, the working directory also automatically changes to the Source
  2757. Directory (:term:`S`).
  2758. To manually run a specific task using ``devshell``, run the
  2759. corresponding ``run.*`` script in the
  2760. ``${``\ :term:`WORKDIR`\ ``}/temp``
  2761. directory (e.g., ``run.do_configure.``\ `pid`). If a task's script does
  2762. not exist, which would be the case if the task was skipped by way of the
  2763. sstate cache, you can create the task by first running it outside of the
  2764. ``devshell``:
  2765. ::
  2766. $ bitbake -c task
  2767. .. note::
  2768. - Execution of a task's ``run.*`` script and BitBake's execution of
  2769. a task are identical. In other words, running the script re-runs
  2770. the task just as it would be run using the ``bitbake -c`` command.
  2771. - Any ``run.*`` file that does not have a ``.pid`` extension is a
  2772. symbolic link (symlink) to the most recent version of that file.
  2773. Remember, that the ``devshell`` is a mechanism that allows you to get
  2774. into the BitBake task execution environment. And as such, all commands
  2775. must be called just as BitBake would call them. That means you need to
  2776. provide the appropriate options for cross-compilation and so forth as
  2777. applicable.
  2778. When you are finished using ``devshell``, exit the shell or close the
  2779. terminal window.
  2780. .. note::
  2781. - It is worth remembering that when using ``devshell`` you need to
  2782. use the full compiler name such as ``arm-poky-linux-gnueabi-gcc``
  2783. instead of just using ``gcc``. The same applies to other
  2784. applications such as ``binutils``, ``libtool`` and so forth.
  2785. BitBake sets up environment variables such as ``CC`` to assist
  2786. applications, such as ``make`` to find the correct tools.
  2787. - It is also worth noting that ``devshell`` still works over X11
  2788. forwarding and similar situations.
  2789. Using a Development Python Shell
  2790. ================================
  2791. Similar to working within a development shell as described in the
  2792. previous section, you can also spawn and work within an interactive
  2793. Python development shell. When debugging certain commands or even when
  2794. just editing packages, ``devpyshell`` can be a useful tool. When you
  2795. invoke ``devpyshell``, all tasks up to and including
  2796. :ref:`ref-tasks-patch` are run for the
  2797. specified target. Then a new terminal is opened. Additionally, key
  2798. Python objects and code are available in the same way they are to
  2799. BitBake tasks, in particular, the data store 'd'. So, commands such as
  2800. the following are useful when exploring the data store and running
  2801. functions:
  2802. ::
  2803. pydevshell> d.getVar("STAGING_DIR")
  2804. '/media/build1/poky/build/tmp/sysroots'
  2805. pydevshell> d.getVar("STAGING_DIR")
  2806. '${TMPDIR}/sysroots'
  2807. pydevshell> d.setVar("FOO", "bar")
  2808. pydevshell> d.getVar("FOO")
  2809. 'bar'
  2810. pydevshell> d.delVar("FOO")
  2811. pydevshell> d.getVar("FOO")
  2812. pydevshell> bb.build.exec_func("do_unpack", d)
  2813. pydevshell>
  2814. The commands execute just as if the OpenEmbedded build
  2815. system were executing them. Consequently, working this way can be
  2816. helpful when debugging a build or preparing software to be used with the
  2817. OpenEmbedded build system.
  2818. Following is an example that uses ``devpyshell`` on a target named
  2819. ``matchbox-desktop``:
  2820. ::
  2821. $ bitbake matchbox-desktop -c devpyshell
  2822. This command spawns a terminal and places you in an interactive Python
  2823. interpreter within the OpenEmbedded build environment. The
  2824. :term:`OE_TERMINAL` variable
  2825. controls what type of shell is opened.
  2826. When you are finished using ``devpyshell``, you can exit the shell
  2827. either by using Ctrl+d or closing the terminal window.
  2828. Building
  2829. ========
  2830. This section describes various build procedures. For example, the steps
  2831. needed for a simple build, a target that uses multiple configurations,
  2832. building an image for more than one machine, and so forth.
  2833. Building a Simple Image
  2834. -----------------------
  2835. In the development environment, you need to build an image whenever you
  2836. change hardware support, add or change system libraries, or add or
  2837. change services that have dependencies. Several methods exist that allow
  2838. you to build an image within the Yocto Project. This section presents
  2839. the basic steps you need to build a simple image using BitBake from a
  2840. build host running Linux.
  2841. .. note::
  2842. - For information on how to build an image using
  2843. :term:`Toaster`, see the
  2844. :doc:`/toaster-manual/index`.
  2845. - For information on how to use ``devtool`` to build images, see the
  2846. ":ref:`sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow`"
  2847. section in the Yocto Project Application Development and the
  2848. Extensible Software Development Kit (eSDK) manual.
  2849. - For a quick example on how to build an image using the
  2850. OpenEmbedded build system, see the
  2851. :doc:`/brief-yoctoprojectqs/index` document.
  2852. The build process creates an entire Linux distribution from source and
  2853. places it in your :term:`Build Directory` under
  2854. ``tmp/deploy/images``. For detailed information on the build process
  2855. using BitBake, see the ":ref:`overview-manual/concepts:images`" section in the
  2856. Yocto Project Overview and Concepts Manual.
  2857. The following figure and list overviews the build process:
  2858. .. image:: figures/bitbake-build-flow.png
  2859. :align: center
  2860. 1. *Set up Your Host Development System to Support Development Using the
  2861. Yocto Project*: See the ":doc:`start`" section for options on how to get a
  2862. build host ready to use the Yocto Project.
  2863. 2. *Initialize the Build Environment:* Initialize the build environment
  2864. by sourcing the build environment script (i.e.
  2865. :ref:`structure-core-script`):
  2866. ::
  2867. $ source oe-init-build-env [build_dir]
  2868. When you use the initialization script, the OpenEmbedded build system
  2869. uses ``build`` as the default :term:`Build Directory` in your current work
  2870. directory. You can use a `build_dir` argument with the script to
  2871. specify a different build directory.
  2872. .. note::
  2873. A common practice is to use a different Build Directory for
  2874. different targets. For example, ``~/build/x86`` for a ``qemux86``
  2875. target, and ``~/build/arm`` for a ``qemuarm`` target.
  2876. 3. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the
  2877. ``conf/local.conf`` configuration file, which is found in the Build
  2878. Directory, is set up how you want it. This file defines many aspects
  2879. of the build environment including the target machine architecture
  2880. through the ``MACHINE`` variable, the packaging format used during
  2881. the build
  2882. (:term:`PACKAGE_CLASSES`),
  2883. and a centralized tarball download directory through the
  2884. :term:`DL_DIR` variable.
  2885. 4. *Build the Image:* Build the image using the ``bitbake`` command:
  2886. ::
  2887. $ bitbake target
  2888. .. note::
  2889. For information on BitBake, see the :doc:`bitbake:index`.
  2890. The target is the name of the recipe you want to build. Common
  2891. targets are the images in ``meta/recipes-core/images``,
  2892. ``meta/recipes-sato/images``, and so forth all found in the
  2893. :term:`Source Directory`. Or, the target
  2894. can be the name of a recipe for a specific piece of software such as
  2895. BusyBox. For more details about the images the OpenEmbedded build
  2896. system supports, see the
  2897. ":ref:`ref-manual/images:Images`" chapter in the Yocto
  2898. Project Reference Manual.
  2899. As an example, the following command builds the
  2900. ``core-image-minimal`` image:
  2901. ::
  2902. $ bitbake core-image-minimal
  2903. Once an
  2904. image has been built, it often needs to be installed. The images and
  2905. kernels built by the OpenEmbedded build system are placed in the
  2906. Build Directory in ``tmp/deploy/images``. For information on how to
  2907. run pre-built images such as ``qemux86`` and ``qemuarm``, see the
  2908. :doc:`/sdk-manual/index` manual. For
  2909. information about how to install these images, see the documentation
  2910. for your particular board or machine.
  2911. Building Images for Multiple Targets Using Multiple Configurations
  2912. ------------------------------------------------------------------
  2913. You can use a single ``bitbake`` command to build multiple images or
  2914. packages for different targets where each image or package requires a
  2915. different configuration (multiple configuration builds). The builds, in
  2916. this scenario, are sometimes referred to as "multiconfigs", and this
  2917. section uses that term throughout.
  2918. This section describes how to set up for multiple configuration builds
  2919. and how to account for cross-build dependencies between the
  2920. multiconfigs.
  2921. Setting Up and Running a Multiple Configuration Build
  2922. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2923. To accomplish a multiple configuration build, you must define each
  2924. target's configuration separately using a parallel configuration file in
  2925. the :term:`Build Directory`, and you
  2926. must follow a required file hierarchy. Additionally, you must enable the
  2927. multiple configuration builds in your ``local.conf`` file.
  2928. Follow these steps to set up and execute multiple configuration builds:
  2929. - *Create Separate Configuration Files*: You need to create a single
  2930. configuration file for each build target (each multiconfig).
  2931. Minimally, each configuration file must define the machine and the
  2932. temporary directory BitBake uses for the build. Suggested practice
  2933. dictates that you do not overlap the temporary directories used
  2934. during the builds. However, it is possible that you can share the
  2935. temporary directory
  2936. (:term:`TMPDIR`). For example,
  2937. consider a scenario with two different multiconfigs for the same
  2938. :term:`MACHINE`: "qemux86" built
  2939. for two distributions such as "poky" and "poky-lsb". In this case,
  2940. you might want to use the same ``TMPDIR``.
  2941. Here is an example showing the minimal statements needed in a
  2942. configuration file for a "qemux86" target whose temporary build
  2943. directory is ``tmpmultix86``:
  2944. ::
  2945. MACHINE = "qemux86"
  2946. TMPDIR = "${TOPDIR}/tmpmultix86"
  2947. The location for these multiconfig configuration files is specific.
  2948. They must reside in the current build directory in a sub-directory of
  2949. ``conf`` named ``multiconfig``. Following is an example that defines
  2950. two configuration files for the "x86" and "arm" multiconfigs:
  2951. .. image:: figures/multiconfig_files.png
  2952. :align: center
  2953. The reason for this required file hierarchy is because the ``BBPATH``
  2954. variable is not constructed until the layers are parsed.
  2955. Consequently, using the configuration file as a pre-configuration
  2956. file is not possible unless it is located in the current working
  2957. directory.
  2958. - *Add the BitBake Multi-configuration Variable to the Local
  2959. Configuration File*: Use the
  2960. :term:`BBMULTICONFIG`
  2961. variable in your ``conf/local.conf`` configuration file to specify
  2962. each multiconfig. Continuing with the example from the previous
  2963. figure, the ``BBMULTICONFIG`` variable needs to enable two
  2964. multiconfigs: "x86" and "arm" by specifying each configuration file:
  2965. ::
  2966. BBMULTICONFIG = "x86 arm"
  2967. .. note::
  2968. A "default" configuration already exists by definition. This
  2969. configuration is named: "" (i.e. empty string) and is defined by
  2970. the variables coming from your ``local.conf``
  2971. file. Consequently, the previous example actually adds two
  2972. additional configurations to your build: "arm" and "x86" along
  2973. with "".
  2974. - *Launch BitBake*: Use the following BitBake command form to launch
  2975. the multiple configuration build:
  2976. ::
  2977. $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ]
  2978. For the example in this section, the following command applies:
  2979. ::
  2980. $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base
  2981. The previous BitBake command builds a ``core-image-minimal`` image
  2982. that is configured through the ``x86.conf`` configuration file, a
  2983. ``core-image-sato`` image that is configured through the ``arm.conf``
  2984. configuration file and a ``core-image-base`` that is configured
  2985. through your ``local.conf`` configuration file.
  2986. .. note::
  2987. Support for multiple configuration builds in the Yocto Project &DISTRO;
  2988. (&DISTRO_NAME;) Release does not include Shared State (sstate)
  2989. optimizations. Consequently, if a build uses the same object twice
  2990. in, for example, two different ``TMPDIR``
  2991. directories, the build either loads from an existing sstate cache for
  2992. that build at the start or builds the object fresh.
  2993. Enabling Multiple Configuration Build Dependencies
  2994. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2995. Sometimes dependencies can exist between targets (multiconfigs) in a
  2996. multiple configuration build. For example, suppose that in order to
  2997. build a ``core-image-sato`` image for an "x86" multiconfig, the root
  2998. filesystem of an "arm" multiconfig must exist. This dependency is
  2999. essentially that the
  3000. :ref:`ref-tasks-image` task in the
  3001. ``core-image-sato`` recipe depends on the completion of the
  3002. :ref:`ref-tasks-rootfs` task of the
  3003. ``core-image-minimal`` recipe.
  3004. To enable dependencies in a multiple configuration build, you must
  3005. declare the dependencies in the recipe using the following statement
  3006. form:
  3007. ::
  3008. task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend"
  3009. To better show how to use this statement, consider the example scenario
  3010. from the first paragraph of this section. The following statement needs
  3011. to be added to the recipe that builds the ``core-image-sato`` image:
  3012. ::
  3013. do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs"
  3014. In this example, the `from_multiconfig` is "x86". The `to_multiconfig` is "arm". The
  3015. task on which the ``do_image`` task in the recipe depends is the
  3016. ``do_rootfs`` task from the ``core-image-minimal`` recipe associated
  3017. with the "arm" multiconfig.
  3018. Once you set up this dependency, you can build the "x86" multiconfig
  3019. using a BitBake command as follows:
  3020. ::
  3021. $ bitbake mc:x86:core-image-sato
  3022. This command executes all the tasks needed to create the
  3023. ``core-image-sato`` image for the "x86" multiconfig. Because of the
  3024. dependency, BitBake also executes through the ``do_rootfs`` task for the
  3025. "arm" multiconfig build.
  3026. Having a recipe depend on the root filesystem of another build might not
  3027. seem that useful. Consider this change to the statement in the
  3028. ``core-image-sato`` recipe:
  3029. ::
  3030. do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image"
  3031. In this case, BitBake must
  3032. create the ``core-image-minimal`` image for the "arm" build since the
  3033. "x86" build depends on it.
  3034. Because "x86" and "arm" are enabled for multiple configuration builds
  3035. and have separate configuration files, BitBake places the artifacts for
  3036. each build in the respective temporary build directories (i.e.
  3037. :term:`TMPDIR`).
  3038. Building an Initial RAM Filesystem (initramfs) Image
  3039. ----------------------------------------------------
  3040. An initial RAM filesystem (initramfs) image provides a temporary root
  3041. filesystem used for early system initialization (e.g. loading of modules
  3042. needed to locate and mount the "real" root filesystem).
  3043. .. note::
  3044. The initramfs image is the successor of initial RAM disk (initrd). It
  3045. is a "copy in and out" (cpio) archive of the initial filesystem that
  3046. gets loaded into memory during the Linux startup process. Because
  3047. Linux uses the contents of the archive during initialization, the
  3048. initramfs image needs to contain all of the device drivers and tools
  3049. needed to mount the final root filesystem.
  3050. Follow these steps to create an initramfs image:
  3051. 1. *Create the initramfs Image Recipe:* You can reference the
  3052. ``core-image-minimal-initramfs.bb`` recipe found in the
  3053. ``meta/recipes-core`` directory of the :term:`Source Directory`
  3054. as an example
  3055. from which to work.
  3056. 2. *Decide if You Need to Bundle the initramfs Image Into the Kernel
  3057. Image:* If you want the initramfs image that is built to be bundled
  3058. in with the kernel image, set the
  3059. :term:`INITRAMFS_IMAGE_BUNDLE`
  3060. variable to "1" in your ``local.conf`` configuration file and set the
  3061. :term:`INITRAMFS_IMAGE`
  3062. variable in the recipe that builds the kernel image.
  3063. .. note::
  3064. It is recommended that you do bundle the initramfs image with the
  3065. kernel image to avoid circular dependencies between the kernel
  3066. recipe and the initramfs recipe should the initramfs image include
  3067. kernel modules.
  3068. Setting the ``INITRAMFS_IMAGE_BUNDLE`` flag causes the initramfs
  3069. image to be unpacked into the ``${B}/usr/`` directory. The unpacked
  3070. initramfs image is then passed to the kernel's ``Makefile`` using the
  3071. :term:`CONFIG_INITRAMFS_SOURCE`
  3072. variable, allowing the initramfs image to be built into the kernel
  3073. normally.
  3074. .. note::
  3075. If you choose to not bundle the initramfs image with the kernel
  3076. image, you are essentially using an
  3077. `Initial RAM Disk (initrd) <https://en.wikipedia.org/wiki/Initrd>`__.
  3078. Creating an initrd is handled primarily through the :term:`INITRD_IMAGE`,
  3079. ``INITRD_LIVE``, and ``INITRD_IMAGE_LIVE`` variables. For more
  3080. information, see the :ref:`ref-classes-image-live` file.
  3081. 3. *Optionally Add Items to the initramfs Image Through the initramfs
  3082. Image Recipe:* If you add items to the initramfs image by way of its
  3083. recipe, you should use
  3084. :term:`PACKAGE_INSTALL`
  3085. rather than
  3086. :term:`IMAGE_INSTALL`.
  3087. ``PACKAGE_INSTALL`` gives more direct control of what is added to the
  3088. image as compared to the defaults you might not necessarily want that
  3089. are set by the :ref:`image <ref-classes-image>`
  3090. or :ref:`core-image <ref-classes-core-image>`
  3091. classes.
  3092. 4. *Build the Kernel Image and the initramfs Image:* Build your kernel
  3093. image using BitBake. Because the initramfs image recipe is a
  3094. dependency of the kernel image, the initramfs image is built as well
  3095. and bundled with the kernel image if you used the
  3096. :term:`INITRAMFS_IMAGE_BUNDLE`
  3097. variable described earlier.
  3098. Building a Tiny System
  3099. ----------------------
  3100. Very small distributions have some significant advantages such as
  3101. requiring less on-die or in-package memory (cheaper), better performance
  3102. through efficient cache usage, lower power requirements due to less
  3103. memory, faster boot times, and reduced development overhead. Some
  3104. real-world examples where a very small distribution gives you distinct
  3105. advantages are digital cameras, medical devices, and small headless
  3106. systems.
  3107. This section presents information that shows you how you can trim your
  3108. distribution to even smaller sizes than the ``poky-tiny`` distribution,
  3109. which is around 5 Mbytes, that can be built out-of-the-box using the
  3110. Yocto Project.
  3111. Tiny System Overview
  3112. ~~~~~~~~~~~~~~~~~~~~
  3113. The following list presents the overall steps you need to consider and
  3114. perform to create distributions with smaller root filesystems, achieve
  3115. faster boot times, maintain your critical functionality, and avoid
  3116. initial RAM disks:
  3117. - `Determine your goals and guiding
  3118. principles. <#goals-and-guiding-principles>`__
  3119. - `Understand what contributes to your image
  3120. size. <#understand-what-gives-your-image-size>`__
  3121. - `Reduce the size of the root
  3122. filesystem. <#trim-the-root-filesystem>`__
  3123. - `Reduce the size of the kernel. <#trim-the-kernel>`__
  3124. - `Eliminate packaging
  3125. requirements. <#remove-package-management-requirements>`__
  3126. - `Look for other ways to minimize
  3127. size. <#look-for-other-ways-to-minimize-size>`__
  3128. - `Iterate on the process. <#iterate-on-the-process>`__
  3129. Goals and Guiding Principles
  3130. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3131. Before you can reach your destination, you need to know where you are
  3132. going. Here is an example list that you can use as a guide when creating
  3133. very small distributions:
  3134. - Determine how much space you need (e.g. a kernel that is 1 Mbyte or
  3135. less and a root filesystem that is 3 Mbytes or less).
  3136. - Find the areas that are currently taking 90% of the space and
  3137. concentrate on reducing those areas.
  3138. - Do not create any difficult "hacks" to achieve your goals.
  3139. - Leverage the device-specific options.
  3140. - Work in a separate layer so that you keep changes isolated. For
  3141. information on how to create layers, see the "`Understanding and
  3142. Creating Layers <#understanding-and-creating-layers>`__" section.
  3143. Understand What Contributes to Your Image Size
  3144. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3145. It is easiest to have something to start with when creating your own
  3146. distribution. You can use the Yocto Project out-of-the-box to create the
  3147. ``poky-tiny`` distribution. Ultimately, you will want to make changes in
  3148. your own distribution that are likely modeled after ``poky-tiny``.
  3149. .. note::
  3150. To use ``poky-tiny`` in your build, set the ``DISTRO`` variable in your
  3151. ``local.conf`` file to "poky-tiny" as described in the
  3152. ":ref:`dev-manual/common-tasks:creating your own distribution`"
  3153. section.
  3154. Understanding some memory concepts will help you reduce the system size.
  3155. Memory consists of static, dynamic, and temporary memory. Static memory
  3156. is the TEXT (code), DATA (initialized data in the code), and BSS
  3157. (uninitialized data) sections. Dynamic memory represents memory that is
  3158. allocated at runtime: stacks, hash tables, and so forth. Temporary
  3159. memory is recovered after the boot process. This memory consists of
  3160. memory used for decompressing the kernel and for the ``__init__``
  3161. functions.
  3162. To help you see where you currently are with kernel and root filesystem
  3163. sizes, you can use two tools found in the :term:`Source Directory`
  3164. in the
  3165. ``scripts/tiny/`` directory:
  3166. - ``ksize.py``: Reports component sizes for the kernel build objects.
  3167. - ``dirsize.py``: Reports component sizes for the root filesystem.
  3168. This next tool and command help you organize configuration fragments and
  3169. view file dependencies in a human-readable form:
  3170. - ``merge_config.sh``: Helps you manage configuration files and
  3171. fragments within the kernel. With this tool, you can merge individual
  3172. configuration fragments together. The tool allows you to make
  3173. overrides and warns you of any missing configuration options. The
  3174. tool is ideal for allowing you to iterate on configurations, create
  3175. minimal configurations, and create configuration files for different
  3176. machines without having to duplicate your process.
  3177. The ``merge_config.sh`` script is part of the Linux Yocto kernel Git
  3178. repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``,
  3179. ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig``
  3180. directory.
  3181. For more information on configuration fragments, see the
  3182. ":ref:`kernel-dev/common:creating configuration fragments`"
  3183. section in the Yocto Project Linux Kernel Development Manual.
  3184. - ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command
  3185. with these options brings up a Dependency Explorer from which you can
  3186. view file dependencies. Understanding these dependencies allows you
  3187. to make informed decisions when cutting out various pieces of the
  3188. kernel and root filesystem.
  3189. Trim the Root Filesystem
  3190. ~~~~~~~~~~~~~~~~~~~~~~~~
  3191. The root filesystem is made up of packages for booting, libraries, and
  3192. applications. To change things, you can configure how the packaging
  3193. happens, which changes the way you build them. You can also modify the
  3194. filesystem itself or select a different filesystem.
  3195. First, find out what is hogging your root filesystem by running the
  3196. ``dirsize.py`` script from your root directory:
  3197. ::
  3198. $ cd root-directory-of-image
  3199. $ dirsize.py 100000 > dirsize-100k.log
  3200. $ cat dirsize-100k.log
  3201. You can apply a filter to the script to ignore files
  3202. under a certain size. The previous example filters out any files below
  3203. 100 Kbytes. The sizes reported by the tool are uncompressed, and thus
  3204. will be smaller by a relatively constant factor in a compressed root
  3205. filesystem. When you examine your log file, you can focus on areas of
  3206. the root filesystem that take up large amounts of memory.
  3207. You need to be sure that what you eliminate does not cripple the
  3208. functionality you need. One way to see how packages relate to each other
  3209. is by using the Dependency Explorer UI with the BitBake command:
  3210. ::
  3211. $ cd image-directory
  3212. $ bitbake -u taskexp -g image
  3213. Use the interface to
  3214. select potential packages you wish to eliminate and see their dependency
  3215. relationships.
  3216. When deciding how to reduce the size, get rid of packages that result in
  3217. minimal impact on the feature set. For example, you might not need a VGA
  3218. display. Or, you might be able to get by with ``devtmpfs`` and ``mdev``
  3219. instead of ``udev``.
  3220. Use your ``local.conf`` file to make changes. For example, to eliminate
  3221. ``udev`` and ``glib``, set the following in the local configuration
  3222. file:
  3223. ::
  3224. VIRTUAL-RUNTIME_dev_manager = ""
  3225. Finally, you should consider exactly the type of root filesystem you
  3226. need to meet your needs while also reducing its size. For example,
  3227. consider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an
  3228. ``initramfs`` using ``initramfs``. Be aware that ``ext3`` requires a 1
  3229. Mbyte journal. If you are okay with running read-only, you do not need
  3230. this journal.
  3231. .. note::
  3232. After each round of elimination, you need to rebuild your system and
  3233. then use the tools to see the effects of your reductions.
  3234. Trim the Kernel
  3235. ~~~~~~~~~~~~~~~
  3236. The kernel is built by including policies for hardware-independent
  3237. aspects. What subsystems do you enable? For what architecture are you
  3238. building? Which drivers do you build by default?
  3239. .. note::
  3240. You can modify the kernel source if you want to help with boot time.
  3241. Run the ``ksize.py`` script from the top-level Linux build directory to
  3242. get an idea of what is making up the kernel:
  3243. ::
  3244. $ cd top-level-linux-build-directory
  3245. $ ksize.py > ksize.log
  3246. $ cat ksize.log
  3247. When you examine the log, you will see how much space is taken up with
  3248. the built-in ``.o`` files for drivers, networking, core kernel files,
  3249. filesystem, sound, and so forth. The sizes reported by the tool are
  3250. uncompressed, and thus will be smaller by a relatively constant factor
  3251. in a compressed kernel image. Look to reduce the areas that are large
  3252. and taking up around the "90% rule."
  3253. To examine, or drill down, into any particular area, use the ``-d``
  3254. option with the script:
  3255. ::
  3256. $ ksize.py -d > ksize.log
  3257. Using this option
  3258. breaks out the individual file information for each area of the kernel
  3259. (e.g. drivers, networking, and so forth).
  3260. Use your log file to see what you can eliminate from the kernel based on
  3261. features you can let go. For example, if you are not going to need
  3262. sound, you do not need any drivers that support sound.
  3263. After figuring out what to eliminate, you need to reconfigure the kernel
  3264. to reflect those changes during the next build. You could run
  3265. ``menuconfig`` and make all your changes at once. However, that makes it
  3266. difficult to see the effects of your individual eliminations and also
  3267. makes it difficult to replicate the changes for perhaps another target
  3268. device. A better method is to start with no configurations using
  3269. ``allnoconfig``, create configuration fragments for individual changes,
  3270. and then manage the fragments into a single configuration file using
  3271. ``merge_config.sh``. The tool makes it easy for you to iterate using the
  3272. configuration change and build cycle.
  3273. Each time you make configuration changes, you need to rebuild the kernel
  3274. and check to see what impact your changes had on the overall size.
  3275. Remove Package Management Requirements
  3276. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3277. Packaging requirements add size to the image. One way to reduce the size
  3278. of the image is to remove all the packaging requirements from the image.
  3279. This reduction includes both removing the package manager and its unique
  3280. dependencies as well as removing the package management data itself.
  3281. To eliminate all the packaging requirements for an image, be sure that
  3282. "package-management" is not part of your
  3283. :term:`IMAGE_FEATURES`
  3284. statement for the image. When you remove this feature, you are removing
  3285. the package manager as well as its dependencies from the root
  3286. filesystem.
  3287. Look for Other Ways to Minimize Size
  3288. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3289. Depending on your particular circumstances, other areas that you can
  3290. trim likely exist. The key to finding these areas is through tools and
  3291. methods described here combined with experimentation and iteration. Here
  3292. are a couple of areas to experiment with:
  3293. - ``glibc``: In general, follow this process:
  3294. 1. Remove ``glibc`` features from
  3295. :term:`DISTRO_FEATURES`
  3296. that you think you do not need.
  3297. 2. Build your distribution.
  3298. 3. If the build fails due to missing symbols in a package, determine
  3299. if you can reconfigure the package to not need those features. For
  3300. example, change the configuration to not support wide character
  3301. support as is done for ``ncurses``. Or, if support for those
  3302. characters is needed, determine what ``glibc`` features provide
  3303. the support and restore the configuration.
  3304. 4. Rebuild and repeat the process.
  3305. - ``busybox``: For BusyBox, use a process similar as described for
  3306. ``glibc``. A difference is you will need to boot the resulting system
  3307. to see if you are able to do everything you expect from the running
  3308. system. You need to be sure to integrate configuration fragments into
  3309. Busybox because BusyBox handles its own core features and then allows
  3310. you to add configuration fragments on top.
  3311. Iterate on the Process
  3312. ~~~~~~~~~~~~~~~~~~~~~~
  3313. If you have not reached your goals on system size, you need to iterate
  3314. on the process. The process is the same. Use the tools and see just what
  3315. is taking up 90% of the root filesystem and the kernel. Decide what you
  3316. can eliminate without limiting your device beyond what you need.
  3317. Depending on your system, a good place to look might be Busybox, which
  3318. provides a stripped down version of Unix tools in a single, executable
  3319. file. You might be able to drop virtual terminal services or perhaps
  3320. ipv6.
  3321. Building Images for More than One Machine
  3322. -----------------------------------------
  3323. A common scenario developers face is creating images for several
  3324. different machines that use the same software environment. In this
  3325. situation, it is tempting to set the tunings and optimization flags for
  3326. each build specifically for the targeted hardware (i.e. "maxing out" the
  3327. tunings). Doing so can considerably add to build times and package feed
  3328. maintenance collectively for the machines. For example, selecting tunes
  3329. that are extremely specific to a CPU core used in a system might enable
  3330. some micro optimizations in GCC for that particular system but would
  3331. otherwise not gain you much of a performance difference across the other
  3332. systems as compared to using a more general tuning across all the builds
  3333. (e.g. setting :term:`DEFAULTTUNE`
  3334. specifically for each machine's build). Rather than "max out" each
  3335. build's tunings, you can take steps that cause the OpenEmbedded build
  3336. system to reuse software across the various machines where it makes
  3337. sense.
  3338. If build speed and package feed maintenance are considerations, you
  3339. should consider the points in this section that can help you optimize
  3340. your tunings to best consider build times and package feed maintenance.
  3341. - *Share the Build Directory:* If at all possible, share the
  3342. :term:`TMPDIR` across builds. The
  3343. Yocto Project supports switching between different
  3344. :term:`MACHINE` values in the same
  3345. ``TMPDIR``. This practice is well supported and regularly used by
  3346. developers when building for multiple machines. When you use the same
  3347. ``TMPDIR`` for multiple machine builds, the OpenEmbedded build system
  3348. can reuse the existing native and often cross-recipes for multiple
  3349. machines. Thus, build time decreases.
  3350. .. note::
  3351. If :term:`DISTRO` settings change or fundamental configuration settings
  3352. such as the filesystem layout, you need to work with a clean ``TMPDIR``.
  3353. Sharing ``TMPDIR`` under these circumstances might work but since it is
  3354. not guaranteed, you should use a clean ``TMPDIR``.
  3355. - *Enable the Appropriate Package Architecture:* By default, the
  3356. OpenEmbedded build system enables three levels of package
  3357. architectures: "all", "tune" or "package", and "machine". Any given
  3358. recipe usually selects one of these package architectures (types) for
  3359. its output. Depending for what a given recipe creates packages,
  3360. making sure you enable the appropriate package architecture can
  3361. directly impact the build time.
  3362. A recipe that just generates scripts can enable "all" architecture
  3363. because there are no binaries to build. To specifically enable "all"
  3364. architecture, be sure your recipe inherits the
  3365. :ref:`allarch <ref-classes-allarch>` class.
  3366. This class is useful for "all" architectures because it configures
  3367. many variables so packages can be used across multiple architectures.
  3368. If your recipe needs to generate packages that are machine-specific
  3369. or when one of the build or runtime dependencies is already
  3370. machine-architecture dependent, which makes your recipe also
  3371. machine-architecture dependent, make sure your recipe enables the
  3372. "machine" package architecture through the
  3373. :term:`MACHINE_ARCH`
  3374. variable:
  3375. ::
  3376. PACKAGE_ARCH = "${MACHINE_ARCH}"
  3377. When you do not
  3378. specifically enable a package architecture through the
  3379. :term:`PACKAGE_ARCH`, The
  3380. OpenEmbedded build system defaults to the
  3381. :term:`TUNE_PKGARCH` setting:
  3382. ::
  3383. PACKAGE_ARCH = "${TUNE_PKGARCH}"
  3384. - *Choose a Generic Tuning File if Possible:* Some tunes are more
  3385. generic and can run on multiple targets (e.g. an ``armv5`` set of
  3386. packages could run on ``armv6`` and ``armv7`` processors in most
  3387. cases). Similarly, ``i486`` binaries could work on ``i586`` and
  3388. higher processors. You should realize, however, that advances on
  3389. newer processor versions would not be used.
  3390. If you select the same tune for several different machines, the
  3391. OpenEmbedded build system reuses software previously built, thus
  3392. speeding up the overall build time. Realize that even though a new
  3393. sysroot for each machine is generated, the software is not recompiled
  3394. and only one package feed exists.
  3395. - *Manage Granular Level Packaging:* Sometimes cases exist where
  3396. injecting another level of package architecture beyond the three
  3397. higher levels noted earlier can be useful. For example, consider how
  3398. NXP (formerly Freescale) allows for the easy reuse of binary packages
  3399. in their layer
  3400. :yocto_git:`meta-freescale </meta-freescale/>`.
  3401. In this example, the
  3402. :yocto_git:`fsl-dynamic-packagearch </meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass>`
  3403. class shares GPU packages for i.MX53 boards because all boards share
  3404. the AMD GPU. The i.MX6-based boards can do the same because all
  3405. boards share the Vivante GPU. This class inspects the BitBake
  3406. datastore to identify if the package provides or depends on one of
  3407. the sub-architecture values. If so, the class sets the
  3408. :term:`PACKAGE_ARCH` value
  3409. based on the ``MACHINE_SUBARCH`` value. If the package does not
  3410. provide or depend on one of the sub-architecture values but it
  3411. matches a value in the machine-specific filter, it sets
  3412. :term:`MACHINE_ARCH`. This
  3413. behavior reduces the number of packages built and saves build time by
  3414. reusing binaries.
  3415. - *Use Tools to Debug Issues:* Sometimes you can run into situations
  3416. where software is being rebuilt when you think it should not be. For
  3417. example, the OpenEmbedded build system might not be using shared
  3418. state between machines when you think it should be. These types of
  3419. situations are usually due to references to machine-specific
  3420. variables such as :term:`MACHINE`,
  3421. :term:`SERIAL_CONSOLES`,
  3422. :term:`XSERVER`,
  3423. :term:`MACHINE_FEATURES`,
  3424. and so forth in code that is supposed to only be tune-specific or
  3425. when the recipe depends
  3426. (:term:`DEPENDS`,
  3427. :term:`RDEPENDS`,
  3428. :term:`RRECOMMENDS`,
  3429. :term:`RSUGGESTS`, and so forth)
  3430. on some other recipe that already has
  3431. :term:`PACKAGE_ARCH` defined
  3432. as "${MACHINE_ARCH}".
  3433. .. note::
  3434. Patches to fix any issues identified are most welcome as these
  3435. issues occasionally do occur.
  3436. For such cases, you can use some tools to help you sort out the
  3437. situation:
  3438. - ``state-diff-machines.sh``*:* You can find this tool in the
  3439. ``scripts`` directory of the Source Repositories. See the comments
  3440. in the script for information on how to use the tool.
  3441. - *BitBake's "-S printdiff" Option:* Using this option causes
  3442. BitBake to try to establish the closest signature match it can
  3443. (e.g. in the shared state cache) and then run ``bitbake-diffsigs``
  3444. over the matches to determine the stamps and delta where these two
  3445. stamp trees diverge.
  3446. Building Software from an External Source
  3447. -----------------------------------------
  3448. By default, the OpenEmbedded build system uses the
  3449. :term:`Build Directory` when building source
  3450. code. The build process involves fetching the source files, unpacking
  3451. them, and then patching them if necessary before the build takes place.
  3452. Situations exist where you might want to build software from source
  3453. files that are external to and thus outside of the OpenEmbedded build
  3454. system. For example, suppose you have a project that includes a new BSP
  3455. with a heavily customized kernel. And, you want to minimize exposing the
  3456. build system to the development team so that they can focus on their
  3457. project and maintain everyone's workflow as much as possible. In this
  3458. case, you want a kernel source directory on the development machine
  3459. where the development occurs. You want the recipe's
  3460. :term:`SRC_URI` variable to point to
  3461. the external directory and use it as is, not copy it.
  3462. To build from software that comes from an external source, all you need
  3463. to do is inherit the
  3464. :ref:`externalsrc <ref-classes-externalsrc>` class
  3465. and then set the
  3466. :term:`EXTERNALSRC` variable to
  3467. point to your external source code. Here are the statements to put in
  3468. your ``local.conf`` file:
  3469. ::
  3470. INHERIT += "externalsrc"
  3471. EXTERNALSRC_pn-myrecipe = "path-to-your-source-tree"
  3472. This next example shows how to accomplish the same thing by setting
  3473. ``EXTERNALSRC`` in the recipe itself or in the recipe's append file:
  3474. ::
  3475. EXTERNALSRC = "path"
  3476. EXTERNALSRC_BUILD = "path"
  3477. .. note::
  3478. In order for these settings to take effect, you must globally or
  3479. locally inherit the :ref:`externalsrc <ref-classes-externalsrc>`
  3480. class.
  3481. By default, ``externalsrc.bbclass`` builds the source code in a
  3482. directory separate from the external source directory as specified by
  3483. :term:`EXTERNALSRC`. If you need
  3484. to have the source built in the same directory in which it resides, or
  3485. some other nominated directory, you can set
  3486. :term:`EXTERNALSRC_BUILD`
  3487. to point to that directory:
  3488. ::
  3489. EXTERNALSRC_BUILD_pn-myrecipe = "path-to-your-source-tree"
  3490. Replicating a Build Offline
  3491. ---------------------------
  3492. It can be useful to take a "snapshot" of upstream sources used in a
  3493. build and then use that "snapshot" later to replicate the build offline.
  3494. To do so, you need to first prepare and populate your downloads
  3495. directory your "snapshot" of files. Once your downloads directory is
  3496. ready, you can use it at any time and from any machine to replicate your
  3497. build.
  3498. Follow these steps to populate your Downloads directory:
  3499. 1. *Create a Clean Downloads Directory:* Start with an empty downloads
  3500. directory (:term:`DL_DIR`). You
  3501. start with an empty downloads directory by either removing the files
  3502. in the existing directory or by setting ``DL_DIR`` to point to either
  3503. an empty location or one that does not yet exist.
  3504. 2. *Generate Tarballs of the Source Git Repositories:* Edit your
  3505. ``local.conf`` configuration file as follows:
  3506. ::
  3507. DL_DIR = "/home/your-download-dir/"
  3508. BB_GENERATE_MIRROR_TARBALLS = "1"
  3509. During
  3510. the fetch process in the next step, BitBake gathers the source files
  3511. and creates tarballs in the directory pointed to by ``DL_DIR``. See
  3512. the
  3513. :term:`BB_GENERATE_MIRROR_TARBALLS`
  3514. variable for more information.
  3515. 3. *Populate Your Downloads Directory Without Building:* Use BitBake to
  3516. fetch your sources but inhibit the build:
  3517. ::
  3518. $ bitbake target --runonly=fetch
  3519. The downloads directory (i.e. ``${DL_DIR}``) now has
  3520. a "snapshot" of the source files in the form of tarballs, which can
  3521. be used for the build.
  3522. 4. *Optionally Remove Any Git or other SCM Subdirectories From the
  3523. Downloads Directory:* If you want, you can clean up your downloads
  3524. directory by removing any Git or other Source Control Management
  3525. (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs
  3526. already contain these subdirectories.
  3527. Once your downloads directory has everything it needs regarding source
  3528. files, you can create your "own-mirror" and build your target.
  3529. Understand that you can use the files to build the target offline from
  3530. any machine and at any time.
  3531. Follow these steps to build your target using the files in the downloads
  3532. directory:
  3533. 1. *Using Local Files Only:* Inside your ``local.conf`` file, add the
  3534. :term:`SOURCE_MIRROR_URL`
  3535. variable, inherit the
  3536. :ref:`own-mirrors <ref-classes-own-mirrors>`
  3537. class, and use the
  3538. :term:`bitbake:BB_NO_NETWORK`
  3539. variable to your ``local.conf``.
  3540. ::
  3541. SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/"
  3542. INHERIT += "own-mirrors"
  3543. BB_NO_NETWORK = "1"
  3544. The ``SOURCE_MIRROR_URL`` and ``own-mirror``
  3545. class set up the system to use the downloads directory as your "own
  3546. mirror". Using the ``BB_NO_NETWORK`` variable makes sure that
  3547. BitBake's fetching process in step 3 stays local, which means files
  3548. from your "own-mirror" are used.
  3549. 2. *Start With a Clean Build:* You can start with a clean build by
  3550. removing the
  3551. ``${``\ :term:`TMPDIR`\ ``}``
  3552. directory or using a new :term:`Build Directory`.
  3553. 3. *Build Your Target:* Use BitBake to build your target:
  3554. ::
  3555. $ bitbake target
  3556. The build completes using the known local "snapshot" of source
  3557. files from your mirror. The resulting tarballs for your "snapshot" of
  3558. source files are in the downloads directory.
  3559. .. note::
  3560. The offline build does not work if recipes attempt to find the
  3561. latest version of software by setting
  3562. :term:`SRCREV` to
  3563. ``${``\ :term:`AUTOREV`\ ``}``:
  3564. ::
  3565. SRCREV = "${AUTOREV}"
  3566. When a recipe sets ``SRCREV`` to
  3567. ``${AUTOREV}``, the build system accesses the network in an
  3568. attempt to determine the latest version of software from the SCM.
  3569. Typically, recipes that use ``AUTOREV`` are custom or modified
  3570. recipes. Recipes that reside in public repositories usually do not
  3571. use ``AUTOREV``.
  3572. If you do have recipes that use ``AUTOREV``, you can take steps to
  3573. still use the recipes in an offline build. Do the following:
  3574. 1. Use a configuration generated by enabling `build
  3575. history <#maintaining-build-output-quality>`__.
  3576. 2. Use the ``buildhistory-collect-srcrevs`` command to collect the
  3577. stored ``SRCREV`` values from the build's history. For more
  3578. information on collecting these values, see the "`Build History
  3579. Package Information <#build-history-package-information>`__"
  3580. section.
  3581. 3. Once you have the correct source revisions, you can modify
  3582. those recipes to to set ``SRCREV`` to specific versions of the
  3583. software.
  3584. Speeding Up a Build
  3585. ===================
  3586. Build time can be an issue. By default, the build system uses simple
  3587. controls to try and maximize build efficiency. In general, the default
  3588. settings for all the following variables result in the most efficient
  3589. build times when dealing with single socket systems (i.e. a single CPU).
  3590. If you have multiple CPUs, you might try increasing the default values
  3591. to gain more speed. See the descriptions in the glossary for each
  3592. variable for more information:
  3593. - :term:`BB_NUMBER_THREADS`:
  3594. The maximum number of threads BitBake simultaneously executes.
  3595. - :term:`bitbake:BB_NUMBER_PARSE_THREADS`:
  3596. The number of threads BitBake uses during parsing.
  3597. - :term:`PARALLEL_MAKE`: Extra
  3598. options passed to the ``make`` command during the
  3599. :ref:`ref-tasks-compile` task in
  3600. order to specify parallel compilation on the local build host.
  3601. - :term:`PARALLEL_MAKEINST`:
  3602. Extra options passed to the ``make`` command during the
  3603. :ref:`ref-tasks-install` task in
  3604. order to specify parallel installation on the local build host.
  3605. As mentioned, these variables all scale to the number of processor cores
  3606. available on the build system. For single socket systems, this
  3607. auto-scaling ensures that the build system fundamentally takes advantage
  3608. of potential parallel operations during the build based on the build
  3609. machine's capabilities.
  3610. Following are additional factors that can affect build speed:
  3611. - File system type: The file system type that the build is being
  3612. performed on can also influence performance. Using ``ext4`` is
  3613. recommended as compared to ``ext2`` and ``ext3`` due to ``ext4``
  3614. improved features such as extents.
  3615. - Disabling the updating of access time using ``noatime``: The
  3616. ``noatime`` mount option prevents the build system from updating file
  3617. and directory access times.
  3618. - Setting a longer commit: Using the "commit=" mount option increases
  3619. the interval in seconds between disk cache writes. Changing this
  3620. interval from the five second default to something longer increases
  3621. the risk of data loss but decreases the need to write to the disk,
  3622. thus increasing the build performance.
  3623. - Choosing the packaging backend: Of the available packaging backends,
  3624. IPK is the fastest. Additionally, selecting a singular packaging
  3625. backend also helps.
  3626. - Using ``tmpfs`` for :term:`TMPDIR`
  3627. as a temporary file system: While this can help speed up the build,
  3628. the benefits are limited due to the compiler using ``-pipe``. The
  3629. build system goes to some lengths to avoid ``sync()`` calls into the
  3630. file system on the principle that if there was a significant failure,
  3631. the :term:`Build Directory`
  3632. contents could easily be rebuilt.
  3633. - Inheriting the
  3634. :ref:`rm_work <ref-classes-rm-work>` class:
  3635. Inheriting this class has shown to speed up builds due to
  3636. significantly lower amounts of data stored in the data cache as well
  3637. as on disk. Inheriting this class also makes cleanup of
  3638. :term:`TMPDIR` faster, at the
  3639. expense of being easily able to dive into the source code. File
  3640. system maintainers have recommended that the fastest way to clean up
  3641. large numbers of files is to reformat partitions rather than delete
  3642. files due to the linear nature of partitions. This, of course,
  3643. assumes you structure the disk partitions and file systems in a way
  3644. that this is practical.
  3645. Aside from the previous list, you should keep some trade offs in mind
  3646. that can help you speed up the build:
  3647. - Remove items from
  3648. :term:`DISTRO_FEATURES`
  3649. that you might not need.
  3650. - Exclude debug symbols and other debug information: If you do not need
  3651. these symbols and other debug information, disabling the ``*-dbg``
  3652. package generation can speed up the build. You can disable this
  3653. generation by setting the
  3654. :term:`INHIBIT_PACKAGE_DEBUG_SPLIT`
  3655. variable to "1".
  3656. - Disable static library generation for recipes derived from
  3657. ``autoconf`` or ``libtool``: Following is an example showing how to
  3658. disable static libraries and still provide an override to handle
  3659. exceptions:
  3660. ::
  3661. STATICLIBCONF = "--disable-static"
  3662. STATICLIBCONF_sqlite3-native = ""
  3663. EXTRA_OECONF += "${STATICLIBCONF}"
  3664. .. note::
  3665. - Some recipes need static libraries in order to work correctly
  3666. (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides,
  3667. as in the previous example, account for these kinds of
  3668. exceptions.
  3669. - Some packages have packaging code that assumes the presence of
  3670. the static libraries. If so, you might need to exclude them as
  3671. well.
  3672. Working With Libraries
  3673. ======================
  3674. Libraries are an integral part of your system. This section describes
  3675. some common practices you might find helpful when working with libraries
  3676. to build your system:
  3677. - `How to include static library
  3678. files <#including-static-library-files>`__
  3679. - `How to use the Multilib feature to combine multiple versions of
  3680. library files into a single
  3681. image <#combining-multiple-versions-library-files-into-one-image>`__
  3682. - `How to install multiple versions of the same library in parallel on
  3683. the same
  3684. system <#installing-multiple-versions-of-the-same-library>`__
  3685. Including Static Library Files
  3686. ------------------------------
  3687. If you are building a library and the library offers static linking, you
  3688. can control which static library files (``*.a`` files) get included in
  3689. the built library.
  3690. The :term:`PACKAGES` and
  3691. :term:`FILES_* <FILES>` variables in the
  3692. ``meta/conf/bitbake.conf`` configuration file define how files installed
  3693. by the ``do_install`` task are packaged. By default, the ``PACKAGES``
  3694. variable includes ``${PN}-staticdev``, which represents all static
  3695. library files.
  3696. .. note::
  3697. Some previously released versions of the Yocto Project defined the
  3698. static library files through ``${PN}-dev``.
  3699. Following is part of the BitBake configuration file, where you can see
  3700. how the static library files are defined:
  3701. ::
  3702. PACKAGE_BEFORE_PN ?= ""
  3703. PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
  3704. PACKAGES_DYNAMIC = "^${PN}-locale-.*"
  3705. FILES = ""
  3706. FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
  3707. ${sysconfdir} ${sharedstatedir} ${localstatedir} \
  3708. ${base_bindir}/* ${base_sbindir}/* \
  3709. ${base_libdir}/*${SOLIBS} \
  3710. ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
  3711. ${datadir}/${BPN} ${libdir}/${BPN}/* \
  3712. ${datadir}/pixmaps ${datadir}/applications \
  3713. ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
  3714. ${libdir}/bonobo/servers"
  3715. FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
  3716. FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
  3717. ${datadir}/gnome/help"
  3718. SECTION_${PN}-doc = "doc"
  3719. FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
  3720. FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
  3721. ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
  3722. ${datadir}/aclocal ${base_libdir}/*.o \
  3723. ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
  3724. SECTION_${PN}-dev = "devel"
  3725. ALLOW_EMPTY_${PN}-dev = "1"
  3726. RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
  3727. FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
  3728. SECTION_${PN}-staticdev = "devel"
  3729. RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
  3730. Combining Multiple Versions of Library Files into One Image
  3731. -----------------------------------------------------------
  3732. The build system offers the ability to build libraries with different
  3733. target optimizations or architecture formats and combine these together
  3734. into one system image. You can link different binaries in the image
  3735. against the different libraries as needed for specific use cases. This
  3736. feature is called "Multilib".
  3737. An example would be where you have most of a system compiled in 32-bit
  3738. mode using 32-bit libraries, but you have something large, like a
  3739. database engine, that needs to be a 64-bit application and uses 64-bit
  3740. libraries. Multilib allows you to get the best of both 32-bit and 64-bit
  3741. libraries.
  3742. While the Multilib feature is most commonly used for 32 and 64-bit
  3743. differences, the approach the build system uses facilitates different
  3744. target optimizations. You could compile some binaries to use one set of
  3745. libraries and other binaries to use a different set of libraries. The
  3746. libraries could differ in architecture, compiler options, or other
  3747. optimizations.
  3748. Several examples exist in the ``meta-skeleton`` layer found in the
  3749. :term:`Source Directory`:
  3750. - ``conf/multilib-example.conf`` configuration file
  3751. - ``conf/multilib-example2.conf`` configuration file
  3752. - ``recipes-multilib/images/core-image-multilib-example.bb`` recipe
  3753. Preparing to Use Multilib
  3754. ~~~~~~~~~~~~~~~~~~~~~~~~~
  3755. User-specific requirements drive the Multilib feature. Consequently,
  3756. there is no one "out-of-the-box" configuration that likely exists to
  3757. meet your needs.
  3758. In order to enable Multilib, you first need to ensure your recipe is
  3759. extended to support multiple libraries. Many standard recipes are
  3760. already extended and support multiple libraries. You can check in the
  3761. ``meta/conf/multilib.conf`` configuration file in the
  3762. :term:`Source Directory` to see how this is
  3763. done using the
  3764. :term:`BBCLASSEXTEND` variable.
  3765. Eventually, all recipes will be covered and this list will not be
  3766. needed.
  3767. For the most part, the Multilib class extension works automatically to
  3768. extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where
  3769. ``MLPREFIX`` is the particular multilib (e.g. "lib32-" or "lib64-").
  3770. Standard variables such as
  3771. :term:`DEPENDS`,
  3772. :term:`RDEPENDS`,
  3773. :term:`RPROVIDES`,
  3774. :term:`RRECOMMENDS`,
  3775. :term:`PACKAGES`, and
  3776. :term:`PACKAGES_DYNAMIC` are
  3777. automatically extended by the system. If you are extending any manual
  3778. code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure
  3779. those names are extended correctly. This automatic extension code
  3780. resides in ``multilib.bbclass``.
  3781. Using Multilib
  3782. ~~~~~~~~~~~~~~
  3783. After you have set up the recipes, you need to define the actual
  3784. combination of multiple libraries you want to build. You accomplish this
  3785. through your ``local.conf`` configuration file in the
  3786. :term:`Build Directory`. An example
  3787. configuration would be as follows:
  3788. ::
  3789. MACHINE = "qemux86-64"
  3790. require conf/multilib.conf
  3791. MULTILIBS = "multilib:lib32"
  3792. DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
  3793. IMAGE_INSTALL_append = "lib32-glib-2.0"
  3794. This example enables an additional library named
  3795. ``lib32`` alongside the normal target packages. When combining these
  3796. "lib32" alternatives, the example uses "x86" for tuning. For information
  3797. on this particular tuning, see
  3798. ``meta/conf/machine/include/ia32/arch-ia32.inc``.
  3799. The example then includes ``lib32-glib-2.0`` in all the images, which
  3800. illustrates one method of including a multiple library dependency. You
  3801. can use a normal image build to include this dependency, for example:
  3802. ::
  3803. $ bitbake core-image-sato
  3804. You can also build Multilib packages
  3805. specifically with a command like this:
  3806. ::
  3807. $ bitbake lib32-glib-2.0
  3808. Additional Implementation Details
  3809. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3810. Generic implementation details as well as details that are specific to
  3811. package management systems exist. Following are implementation details
  3812. that exist regardless of the package management system:
  3813. - The typical convention used for the class extension code as used by
  3814. Multilib assumes that all package names specified in
  3815. :term:`PACKAGES` that contain
  3816. ``${PN}`` have ``${PN}`` at the start of the name. When that
  3817. convention is not followed and ``${PN}`` appears at the middle or the
  3818. end of a name, problems occur.
  3819. - The :term:`TARGET_VENDOR`
  3820. value under Multilib will be extended to "-vendormlmultilib" (e.g.
  3821. "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this
  3822. slightly unwieldy contraction is that any "-" characters in the
  3823. vendor string presently break Autoconf's ``config.sub``, and other
  3824. separators are problematic for different reasons.
  3825. For the RPM Package Management System, the following implementation
  3826. details exist:
  3827. - A unique architecture is defined for the Multilib packages, along
  3828. with creating a unique deploy folder under ``tmp/deploy/rpm`` in the
  3829. :term:`Build Directory`. For
  3830. example, consider ``lib32`` in a ``qemux86-64`` image. The possible
  3831. architectures in the system are "all", "qemux86_64",
  3832. "lib32_qemux86_64", and "lib32_x86".
  3833. - The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM
  3834. packaging. The naming for a normal RPM package and a Multilib RPM
  3835. package in a ``qemux86-64`` system resolves to something similar to
  3836. ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``,
  3837. respectively.
  3838. - When installing a Multilib image, the RPM backend first installs the
  3839. base image and then installs the Multilib libraries.
  3840. - The build system relies on RPM to resolve the identical files in the
  3841. two (or more) Multilib packages.
  3842. For the IPK Package Management System, the following implementation
  3843. details exist:
  3844. - The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK
  3845. packaging. The naming for a normal RPM package and a Multilib IPK
  3846. package in a ``qemux86-64`` system resolves to something like
  3847. ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw_x86.ipk``,
  3848. respectively.
  3849. - The IPK deploy folder is not modified with ``${MLPREFIX}`` because
  3850. packages with and without the Multilib feature can exist in the same
  3851. folder due to the ``${PN}`` differences.
  3852. - IPK defines a sanity check for Multilib installation using certain
  3853. rules for file comparison, overridden, etc.
  3854. Installing Multiple Versions of the Same Library
  3855. ------------------------------------------------
  3856. Situations can exist where you need to install and use multiple versions
  3857. of the same library on the same system at the same time. These
  3858. situations almost always exist when a library API changes and you have
  3859. multiple pieces of software that depend on the separate versions of the
  3860. library. To accommodate these situations, you can install multiple
  3861. versions of the same library in parallel on the same system.
  3862. The process is straightforward as long as the libraries use proper
  3863. versioning. With properly versioned libraries, all you need to do to
  3864. individually specify the libraries is create separate, appropriately
  3865. named recipes where the :term:`PN` part of
  3866. the name includes a portion that differentiates each library version
  3867. (e.g. the major part of the version number). Thus, instead of having a
  3868. single recipe that loads one version of a library (e.g. ``clutter``),
  3869. you provide multiple recipes that result in different versions of the
  3870. libraries you want. As an example, the following two recipes would allow
  3871. the two separate versions of the ``clutter`` library to co-exist on the
  3872. same system:
  3873. .. code-block:: none
  3874. clutter-1.6_1.6.20.bb
  3875. clutter-1.8_1.8.4.bb
  3876. Additionally, if
  3877. you have other recipes that depend on a given library, you need to use
  3878. the :term:`DEPENDS` variable to
  3879. create the dependency. Continuing with the same example, if you want to
  3880. have a recipe depend on the 1.8 version of the ``clutter`` library, use
  3881. the following in your recipe:
  3882. ::
  3883. DEPENDS = "clutter-1.8"
  3884. Using x32 psABI
  3885. ===============
  3886. x32 processor-specific Application Binary Interface (`x32
  3887. psABI <https://software.intel.com/en-us/node/628948>`__) is a native
  3888. 32-bit processor-specific ABI for Intel 64 (x86-64) architectures. An
  3889. ABI defines the calling conventions between functions in a processing
  3890. environment. The interface determines what registers are used and what
  3891. the sizes are for various C data types.
  3892. Some processing environments prefer using 32-bit applications even when
  3893. running on Intel 64-bit platforms. Consider the i386 psABI, which is a
  3894. very old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not
  3895. provide efficient use and access of the Intel 64-bit processor
  3896. resources, leaving the system underutilized. Now consider the x86_64
  3897. psABI. This ABI is newer and uses 64-bits for data sizes and program
  3898. pointers. The extra bits increase the footprint size of the programs,
  3899. libraries, and also increases the memory and file system size
  3900. requirements. Executing under the x32 psABI enables user programs to
  3901. utilize CPU and system resources more efficiently while keeping the
  3902. memory footprint of the applications low. Extra bits are used for
  3903. registers but not for addressing mechanisms.
  3904. The Yocto Project supports the final specifications of x32 psABI as
  3905. follows:
  3906. - You can create packages and images in x32 psABI format on x86_64
  3907. architecture targets.
  3908. - You can successfully build recipes with the x32 toolchain.
  3909. - You can create and boot ``core-image-minimal`` and
  3910. ``core-image-sato`` images.
  3911. - RPM Package Manager (RPM) support exists for x32 binaries.
  3912. - Support for large images exists.
  3913. To use the x32 psABI, you need to edit your ``conf/local.conf``
  3914. configuration file as follows:
  3915. ::
  3916. MACHINE = "qemux86-64"
  3917. DEFAULTTUNE = "x86-64-x32"
  3918. baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \
  3919. or 'INVALID')) or 'lib'}"
  3920. Once you have set
  3921. up your configuration file, use BitBake to build an image that supports
  3922. the x32 psABI. Here is an example:
  3923. ::
  3924. $ bitbake core-image-sato
  3925. Enabling GObject Introspection Support
  3926. ======================================
  3927. `GObject
  3928. introspection <https://wiki.gnome.org/Projects/GObjectIntrospection>`__
  3929. is the standard mechanism for accessing GObject-based software from
  3930. runtime environments. GObject is a feature of the GLib library that
  3931. provides an object framework for the GNOME desktop and related software.
  3932. GObject Introspection adds information to GObject that allows objects
  3933. created within it to be represented across different programming
  3934. languages. If you want to construct GStreamer pipelines using Python, or
  3935. control UPnP infrastructure using Javascript and GUPnP, GObject
  3936. introspection is the only way to do it.
  3937. This section describes the Yocto Project support for generating and
  3938. packaging GObject introspection data. GObject introspection data is a
  3939. description of the API provided by libraries built on top of GLib
  3940. framework, and, in particular, that framework's GObject mechanism.
  3941. GObject Introspection Repository (GIR) files go to ``-dev`` packages,
  3942. ``typelib`` files go to main packages as they are packaged together with
  3943. libraries that are introspected.
  3944. The data is generated when building such a library, by linking the
  3945. library with a small executable binary that asks the library to describe
  3946. itself, and then executing the binary and processing its output.
  3947. Generating this data in a cross-compilation environment is difficult
  3948. because the library is produced for the target architecture, but its
  3949. code needs to be executed on the build host. This problem is solved with
  3950. the OpenEmbedded build system by running the code through QEMU, which
  3951. allows precisely that. Unfortunately, QEMU does not always work
  3952. perfectly as mentioned in the "`Known Issues <#known-issues>`__"
  3953. section.
  3954. Enabling the Generation of Introspection Data
  3955. ---------------------------------------------
  3956. Enabling the generation of introspection data (GIR files) in your
  3957. library package involves the following:
  3958. 1. Inherit the
  3959. :ref:`gobject-introspection <ref-classes-gobject-introspection>`
  3960. class.
  3961. 2. Make sure introspection is not disabled anywhere in the recipe or
  3962. from anything the recipe includes. Also, make sure that
  3963. "gobject-introspection-data" is not in
  3964. :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
  3965. and that "qemu-usermode" is not in
  3966. :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
  3967. If either of these conditions exist, nothing will happen.
  3968. 3. Try to build the recipe. If you encounter build errors that look like
  3969. something is unable to find ``.so`` libraries, check where these
  3970. libraries are located in the source tree and add the following to the
  3971. recipe:
  3972. ::
  3973. GIR_EXTRA_LIBS_PATH = "${B}/something/.libs"
  3974. .. note::
  3975. See recipes in the ``oe-core`` repository that use that
  3976. ``GIR_EXTRA_LIBS_PATH`` variable as an example.
  3977. 4. Look for any other errors, which probably mean that introspection
  3978. support in a package is not entirely standard, and thus breaks down
  3979. in a cross-compilation environment. For such cases, custom-made fixes
  3980. are needed. A good place to ask and receive help in these cases is
  3981. the :ref:`Yocto Project mailing
  3982. lists <resources-mailinglist>`.
  3983. .. note::
  3984. Using a library that no longer builds against the latest Yocto
  3985. Project release and prints introspection related errors is a good
  3986. candidate for the previous procedure.
  3987. Disabling the Generation of Introspection Data
  3988. ----------------------------------------------
  3989. You might find that you do not want to generate introspection data. Or,
  3990. perhaps QEMU does not work on your build host and target architecture
  3991. combination. If so, you can use either of the following methods to
  3992. disable GIR file generations:
  3993. - Add the following to your distro configuration:
  3994. ::
  3995. DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
  3996. Adding this statement disables generating introspection data using
  3997. QEMU but will still enable building introspection tools and libraries
  3998. (i.e. building them does not require the use of QEMU).
  3999. - Add the following to your machine configuration:
  4000. ::
  4001. MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
  4002. Adding this statement disables the use of QEMU when building packages for your
  4003. machine. Currently, this feature is used only by introspection
  4004. recipes and has the same effect as the previously described option.
  4005. .. note::
  4006. Future releases of the Yocto Project might have other features
  4007. affected by this option.
  4008. If you disable introspection data, you can still obtain it through other
  4009. means such as copying the data from a suitable sysroot, or by generating
  4010. it on the target hardware. The OpenEmbedded build system does not
  4011. currently provide specific support for these techniques.
  4012. Testing that Introspection Works in an Image
  4013. --------------------------------------------
  4014. Use the following procedure to test if generating introspection data is
  4015. working in an image:
  4016. 1. Make sure that "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. 2. Build ``core-image-sato``.
  4021. 3. Launch a Terminal and then start Python in the terminal.
  4022. 4. Enter the following in the terminal:
  4023. ::
  4024. >>> from gi.repository import GLib
  4025. >>> GLib.get_host_name()
  4026. 5. For something a little more advanced, enter the following see:
  4027. https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html
  4028. Known Issues
  4029. ------------
  4030. The following know issues exist for GObject Introspection Support:
  4031. - ``qemu-ppc64`` immediately crashes. Consequently, you cannot build
  4032. introspection data on that architecture.
  4033. - x32 is not supported by QEMU. Consequently, introspection data is
  4034. disabled.
  4035. - musl causes transient GLib binaries to crash on assertion failures.
  4036. Consequently, generating introspection data is disabled.
  4037. - Because QEMU is not able to run the binaries correctly, introspection
  4038. is disabled for some specific packages under specific architectures
  4039. (e.g. ``gcr``, ``libsecret``, and ``webkit``).
  4040. - QEMU usermode might not work properly when running 64-bit binaries
  4041. under 32-bit host machines. In particular, "qemumips64" is known to
  4042. not work under i686.
  4043. Optionally Using an External Toolchain
  4044. ======================================
  4045. You might want to use an external toolchain as part of your development.
  4046. If this is the case, the fundamental steps you need to accomplish are as
  4047. follows:
  4048. - Understand where the installed toolchain resides. For cases where you
  4049. need to build the external toolchain, you would need to take separate
  4050. steps to build and install the toolchain.
  4051. - Make sure you add the layer that contains the toolchain to your
  4052. ``bblayers.conf`` file through the
  4053. :term:`BBLAYERS` variable.
  4054. - Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file
  4055. to the location in which you installed the toolchain.
  4056. A good example of an external toolchain used with the Yocto Project is
  4057. Mentor Graphics Sourcery G++ Toolchain. You can see information on how
  4058. to use that particular layer in the ``README`` file at
  4059. https://github.com/MentorEmbedded/meta-sourcery/. You can find
  4060. further information by reading about the
  4061. :term:`TCMODE` variable in the Yocto
  4062. Project Reference Manual's variable glossary.
  4063. Creating Partitioned Images Using Wic
  4064. =====================================
  4065. Creating an image for a particular hardware target using the
  4066. OpenEmbedded build system does not necessarily mean you can boot that
  4067. image as is on your device. Physical devices accept and boot images in
  4068. various ways depending on the specifics of the device. Usually,
  4069. information about the hardware can tell you what image format the device
  4070. requires. Should your device require multiple partitions on an SD card,
  4071. flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to
  4072. create the properly partitioned image.
  4073. The ``wic`` command generates partitioned images from existing
  4074. OpenEmbedded build artifacts. Image generation is driven by partitioning
  4075. commands contained in an Openembedded kickstart file (``.wks``)
  4076. specified either directly on the command line or as one of a selection
  4077. of canned kickstart files as shown with the ``wic list images`` command
  4078. in the "`Using an Existing Kickstart
  4079. File <#using-a-provided-kickstart-file>`__" section. When you apply the
  4080. command to a given set of build artifacts, the result is an image or set
  4081. of images that can be directly written onto media and used on a
  4082. particular system.
  4083. .. note::
  4084. For a kickstart file reference, see the
  4085. ":ref:`ref-manual/kickstart:openembedded kickstart (\`\`.wks\`\`) reference`"
  4086. Chapter in the Yocto Project Reference Manual.
  4087. The ``wic`` command and the infrastructure it is based on is by
  4088. definition incomplete. The purpose of the command is to allow the
  4089. generation of customized images, and as such, was designed to be
  4090. completely extensible through a plugin interface. See the "`Using the
  4091. Wic PlugIn Interface <#wic-using-the-wic-plugin-interface>`__" section
  4092. for information on these plugins.
  4093. This section provides some background information on Wic, describes what
  4094. you need to have in place to run the tool, provides instruction on how
  4095. to use the Wic utility, provides information on using the Wic plugins
  4096. interface, and provides several examples that show how to use Wic.
  4097. Background
  4098. ----------
  4099. This section provides some background on the Wic utility. While none of
  4100. this information is required to use Wic, you might find it interesting.
  4101. - The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The
  4102. "oe" diphthong in "oeic" was promoted to the letter "w", because
  4103. "oeic" is both difficult to remember and to pronounce.
  4104. - Wic is loosely based on the Meego Image Creator (``mic``) framework.
  4105. The Wic implementation has been heavily modified to make direct use
  4106. of OpenEmbedded build artifacts instead of package installation and
  4107. configuration, which are already incorporated within the OpenEmbedded
  4108. artifacts.
  4109. - Wic is a completely independent standalone utility that initially
  4110. provides easier-to-use and more flexible replacements for an existing
  4111. functionality in OE-Core's
  4112. :ref:`image-live <ref-classes-image-live>`
  4113. class. The difference between Wic and those examples is that with Wic
  4114. the functionality of those scripts is implemented by a
  4115. general-purpose partitioning language, which is based on Redhat
  4116. kickstart syntax.
  4117. Requirements
  4118. ------------
  4119. In order to use the Wic utility with the OpenEmbedded Build system, your
  4120. system needs to meet the following requirements:
  4121. - The Linux distribution on your development host must support the
  4122. Yocto Project. See the ":ref:`detailed-supported-distros`"
  4123. section in the Yocto Project Reference Manual for the list of
  4124. distributions that support the Yocto Project.
  4125. - The standard system utilities, such as ``cp``, must be installed on
  4126. your development host system.
  4127. - You must have sourced the build environment setup script (i.e.
  4128. :ref:`structure-core-script`) found in the
  4129. :term:`Build Directory`.
  4130. - You need to have the build artifacts already available, which
  4131. typically means that you must have already created an image using the
  4132. Openembedded build system (e.g. ``core-image-minimal``). While it
  4133. might seem redundant to generate an image in order to create an image
  4134. using Wic, the current version of Wic requires the artifacts in the
  4135. form generated by the OpenEmbedded build system.
  4136. - You must build several native tools, which are built to run on the
  4137. build system:
  4138. ::
  4139. $ bitbake parted-native dosfstools-native mtools-native
  4140. - Include "wic" as part of the
  4141. :term:`IMAGE_FSTYPES`
  4142. variable.
  4143. - Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>`
  4144. as part of the :term:`WKS_FILE` variable
  4145. Getting Help
  4146. ------------
  4147. You can get general help for the ``wic`` command by entering the ``wic``
  4148. command by itself or by entering the command with a help argument as
  4149. follows:
  4150. ::
  4151. $ wic -h
  4152. $ wic --help
  4153. $ wic help
  4154. Currently, Wic supports seven commands: ``cp``, ``create``, ``help``,
  4155. ``list``, ``ls``, ``rm``, and ``write``. You can get help for all these
  4156. commands except "help" by using the following form:
  4157. ::
  4158. $ wic help command
  4159. For example, the following command returns help for the ``write``
  4160. command:
  4161. ::
  4162. $ wic help write
  4163. Wic supports help for three topics: ``overview``, ``plugins``, and
  4164. ``kickstart``. You can get help for any topic using the following form:
  4165. ::
  4166. $ wic help topic
  4167. For example, the following returns overview help for Wic:
  4168. ::
  4169. $ wic help overview
  4170. One additional level of help exists for Wic. You can get help on
  4171. individual images through the ``list`` command. You can use the ``list``
  4172. command to return the available Wic images as follows:
  4173. ::
  4174. $ wic list images
  4175. genericx86 Create an EFI disk image for genericx86*
  4176. beaglebone-yocto Create SD card image for Beaglebone
  4177. edgerouter Create SD card image for Edgerouter
  4178. qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
  4179. directdisk-gpt Create a 'pcbios' direct disk image
  4180. mkefidisk Create an EFI disk image
  4181. directdisk Create a 'pcbios' direct disk image
  4182. systemd-bootdisk Create an EFI disk image with systemd-boot
  4183. mkhybridiso Create a hybrid ISO image
  4184. sdimage-bootpart Create SD card image with a boot partition
  4185. directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
  4186. directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
  4187. Once you know the list of available
  4188. Wic images, you can use ``help`` with the command to get help on a
  4189. particular image. For example, the following command returns help on the
  4190. "beaglebone-yocto" image:
  4191. ::
  4192. $ wic list beaglebone-yocto help
  4193. Creates a partitioned SD card image for Beaglebone.
  4194. Boot files are located in the first vfat partition.
  4195. Operational Modes
  4196. -----------------
  4197. You can use Wic in two different modes, depending on how much control
  4198. you need for specifying the Openembedded build artifacts that are used
  4199. for creating the image: Raw and Cooked:
  4200. - *Raw Mode:* You explicitly specify build artifacts through Wic
  4201. command-line arguments.
  4202. - *Cooked Mode:* The current
  4203. :term:`MACHINE` setting and image
  4204. name are used to automatically locate and provide the build
  4205. artifacts. You just supply a kickstart file and the name of the image
  4206. from which to use artifacts.
  4207. Regardless of the mode you use, you need to have the build artifacts
  4208. ready and available.
  4209. Raw Mode
  4210. ~~~~~~~~
  4211. Running Wic in raw mode allows you to specify all the partitions through
  4212. the ``wic`` command line. The primary use for raw mode is if you have
  4213. built your kernel outside of the Yocto Project
  4214. :term:`Build Directory`. In other words, you
  4215. can point to arbitrary kernel, root filesystem locations, and so forth.
  4216. Contrast this behavior with cooked mode where Wic looks in the Build
  4217. Directory (e.g. ``tmp/deploy/images/``\ machine).
  4218. The general form of the ``wic`` command in raw mode is:
  4219. ::
  4220. $ wic create wks_file options ...
  4221. Where:
  4222. wks_file:
  4223. An OpenEmbedded kickstart file. You can provide
  4224. your own custom file or use a file from a set of
  4225. existing files as described by further options.
  4226. optional arguments:
  4227. -h, --help show this help message and exit
  4228. -o OUTDIR, --outdir OUTDIR
  4229. name of directory to create image in
  4230. -e IMAGE_NAME, --image-name IMAGE_NAME
  4231. name of the image to use the artifacts from e.g. core-
  4232. image-sato
  4233. -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR
  4234. path to the /rootfs dir to use as the .wks rootfs
  4235. source
  4236. -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR
  4237. path to the dir containing the boot artifacts (e.g.
  4238. /EFI or /syslinux dirs) to use as the .wks bootimg
  4239. source
  4240. -k KERNEL_DIR, --kernel-dir KERNEL_DIR
  4241. path to the dir containing the kernel to use in the
  4242. .wks bootimg
  4243. -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT
  4244. path to the native sysroot containing the tools to use
  4245. to build the image
  4246. -s, --skip-build-check
  4247. skip the build check
  4248. -f, --build-rootfs build rootfs
  4249. -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
  4250. compress image with specified compressor
  4251. -m, --bmap generate .bmap
  4252. --no-fstab-update Do not change fstab file.
  4253. -v VARS_DIR, --vars VARS_DIR
  4254. directory with <image>.env files that store bitbake
  4255. variables
  4256. -D, --debug output debug information
  4257. .. note::
  4258. You do not need root privileges to run Wic. In fact, you should not
  4259. run as root when using the utility.
  4260. Cooked Mode
  4261. ~~~~~~~~~~~
  4262. Running Wic in cooked mode leverages off artifacts in the Build
  4263. Directory. In other words, you do not have to specify kernel or root
  4264. filesystem locations as part of the command. All you need to provide is
  4265. a kickstart file and the name of the image from which to use artifacts
  4266. by using the "-e" option. Wic looks in the Build Directory (e.g.
  4267. ``tmp/deploy/images/``\ machine) for artifacts.
  4268. The general form of the ``wic`` command using Cooked Mode is as follows:
  4269. ::
  4270. $ wic create wks_file -e IMAGE_NAME
  4271. Where:
  4272. wks_file:
  4273. An OpenEmbedded kickstart file. You can provide
  4274. your own custom file or use a file from a set of
  4275. existing files provided with the Yocto Project
  4276. release.
  4277. required argument:
  4278. -e IMAGE_NAME, --image-name IMAGE_NAME
  4279. name of the image to use the artifacts from e.g. core-
  4280. image-sato
  4281. Using an Existing Kickstart File
  4282. --------------------------------
  4283. If you do not want to create your own kickstart file, you can use an
  4284. existing file provided by the Wic installation. As shipped, kickstart
  4285. files can be found in the :ref:`overview-manual/development-environment:yocto project source repositories` in the
  4286. following two locations:
  4287. ::
  4288. poky/meta-yocto-bsp/wic
  4289. poky/scripts/lib/wic/canned-wks
  4290. Use the following command to list the available kickstart files:
  4291. ::
  4292. $ wic list images
  4293. genericx86 Create an EFI disk image for genericx86*
  4294. beaglebone-yocto Create SD card image for Beaglebone
  4295. edgerouter Create SD card image for Edgerouter
  4296. qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
  4297. directdisk-gpt Create a 'pcbios' direct disk image
  4298. mkefidisk Create an EFI disk image
  4299. directdisk Create a 'pcbios' direct disk image
  4300. systemd-bootdisk Create an EFI disk image with systemd-boot
  4301. mkhybridiso Create a hybrid ISO image
  4302. sdimage-bootpart Create SD card image with a boot partition
  4303. directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
  4304. directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
  4305. When you use an existing file, you
  4306. do not have to use the ``.wks`` extension. Here is an example in Raw
  4307. Mode that uses the ``directdisk`` file:
  4308. ::
  4309. $ wic create directdisk -r rootfs_dir -b bootimg_dir \
  4310. -k kernel_dir -n native_sysroot
  4311. Here are the actual partition language commands used in the
  4312. ``genericx86.wks`` file to generate an image:
  4313. ::
  4314. # short-description: Create an EFI disk image for genericx86*
  4315. # long-description: Creates a partitioned EFI disk image for genericx86* machines
  4316. part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
  4317. part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
  4318. part swap --ondisk sda --size 44 --label swap1 --fstype=swap
  4319. bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
  4320. Using the Wic Plugin Interface
  4321. ------------------------------
  4322. You can extend and specialize Wic functionality by using Wic plugins.
  4323. This section explains the Wic plugin interface.
  4324. .. note::
  4325. Wic plugins consist of "source" and "imager" plugins. Imager plugins
  4326. are beyond the scope of this section.
  4327. Source plugins provide a mechanism to customize partition content during
  4328. the Wic image generation process. You can use source plugins to map
  4329. values that you specify using ``--source`` commands in kickstart files
  4330. (i.e. ``*.wks``) to a plugin implementation used to populate a given
  4331. partition.
  4332. .. note::
  4333. If you use plugins that have build-time dependencies (e.g. native
  4334. tools, bootloaders, and so forth) when building a Wic image, you need
  4335. to specify those dependencies using the :term:`WKS_FILE_DEPENDS`
  4336. variable.
  4337. Source plugins are subclasses defined in plugin files. As shipped, the
  4338. Yocto Project provides several plugin files. You can see the source
  4339. plugin files that ship with the Yocto Project
  4340. :yocto_git:`here </poky/tree/scripts/lib/wic/plugins/source>`.
  4341. Each of these plugin files contains source plugins that are designed to
  4342. populate a specific Wic image partition.
  4343. Source plugins are subclasses of the ``SourcePlugin`` class, which is
  4344. defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example,
  4345. the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py``
  4346. file is a subclass of the ``SourcePlugin`` class, which is found in the
  4347. ``pluginbase.py`` file.
  4348. You can also implement source plugins in a layer outside of the Source
  4349. Repositories (external layer). To do so, be sure that your plugin files
  4350. are located in a directory whose path is
  4351. ``scripts/lib/wic/plugins/source/`` within your external layer. When the
  4352. plugin files are located there, the source plugins they contain are made
  4353. available to Wic.
  4354. When the Wic implementation needs to invoke a partition-specific
  4355. implementation, it looks for the plugin with the same name as the
  4356. ``--source`` parameter used in the kickstart file given to that
  4357. partition. For example, if the partition is set up using the following
  4358. command in a kickstart file:
  4359. ::
  4360. part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
  4361. The methods defined as class
  4362. members of the matching source plugin (i.e. ``bootimg-pcbios``) in the
  4363. ``bootimg-pcbios.py`` plugin file are used.
  4364. To be more concrete, here is the corresponding plugin definition from
  4365. the ``bootimg-pcbios.py`` file for the previous command along with an
  4366. example method called by the Wic implementation when it needs to prepare
  4367. a partition using an implementation-specific function:
  4368. ::
  4369. .
  4370. .
  4371. .
  4372. class BootimgPcbiosPlugin(SourcePlugin):
  4373. """
  4374. Create MBR boot partition and install syslinux on it.
  4375. """
  4376. name = 'bootimg-pcbios'
  4377. .
  4378. .
  4379. .
  4380. @classmethod
  4381. def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
  4382. oe_builddir, bootimg_dir, kernel_dir,
  4383. rootfs_dir, native_sysroot):
  4384. """
  4385. Called to do the actual content population for a partition i.e. it
  4386. 'prepares' the partition to be incorporated into the image.
  4387. In this case, prepare content for legacy bios boot partition.
  4388. """
  4389. .
  4390. .
  4391. .
  4392. If a
  4393. subclass (plugin) itself does not implement a particular function, Wic
  4394. locates and uses the default version in the superclass. It is for this
  4395. reason that all source plugins are derived from the ``SourcePlugin``
  4396. class.
  4397. The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines
  4398. a set of methods that source plugins can implement or override. Any
  4399. plugins (subclass of ``SourcePlugin``) that do not implement a
  4400. particular method inherit the implementation of the method from the
  4401. ``SourcePlugin`` class. For more information, see the ``SourcePlugin``
  4402. class in the ``pluginbase.py`` file for details:
  4403. The following list describes the methods implemented in the
  4404. ``SourcePlugin`` class:
  4405. - ``do_prepare_partition()``: Called to populate a partition with
  4406. actual content. In other words, the method prepares the final
  4407. partition image that is incorporated into the disk image.
  4408. - ``do_configure_partition()``: Called before
  4409. ``do_prepare_partition()`` to create custom configuration files for a
  4410. partition (e.g. syslinux or grub configuration files).
  4411. - ``do_install_disk()``: Called after all partitions have been
  4412. prepared and assembled into a disk image. This method provides a hook
  4413. to allow finalization of a disk image (e.g. writing an MBR).
  4414. - ``do_stage_partition()``: Special content-staging hook called
  4415. before ``do_prepare_partition()``. This method is normally empty.
  4416. Typically, a partition just uses the passed-in parameters (e.g. the
  4417. unmodified value of ``bootimg_dir``). However, in some cases, things
  4418. might need to be more tailored. As an example, certain files might
  4419. additionally need to be taken from ``bootimg_dir + /boot``. This hook
  4420. allows those files to be staged in a customized fashion.
  4421. .. note::
  4422. ``get_bitbake_var()`` allows you to access non-standard variables that
  4423. you might want to use for this behavior.
  4424. You can extend the source plugin mechanism. To add more hooks, create
  4425. more source plugin methods within ``SourcePlugin`` and the corresponding
  4426. derived subclasses. The code that calls the plugin methods uses the
  4427. ``plugin.get_source_plugin_methods()`` function to find the method or
  4428. methods needed by the call. Retrieval of those methods is accomplished
  4429. by filling up a dict with keys that contain the method names of
  4430. interest. On success, these will be filled in with the actual methods.
  4431. See the Wic implementation for examples and details.
  4432. Wic Examples
  4433. ------------
  4434. This section provides several examples that show how to use the Wic
  4435. utility. All the examples assume the list of requirements in the
  4436. "`Requirements <#wic-requirements>`__" section have been met. The
  4437. examples assume the previously generated image is
  4438. ``core-image-minimal``.
  4439. Generate an Image using an Existing Kickstart File
  4440. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4441. This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart
  4442. file:
  4443. ::
  4444. $ wic create mkefidisk -e core-image-minimal
  4445. INFO: Building wic-tools...
  4446. .
  4447. .
  4448. .
  4449. INFO: The new image(s) can be found here:
  4450. ./mkefidisk-201804191017-sda.direct
  4451. The following build artifacts were used to create the image(s):
  4452. ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
  4453. BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
  4454. KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
  4455. NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4456. INFO: The image(s) were created using OE kickstart file:
  4457. /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
  4458. The previous example shows the easiest way to create an image by running
  4459. in cooked mode and supplying a kickstart file and the "-e" option to
  4460. point to the existing build artifacts. Your ``local.conf`` file needs to
  4461. have the :term:`MACHINE` variable set
  4462. to the machine you are using, which is "qemux86" in this example.
  4463. Once the image builds, the output provides image location, artifact use,
  4464. and kickstart file information.
  4465. .. note::
  4466. You should always verify the details provided in the output to make
  4467. sure that the image was indeed created exactly as expected.
  4468. Continuing with the example, you can now write the image from the Build
  4469. Directory onto a USB stick, or whatever media for which you built your
  4470. image, and boot from the media. You can write the image by using
  4471. ``bmaptool`` or ``dd``:
  4472. ::
  4473. $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX
  4474. or ::
  4475. $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX
  4476. .. note::
  4477. For more information on how to use the ``bmaptool``
  4478. to flash a device with an image, see the
  4479. ":ref:`dev-manual/common-tasks:flashing images using \`\`bmaptool\`\``"
  4480. section.
  4481. Using a Modified Kickstart File
  4482. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4483. Because partitioned image creation is driven by the kickstart file, it
  4484. is easy to affect image creation by changing the parameters in the file.
  4485. This next example demonstrates that through modification of the
  4486. ``directdisk-gpt`` kickstart file.
  4487. As mentioned earlier, you can use the command ``wic list images`` to
  4488. show the list of existing kickstart files. The directory in which the
  4489. ``directdisk-gpt.wks`` file resides is
  4490. ``scripts/lib/image/canned-wks/``, which is located in the
  4491. :term:`Source Directory` (e.g. ``poky``).
  4492. Because available files reside in this directory, you can create and add
  4493. your own custom files to the directory. Subsequent use of the
  4494. ``wic list images`` command would then include your kickstart files.
  4495. In this example, the existing ``directdisk-gpt`` file already does most
  4496. of what is needed. However, for the hardware in this example, the image
  4497. will need to boot from ``sdb`` instead of ``sda``, which is what the
  4498. ``directdisk-gpt`` kickstart file uses.
  4499. The example begins by making a copy of the ``directdisk-gpt.wks`` file
  4500. in the ``scripts/lib/image/canned-wks`` directory and then by changing
  4501. the lines that specify the target disk from which to boot.
  4502. ::
  4503. $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
  4504. /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
  4505. Next, the example modifies the ``directdisksdb-gpt.wks`` file and
  4506. changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The
  4507. example changes the following two lines and leaves the remaining lines
  4508. untouched:
  4509. ::
  4510. part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
  4511. part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
  4512. Once the lines are changed, the
  4513. example generates the ``directdisksdb-gpt`` image. The command points
  4514. the process at the ``core-image-minimal`` artifacts for the Next Unit of
  4515. Computing (nuc) :term:`MACHINE` the
  4516. ``local.conf``.
  4517. ::
  4518. $ wic create directdisksdb-gpt -e core-image-minimal
  4519. INFO: Building wic-tools...
  4520. .
  4521. .
  4522. .
  4523. Initialising tasks: 100% |#######################################| Time: 0:00:01
  4524. NOTE: Executing SetScene Tasks
  4525. NOTE: Executing RunQueue Tasks
  4526. NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
  4527. INFO: Creating image(s)...
  4528. INFO: The new image(s) can be found here:
  4529. ./directdisksdb-gpt-201710090938-sdb.direct
  4530. The following build artifacts were used to create the image(s):
  4531. ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
  4532. BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
  4533. KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
  4534. NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4535. INFO: The image(s) were created using OE kickstart file:
  4536. /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
  4537. Continuing with the example, you can now directly ``dd`` the image to a
  4538. USB stick, or whatever media for which you built your image, and boot
  4539. the resulting media:
  4540. ::
  4541. $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
  4542. 140966+0 records in
  4543. 140966+0 records out
  4544. 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
  4545. $ sudo eject /dev/sdb
  4546. Using a Modified Kickstart File and Running in Raw Mode
  4547. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4548. This next example manually specifies each build artifact (runs in Raw
  4549. Mode) and uses a modified kickstart file. The example also uses the
  4550. ``-o`` option to cause Wic to create the output somewhere other than the
  4551. default output directory, which is the current directory:
  4552. ::
  4553. $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
  4554. --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
  4555. --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
  4556. --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
  4557. --native-sysroot /home/stephano/build/master/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4558. INFO: Creating image(s)...
  4559. INFO: The new image(s) can be found here:
  4560. /home/stephano/testwic/test-201710091445-sdb.direct
  4561. The following build artifacts were used to create the image(s):
  4562. ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
  4563. BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
  4564. KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
  4565. NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4566. INFO: The image(s) were created using OE kickstart file:
  4567. /home/stephano/my_yocto/test.wks
  4568. For this example,
  4569. :term:`MACHINE` did not have to be
  4570. specified in the ``local.conf`` file since the artifact is manually
  4571. specified.
  4572. Using Wic to Manipulate an Image
  4573. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4574. Wic image manipulation allows you to shorten turnaround time during
  4575. image development. For example, you can use Wic to delete the kernel
  4576. partition of a Wic image and then insert a newly built kernel. This
  4577. saves you time from having to rebuild the entire image each time you
  4578. modify the kernel.
  4579. .. note::
  4580. In order to use Wic to manipulate a Wic image as in this example,
  4581. your development machine must have the ``mtools`` package installed.
  4582. The following example examines the contents of the Wic image, deletes
  4583. the existing kernel, and then inserts a new kernel:
  4584. 1. *List the Partitions:* Use the ``wic ls`` command to list all the
  4585. partitions in the Wic image:
  4586. ::
  4587. $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
  4588. Num Start End Size Fstype
  4589. 1 1048576 25041919 23993344 fat16
  4590. 2 25165824 72157183 46991360 ext4
  4591. The previous output shows two partitions in the
  4592. ``core-image-minimal-qemux86.wic`` image.
  4593. 2. *Examine a Particular Partition:* Use the ``wic ls`` command again
  4594. but in a different form to examine a particular partition.
  4595. .. note::
  4596. You can get command usage on any Wic command using the following
  4597. form:
  4598. ::
  4599. $ wic help command
  4600. For example, the following command shows you the various ways to
  4601. use the
  4602. wic ls
  4603. command:
  4604. ::
  4605. $ wic help ls
  4606. The following command shows what is in Partition one:
  4607. ::
  4608. $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
  4609. Volume in drive : is boot
  4610. Volume Serial Number is E894-1809
  4611. Directory for ::/
  4612. libcom32 c32 186500 2017-10-09 16:06
  4613. libutil c32 24148 2017-10-09 16:06
  4614. syslinux cfg 220 2017-10-09 16:06
  4615. vesamenu c32 27104 2017-10-09 16:06
  4616. vmlinuz 6904608 2017-10-09 16:06
  4617. 5 files 7 142 580 bytes
  4618. 16 582 656 bytes free
  4619. The previous output shows five files, with the
  4620. ``vmlinuz`` being the kernel.
  4621. .. note::
  4622. If you see the following error, you need to update or create a
  4623. ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1"
  4624. in the file. Then, run the Wic command again:
  4625. ::
  4626. ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
  4627. output: Total number of sectors (47824) not a multiple of sectors per track (32)!
  4628. Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
  4629. 3. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the
  4630. ``vmlinuz`` file (kernel):
  4631. ::
  4632. $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
  4633. 4. *Add In the New Kernel:* Use the ``wic cp`` command to add the
  4634. updated kernel to the Wic image. Depending on how you built your
  4635. kernel, it could be in different places. If you used ``devtool`` and
  4636. an SDK to build your kernel, it resides in the ``tmp/work`` directory
  4637. of the extensible SDK. If you used ``make`` to build the kernel, the
  4638. kernel will be in the ``workspace/sources`` area.
  4639. The following example assumes ``devtool`` was used to build the
  4640. kernel:
  4641. ::
  4642. 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 \
  4643. ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
  4644. Once the new kernel is added back into the image, you can use the
  4645. ``dd`` command or :ref:`bmaptool
  4646. <dev-manual/common-tasks:flashing images using \`\`bmaptool\`\`>`
  4647. to flash your wic image onto an SD card or USB stick and test your
  4648. target.
  4649. .. note::
  4650. Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``.
  4651. Flashing Images Using ``bmaptool``
  4652. ==================================
  4653. A fast and easy way to flash an image to a bootable device is to use
  4654. Bmaptool, which is integrated into the OpenEmbedded build system.
  4655. Bmaptool is a generic tool that creates a file's block map (bmap) and
  4656. then uses that map to copy the file. As compared to traditional tools
  4657. such as dd or cp, Bmaptool can copy (or flash) large files like raw
  4658. system image files much faster.
  4659. .. note::
  4660. - If you are using Ubuntu or Debian distributions, you can install
  4661. the ``bmap-tools`` package using the following command and then
  4662. use the tool without specifying ``PATH`` even from the root
  4663. account:
  4664. ::
  4665. $ sudo apt-get install bmap-tools
  4666. - If you are unable to install the ``bmap-tools`` package, you will
  4667. need to build Bmaptool before using it. Use the following command:
  4668. ::
  4669. $ bitbake bmap-tools-native
  4670. Following, is an example that shows how to flash a Wic image. Realize
  4671. that while this example uses a Wic image, you can use Bmaptool to flash
  4672. any type of image. Use these steps to flash an image using Bmaptool:
  4673. 1. *Update your local.conf File:* You need to have the following set
  4674. in your ``local.conf`` file before building your image:
  4675. ::
  4676. IMAGE_FSTYPES += "wic wic.bmap"
  4677. 2. *Get Your Image:* Either have your image ready (pre-built with the
  4678. :term:`IMAGE_FSTYPES`
  4679. setting previously mentioned) or take the step to build the image:
  4680. ::
  4681. $ bitbake image
  4682. 3. *Flash the Device:* Flash the device with the image by using Bmaptool
  4683. depending on your particular setup. The following commands assume the
  4684. image resides in the Build Directory's ``deploy/images/`` area:
  4685. - If you have write access to the media, use this command form:
  4686. ::
  4687. $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
  4688. - If you do not have write access to the media, set your permissions
  4689. first and then use the same command form:
  4690. ::
  4691. $ sudo chmod 666 /dev/sdX
  4692. $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
  4693. For help on the ``bmaptool`` command, use the following command:
  4694. ::
  4695. $ bmaptool --help
  4696. Making Images More Secure
  4697. =========================
  4698. Security is of increasing concern for embedded devices. Consider the
  4699. issues and problems discussed in just this sampling of work found across
  4700. the Internet:
  4701. - *"*\ `Security Risks of Embedded
  4702. Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"*
  4703. by Bruce Schneier
  4704. - *"*\ `Internet Census
  4705. 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna
  4706. Botnet
  4707. - *"*\ `Security Issues for Embedded
  4708. Devices <http://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"*
  4709. by Jake Edge
  4710. When securing your image is of concern, there are steps, tools, and
  4711. variables that you can consider to help you reach the security goals you
  4712. need for your particular device. Not all situations are identical when
  4713. it comes to making an image secure. Consequently, this section provides
  4714. some guidance and suggestions for consideration when you want to make
  4715. your image more secure.
  4716. .. note::
  4717. Because the security requirements and risks are different for every
  4718. type of device, this section cannot provide a complete reference on
  4719. securing your custom OS. It is strongly recommended that you also
  4720. consult other sources of information on embedded Linux system
  4721. hardening and on security.
  4722. General Considerations
  4723. ----------------------
  4724. General considerations exist that help you create more secure images.
  4725. You should consider the following suggestions to help make your device
  4726. more secure:
  4727. - Scan additional code you are adding to the system (e.g. application
  4728. code) by using static analysis tools. Look for buffer overflows and
  4729. other potential security problems.
  4730. - Pay particular attention to the security for any web-based
  4731. administration interface.
  4732. Web interfaces typically need to perform administrative functions and
  4733. tend to need to run with elevated privileges. Thus, the consequences
  4734. resulting from the interface's security becoming compromised can be
  4735. serious. Look for common web vulnerabilities such as
  4736. cross-site-scripting (XSS), unvalidated inputs, and so forth.
  4737. As with system passwords, the default credentials for accessing a
  4738. web-based interface should not be the same across all devices. This
  4739. is particularly true if the interface is enabled by default as it can
  4740. be assumed that many end-users will not change the credentials.
  4741. - Ensure you can update the software on the device to mitigate
  4742. vulnerabilities discovered in the future. This consideration
  4743. especially applies when your device is network-enabled.
  4744. - Ensure you remove or disable debugging functionality before producing
  4745. the final image. For information on how to do this, see the
  4746. "`Considerations Specific to the OpenEmbedded Build
  4747. System <#considerations-specific-to-the-openembedded-build-system>`__"
  4748. section.
  4749. - Ensure you have no network services listening that are not needed.
  4750. - Remove any software from the image that is not needed.
  4751. - Enable hardware support for secure boot functionality when your
  4752. device supports this functionality.
  4753. Security Flags
  4754. --------------
  4755. The Yocto Project has security flags that you can enable that help make
  4756. your build output more secure. The security flags are in the
  4757. ``meta/conf/distro/include/security_flags.inc`` file in your
  4758. :term:`Source Directory` (e.g. ``poky``).
  4759. .. note::
  4760. Depending on the recipe, certain security flags are enabled and
  4761. disabled by default.
  4762. Use the following line in your ``local.conf`` file or in your custom
  4763. distribution configuration file to enable the security compiler and
  4764. linker flags for your build:
  4765. ::
  4766. require conf/distro/include/security_flags.inc
  4767. Considerations Specific to the OpenEmbedded Build System
  4768. --------------------------------------------------------
  4769. You can take some steps that are specific to the OpenEmbedded build
  4770. system to make your images more secure:
  4771. - Ensure "debug-tweaks" is not one of your selected
  4772. :term:`IMAGE_FEATURES`.
  4773. When creating a new project, the default is to provide you with an
  4774. initial ``local.conf`` file that enables this feature using the
  4775. :term:`EXTRA_IMAGE_FEATURES`
  4776. variable with the line:
  4777. ::
  4778. EXTRA_IMAGE_FEATURES = "debug-tweaks"
  4779. To disable that feature, simply comment out that line in your
  4780. ``local.conf`` file, or make sure ``IMAGE_FEATURES`` does not contain
  4781. "debug-tweaks" before producing your final image. Among other things,
  4782. leaving this in place sets the root password as blank, which makes
  4783. logging in for debugging or inspection easy during development but
  4784. also means anyone can easily log in during production.
  4785. - It is possible to set a root password for the image and also to set
  4786. passwords for any extra users you might add (e.g. administrative or
  4787. service type users). When you set up passwords for multiple images or
  4788. users, you should not duplicate passwords.
  4789. To set up passwords, use the
  4790. :ref:`extrausers <ref-classes-extrausers>`
  4791. class, which is the preferred method. For an example on how to set up
  4792. both root and user passwords, see the
  4793. ":ref:`extrausers.bbclass <ref-classes-extrausers>`"
  4794. section.
  4795. .. note::
  4796. When adding extra user accounts or setting a root password, be
  4797. cautious about setting the same password on every device. If you
  4798. do this, and the password you have set is exposed, then every
  4799. device is now potentially compromised. If you need this access but
  4800. want to ensure security, consider setting a different, random
  4801. password for each device. Typically, you do this as a separate
  4802. step after you deploy the image onto the device.
  4803. - Consider enabling a Mandatory Access Control (MAC) framework such as
  4804. SMACK or SELinux and tuning it appropriately for your device's usage.
  4805. You can find more information in the
  4806. :yocto_git:`meta-selinux </meta-selinux/>` layer.
  4807. Tools for Hardening Your Image
  4808. ------------------------------
  4809. The Yocto Project provides tools for making your image more secure. You
  4810. can find these tools in the ``meta-security`` layer of the
  4811. :yocto_git:`Yocto Project Source Repositories <>`.
  4812. Creating Your Own Distribution
  4813. ==============================
  4814. When you build an image using the Yocto Project and do not alter any
  4815. distribution :term:`Metadata`, you are
  4816. creating a Poky distribution. If you wish to gain more control over
  4817. package alternative selections, compile-time options, and other
  4818. low-level configurations, you can create your own distribution.
  4819. To create your own distribution, the basic steps consist of creating
  4820. your own distribution layer, creating your own distribution
  4821. configuration file, and then adding any needed code and Metadata to the
  4822. layer. The following steps provide some more detail:
  4823. - *Create a layer for your new distro:* Create your distribution layer
  4824. so that you can keep your Metadata and code for the distribution
  4825. separate. It is strongly recommended that you create and use your own
  4826. layer for configuration and code. Using your own layer as compared to
  4827. just placing configurations in a ``local.conf`` configuration file
  4828. makes it easier to reproduce the same build configuration when using
  4829. multiple build machines. See the
  4830. ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
  4831. section for information on how to quickly set up a layer.
  4832. - *Create the distribution configuration file:* The distribution
  4833. configuration file needs to be created in the ``conf/distro``
  4834. directory of your layer. You need to name it using your distribution
  4835. name (e.g. ``mydistro.conf``).
  4836. .. note::
  4837. The :term:`DISTRO` variable in your ``local.conf`` file determines the
  4838. name of your distribution.
  4839. You can split out parts of your configuration file into include files
  4840. and then "require" them from within your distribution configuration
  4841. file. Be sure to place the include files in the
  4842. ``conf/distro/include`` directory of your layer. A common example
  4843. usage of include files would be to separate out the selection of
  4844. desired version and revisions for individual recipes.
  4845. Your configuration file needs to set the following required
  4846. variables:
  4847. - :term:`DISTRO_NAME`
  4848. - :term:`DISTRO_VERSION`
  4849. These following variables are optional and you typically set them
  4850. from the distribution configuration file:
  4851. - :term:`DISTRO_FEATURES`
  4852. - :term:`DISTRO_EXTRA_RDEPENDS`
  4853. - :term:`DISTRO_EXTRA_RRECOMMENDS`
  4854. - :term:`TCLIBC`
  4855. .. tip::
  4856. If you want to base your distribution configuration file on the
  4857. very basic configuration from OE-Core, you can use
  4858. ``conf/distro/defaultsetup.conf`` as a reference and just include
  4859. variables that differ as compared to ``defaultsetup.conf``.
  4860. Alternatively, you can create a distribution configuration file
  4861. from scratch using the ``defaultsetup.conf`` file or configuration files
  4862. from other distributions such as Poky or Angstrom as references.
  4863. - *Provide miscellaneous variables:* Be sure to define any other
  4864. variables for which you want to create a default or enforce as part
  4865. of the distribution configuration. You can include nearly any
  4866. variable from the ``local.conf`` file. The variables you use are not
  4867. limited to the list in the previous bulleted item.
  4868. - *Point to Your distribution configuration file:* In your
  4869. ``local.conf`` file in the :term:`Build Directory`,
  4870. set your
  4871. :term:`DISTRO` variable to point to
  4872. your distribution's configuration file. For example, if your
  4873. distribution's configuration file is named ``mydistro.conf``, then
  4874. you point to it as follows:
  4875. ::
  4876. DISTRO = "mydistro"
  4877. - *Add more to the layer if necessary:* Use your layer to hold other
  4878. information needed for the distribution:
  4879. - Add recipes for installing distro-specific configuration files
  4880. that are not already installed by another recipe. If you have
  4881. distro-specific configuration files that are included by an
  4882. existing recipe, you should add an append file (``.bbappend``) for
  4883. those. For general information and recommendations on how to add
  4884. recipes to your layer, see the "`Creating Your Own
  4885. Layer <#creating-your-own-layer>`__" and "`Following Best
  4886. Practices When Creating
  4887. Layers <#best-practices-to-follow-when-creating-layers>`__"
  4888. sections.
  4889. - Add any image recipes that are specific to your distribution.
  4890. - Add a ``psplash`` append file for a branded splash screen. For
  4891. information on append files, see the "`Using .bbappend Files in
  4892. Your Layer <#using-bbappend-files>`__" section.
  4893. - Add any other append files to make custom changes that are
  4894. specific to individual recipes.
  4895. Creating a Custom Template Configuration Directory
  4896. ==================================================
  4897. If you are producing your own customized version of the build system for
  4898. use by other users, you might want to customize the message shown by the
  4899. setup script or you might want to change the template configuration
  4900. files (i.e. ``local.conf`` and ``bblayers.conf``) that are created in a
  4901. new build directory.
  4902. The OpenEmbedded build system uses the environment variable
  4903. ``TEMPLATECONF`` to locate the directory from which it gathers
  4904. configuration information that ultimately ends up in the
  4905. :term:`Build Directory` ``conf`` directory.
  4906. By default, ``TEMPLATECONF`` is set as follows in the ``poky``
  4907. repository:
  4908. ::
  4909. TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
  4910. This is the
  4911. directory used by the build system to find templates from which to build
  4912. some key configuration files. If you look at this directory, you will
  4913. see the ``bblayers.conf.sample``, ``local.conf.sample``, and
  4914. ``conf-notes.txt`` files. The build system uses these files to form the
  4915. respective ``bblayers.conf`` file, ``local.conf`` file, and display the
  4916. list of BitBake targets when running the setup script.
  4917. To override these default configuration files with configurations you
  4918. want used within every new Build Directory, simply set the
  4919. ``TEMPLATECONF`` variable to your directory. The ``TEMPLATECONF``
  4920. variable is set in the ``.templateconf`` file, which is in the top-level
  4921. :term:`Source Directory` folder
  4922. (e.g. ``poky``). Edit the ``.templateconf`` so that it can locate your
  4923. directory.
  4924. Best practices dictate that you should keep your template configuration
  4925. directory in your custom distribution layer. For example, suppose you
  4926. have a layer named ``meta-mylayer`` located in your home directory and
  4927. you want your template configuration directory named ``myconf``.
  4928. Changing the ``.templateconf`` as follows causes the OpenEmbedded build
  4929. system to look in your directory and base its configuration files on the
  4930. ``*.sample`` configuration files it finds. The final configuration files
  4931. (i.e. ``local.conf`` and ``bblayers.conf`` ultimately still end up in
  4932. your Build Directory, but they are based on your ``*.sample`` files.
  4933. ::
  4934. TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
  4935. Aside from the ``*.sample`` configuration files, the ``conf-notes.txt``
  4936. also resides in the default ``meta-poky/conf`` directory. The script
  4937. that sets up the build environment (i.e.
  4938. :ref:`structure-core-script`) uses this file to
  4939. display BitBake targets as part of the script output. Customizing this
  4940. ``conf-notes.txt`` file is a good way to make sure your list of custom
  4941. targets appears as part of the script's output.
  4942. Here is the default list of targets displayed as a result of running
  4943. either of the setup scripts:
  4944. ::
  4945. You can now run 'bitbake <target>'
  4946. Common targets are:
  4947. core-image-minimal
  4948. core-image-sato
  4949. meta-toolchain
  4950. meta-ide-support
  4951. Changing the listed common targets is as easy as editing your version of
  4952. ``conf-notes.txt`` in your custom template configuration directory and
  4953. making sure you have ``TEMPLATECONF`` set to your directory.
  4954. Conserving Disk Space During Builds
  4955. ===================================
  4956. To help conserve disk space during builds, you can add the following
  4957. statement to your project's ``local.conf`` configuration file found in
  4958. the :term:`Build Directory`:
  4959. ::
  4960. INHERIT += "rm_work"
  4961. Adding this statement deletes the work directory used for
  4962. building a recipe once the recipe is built. For more information on
  4963. "rm_work", see the
  4964. :ref:`rm_work <ref-classes-rm-work>` class in the
  4965. Yocto Project Reference Manual.
  4966. Working with Packages
  4967. =====================
  4968. This section describes a few tasks that involve packages:
  4969. - `Excluding packages from an
  4970. image <#excluding-packages-from-an-image>`__
  4971. - `Incrementing a binary package
  4972. version <#incrementing-a-binary-package-version>`__
  4973. - `Handling optional module
  4974. packaging <#handling-optional-module-packaging>`__
  4975. - `Using runtime package
  4976. management <#using-runtime-package-management>`__
  4977. - `Generating and using signed
  4978. packages <#generating-and-using-signed-packages>`__
  4979. - `Setting up and running package test
  4980. (ptest) <#testing-packages-with-ptest>`__
  4981. - `Creating node package manager (NPM)
  4982. packages <#creating-node-package-manager-npm-packages>`__
  4983. - `Adding custom metadata to
  4984. packages <#adding-custom-metadata-to-packages>`__
  4985. Excluding Packages from an Image
  4986. --------------------------------
  4987. You might find it necessary to prevent specific packages from being
  4988. installed into an image. If so, you can use several variables to direct
  4989. the build system to essentially ignore installing recommended packages
  4990. or to not install a package at all.
  4991. The following list introduces variables you can use to prevent packages
  4992. from being installed into your image. Each of these variables only works
  4993. with IPK and RPM package types. Support for Debian packages does not
  4994. exist. Also, you can use these variables from your ``local.conf`` file
  4995. or attach them to a specific image recipe by using a recipe name
  4996. override. For more detail on the variables, see the descriptions in the
  4997. Yocto Project Reference Manual's glossary chapter.
  4998. - :term:`BAD_RECOMMENDATIONS`:
  4999. Use this variable to specify "recommended-only" packages that you do
  5000. not want installed.
  5001. - :term:`NO_RECOMMENDATIONS`:
  5002. Use this variable to prevent all "recommended-only" packages from
  5003. being installed.
  5004. - :term:`PACKAGE_EXCLUDE`:
  5005. Use this variable to prevent specific packages from being installed
  5006. regardless of whether they are "recommended-only" or not. You need to
  5007. realize that the build process could fail with an error when you
  5008. prevent the installation of a package whose presence is required by
  5009. an installed package.
  5010. Incrementing a Package Version
  5011. ------------------------------
  5012. This section provides some background on how binary package versioning
  5013. is accomplished and presents some of the services, variables, and
  5014. terminology involved.
  5015. In order to understand binary package versioning, you need to consider
  5016. the following:
  5017. - Binary Package: The binary package that is eventually built and
  5018. installed into an image.
  5019. - Binary Package Version: The binary package version is composed of two
  5020. components - a version and a revision.
  5021. .. note::
  5022. Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved
  5023. but this discussion for the most part ignores ``PE``.
  5024. The version and revision are taken from the
  5025. :term:`PV` and
  5026. :term:`PR` variables, respectively.
  5027. - ``PV``: The recipe version. ``PV`` represents the version of the
  5028. software being packaged. Do not confuse ``PV`` with the binary
  5029. package version.
  5030. - ``PR``: The recipe revision.
  5031. - :term:`SRCPV`: The OpenEmbedded
  5032. build system uses this string to help define the value of ``PV`` when
  5033. the source code revision needs to be included in it.
  5034. - :yocto_wiki:`PR Service </PR_Service>`: A
  5035. network-based service that helps automate keeping package feeds
  5036. compatible with existing package manager applications such as RPM,
  5037. APT, and OPKG.
  5038. Whenever the binary package content changes, the binary package version
  5039. must change. Changing the binary package version is accomplished by
  5040. changing or "bumping" the ``PR`` and/or ``PV`` values. Increasing these
  5041. values occurs one of two ways:
  5042. - Automatically using a Package Revision Service (PR Service).
  5043. - Manually incrementing the ``PR`` and/or ``PV`` variables.
  5044. Given a primary challenge of any build system and its users is how to
  5045. maintain a package feed that is compatible with existing package manager
  5046. applications such as RPM, APT, and OPKG, using an automated system is
  5047. much preferred over a manual system. In either system, the main
  5048. requirement is that binary package version numbering increases in a
  5049. linear fashion and that a number of version components exist that
  5050. support that linear progression. For information on how to ensure
  5051. package revisioning remains linear, see the "`Automatically Incrementing
  5052. a Binary Package Revision
  5053. Number <#automatically-incrementing-a-binary-package-revision-number>`__"
  5054. section.
  5055. The following three sections provide related information on the PR
  5056. Service, the manual method for "bumping" ``PR`` and/or ``PV``, and on
  5057. how to ensure binary package revisioning remains linear.
  5058. Working With a PR Service
  5059. ~~~~~~~~~~~~~~~~~~~~~~~~~
  5060. As mentioned, attempting to maintain revision numbers in the
  5061. :term:`Metadata` is error prone, inaccurate,
  5062. and causes problems for people submitting recipes. Conversely, the PR
  5063. Service automatically generates increasing numbers, particularly the
  5064. revision field, which removes the human element.
  5065. .. note::
  5066. For additional information on using a PR Service, you can see the
  5067. :yocto_wiki:`PR Service </PR_Service>` wiki page.
  5068. The Yocto Project uses variables in order of decreasing priority to
  5069. facilitate revision numbering (i.e.
  5070. :term:`PE`,
  5071. :term:`PV`, and
  5072. :term:`PR` for epoch, version, and
  5073. revision, respectively). The values are highly dependent on the policies
  5074. and procedures of a given distribution and package feed.
  5075. Because the OpenEmbedded build system uses
  5076. ":ref:`signatures <overview-manual/concepts:checksums (signatures)>`", which are
  5077. unique to a given build, the build system knows when to rebuild
  5078. packages. All the inputs into a given task are represented by a
  5079. signature, which can trigger a rebuild when different. Thus, the build
  5080. system itself does not rely on the ``PR``, ``PV``, and ``PE`` numbers to
  5081. trigger a rebuild. The signatures, however, can be used to generate
  5082. these values.
  5083. The PR Service works with both ``OEBasic`` and ``OEBasicHash``
  5084. generators. The value of ``PR`` bumps when the checksum changes and the
  5085. different generator mechanisms change signatures under different
  5086. circumstances.
  5087. As implemented, the build system includes values from the PR Service
  5088. into the ``PR`` field as an addition using the form "``.x``" so ``r0``
  5089. becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing
  5090. ``PR`` values to be used for whatever reasons, which include manual
  5091. ``PR`` bumps, should it be necessary.
  5092. By default, the PR Service is not enabled or running. Thus, the packages
  5093. generated are just "self consistent". The build system adds and removes
  5094. packages and there are no guarantees about upgrade paths but images will
  5095. be consistent and correct with the latest changes.
  5096. The simplest form for a PR Service is for it to exist for a single host
  5097. development system that builds the package feed (building system). For
  5098. this scenario, you can enable a local PR Service by setting
  5099. :term:`PRSERV_HOST` in your
  5100. ``local.conf`` file in the :term:`Build Directory`:
  5101. ::
  5102. PRSERV_HOST = "localhost:0"
  5103. Once the service is started, packages will automatically
  5104. get increasing ``PR`` values and BitBake takes care of starting and
  5105. stopping the server.
  5106. If you have a more complex setup where multiple host development systems
  5107. work against a common, shared package feed, you have a single PR Service
  5108. running and it is connected to each building system. For this scenario,
  5109. you need to start the PR Service using the ``bitbake-prserv`` command:
  5110. ::
  5111. bitbake-prserv --host ip --port port --start
  5112. In addition to
  5113. hand-starting the service, you need to update the ``local.conf`` file of
  5114. each building system as described earlier so each system points to the
  5115. server and port.
  5116. It is also recommended you use build history, which adds some sanity
  5117. checks to binary package versions, in conjunction with the server that
  5118. is running the PR Service. To enable build history, add the following to
  5119. each building system's ``local.conf`` file:
  5120. ::
  5121. # It is recommended to activate "buildhistory" for testing the PR service
  5122. INHERIT += "buildhistory"
  5123. BUILDHISTORY_COMMIT = "1"
  5124. For information on build
  5125. history, see the "`Maintaining Build Output
  5126. Quality <#maintaining-build-output-quality>`__" section.
  5127. .. note::
  5128. The OpenEmbedded build system does not maintain ``PR`` information as
  5129. part of the shared state (sstate) packages. If you maintain an sstate
  5130. feed, its expected that either all your building systems that
  5131. contribute to the sstate feed use a shared PR Service, or you do not
  5132. run a PR Service on any of your building systems. Having some systems
  5133. use a PR Service while others do not leads to obvious problems.
  5134. For more information on shared state, see the
  5135. ":ref:`overview-manual/concepts:shared state cache`"
  5136. section in the Yocto Project Overview and Concepts Manual.
  5137. Manually Bumping PR
  5138. ~~~~~~~~~~~~~~~~~~~
  5139. The alternative to setting up a PR Service is to manually "bump" the
  5140. :term:`PR` variable.
  5141. If a committed change results in changing the package output, then the
  5142. value of the PR variable needs to be increased (or "bumped") as part of
  5143. that commit. For new recipes you should add the ``PR`` variable and set
  5144. its initial value equal to "r0", which is the default. Even though the
  5145. default value is "r0", the practice of adding it to a new recipe makes
  5146. it harder to forget to bump the variable when you make changes to the
  5147. recipe in future.
  5148. If you are sharing a common ``.inc`` file with multiple recipes, you can
  5149. also use the ``INC_PR`` variable to ensure that the recipes sharing the
  5150. ``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The
  5151. ``.inc`` file must set ``INC_PR`` (initially to "r0"), and all recipes
  5152. referring to it should set ``PR`` to "${INC_PR}.0" initially,
  5153. incrementing the last number when the recipe is changed. If the ``.inc``
  5154. file is changed then its ``INC_PR`` should be incremented.
  5155. When upgrading the version of a binary package, assuming the ``PV``
  5156. changes, the ``PR`` variable should be reset to "r0" (or "${INC_PR}.0"
  5157. if you are using ``INC_PR``).
  5158. Usually, version increases occur only to binary packages. However, if
  5159. for some reason ``PV`` changes but does not increase, you can increase
  5160. the ``PE`` variable (Package Epoch). The ``PE`` variable defaults to
  5161. "0".
  5162. Binary package version numbering strives to follow the `Debian Version
  5163. Field Policy
  5164. Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__.
  5165. These guidelines define how versions are compared and what "increasing"
  5166. a version means.
  5167. Automatically Incrementing a Package Version Number
  5168. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5169. When fetching a repository, BitBake uses the
  5170. :term:`SRCREV` variable to determine
  5171. the specific source code revision from which to build. You set the
  5172. ``SRCREV`` variable to
  5173. :term:`AUTOREV` to cause the
  5174. OpenEmbedded build system to automatically use the latest revision of
  5175. the software:
  5176. ::
  5177. SRCREV = "${AUTOREV}"
  5178. Furthermore, you need to reference ``SRCPV`` in ``PV`` in order to
  5179. automatically update the version whenever the revision of the source
  5180. code changes. Here is an example:
  5181. ::
  5182. PV = "1.0+git${SRCPV}"
  5183. The OpenEmbedded build system substitutes ``SRCPV`` with the following:
  5184. .. code-block:: none
  5185. AUTOINC+source_code_revision
  5186. The build system replaces the ``AUTOINC``
  5187. with a number. The number used depends on the state of the PR Service:
  5188. - If PR Service is enabled, the build system increments the number,
  5189. which is similar to the behavior of
  5190. :term:`PR`. This behavior results in
  5191. linearly increasing package versions, which is desirable. Here is an
  5192. example:
  5193. .. code-block:: none
  5194. hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
  5195. hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
  5196. - If PR Service is not enabled, the build system replaces the
  5197. ``AUTOINC`` placeholder with zero (i.e. "0"). This results in
  5198. changing the package version since the source revision is included.
  5199. However, package versions are not increased linearly. Here is an
  5200. example:
  5201. .. code-block:: none
  5202. hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
  5203. hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
  5204. In summary, the OpenEmbedded build system does not track the history of
  5205. binary package versions for this purpose. ``AUTOINC``, in this case, is
  5206. comparable to ``PR``. If PR server is not enabled, ``AUTOINC`` in the
  5207. package version is simply replaced by "0". If PR server is enabled, the
  5208. build system keeps track of the package versions and bumps the number
  5209. when the package revision changes.
  5210. Handling Optional Module Packaging
  5211. ----------------------------------
  5212. Many pieces of software split functionality into optional modules (or
  5213. plugins) and the plugins that are built might depend on configuration
  5214. options. To avoid having to duplicate the logic that determines what
  5215. modules are available in your recipe or to avoid having to package each
  5216. module by hand, the OpenEmbedded build system provides functionality to
  5217. handle module packaging dynamically.
  5218. To handle optional module packaging, you need to do two things:
  5219. - Ensure the module packaging is actually done.
  5220. - Ensure that any dependencies on optional modules from other recipes
  5221. are satisfied by your recipe.
  5222. Making Sure the Packaging is Done
  5223. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5224. To ensure the module packaging actually gets done, you use the
  5225. ``do_split_packages`` function within the ``populate_packages`` Python
  5226. function in your recipe. The ``do_split_packages`` function searches for
  5227. a pattern of files or directories under a specified path and creates a
  5228. package for each one it finds by appending to the
  5229. :term:`PACKAGES` variable and
  5230. setting the appropriate values for ``FILES_packagename``,
  5231. ``RDEPENDS_packagename``, ``DESCRIPTION_packagename``, and so forth.
  5232. Here is an example from the ``lighttpd`` recipe:
  5233. ::
  5234. python populate_packages_prepend () {
  5235. lighttpd_libdir = d.expand('${libdir}')
  5236. do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$',
  5237. 'lighttpd-module-%s', 'Lighttpd module for %s',
  5238. extra_depends='')
  5239. }
  5240. The previous example specifies a number of things in the call to
  5241. ``do_split_packages``.
  5242. - A directory within the files installed by your recipe through
  5243. ``do_install`` in which to search.
  5244. - A regular expression used to match module files in that directory. In
  5245. the example, note the parentheses () that mark the part of the
  5246. expression from which the module name should be derived.
  5247. - A pattern to use for the package names.
  5248. - A description for each package.
  5249. - An empty string for ``extra_depends``, which disables the default
  5250. dependency on the main ``lighttpd`` package. Thus, if a file in
  5251. ``${libdir}`` called ``mod_alias.so`` is found, a package called
  5252. ``lighttpd-module-alias`` is created for it and the
  5253. :term:`DESCRIPTION` is set to
  5254. "Lighttpd module for alias".
  5255. Often, packaging modules is as simple as the previous example. However,
  5256. more advanced options exist that you can use within
  5257. ``do_split_packages`` to modify its behavior. And, if you need to, you
  5258. can add more logic by specifying a hook function that is called for each
  5259. package. It is also perfectly acceptable to call ``do_split_packages``
  5260. multiple times if you have more than one set of modules to package.
  5261. For more examples that show how to use ``do_split_packages``, see the
  5262. ``connman.inc`` file in the ``meta/recipes-connectivity/connman/``
  5263. directory of the ``poky`` :ref:`source repository <overview-manual/development-environment:yocto project source repositories>`. You can
  5264. also find examples in ``meta/classes/kernel.bbclass``.
  5265. Following is a reference that shows ``do_split_packages`` mandatory and
  5266. optional arguments:
  5267. ::
  5268. Mandatory arguments
  5269. root
  5270. The path in which to search
  5271. file_regex
  5272. Regular expression to match searched files.
  5273. Use parentheses () to mark the part of this
  5274. expression that should be used to derive the
  5275. module name (to be substituted where %s is
  5276. used in other function arguments as noted below)
  5277. output_pattern
  5278. Pattern to use for the package names. Must
  5279. include %s.
  5280. description
  5281. Description to set for each package. Must
  5282. include %s.
  5283. Optional arguments
  5284. postinst
  5285. Postinstall script to use for all packages
  5286. (as a string)
  5287. recursive
  5288. True to perform a recursive search - default
  5289. False
  5290. hook
  5291. A hook function to be called for every match.
  5292. The function will be called with the following
  5293. arguments (in the order listed):
  5294. f
  5295. Full path to the file/directory match
  5296. pkg
  5297. The package name
  5298. file_regex
  5299. As above
  5300. output_pattern
  5301. As above
  5302. modulename
  5303. The module name derived using file_regex
  5304. extra_depends
  5305. Extra runtime dependencies (RDEPENDS) to be
  5306. set for all packages. The default value of None
  5307. causes a dependency on the main package
  5308. (${PN}) - if you do not want this, pass empty
  5309. string '' for this parameter.
  5310. aux_files_pattern
  5311. Extra item(s) to be added to FILES for each
  5312. package. Can be a single string item or a list
  5313. of strings for multiple items. Must include %s.
  5314. postrm
  5315. postrm script to use for all packages (as a
  5316. string)
  5317. allow_dirs
  5318. True to allow directories to be matched -
  5319. default False
  5320. prepend
  5321. If True, prepend created packages to PACKAGES
  5322. instead of the default False which appends them
  5323. match_path
  5324. match file_regex on the whole relative path to
  5325. the root rather than just the file name
  5326. aux_files_pattern_verbatim
  5327. Extra item(s) to be added to FILES for each
  5328. package, using the actual derived module name
  5329. rather than converting it to something legal
  5330. for a package name. Can be a single string item
  5331. or a list of strings for multiple items. Must
  5332. include %s.
  5333. allow_links
  5334. True to allow symlinks to be matched - default
  5335. False
  5336. summary
  5337. Summary to set for each package. Must include %s;
  5338. defaults to description if not set.
  5339. Satisfying Dependencies
  5340. ~~~~~~~~~~~~~~~~~~~~~~~
  5341. The second part for handling optional module packaging is to ensure that
  5342. any dependencies on optional modules from other recipes are satisfied by
  5343. your recipe. You can be sure these dependencies are satisfied by using
  5344. the :term:`PACKAGES_DYNAMIC`
  5345. variable. Here is an example that continues with the ``lighttpd`` recipe
  5346. shown earlier:
  5347. ::
  5348. PACKAGES_DYNAMIC = "lighttpd-module-.*"
  5349. The name
  5350. specified in the regular expression can of course be anything. In this
  5351. example, it is ``lighttpd-module-`` and is specified as the prefix to
  5352. ensure that any :term:`RDEPENDS` and
  5353. :term:`RRECOMMENDS` on a package
  5354. name starting with the prefix are satisfied during build time. If you
  5355. are using ``do_split_packages`` as described in the previous section,
  5356. the value you put in ``PACKAGES_DYNAMIC`` should correspond to the name
  5357. pattern specified in the call to ``do_split_packages``.
  5358. Using Runtime Package Management
  5359. --------------------------------
  5360. During a build, BitBake always transforms a recipe into one or more
  5361. packages. For example, BitBake takes the ``bash`` recipe and produces a
  5362. number of packages (e.g. ``bash``, ``bash-bashbug``,
  5363. ``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``,
  5364. ``bash-completion-extra``, ``bash-dbg``, and so forth). Not all
  5365. generated packages are included in an image.
  5366. In several situations, you might need to update, add, remove, or query
  5367. the packages on a target device at runtime (i.e. without having to
  5368. generate a new image). Examples of such situations include:
  5369. - You want to provide in-the-field updates to deployed devices (e.g.
  5370. security updates).
  5371. - You want to have a fast turn-around development cycle for one or more
  5372. applications that run on your device.
  5373. - You want to temporarily install the "debug" packages of various
  5374. applications on your device so that debugging can be greatly improved
  5375. by allowing access to symbols and source debugging.
  5376. - You want to deploy a more minimal package selection of your device
  5377. but allow in-the-field updates to add a larger selection for
  5378. customization.
  5379. In all these situations, you have something similar to a more
  5380. traditional Linux distribution in that in-field devices are able to
  5381. receive pre-compiled packages from a server for installation or update.
  5382. Being able to install these packages on a running, in-field device is
  5383. what is termed "runtime package management".
  5384. In order to use runtime package management, you need a host or server
  5385. machine that serves up the pre-compiled packages plus the required
  5386. metadata. You also need package manipulation tools on the target. The
  5387. build machine is a likely candidate to act as the server. However, that
  5388. machine does not necessarily have to be the package server. The build
  5389. machine could push its artifacts to another machine that acts as the
  5390. server (e.g. Internet-facing). In fact, doing so is advantageous for a
  5391. production environment as getting the packages away from the development
  5392. system's build directory prevents accidental overwrites.
  5393. A simple build that targets just one device produces more than one
  5394. package database. In other words, the packages produced by a build are
  5395. separated out into a couple of different package groupings based on
  5396. criteria such as the target's CPU architecture, the target board, or the
  5397. C library used on the target. For example, a build targeting the
  5398. ``qemux86`` device produces the following three package databases:
  5399. ``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86``
  5400. device to be aware of all the packages that were available to it, you
  5401. would need to point it to each of these databases individually. In a
  5402. similar way, a traditional Linux distribution usually is configured to
  5403. be aware of a number of software repositories from which it retrieves
  5404. packages.
  5405. Using runtime package management is completely optional and not required
  5406. for a successful build or deployment in any way. But if you want to make
  5407. use of runtime package management, you need to do a couple things above
  5408. and beyond the basics. The remainder of this section describes what you
  5409. need to do.
  5410. Build Considerations
  5411. ~~~~~~~~~~~~~~~~~~~~
  5412. This section describes build considerations of which you need to be
  5413. aware in order to provide support for runtime package management.
  5414. When BitBake generates packages, it needs to know what format or formats
  5415. to use. In your configuration, you use the
  5416. :term:`PACKAGE_CLASSES`
  5417. variable to specify the format:
  5418. 1. Open the ``local.conf`` file inside your
  5419. :term:`Build Directory` (e.g.
  5420. ``~/poky/build/conf/local.conf``).
  5421. 2. Select the desired package format as follows:
  5422. ::
  5423. PACKAGE_CLASSES ?= "package_packageformat"
  5424. where packageformat can be "ipk", "rpm",
  5425. "deb", or "tar" which are the supported package formats.
  5426. .. note::
  5427. Because the Yocto Project supports four different package formats,
  5428. you can set the variable with more than one argument. However, the
  5429. OpenEmbedded build system only uses the first argument when
  5430. creating an image or Software Development Kit (SDK).
  5431. If you would like your image to start off with a basic package database
  5432. containing the packages in your current build as well as to have the
  5433. relevant tools available on the target for runtime package management,
  5434. you can include "package-management" in the
  5435. :term:`IMAGE_FEATURES`
  5436. variable. Including "package-management" in this configuration variable
  5437. ensures that when the image is assembled for your target, the image
  5438. includes the currently-known package databases as well as the
  5439. target-specific tools required for runtime package management to be
  5440. performed on the target. However, this is not strictly necessary. You
  5441. could start your image off without any databases but only include the
  5442. required on-target package tool(s). As an example, you could include
  5443. "opkg" in your
  5444. :term:`IMAGE_INSTALL` variable
  5445. if you are using the IPK package format. You can then initialize your
  5446. target's package database(s) later once your image is up and running.
  5447. Whenever you perform any sort of build step that can potentially
  5448. generate a package or modify existing package, it is always a good idea
  5449. to re-generate the package index after the build by using the following
  5450. command:
  5451. ::
  5452. $ bitbake package-index
  5453. It might be tempting to build the
  5454. package and the package index at the same time with a command such as
  5455. the following:
  5456. ::
  5457. $ bitbake some-package package-index
  5458. Do not do this as
  5459. BitBake does not schedule the package index for after the completion of
  5460. the package you are building. Consequently, you cannot be sure of the
  5461. package index including information for the package you just built.
  5462. Thus, be sure to run the package update step separately after building
  5463. any packages.
  5464. You can use the
  5465. :term:`PACKAGE_FEED_ARCHS`,
  5466. :term:`PACKAGE_FEED_BASE_PATHS`,
  5467. and
  5468. :term:`PACKAGE_FEED_URIS`
  5469. variables to pre-configure target images to use a package feed. If you
  5470. do not define these variables, then manual steps as described in the
  5471. subsequent sections are necessary to configure the target. You should
  5472. set these variables before building the image in order to produce a
  5473. correctly configured image.
  5474. When your build is complete, your packages reside in the
  5475. ``${TMPDIR}/deploy/packageformat`` directory. For example, if
  5476. ``${``\ :term:`TMPDIR`\ ``}`` is
  5477. ``tmp`` and your selected package type is RPM, then your RPM packages
  5478. are available in ``tmp/deploy/rpm``.
  5479. Host or Server Machine Setup
  5480. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5481. Although other protocols are possible, a server using HTTP typically
  5482. serves packages. If you want to use HTTP, then set up and configure a
  5483. web server such as Apache 2, lighttpd, or Python web server on the
  5484. machine serving the packages.
  5485. To keep things simple, this section describes how to set up a
  5486. Python web server to share package feeds from the developer's
  5487. machine. Although this server might not be the best for a production
  5488. environment, the setup is simple and straight forward. Should you want
  5489. to use a different server more suited for production (e.g. Apache 2,
  5490. Lighttpd, or Nginx), take the appropriate steps to do so.
  5491. From within the build directory where you have built an image based on
  5492. your packaging choice (i.e. the
  5493. :term:`PACKAGE_CLASSES`
  5494. setting), simply start the server. The following example assumes a build
  5495. directory of ``~/poky/build/tmp/deploy/rpm`` and a ``PACKAGE_CLASSES``
  5496. setting of "package_rpm":
  5497. ::
  5498. $ cd ~/poky/build/tmp/deploy/rpm
  5499. $ python3 -m http.server
  5500. Target Setup
  5501. ~~~~~~~~~~~~
  5502. Setting up the target differs depending on the package management
  5503. system. This section provides information for RPM, IPK, and DEB.
  5504. Using RPM
  5505. ^^^^^^^^^
  5506. The `Dandified Packaging
  5507. Tool <https://en.wikipedia.org/wiki/DNF_(software)>`__ (DNF) performs
  5508. runtime package management of RPM packages. In order to use DNF for
  5509. runtime package management, you must perform an initial setup on the
  5510. target machine for cases where the ``PACKAGE_FEED_*`` variables were not
  5511. set as part of the image that is running on the target. This means if
  5512. you built your image and did not not use these variables as part of the
  5513. build and your image is now running on the target, you need to perform
  5514. the steps in this section if you want to use runtime package management.
  5515. .. note::
  5516. For information on the ``PACKAGE_FEED_*`` variables, see
  5517. :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and
  5518. :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables
  5519. glossary.
  5520. On the target, you must inform DNF that package databases are available.
  5521. You do this by creating a file named
  5522. ``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``.
  5523. As an example, assume the target is able to use the following package
  5524. databases: ``all``, ``i586``, and ``qemux86`` from a server named
  5525. ``my.server``. The specifics for setting up the web server are up to
  5526. you. The critical requirement is that the URIs in the target repository
  5527. configuration point to the correct remote location for the feeds.
  5528. .. note::
  5529. For development purposes, you can point the web server to the build
  5530. system's ``deploy`` directory. However, for production use, it is better to
  5531. copy the package directories to a location outside of the build area and use
  5532. that location. Doing so avoids situations where the build system
  5533. overwrites or changes the ``deploy`` directory.
  5534. When telling DNF where to look for the package databases, you must
  5535. declare individual locations per architecture or a single location used
  5536. for all architectures. You cannot do both:
  5537. - *Create an Explicit List of Architectures:* Define individual base
  5538. URLs to identify where each package database is located:
  5539. .. code-block:: none
  5540. [oe-packages]
  5541. baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
  5542. This example
  5543. informs DNF about individual package databases for all three
  5544. architectures.
  5545. - *Create a Single (Full) Package Index:* Define a single base URL that
  5546. identifies where a full package database is located:
  5547. ::
  5548. [oe-packages]
  5549. baseurl=http://my.server/rpm
  5550. This example informs DNF about a single
  5551. package database that contains all the package index information for
  5552. all supported architectures.
  5553. Once you have informed DNF where to find the package databases, you need
  5554. to fetch them:
  5555. .. code-block:: none
  5556. # dnf makecache
  5557. DNF is now able to find, install, and
  5558. upgrade packages from the specified repository or repositories.
  5559. .. note::
  5560. See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for
  5561. additional information.
  5562. Using IPK
  5563. ^^^^^^^^^
  5564. The ``opkg`` application performs runtime package management of IPK
  5565. packages. You must perform an initial setup for ``opkg`` on the target
  5566. machine if the
  5567. :term:`PACKAGE_FEED_ARCHS`,
  5568. :term:`PACKAGE_FEED_BASE_PATHS`,
  5569. and
  5570. :term:`PACKAGE_FEED_URIS`
  5571. variables have not been set or the target image was built before the
  5572. variables were set.
  5573. The ``opkg`` application uses configuration files to find available
  5574. package databases. Thus, you need to create a configuration file inside
  5575. the ``/etc/opkg/`` direction, which informs ``opkg`` of any repository
  5576. you want to use.
  5577. As an example, suppose you are serving packages from a ``ipk/``
  5578. directory containing the ``i586``, ``all``, and ``qemux86`` databases
  5579. through an HTTP server named ``my.server``. On the target, create a
  5580. configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/``
  5581. directory containing the following:
  5582. .. code-block:: none
  5583. src/gz all http://my.server/ipk/all
  5584. src/gz i586 http://my.server/ipk/i586
  5585. src/gz qemux86 http://my.server/ipk/qemux86
  5586. Next, instruct ``opkg`` to fetch the
  5587. repository information:
  5588. .. code-block:: none
  5589. # opkg update
  5590. The ``opkg`` application is now able to find, install, and upgrade packages
  5591. from the specified repository.
  5592. Using DEB
  5593. ^^^^^^^^^
  5594. The ``apt`` application performs runtime package management of DEB
  5595. packages. This application uses a source list file to find available
  5596. package databases. You must perform an initial setup for ``apt`` on the
  5597. target machine if the
  5598. :term:`PACKAGE_FEED_ARCHS`,
  5599. :term:`PACKAGE_FEED_BASE_PATHS`,
  5600. and
  5601. :term:`PACKAGE_FEED_URIS`
  5602. variables have not been set or the target image was built before the
  5603. variables were set.
  5604. To inform ``apt`` of the repository you want to use, you might create a
  5605. list file (e.g. ``my_repo.list``) inside the
  5606. ``/etc/apt/sources.list.d/`` directory. As an example, suppose you are
  5607. serving packages from a ``deb/`` directory containing the ``i586``,
  5608. ``all``, and ``qemux86`` databases through an HTTP server named
  5609. ``my.server``. The list file should contain:
  5610. .. code-block:: none
  5611. deb http://my.server/deb/all ./
  5612. deb http://my.server/deb/i586 ./
  5613. deb http://my.server/deb/qemux86 ./
  5614. Next, instruct the ``apt`` application
  5615. to fetch the repository information:
  5616. .. code-block:: none
  5617. # apt-get update
  5618. After this step,
  5619. ``apt`` is able to find, install, and upgrade packages from the
  5620. specified repository.
  5621. Generating and Using Signed Packages
  5622. ------------------------------------
  5623. In order to add security to RPM packages used during a build, you can
  5624. take steps to securely sign them. Once a signature is verified, the
  5625. OpenEmbedded build system can use the package in the build. If security
  5626. fails for a signed package, the build system aborts the build.
  5627. This section describes how to sign RPM packages during a build and how
  5628. to use signed package feeds (repositories) when doing a build.
  5629. Signing RPM Packages
  5630. ~~~~~~~~~~~~~~~~~~~~
  5631. To enable signing RPM packages, you must set up the following
  5632. configurations in either your ``local.config`` or ``distro.config``
  5633. file:
  5634. ::
  5635. # Inherit sign_rpm.bbclass to enable signing functionality
  5636. INHERIT += " sign_rpm"
  5637. # Define the GPG key that will be used for signing.
  5638. RPM_GPG_NAME = "key_name"
  5639. # Provide passphrase for the key
  5640. RPM_GPG_PASSPHRASE = "passphrase"
  5641. .. note::
  5642. Be sure to supply appropriate values for both `key_name` and
  5643. `passphrase`.
  5644. Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in
  5645. the previous example, two optional variables related to signing exist:
  5646. - *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed
  5647. when the package is signed.
  5648. - *GPG_PATH:* Specifies the ``gpg`` home directory used when the
  5649. package is signed.
  5650. Processing Package Feeds
  5651. ~~~~~~~~~~~~~~~~~~~~~~~~
  5652. In addition to being able to sign RPM packages, you can also enable
  5653. signed package feeds for IPK and RPM packages.
  5654. The steps you need to take to enable signed package feed use are similar
  5655. to the steps used to sign RPM packages. You must define the following in
  5656. your ``local.config`` or ``distro.config`` file:
  5657. ::
  5658. INHERIT += "sign_package_feed"
  5659. PACKAGE_FEED_GPG_NAME = "key_name"
  5660. PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase"
  5661. For signed package feeds, the passphrase must exist in a separate file,
  5662. which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE``
  5663. variable. Regarding security, keeping a plain text passphrase out of the
  5664. configuration is more secure.
  5665. Aside from the ``PACKAGE_FEED_GPG_NAME`` and
  5666. ``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables
  5667. related to signed package feeds exist:
  5668. - *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed
  5669. when the package is signed.
  5670. - *GPG_PATH:* Specifies the ``gpg`` home directory used when the
  5671. package is signed.
  5672. - *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg``
  5673. signature. This variable applies only to RPM and IPK package feeds.
  5674. Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are
  5675. "ASC", which is the default and specifies ascii armored, and "BIN",
  5676. which specifies binary.
  5677. Testing Packages With ptest
  5678. ---------------------------
  5679. A Package Test (ptest) runs tests against packages built by the
  5680. OpenEmbedded build system on the target machine. A ptest contains at
  5681. least two items: the actual test, and a shell script (``run-ptest``)
  5682. that starts the test. The shell script that starts the test must not
  5683. contain the actual test - the script only starts the test. On the other
  5684. hand, the test can be anything from a simple shell script that runs a
  5685. binary and checks the output to an elaborate system of test binaries and
  5686. data files.
  5687. The test generates output in the format used by Automake:
  5688. ::
  5689. result: testname
  5690. where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and
  5691. the testname can be any identifying string.
  5692. For a list of Yocto Project recipes that are already enabled with ptest,
  5693. see the :yocto_wiki:`Ptest </Ptest>` wiki page.
  5694. .. note::
  5695. A recipe is "ptest-enabled" if it inherits the
  5696. :ref:`ptest <ref-classes-ptest>` class.
  5697. Adding ptest to Your Build
  5698. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  5699. To add package testing to your build, add the
  5700. :term:`DISTRO_FEATURES` and
  5701. :term:`EXTRA_IMAGE_FEATURES`
  5702. variables to your ``local.conf`` file, which is found in the
  5703. :term:`Build Directory`:
  5704. ::
  5705. DISTRO_FEATURES_append = " ptest"
  5706. EXTRA_IMAGE_FEATURES += "ptest-pkgs"
  5707. Once your build is complete, the ptest files are installed into the
  5708. ``/usr/lib/package/ptest`` directory within the image, where ``package``
  5709. is the name of the package.
  5710. Running ptest
  5711. ~~~~~~~~~~~~~
  5712. The ``ptest-runner`` package installs a shell script that loops through
  5713. all installed ptest test suites and runs them in sequence. Consequently,
  5714. you might want to add this package to your image.
  5715. Getting Your Package Ready
  5716. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  5717. In order to enable a recipe to run installed ptests on target hardware,
  5718. you need to prepare the recipes that build the packages you want to
  5719. test. Here is what you have to do for each recipe:
  5720. - *Be sure the recipe inherits
  5721. the* :ref:`ptest <ref-classes-ptest>` *class:*
  5722. Include the following line in each recipe:
  5723. ::
  5724. inherit ptest
  5725. - *Create run-ptest:* This script starts your test. Locate the
  5726. script where you will refer to it using
  5727. :term:`SRC_URI`. Here is an
  5728. example that starts a test for ``dbus``:
  5729. ::
  5730. #!/bin/sh
  5731. cd test
  5732. make -k runtest-TESTS
  5733. - *Ensure dependencies are met:* If the test adds build or runtime
  5734. dependencies that normally do not exist for the package (such as
  5735. requiring "make" to run the test suite), use the
  5736. :term:`DEPENDS` and
  5737. :term:`RDEPENDS` variables in
  5738. your recipe in order for the package to meet the dependencies. Here
  5739. is an example where the package has a runtime dependency on "make":
  5740. ::
  5741. RDEPENDS_${PN}-ptest += "make"
  5742. - *Add a function to build the test suite:* Not many packages support
  5743. cross-compilation of their test suites. Consequently, you usually
  5744. need to add a cross-compilation function to the package.
  5745. Many packages based on Automake compile and run the test suite by
  5746. using a single command such as ``make check``. However, the host
  5747. ``make check`` builds and runs on the same computer, while
  5748. cross-compiling requires that the package is built on the host but
  5749. executed for the target architecture (though often, as in the case
  5750. for ptest, the execution occurs on the host). The built version of
  5751. Automake that ships with the Yocto Project includes a patch that
  5752. separates building and execution. Consequently, packages that use the
  5753. unaltered, patched version of ``make check`` automatically
  5754. cross-compiles.
  5755. Regardless, you still must add a ``do_compile_ptest`` function to
  5756. build the test suite. Add a function similar to the following to your
  5757. recipe:
  5758. ::
  5759. do_compile_ptest() {
  5760. oe_runmake buildtest-TESTS
  5761. }
  5762. - *Ensure special configurations are set:* If the package requires
  5763. special configurations prior to compiling the test code, you must
  5764. insert a ``do_configure_ptest`` function into the recipe.
  5765. - *Install the test suite:* The ``ptest`` class automatically copies
  5766. the file ``run-ptest`` to the target and then runs make
  5767. ``install-ptest`` to run the tests. If this is not enough, you need
  5768. to create a ``do_install_ptest`` function and make sure it gets
  5769. called after the "make install-ptest" completes.
  5770. Creating Node Package Manager (NPM) Packages
  5771. --------------------------------------------
  5772. `NPM <https://en.wikipedia.org/wiki/Npm_(software)>`__ is a package
  5773. manager for the JavaScript programming language. The Yocto Project
  5774. supports the NPM :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>`. You can
  5775. use this fetcher in combination with
  5776. :doc:`devtool </ref-manual/devtool-reference>` to create
  5777. recipes that produce NPM packages.
  5778. Two workflows exist that allow you to create NPM packages using
  5779. ``devtool``: the NPM registry modules method and the NPM project code
  5780. method.
  5781. .. note::
  5782. While it is possible to create NPM recipes manually, using
  5783. ``devtool`` is far simpler.
  5784. Additionally, some requirements and caveats exist.
  5785. Requirements and Caveats
  5786. ~~~~~~~~~~~~~~~~~~~~~~~~
  5787. You need to be aware of the following before using ``devtool`` to create
  5788. NPM packages:
  5789. - Of the two methods that you can use ``devtool`` to create NPM
  5790. packages, the registry approach is slightly simpler. However, you
  5791. might consider the project approach because you do not have to
  5792. publish your module in the NPM registry
  5793. (`npm-registry <https://docs.npmjs.com/misc/registry>`_), which
  5794. is NPM's public registry.
  5795. - Be familiar with
  5796. :doc:`devtool </ref-manual/devtool-reference>`.
  5797. - The NPM host tools need the native ``nodejs-npm`` package, which is
  5798. part of the OpenEmbedded environment. You need to get the package by
  5799. cloning the https://github.com/openembedded/meta-openembedded
  5800. repository out of GitHub. Be sure to add the path to your local copy
  5801. to your ``bblayers.conf`` file.
  5802. - ``devtool`` cannot detect native libraries in module dependencies.
  5803. Consequently, you must manually add packages to your recipe.
  5804. - While deploying NPM packages, ``devtool`` cannot determine which
  5805. dependent packages are missing on the target (e.g. the node runtime
  5806. ``nodejs``). Consequently, you need to find out what files are
  5807. missing and be sure they are on the target.
  5808. - Although you might not need NPM to run your node package, it is
  5809. useful to have NPM on your target. The NPM package name is
  5810. ``nodejs-npm``.
  5811. Using the Registry Modules Method
  5812. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5813. This section presents an example that uses the ``cute-files`` module,
  5814. which is a file browser web application.
  5815. .. note::
  5816. You must know the ``cute-files`` module version.
  5817. The first thing you need to do is use ``devtool`` and the NPM fetcher to
  5818. create the recipe:
  5819. ::
  5820. $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2"
  5821. The
  5822. ``devtool add`` command runs ``recipetool create`` and uses the same
  5823. fetch URI to download each dependency and capture license details where
  5824. possible. The result is a generated recipe.
  5825. The recipe file is fairly simple and contains every license that
  5826. ``recipetool`` finds and includes the licenses in the recipe's
  5827. :term:`LIC_FILES_CHKSUM`
  5828. variables. You need to examine the variables and look for those with
  5829. "unknown" in the :term:`LICENSE`
  5830. field. You need to track down the license information for "unknown"
  5831. modules and manually add the information to the recipe.
  5832. ``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap
  5833. files capture the version of all dependent modules. Many packages do not
  5834. provide shrinkwrap files. ``recipetool`` create a shrinkwrap file as it
  5835. runs.
  5836. .. note::
  5837. A package is created for each sub-module. This policy is the only
  5838. practical way to have the licenses for all of the dependencies
  5839. represented in the license manifest of the image.
  5840. The ``devtool edit-recipe`` command lets you take a look at the recipe:
  5841. ::
  5842. $ devtool edit-recipe cute-files
  5843. SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
  5844. LICENSE = "MIT & ISC & Unknown"
  5845. LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
  5846. file://node_modules/toidentifier/LICENSE;md5=1a261071a044d02eb6f2bb47f51a3502 \
  5847. file://node_modules/debug/LICENSE;md5=ddd815a475e7338b0be7a14d8ee35a99 \
  5848. ...
  5849. SRC_URI = " \
  5850. npm://registry.npmjs.org/;package=cute-files;version=${PV} \
  5851. npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
  5852. "
  5853. S = "${WORKDIR}/npm"
  5854. inherit npm LICENSE_${PN} = "MIT"
  5855. LICENSE_${PN}-accepts = "MIT"
  5856. LICENSE_${PN}-array-flatten = "MIT"
  5857. ...
  5858. LICENSE_${PN}-vary = "MIT"
  5859. Three key points exist in the previous example:
  5860. - :term:`SRC_URI` uses the NPM
  5861. scheme so that the NPM fetcher is used.
  5862. - ``recipetool`` collects all the license information. If a
  5863. sub-module's license is unavailable, the sub-module's name appears in
  5864. the comments.
  5865. - The ``inherit npm`` statement causes the
  5866. :ref:`npm <ref-classes-npm>` class to package
  5867. up all the modules.
  5868. You can run the following command to build the ``cute-files`` package:
  5869. ::
  5870. $ devtool build cute-files
  5871. Remember that ``nodejs`` must be installed on
  5872. the target before your package.
  5873. Assuming 192.168.7.2 for the target's IP address, use the following
  5874. command to deploy your package:
  5875. ::
  5876. $ devtool deploy-target -s cute-files root@192.168.7.2
  5877. Once the package is installed on the target, you can
  5878. test the application:
  5879. .. note::
  5880. Because of a known issue, you cannot simply run ``cute-files`` as you would
  5881. if you had run ``npm install``.
  5882. ::
  5883. $ cd /usr/lib/node_modules/cute-files
  5884. $ node cute-files.js
  5885. On a browser,
  5886. go to ``http://192.168.7.2:3000`` and you see the following:
  5887. .. image:: figures/cute-files-npm-example.png
  5888. :align: center
  5889. You can find the recipe in ``workspace/recipes/cute-files``. You can use
  5890. the recipe in any layer you choose.
  5891. Using the NPM Projects Code Method
  5892. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5893. Although it is useful to package modules already in the NPM registry,
  5894. adding ``node.js`` projects under development is a more common developer
  5895. use case.
  5896. This section covers the NPM projects code method, which is very similar
  5897. to the "registry" approach described in the previous section. In the NPM
  5898. projects method, you provide ``devtool`` with an URL that points to the
  5899. source files.
  5900. Replicating the same example, (i.e. ``cute-files``) use the following
  5901. command:
  5902. ::
  5903. $ devtool add https://github.com/martinaglv/cute-files.git
  5904. The
  5905. recipe this command generates is very similar to the recipe created in
  5906. the previous section. However, the ``SRC_URI`` looks like the following:
  5907. ::
  5908. SRC_URI = " \
  5909. git://github.com/martinaglv/cute-files.git;protocol=https \
  5910. npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
  5911. "
  5912. In this example,
  5913. the main module is taken from the Git repository and dependencies are
  5914. taken from the NPM registry. Other than those differences, the recipe is
  5915. basically the same between the two methods. You can build and deploy the
  5916. package exactly as described in the previous section that uses the
  5917. registry modules method.
  5918. Adding custom metadata to packages
  5919. ----------------------------------
  5920. The variable
  5921. :term:`PACKAGE_ADD_METADATA`
  5922. can be used to add additional metadata to packages. This is reflected in
  5923. the package control/spec file. To take the ipk format for example, the
  5924. CONTROL file stored inside would contain the additional metadata as
  5925. additional lines.
  5926. The variable can be used in multiple ways, including using suffixes to
  5927. set it for a specific package type and/or package. Note that the order
  5928. of precedence is the same as this list:
  5929. - ``PACKAGE_ADD_METADATA_<PKGTYPE>_<PN>``
  5930. - ``PACKAGE_ADD_METADATA_<PKGTYPE>``
  5931. - ``PACKAGE_ADD_METADATA_<PN>``
  5932. - ``PACKAGE_ADD_METADATA``
  5933. `<PKGTYPE>` is a parameter and expected to be a distinct name of specific
  5934. package type:
  5935. - IPK for .ipk packages
  5936. - DEB for .deb packages
  5937. - RPM for .rpm packages
  5938. `<PN>` is a parameter and expected to be a package name.
  5939. The variable can contain multiple [one-line] metadata fields separated
  5940. by the literal sequence '\\n'. The separator can be redefined using the
  5941. variable flag ``separator``.
  5942. The following is an example that adds two custom fields for ipk
  5943. packages:
  5944. ::
  5945. PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets"
  5946. Efficiently Fetching Source Files During a Build
  5947. ================================================
  5948. The OpenEmbedded build system works with source files located through
  5949. the :term:`SRC_URI` variable. When
  5950. you build something using BitBake, a big part of the operation is
  5951. locating and downloading all the source tarballs. For images,
  5952. downloading all the source for various packages can take a significant
  5953. amount of time.
  5954. This section shows you how you can use mirrors to speed up fetching
  5955. source files and how you can pre-fetch files all of which leads to more
  5956. efficient use of resources and time.
  5957. Setting up Effective Mirrors
  5958. ----------------------------
  5959. A good deal that goes into a Yocto Project build is simply downloading
  5960. all of the source tarballs. Maybe you have been working with another
  5961. build system (OpenEmbedded or Angstrom) for which you have built up a
  5962. sizable directory of source tarballs. Or, perhaps someone else has such
  5963. a directory for which you have read access. If so, you can save time by
  5964. adding statements to your configuration file so that the build process
  5965. checks local directories first for existing tarballs before checking the
  5966. Internet.
  5967. Here is an efficient way to set it up in your ``local.conf`` file:
  5968. ::
  5969. SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
  5970. INHERIT += "own-mirrors"
  5971. BB_GENERATE_MIRROR_TARBALLS = "1"
  5972. # BB_NO_NETWORK = "1"
  5973. In the previous example, the
  5974. :term:`BB_GENERATE_MIRROR_TARBALLS`
  5975. variable causes the OpenEmbedded build system to generate tarballs of
  5976. the Git repositories and store them in the
  5977. :term:`DL_DIR` directory. Due to
  5978. performance reasons, generating and storing these tarballs is not the
  5979. build system's default behavior.
  5980. You can also use the
  5981. :term:`PREMIRRORS` variable. For
  5982. an example, see the variable's glossary entry in the Yocto Project
  5983. Reference Manual.
  5984. Getting Source Files and Suppressing the Build
  5985. ----------------------------------------------
  5986. Another technique you can use to ready yourself for a successive string
  5987. of build operations, is to pre-fetch all the source files without
  5988. actually starting a build. This technique lets you work through any
  5989. download issues and ultimately gathers all the source files into your
  5990. download directory :ref:`structure-build-downloads`,
  5991. which is located with :term:`DL_DIR`.
  5992. Use the following BitBake command form to fetch all the necessary
  5993. sources without starting the build:
  5994. ::
  5995. $ bitbake target --runall=fetch
  5996. This
  5997. variation of the BitBake command guarantees that you have all the
  5998. sources for that BitBake target should you disconnect from the Internet
  5999. and want to do the build later offline.
  6000. Selecting an Initialization Manager
  6001. ===================================
  6002. By default, the Yocto Project uses SysVinit as the initialization
  6003. manager. However, support also exists for systemd, which is a full
  6004. replacement for init with parallel starting of services, reduced shell
  6005. overhead and other features that are used by many distributions.
  6006. Within the system, SysVinit treats system components as services. These
  6007. services are maintained as shell scripts stored in the ``/etc/init.d/``
  6008. directory. Services organize into different run levels. This
  6009. organization is maintained by putting links to the services in the
  6010. ``/etc/rcN.d/`` directories, where `N/` is one of the following options:
  6011. "S", "0", "1", "2", "3", "4", "5", or "6".
  6012. .. note::
  6013. Each runlevel has a dependency on the previous runlevel. This
  6014. dependency allows the services to work properly.
  6015. In comparison, systemd treats components as units. Using units is a
  6016. broader concept as compared to using a service. A unit includes several
  6017. different types of entities. Service is one of the types of entities.
  6018. The runlevel concept in SysVinit corresponds to the concept of a target
  6019. in systemd, where target is also a type of supported unit.
  6020. In a SysVinit-based system, services load sequentially (i.e. one by one)
  6021. during init and parallelization is not supported. With systemd, services
  6022. start in parallel. Needless to say, the method can have an impact on
  6023. system startup performance.
  6024. If you want to use SysVinit, you do not have to do anything. But, if you
  6025. want to use systemd, you must take some steps as described in the
  6026. following sections.
  6027. Using systemd Exclusively
  6028. -------------------------
  6029. Set these variables in your distribution configuration file as follows:
  6030. ::
  6031. DISTRO_FEATURES_append = " systemd"
  6032. VIRTUAL-RUNTIME_init_manager = "systemd"
  6033. You can also prevent the SysVinit distribution feature from
  6034. being automatically enabled as follows:
  6035. ::
  6036. DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
  6037. Doing so removes any
  6038. redundant SysVinit scripts.
  6039. To remove initscripts from your image altogether, set this variable
  6040. also:
  6041. ::
  6042. VIRTUAL-RUNTIME_initscripts = ""
  6043. For information on the backfill variable, see
  6044. :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`.
  6045. Using systemd for the Main Image and Using SysVinit for the Rescue Image
  6046. ------------------------------------------------------------------------
  6047. Set these variables in your distribution configuration file as follows:
  6048. ::
  6049. DISTRO_FEATURES_append = " systemd"
  6050. VIRTUAL-RUNTIME_init_manager = "systemd"
  6051. Doing so causes your main image to use the
  6052. ``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal
  6053. image cannot use this package group. However, it can install SysVinit
  6054. and the appropriate packages will have support for both systemd and
  6055. SysVinit.
  6056. Selecting a Device Manager
  6057. ==========================
  6058. The Yocto Project provides multiple ways to manage the device manager
  6059. (``/dev``):
  6060. - Persistent and Pre-Populated\ ``/dev``: For this case, the ``/dev``
  6061. directory is persistent and the required device nodes are created
  6062. during the build.
  6063. - Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev``
  6064. directory is provided by the kernel as an in-memory file system and
  6065. is automatically populated by the kernel at runtime. Additional
  6066. configuration of device nodes is done in user space by a device
  6067. manager like ``udev`` or ``busybox-mdev``.
  6068. Using Persistent and Pre-Populated\ ``/dev``
  6069. --------------------------------------------
  6070. To use the static method for device population, you need to set the
  6071. :term:`USE_DEVFS` variable to "0"
  6072. as follows:
  6073. ::
  6074. USE_DEVFS = "0"
  6075. The content of the resulting ``/dev`` directory is defined in a Device
  6076. Table file. The
  6077. :term:`IMAGE_DEVICE_TABLES`
  6078. variable defines the Device Table to use and should be set in the
  6079. machine or distro configuration file. Alternatively, you can set this
  6080. variable in your ``local.conf`` configuration file.
  6081. If you do not define the ``IMAGE_DEVICE_TABLES`` variable, the default
  6082. ``device_table-minimal.txt`` is used:
  6083. ::
  6084. IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
  6085. The population is handled by the ``makedevs`` utility during image
  6086. creation:
  6087. Using ``devtmpfs`` and a Device Manager
  6088. ---------------------------------------
  6089. To use the dynamic method for device population, you need to use (or be
  6090. sure to set) the :term:`USE_DEVFS`
  6091. variable to "1", which is the default:
  6092. ::
  6093. USE_DEVFS = "1"
  6094. With this
  6095. setting, the resulting ``/dev`` directory is populated by the kernel
  6096. using ``devtmpfs``. Make sure the corresponding kernel configuration
  6097. variable ``CONFIG_DEVTMPFS`` is set when building you build a Linux
  6098. kernel.
  6099. All devices created by ``devtmpfs`` will be owned by ``root`` and have
  6100. permissions ``0600``.
  6101. To have more control over the device nodes, you can use a device manager
  6102. like ``udev`` or ``busybox-mdev``. You choose the device manager by
  6103. defining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or
  6104. distro configuration file. Alternatively, you can set this variable in
  6105. your ``local.conf`` configuration file:
  6106. ::
  6107. VIRTUAL-RUNTIME_dev_manager = "udev"
  6108. # Some alternative values
  6109. # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
  6110. # VIRTUAL-RUNTIME_dev_manager = "systemd"
  6111. Using an External SCM
  6112. =====================
  6113. If you're working on a recipe that pulls from an external Source Code
  6114. Manager (SCM), it is possible to have the OpenEmbedded build system
  6115. notice new recipe changes added to the SCM and then build the resulting
  6116. packages that depend on the new recipes by using the latest versions.
  6117. This only works for SCMs from which it is possible to get a sensible
  6118. revision number for changes. Currently, you can do this with Apache
  6119. Subversion (SVN), Git, and Bazaar (BZR) repositories.
  6120. To enable this behavior, the :term:`PV` of
  6121. the recipe needs to reference
  6122. :term:`SRCPV`. Here is an example:
  6123. ::
  6124. PV = "1.2.3+git${SRCPV}"
  6125. Then, you can add the following to your
  6126. ``local.conf``:
  6127. ::
  6128. SRCREV_pn-PN = "${AUTOREV}"
  6129. :term:`PN` is the name of the recipe for
  6130. which you want to enable automatic source revision updating.
  6131. If you do not want to update your local configuration file, you can add
  6132. the following directly to the recipe to finish enabling the feature:
  6133. ::
  6134. SRCREV = "${AUTOREV}"
  6135. The Yocto Project provides a distribution named ``poky-bleeding``, whose
  6136. configuration file contains the line:
  6137. ::
  6138. require conf/distro/include/poky-floating-revisions.inc
  6139. This line pulls in the
  6140. listed include file that contains numerous lines of exactly that form:
  6141. ::
  6142. #SRCREV_pn-opkg-native ?= "${AUTOREV}"
  6143. #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
  6144. #SRCREV_pn-opkg ?= "${AUTOREV}"
  6145. #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
  6146. #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
  6147. SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
  6148. SRCREV_pn-matchbox-common ?= "${AUTOREV}"
  6149. SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
  6150. SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
  6151. SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
  6152. SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
  6153. SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
  6154. SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
  6155. SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
  6156. SRCREV_pn-settings-daemon ?= "${AUTOREV}"
  6157. SRCREV_pn-screenshot ?= "${AUTOREV}"
  6158. . . .
  6159. These lines allow you to
  6160. experiment with building a distribution that tracks the latest
  6161. development source for numerous packages.
  6162. .. note::
  6163. The ``poky-bleeding`` distribution is not tested on a regular basis. Keep
  6164. this in mind if you use it.
  6165. Creating a Read-Only Root Filesystem
  6166. ====================================
  6167. Suppose, for security reasons, you need to disable your target device's
  6168. root filesystem's write permissions (i.e. you need a read-only root
  6169. filesystem). Or, perhaps you are running the device's operating system
  6170. from a read-only storage device. For either case, you can customize your
  6171. image for that behavior.
  6172. .. note::
  6173. Supporting a read-only root filesystem requires that the system and
  6174. applications do not try to write to the root filesystem. You must
  6175. configure all parts of the target system to write elsewhere, or to
  6176. gracefully fail in the event of attempting to write to the root
  6177. filesystem.
  6178. Creating the Root Filesystem
  6179. ----------------------------
  6180. To create the read-only root filesystem, simply add the
  6181. "read-only-rootfs" feature to your image, normally in one of two ways.
  6182. The first way is to add the "read-only-rootfs" image feature in the
  6183. image's recipe file via the ``IMAGE_FEATURES`` variable:
  6184. ::
  6185. IMAGE_FEATURES += "read-only-rootfs"
  6186. As an alternative, you can add the same feature
  6187. from within your build directory's ``local.conf`` file with the
  6188. associated ``EXTRA_IMAGE_FEATURES`` variable, as in:
  6189. ::
  6190. EXTRA_IMAGE_FEATURES = "read-only-rootfs"
  6191. For more information on how to use these variables, see the
  6192. ":ref:`dev-manual/common-tasks:Customizing Images Using Custom \`\`IMAGE_FEATURES\`\` and \`\`EXTRA_IMAGE_FEATURES\`\``"
  6193. section. For information on the variables, see
  6194. :term:`IMAGE_FEATURES` and
  6195. :term:`EXTRA_IMAGE_FEATURES`.
  6196. Post-Installation Scripts and Read-Only Root Filesystem
  6197. -------------------------------------------------------
  6198. It is very important that you make sure all post-Installation
  6199. (``pkg_postinst``) scripts for packages that are installed into the
  6200. image can be run at the time when the root filesystem is created during
  6201. the build on the host system. These scripts cannot attempt to run during
  6202. first-boot on the target device. With the "read-only-rootfs" feature
  6203. enabled, the build system checks during root filesystem creation to make
  6204. sure all post-installation scripts succeed. If any of these scripts
  6205. still need to be run after the root filesystem is created, the build
  6206. immediately fails. These build-time checks ensure that the build fails
  6207. rather than the target device fails later during its initial boot
  6208. operation.
  6209. Most of the common post-installation scripts generated by the build
  6210. system for the out-of-the-box Yocto Project are engineered so that they
  6211. can run during root filesystem creation (e.g. post-installation scripts
  6212. for caching fonts). However, if you create and add custom scripts, you
  6213. need to be sure they can be run during this file system creation.
  6214. Here are some common problems that prevent post-installation scripts
  6215. from running during root filesystem creation:
  6216. - *Not using $D in front of absolute paths:* The build system defines
  6217. ``$``\ :term:`D` when the root
  6218. filesystem is created. Furthermore, ``$D`` is blank when the script
  6219. is run on the target device. This implies two purposes for ``$D``:
  6220. ensuring paths are valid in both the host and target environments,
  6221. and checking to determine which environment is being used as a method
  6222. for taking appropriate actions.
  6223. - *Attempting to run processes that are specific to or dependent on the
  6224. target architecture:* You can work around these attempts by using
  6225. native tools, which run on the host system, to accomplish the same
  6226. tasks, or by alternatively running the processes under QEMU, which
  6227. has the ``qemu_run_binary`` function. For more information, see the
  6228. :ref:`qemu <ref-classes-qemu>` class.
  6229. Areas With Write Access
  6230. -----------------------
  6231. With the "read-only-rootfs" feature enabled, any attempt by the target
  6232. to write to the root filesystem at runtime fails. Consequently, you must
  6233. make sure that you configure processes and applications that attempt
  6234. these types of writes do so to directories with write access (e.g.
  6235. ``/tmp`` or ``/var/run``).
  6236. Maintaining Build Output Quality
  6237. ================================
  6238. Many factors can influence the quality of a build. For example, if you
  6239. upgrade a recipe to use a new version of an upstream software package or
  6240. you experiment with some new configuration options, subtle changes can
  6241. occur that you might not detect until later. Consider the case where
  6242. your recipe is using a newer version of an upstream package. In this
  6243. case, a new version of a piece of software might introduce an optional
  6244. dependency on another library, which is auto-detected. If that library
  6245. has already been built when the software is building, the software will
  6246. link to the built library and that library will be pulled into your
  6247. image along with the new software even if you did not want the library.
  6248. The :ref:`buildhistory <ref-classes-buildhistory>`
  6249. class exists to help you maintain the quality of your build output. You
  6250. can use the class to highlight unexpected and possibly unwanted changes
  6251. in the build output. When you enable build history, it records
  6252. information about the contents of each package and image and then
  6253. commits that information to a local Git repository where you can examine
  6254. the information.
  6255. The remainder of this section describes the following:
  6256. - :ref:`How you can enable and disable build history <dev-manual/common-tasks:enabling and disabling build history>`
  6257. - :ref:`How to understand what the build history contains <dev-manual/common-tasks:understanding what the build history contains>`
  6258. - :ref:`How to limit the information used for build history <dev-manual/common-tasks:using build history to gather image information only>`
  6259. - :ref:`How to examine the build history from both a command-line and web interface <dev-manual/common-tasks:examining build history information>`
  6260. Enabling and Disabling Build History
  6261. ------------------------------------
  6262. Build history is disabled by default. To enable it, add the following
  6263. ``INHERIT`` statement and set the
  6264. :term:`BUILDHISTORY_COMMIT`
  6265. variable to "1" at the end of your ``conf/local.conf`` file found in the
  6266. :term:`Build Directory`:
  6267. ::
  6268. INHERIT += "buildhistory"
  6269. BUILDHISTORY_COMMIT = "1"
  6270. Enabling build history as
  6271. previously described causes the OpenEmbedded build system to collect
  6272. build output information and commit it as a single commit to a local
  6273. :ref:`overview-manual/development-environment:git` repository.
  6274. .. note::
  6275. Enabling build history increases your build times slightly,
  6276. particularly for images, and increases the amount of disk space used
  6277. during the build.
  6278. You can disable build history by removing the previous statements from
  6279. your ``conf/local.conf`` file.
  6280. Understanding What the Build History Contains
  6281. ---------------------------------------------
  6282. Build history information is kept in
  6283. ``${``\ :term:`TOPDIR`\ ``}/buildhistory``
  6284. in the Build Directory as defined by the
  6285. :term:`BUILDHISTORY_DIR`
  6286. variable. The following is an example abbreviated listing:
  6287. .. image:: figures/buildhistory.png
  6288. :align: center
  6289. At the top level, a ``metadata-revs`` file exists that lists the
  6290. revisions of the repositories for the enabled layers when the build was
  6291. produced. The rest of the data splits into separate ``packages``,
  6292. ``images`` and ``sdk`` directories, the contents of which are described
  6293. as follows.
  6294. Build History Package Information
  6295. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6296. The history for each package contains a text file that has name-value
  6297. pairs with information about the package. For example,
  6298. ``buildhistory/packages/i586-poky-linux/busybox/busybox/latest``
  6299. contains the following:
  6300. .. code-block:: none
  6301. PV = 1.22.1
  6302. PR = r32
  6303. RPROVIDES =
  6304. RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
  6305. RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
  6306. PKGSIZE = 540168
  6307. FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
  6308. /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
  6309. /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
  6310. /usr/share/pixmaps /usr/share/applications /usr/share/idl \
  6311. /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
  6312. FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
  6313. /etc/busybox.links.nosuid /etc/busybox.links.suid
  6314. Most of these
  6315. name-value pairs correspond to variables used to produce the package.
  6316. The exceptions are ``FILELIST``, which is the actual list of files in
  6317. the package, and ``PKGSIZE``, which is the total size of files in the
  6318. package in bytes.
  6319. A file also exists that corresponds to the recipe from which the package
  6320. came (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``):
  6321. .. code-block:: none
  6322. PV = 1.22.1
  6323. PR = r32
  6324. DEPENDS = initscripts kern-tools-native update-rc.d-native \
  6325. virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
  6326. virtual/libc virtual/update-alternatives
  6327. PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
  6328. busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
  6329. busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
  6330. Finally, for those recipes fetched from a version control system (e.g.,
  6331. Git), a file exists that lists source revisions that are specified in
  6332. the recipe and lists the actual revisions used during the build. Listed
  6333. and actual revisions might differ when
  6334. :term:`SRCREV` is set to
  6335. ${:term:`AUTOREV`}. Here is an
  6336. example assuming
  6337. ``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``):
  6338. ::
  6339. # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
  6340. SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
  6341. # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
  6342. SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f"
  6343. You can use the
  6344. ``buildhistory-collect-srcrevs`` command with the ``-a`` option to
  6345. collect the stored ``SRCREV`` values from build history and report them
  6346. in a format suitable for use in global configuration (e.g.,
  6347. ``local.conf`` or a distro include file) to override floating
  6348. ``AUTOREV`` values to a fixed set of revisions. Here is some example
  6349. output from this command:
  6350. ::
  6351. $ buildhistory-collect-srcrevs -a
  6352. # i586-poky-linux
  6353. SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
  6354. SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
  6355. SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
  6356. SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
  6357. # x86_64-linux
  6358. SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
  6359. SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
  6360. SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
  6361. SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
  6362. SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
  6363. SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
  6364. SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
  6365. SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
  6366. SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
  6367. # qemux86-poky-linux
  6368. SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
  6369. SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
  6370. # all-poky-linux
  6371. SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
  6372. .. note::
  6373. Here are some notes on using the ``buildhistory-collect-srcrevs`` command:
  6374. - By default, only values where the ``SRCREV`` was not hardcoded
  6375. (usually when ``AUTOREV`` is used) are reported. Use the ``-a``
  6376. option to see all ``SRCREV`` values.
  6377. - The output statements might not have any effect if overrides are
  6378. applied elsewhere in the build system configuration. Use the
  6379. ``-f`` option to add the ``forcevariable`` override to each output
  6380. line if you need to work around this restriction.
  6381. - The script does apply special handling when building for multiple
  6382. machines. However, the script does place a comment before each set
  6383. of values that specifies which triplet to which they belong as
  6384. previously shown (e.g., ``i586-poky-linux``).
  6385. Build History Image Information
  6386. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6387. The files produced for each image are as follows:
  6388. - ``image-files:`` A directory containing selected files from the root
  6389. filesystem. The files are defined by
  6390. :term:`BUILDHISTORY_IMAGE_FILES`.
  6391. - ``build-id.txt:`` Human-readable information about the build
  6392. configuration and metadata source revisions. This file contains the
  6393. full build header as printed by BitBake.
  6394. - ``*.dot:`` Dependency graphs for the image that are compatible with
  6395. ``graphviz``.
  6396. - ``files-in-image.txt:`` A list of files in the image with
  6397. permissions, owner, group, size, and symlink information.
  6398. - ``image-info.txt:`` A text file containing name-value pairs with
  6399. information about the image. See the following listing example for
  6400. more information.
  6401. - ``installed-package-names.txt:`` A list of installed packages by name
  6402. only.
  6403. - ``installed-package-sizes.txt:`` A list of installed packages ordered
  6404. by size.
  6405. - ``installed-packages.txt:`` A list of installed packages with full
  6406. package filenames.
  6407. .. note::
  6408. Installed package information is able to be gathered and produced
  6409. even if package management is disabled for the final image.
  6410. Here is an example of ``image-info.txt``:
  6411. .. code-block:: none
  6412. DISTRO = poky
  6413. DISTRO_VERSION = 1.7
  6414. USER_CLASSES = buildstats image-mklibs image-prelink
  6415. IMAGE_CLASSES = image_types
  6416. IMAGE_FEATURES = debug-tweaks
  6417. IMAGE_LINGUAS =
  6418. IMAGE_INSTALL = packagegroup-core-boot run-postinsts
  6419. BAD_RECOMMENDATIONS =
  6420. NO_RECOMMENDATIONS =
  6421. PACKAGE_EXCLUDE =
  6422. ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
  6423. write_image_manifest ; buildhistory_list_installed_image ; \
  6424. buildhistory_get_image_installed ; ssh_allow_empty_password; \
  6425. postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
  6426. IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
  6427. IMAGESIZE = 6900
  6428. Other than ``IMAGESIZE``,
  6429. which is the total size of the files in the image in Kbytes, the
  6430. name-value pairs are variables that may have influenced the content of
  6431. the image. This information is often useful when you are trying to
  6432. determine why a change in the package or file listings has occurred.
  6433. Using Build History to Gather Image Information Only
  6434. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6435. As you can see, build history produces image information, including
  6436. dependency graphs, so you can see why something was pulled into the
  6437. image. If you are just interested in this information and not interested
  6438. in collecting specific package or SDK information, you can enable
  6439. writing only image information without any history by adding the
  6440. following to your ``conf/local.conf`` file found in the
  6441. :term:`Build Directory`:
  6442. ::
  6443. INHERIT += "buildhistory"
  6444. BUILDHISTORY_COMMIT = "0"
  6445. BUILDHISTORY_FEATURES = "image"
  6446. Here, you set the
  6447. :term:`BUILDHISTORY_FEATURES`
  6448. variable to use the image feature only.
  6449. Build History SDK Information
  6450. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6451. Build history collects similar information on the contents of SDKs (e.g.
  6452. ``bitbake -c populate_sdk imagename``) as compared to information it
  6453. collects for images. Furthermore, this information differs depending on
  6454. whether an extensible or standard SDK is being produced.
  6455. The following list shows the files produced for SDKs:
  6456. - ``files-in-sdk.txt:`` A list of files in the SDK with permissions,
  6457. owner, group, size, and symlink information. This list includes both
  6458. the host and target parts of the SDK.
  6459. - ``sdk-info.txt:`` A text file containing name-value pairs with
  6460. information about the SDK. See the following listing example for more
  6461. information.
  6462. - ``sstate-task-sizes.txt:`` A text file containing name-value pairs
  6463. with information about task group sizes (e.g. ``do_populate_sysroot``
  6464. tasks have a total size). The ``sstate-task-sizes.txt`` file exists
  6465. only when an extensible SDK is created.
  6466. - ``sstate-package-sizes.txt:`` A text file containing name-value pairs
  6467. with information for the shared-state packages and sizes in the SDK.
  6468. The ``sstate-package-sizes.txt`` file exists only when an extensible
  6469. SDK is created.
  6470. - ``sdk-files:`` A folder that contains copies of the files mentioned
  6471. in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output.
  6472. Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is
  6473. specific to the extensible SDK although you can set it differently if
  6474. you would like to pull in specific files from the standard SDK.
  6475. The default files are ``conf/local.conf``, ``conf/bblayers.conf``,
  6476. ``conf/auto.conf``, ``conf/locked-sigs.inc``, and
  6477. ``conf/devtool.conf``. Thus, for an extensible SDK, these files get
  6478. copied into the ``sdk-files`` directory.
  6479. - The following information appears under each of the ``host`` and
  6480. ``target`` directories for the portions of the SDK that run on the
  6481. host and on the target, respectively:
  6482. .. note::
  6483. The following files for the most part are empty when producing an
  6484. extensible SDK because this type of SDK is not constructed from
  6485. packages as is the standard SDK.
  6486. - ``depends.dot:`` Dependency graph for the SDK that is compatible
  6487. with ``graphviz``.
  6488. - ``installed-package-names.txt:`` A list of installed packages by
  6489. name only.
  6490. - ``installed-package-sizes.txt:`` A list of installed packages
  6491. ordered by size.
  6492. - ``installed-packages.txt:`` A list of installed packages with full
  6493. package filenames.
  6494. Here is an example of ``sdk-info.txt``:
  6495. .. code-block:: none
  6496. DISTRO = poky
  6497. DISTRO_VERSION = 1.3+snapshot-20130327
  6498. SDK_NAME = poky-glibc-i686-arm
  6499. SDK_VERSION = 1.3+snapshot
  6500. SDKMACHINE =
  6501. SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
  6502. BAD_RECOMMENDATIONS =
  6503. SDKSIZE = 352712
  6504. Other than ``SDKSIZE``, which is
  6505. the total size of the files in the SDK in Kbytes, the name-value pairs
  6506. are variables that might have influenced the content of the SDK. This
  6507. information is often useful when you are trying to determine why a
  6508. change in the package or file listings has occurred.
  6509. Examining Build History Information
  6510. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6511. You can examine build history output from the command line or from a web
  6512. interface.
  6513. To see any changes that have occurred (assuming you have
  6514. :term:`BUILDHISTORY_COMMIT` = "1"),
  6515. you can simply use any Git command that allows you to view the history
  6516. of a repository. Here is one method:
  6517. ::
  6518. $ git log -p
  6519. You need to realize,
  6520. however, that this method does show changes that are not significant
  6521. (e.g. a package's size changing by a few bytes).
  6522. A command-line tool called ``buildhistory-diff`` does exist, though,
  6523. that queries the Git repository and prints just the differences that
  6524. might be significant in human-readable form. Here is an example:
  6525. ::
  6526. $ ~/poky/poky/scripts/buildhistory-diff . HEAD^
  6527. Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
  6528. /etc/anotherpkg.conf was added
  6529. /sbin/anotherpkg was added
  6530. * (installed-package-names.txt):
  6531. * anotherpkg was added
  6532. Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
  6533. anotherpkg was added
  6534. packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
  6535. * PR changed from "r0" to "r1"
  6536. * PV changed from "0.1.10" to "0.1.12"
  6537. packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
  6538. * PR changed from "r0" to "r1"
  6539. * PV changed from "0.1.10" to "0.1.12"
  6540. .. note::
  6541. The ``buildhistory-diff`` tool requires the ``GitPython``
  6542. package. Be sure to install it using Pip3 as follows:
  6543. ::
  6544. $ pip3 install GitPython --user
  6545. Alternatively, you can install ``python3-git`` using the appropriate
  6546. distribution package manager (e.g. ``apt-get``, ``dnf``, or ``zipper``).
  6547. To see changes to the build history using a web interface, follow the
  6548. instruction in the ``README`` file
  6549. :yocto_git:`here </buildhistory-web/>`.
  6550. Here is a sample screenshot of the interface:
  6551. .. image:: figures/buildhistory-web.png
  6552. :align: center
  6553. Performing Automated Runtime Testing
  6554. ====================================
  6555. The OpenEmbedded build system makes available a series of automated
  6556. tests for images to verify runtime functionality. You can run these
  6557. tests on either QEMU or actual target hardware. Tests are written in
  6558. Python making use of the ``unittest`` module, and the majority of them
  6559. run commands on the target system over SSH. This section describes how
  6560. you set up the environment to use these tests, run available tests, and
  6561. write and add your own tests.
  6562. For information on the test and QA infrastructure available within the
  6563. Yocto Project, see the ":ref:`ref-manual/release-process:testing and quality assurance`"
  6564. section in the Yocto Project Reference Manual.
  6565. Enabling Tests
  6566. --------------
  6567. Depending on whether you are planning to run tests using QEMU or on the
  6568. hardware, you have to take different steps to enable the tests. See the
  6569. following subsections for information on how to enable both types of
  6570. tests.
  6571. Enabling Runtime Tests on QEMU
  6572. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6573. In order to run tests, you need to do the following:
  6574. - *Set up to avoid interaction with sudo for networking:* To
  6575. accomplish this, you must do one of the following:
  6576. - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all
  6577. commands or just for ``runqemu-ifup``. You must provide the full
  6578. path as that can change if you are using multiple clones of the
  6579. source repository.
  6580. .. note::
  6581. On some distributions, you also need to comment out "Defaults
  6582. requiretty" in ``/etc/sudoers``.
  6583. - Manually configure a tap interface for your system.
  6584. - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which
  6585. should generate a list of tap devices. This is the option
  6586. typically chosen for Autobuilder-type environments.
  6587. .. note::
  6588. - Be sure to use an absolute path when calling this script
  6589. with sudo.
  6590. - The package recipe ``qemu-helper-native`` is required to run
  6591. this script. Build the package using the following command:
  6592. ::
  6593. $ bitbake qemu-helper-native
  6594. - *Set the DISPLAY variable:* You need to set this variable so that
  6595. you have an X server available (e.g. start ``vncserver`` for a
  6596. headless machine).
  6597. - *Be sure your host's firewall accepts incoming connections from
  6598. 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an
  6599. HTTP server on a random high number port, which is used to serve
  6600. files to the target. The DNF module serves
  6601. ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands.
  6602. That means your host's firewall must accept incoming connections from
  6603. 192.168.7.0/24, which is the default IP range used for tap devices by
  6604. ``runqemu``.
  6605. - *Be sure your host has the correct packages installed:* Depending
  6606. your host's distribution, you need to have the following packages
  6607. installed:
  6608. - Ubuntu and Debian: ``sysstat`` and ``iproute2``
  6609. - OpenSUSE: ``sysstat`` and ``iproute2``
  6610. - Fedora: ``sysstat`` and ``iproute``
  6611. - CentOS: ``sysstat`` and ``iproute``
  6612. Once you start running the tests, the following happens:
  6613. 1. A copy of the root filesystem is written to ``${WORKDIR}/testimage``.
  6614. 2. The image is booted under QEMU using the standard ``runqemu`` script.
  6615. 3. A default timeout of 500 seconds occurs to allow for the boot process
  6616. to reach the login prompt. You can change the timeout period by
  6617. setting
  6618. :term:`TEST_QEMUBOOT_TIMEOUT`
  6619. in the ``local.conf`` file.
  6620. 4. Once the boot process is reached and the login prompt appears, the
  6621. tests run. The full boot log is written to
  6622. ``${WORKDIR}/testimage/qemu_boot_log``.
  6623. 5. Each test module loads in the order found in ``TEST_SUITES``. You can
  6624. find the full output of the commands run over SSH in
  6625. ``${WORKDIR}/testimgage/ssh_target_log``.
  6626. 6. If no failures occur, the task running the tests ends successfully.
  6627. You can find the output from the ``unittest`` in the task log at
  6628. ``${WORKDIR}/temp/log.do_testimage``.
  6629. Enabling Runtime Tests on Hardware
  6630. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6631. The OpenEmbedded build system can run tests on real hardware, and for
  6632. certain devices it can also deploy the image to be tested onto the
  6633. device beforehand.
  6634. For automated deployment, a "master image" is installed onto the
  6635. hardware once as part of setup. Then, each time tests are to be run, the
  6636. following occurs:
  6637. 1. The master image is booted into and used to write the image to be
  6638. tested to a second partition.
  6639. 2. The device is then rebooted using an external script that you need to
  6640. provide.
  6641. 3. The device boots into the image to be tested.
  6642. When running tests (independent of whether the image has been deployed
  6643. automatically or not), the device is expected to be connected to a
  6644. network on a pre-determined IP address. You can either use static IP
  6645. addresses written into the image, or set the image to use DHCP and have
  6646. your DHCP server on the test network assign a known IP address based on
  6647. the MAC address of the device.
  6648. In order to run tests on hardware, you need to set ``TEST_TARGET`` to an
  6649. appropriate value. For QEMU, you do not have to change anything, the
  6650. default value is "qemu". For running tests on hardware, the following
  6651. options exist:
  6652. - *"simpleremote":* Choose "simpleremote" if you are going to run tests
  6653. on a target system that is already running the image to be tested and
  6654. is available on the network. You can use "simpleremote" in
  6655. conjunction with either real hardware or an image running within a
  6656. separately started QEMU or any other virtual machine manager.
  6657. - *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is
  6658. an EFI-based machine with ``systemd-boot`` as bootloader and
  6659. ``core-image-testmaster`` (or something similar) is installed. Also,
  6660. your hardware under test must be in a DHCP-enabled network that gives
  6661. it the same IP address for each reboot.
  6662. If you choose "SystemdbootTarget", there are additional requirements
  6663. and considerations. See the "`Selecting
  6664. SystemdbootTarget <#selecting-systemdboottarget>`__" section, which
  6665. follows, for more information.
  6666. - *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying
  6667. images and running tests on the BeagleBone "Black" or original
  6668. "White" hardware. For information on how to use these tests, see the
  6669. comments at the top of the BeagleBoneTarget
  6670. ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file.
  6671. - *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying
  6672. images and running tests on the Ubiquiti Networks EdgeRouter Lite.
  6673. For information on how to use these tests, see the comments at the
  6674. top of the EdgeRouterTarget
  6675. ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file.
  6676. - *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running
  6677. tests on any generic PC that boots using GRUB. For information on how
  6678. to use these tests, see the comments at the top of the GrubTarget
  6679. ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file.
  6680. - *"your-target":* Create your own custom target if you want to run
  6681. tests when you are deploying images and running tests on a custom
  6682. machine within your BSP layer. To do this, you need to add a Python
  6683. unit that defines the target class under ``lib/oeqa/controllers/``
  6684. within your layer. You must also provide an empty ``__init__.py``.
  6685. For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``.
  6686. Selecting SystemdbootTarget
  6687. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6688. If you did not set ``TEST_TARGET`` to "SystemdbootTarget", then you do
  6689. not need any information in this section. You can skip down to the
  6690. "`Running Tests <#qemu-image-running-tests>`__" section.
  6691. If you did set ``TEST_TARGET`` to "SystemdbootTarget", you also need to
  6692. perform a one-time setup of your master image by doing the following:
  6693. 1. *Set EFI_PROVIDER:* Be sure that ``EFI_PROVIDER`` is as follows:
  6694. ::
  6695. EFI_PROVIDER = "systemd-boot"
  6696. 2. *Build the master image:* Build the ``core-image-testmaster`` image.
  6697. The ``core-image-testmaster`` recipe is provided as an example for a
  6698. "master" image and you can customize the image recipe as you would
  6699. any other recipe.
  6700. Here are the image recipe requirements:
  6701. - Inherits ``core-image`` so that kernel modules are installed.
  6702. - Installs normal linux utilities not busybox ones (e.g. ``bash``,
  6703. ``coreutils``, ``tar``, ``gzip``, and ``kmod``).
  6704. - Uses a custom Initial RAM Disk (initramfs) image with a custom
  6705. installer. A normal image that you can install usually creates a
  6706. single rootfs partition. This image uses another installer that
  6707. creates a specific partition layout. Not all Board Support
  6708. Packages (BSPs) can use an installer. For such cases, you need to
  6709. manually create the following partition layout on the target:
  6710. - First partition mounted under ``/boot``, labeled "boot".
  6711. - The main rootfs partition where this image gets installed,
  6712. which is mounted under ``/``.
  6713. - Another partition labeled "testrootfs" where test images get
  6714. deployed.
  6715. 3. *Install image:* Install the image that you just built on the target
  6716. system.
  6717. The final thing you need to do when setting ``TEST_TARGET`` to
  6718. "SystemdbootTarget" is to set up the test image:
  6719. 1. *Set up your local.conf file:* Make sure you have the following
  6720. statements in your ``local.conf`` file:
  6721. ::
  6722. IMAGE_FSTYPES += "tar.gz"
  6723. INHERIT += "testimage"
  6724. TEST_TARGET = "SystemdbootTarget"
  6725. TEST_TARGET_IP = "192.168.2.3"
  6726. 2. *Build your test image:* Use BitBake to build the image:
  6727. ::
  6728. $ bitbake core-image-sato
  6729. Power Control
  6730. ~~~~~~~~~~~~~
  6731. For most hardware targets other than "simpleremote", you can control
  6732. power:
  6733. - You can use ``TEST_POWERCONTROL_CMD`` together with
  6734. ``TEST_POWERCONTROL_EXTRA_ARGS`` as a command that runs on the host
  6735. and does power cycling. The test code passes one argument to that
  6736. command: off, on or cycle (off then on). Here is an example that
  6737. could appear in your ``local.conf`` file:
  6738. ::
  6739. TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
  6740. In this example, the expect
  6741. script does the following:
  6742. .. code-block:: shell
  6743. ssh test@10.11.12.1 "pyctl nuc1 arg"
  6744. It then runs a Python script that controls power for a label called
  6745. ``nuc1``.
  6746. .. note::
  6747. You need to customize ``TEST_POWERCONTROL_CMD`` and
  6748. ``TEST_POWERCONTROL_EXTRA_ARGS`` for your own setup. The one requirement
  6749. is that it accepts "on", "off", and "cycle" as the last argument.
  6750. - When no command is defined, it connects to the device over SSH and
  6751. uses the classic reboot command to reboot the device. Classic reboot
  6752. is fine as long as the machine actually reboots (i.e. the SSH test
  6753. has not failed). It is useful for scenarios where you have a simple
  6754. setup, typically with a single board, and where some manual
  6755. interaction is okay from time to time.
  6756. If you have no hardware to automatically perform power control but still
  6757. wish to experiment with automated hardware testing, you can use the
  6758. ``dialog-power-control`` script that shows a dialog prompting you to perform
  6759. the required power action. This script requires either KDialog or Zenity
  6760. to be installed. To use this script, set the
  6761. :term:`TEST_POWERCONTROL_CMD`
  6762. variable as follows:
  6763. ::
  6764. TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
  6765. Serial Console Connection
  6766. ~~~~~~~~~~~~~~~~~~~~~~~~~
  6767. For test target classes requiring a serial console to interact with the
  6768. bootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget),
  6769. you need to specify a command to use to connect to the serial console of
  6770. the target machine by using the
  6771. :term:`TEST_SERIALCONTROL_CMD`
  6772. variable and optionally the
  6773. :term:`TEST_SERIALCONTROL_EXTRA_ARGS`
  6774. variable.
  6775. These cases could be a serial terminal program if the machine is
  6776. connected to a local serial port, or a ``telnet`` or ``ssh`` command
  6777. connecting to a remote console server. Regardless of the case, the
  6778. command simply needs to connect to the serial console and forward that
  6779. connection to standard input and output as any normal terminal program
  6780. does. For example, to use the picocom terminal program on serial device
  6781. ``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows:
  6782. ::
  6783. TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
  6784. For local
  6785. devices where the serial port device disappears when the device reboots,
  6786. an additional "serdevtry" wrapper script is provided. To use this
  6787. wrapper, simply prefix the terminal command with
  6788. ``${COREBASE}/scripts/contrib/serdevtry``:
  6789. ::
  6790. TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0"
  6791. Running Tests
  6792. -------------
  6793. You can start the tests automatically or manually:
  6794. - *Automatically running tests:* To run the tests automatically after
  6795. the OpenEmbedded build system successfully creates an image, first
  6796. set the
  6797. :term:`TESTIMAGE_AUTO`
  6798. variable to "1" in your ``local.conf`` file in the
  6799. :term:`Build Directory`:
  6800. ::
  6801. TESTIMAGE_AUTO = "1"
  6802. Next, build your image. If the image successfully builds, the
  6803. tests run:
  6804. ::
  6805. bitbake core-image-sato
  6806. - *Manually running tests:* To manually run the tests, first globally
  6807. inherit the
  6808. :ref:`testimage <ref-classes-testimage*>` class
  6809. by editing your ``local.conf`` file:
  6810. ::
  6811. INHERIT += "testimage"
  6812. Next, use BitBake to run the tests:
  6813. ::
  6814. bitbake -c testimage image
  6815. All test files reside in ``meta/lib/oeqa/runtime`` in the
  6816. :term:`Source Directory`. A test name maps
  6817. directly to a Python module. Each test module may contain a number of
  6818. individual tests. Tests are usually grouped together by the area tested
  6819. (e.g tests for systemd reside in ``meta/lib/oeqa/runtime/systemd.py``).
  6820. You can add tests to any layer provided you place them in the proper
  6821. area and you extend :term:`BBPATH` in
  6822. the ``local.conf`` file as normal. Be sure that tests reside in
  6823. ``layer/lib/oeqa/runtime``.
  6824. .. note::
  6825. Be sure that module names do not collide with module names used in
  6826. the default set of test modules in ``meta/lib/oeqa/runtime``.
  6827. You can change the set of tests run by appending or overriding
  6828. :term:`TEST_SUITES` variable in
  6829. ``local.conf``. Each name in ``TEST_SUITES`` represents a required test
  6830. for the image. Test modules named within ``TEST_SUITES`` cannot be
  6831. skipped even if a test is not suitable for an image (e.g. running the
  6832. RPM tests on an image without ``rpm``). Appending "auto" to
  6833. ``TEST_SUITES`` causes the build system to try to run all tests that are
  6834. suitable for the image (i.e. each test module may elect to skip itself).
  6835. The order you list tests in ``TEST_SUITES`` is important and influences
  6836. test dependencies. Consequently, tests that depend on other tests should
  6837. be added after the test on which they depend. For example, since the
  6838. ``ssh`` test depends on the ``ping`` test, "ssh" needs to come after
  6839. "ping" in the list. The test class provides no re-ordering or dependency
  6840. handling.
  6841. .. note::
  6842. Each module can have multiple classes with multiple test methods.
  6843. And, Python ``unittest`` rules apply.
  6844. Here are some things to keep in mind when running tests:
  6845. - The default tests for the image are defined as:
  6846. ::
  6847. DEFAULT_TEST_SUITES_pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg"
  6848. - Add your own test to the list of the by using the following:
  6849. ::
  6850. TEST_SUITES_append = " mytest"
  6851. - Run a specific list of tests as follows:
  6852. ::
  6853. TEST_SUITES = "test1 test2 test3"
  6854. Remember, order is important. Be sure to place a test that is
  6855. dependent on another test later in the order.
  6856. Exporting Tests
  6857. ---------------
  6858. You can export tests so that they can run independently of the build
  6859. system. Exporting tests is required if you want to be able to hand the
  6860. test execution off to a scheduler. You can only export tests that are
  6861. defined in :term:`TEST_SUITES`.
  6862. If your image is already built, make sure the following are set in your
  6863. ``local.conf`` file:
  6864. ::
  6865. INHERIT += "testexport"
  6866. TEST_TARGET_IP = "IP-address-for-the-test-target"
  6867. TEST_SERVER_IP = "IP-address-for-the-test-server"
  6868. You can then export the tests with the
  6869. following BitBake command form:
  6870. ::
  6871. $ bitbake image -c testexport
  6872. Exporting the tests places them in the
  6873. :term:`Build Directory` in
  6874. ``tmp/testexport/``\ image, which is controlled by the
  6875. ``TEST_EXPORT_DIR`` variable.
  6876. You can now run the tests outside of the build environment:
  6877. ::
  6878. $ cd tmp/testexport/image
  6879. $ ./runexported.py testdata.json
  6880. Here is a complete example that shows IP addresses and uses the
  6881. ``core-image-sato`` image:
  6882. ::
  6883. INHERIT += "testexport"
  6884. TEST_TARGET_IP = "192.168.7.2"
  6885. TEST_SERVER_IP = "192.168.7.1"
  6886. Use BitBake to export the tests:
  6887. ::
  6888. $ bitbake core-image-sato -c testexport
  6889. Run the tests outside of
  6890. the build environment using the following:
  6891. ::
  6892. $ cd tmp/testexport/core-image-sato
  6893. $ ./runexported.py testdata.json
  6894. Writing New Tests
  6895. -----------------
  6896. As mentioned previously, all new test files need to be in the proper
  6897. place for the build system to find them. New tests for additional
  6898. functionality outside of the core should be added to the layer that adds
  6899. the functionality, in ``layer/lib/oeqa/runtime`` (as long as
  6900. :term:`BBPATH` is extended in the
  6901. layer's ``layer.conf`` file as normal). Just remember the following:
  6902. - Filenames need to map directly to test (module) names.
  6903. - Do not use module names that collide with existing core tests.
  6904. - Minimally, an empty ``__init__.py`` file must exist in the runtime
  6905. directory.
  6906. To create a new test, start by copying an existing module (e.g.
  6907. ``syslog.py`` or ``gcc.py`` are good ones to use). Test modules can use
  6908. code from ``meta/lib/oeqa/utils``, which are helper classes.
  6909. .. note::
  6910. Structure shell commands such that you rely on them and they return a
  6911. single code for success. Be aware that sometimes you will need to
  6912. parse the output. See the ``df.py`` and ``date.py`` modules for examples.
  6913. You will notice that all test classes inherit ``oeRuntimeTest``, which
  6914. is found in ``meta/lib/oetest.py``. This base class offers some helper
  6915. attributes, which are described in the following sections:
  6916. Class Methods
  6917. ~~~~~~~~~~~~~
  6918. Class methods are as follows:
  6919. - *hasPackage(pkg):* Returns "True" if ``pkg`` is in the installed
  6920. package list of the image, which is based on the manifest file that
  6921. is generated during the ``do_rootfs`` task.
  6922. - *hasFeature(feature):* Returns "True" if the feature is in
  6923. :term:`IMAGE_FEATURES` or
  6924. :term:`DISTRO_FEATURES`.
  6925. Class Attributes
  6926. ~~~~~~~~~~~~~~~~
  6927. Class attributes are as follows:
  6928. - *pscmd:* Equals "ps -ef" if ``procps`` is installed in the image.
  6929. Otherwise, ``pscmd`` equals "ps" (busybox).
  6930. - *tc:* The called test context, which gives access to the
  6931. following attributes:
  6932. - *d:* The BitBake datastore, which allows you to use stuff such
  6933. as ``oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")``.
  6934. - *testslist and testsrequired:* Used internally. The tests
  6935. do not need these.
  6936. - *filesdir:* The absolute path to
  6937. ``meta/lib/oeqa/runtime/files``, which contains helper files for
  6938. tests meant for copying on the target such as small files written
  6939. in C for compilation.
  6940. - *target:* The target controller object used to deploy and
  6941. start an image on a particular target (e.g. Qemu, SimpleRemote,
  6942. and SystemdbootTarget). Tests usually use the following:
  6943. - *ip:* The target's IP address.
  6944. - *server_ip:* The host's IP address, which is usually used
  6945. by the DNF test suite.
  6946. - *run(cmd, timeout=None):* The single, most used method.
  6947. This command is a wrapper for: ``ssh root@host "cmd"``. The
  6948. command returns a tuple: (status, output), which are what their
  6949. names imply - the return code of "cmd" and whatever output it
  6950. produces. The optional timeout argument represents the number
  6951. of seconds the test should wait for "cmd" to return. If the
  6952. argument is "None", the test uses the default instance's
  6953. timeout period, which is 300 seconds. If the argument is "0",
  6954. the test runs until the command returns.
  6955. - *copy_to(localpath, remotepath):*
  6956. ``scp localpath root@ip:remotepath``.
  6957. - *copy_from(remotepath, localpath):*
  6958. ``scp root@host:remotepath localpath``.
  6959. Instance Attributes
  6960. ~~~~~~~~~~~~~~~~~~~
  6961. A single instance attribute exists, which is ``target``. The ``target``
  6962. instance attribute is identical to the class attribute of the same name,
  6963. which is described in the previous section. This attribute exists as
  6964. both an instance and class attribute so tests can use
  6965. ``self.target.run(cmd)`` in instance methods instead of
  6966. ``oeRuntimeTest.tc.target.run(cmd)``.
  6967. Installing Packages in the DUT Without the Package Manager
  6968. ----------------------------------------------------------
  6969. When a test requires a package built by BitBake, it is possible to
  6970. install that package. Installing the package does not require a package
  6971. manager be installed in the device under test (DUT). It does, however,
  6972. require an SSH connection and the target must be using the
  6973. ``sshcontrol`` class.
  6974. .. note::
  6975. This method uses ``scp`` to copy files from the host to the target, which
  6976. causes permissions and special attributes to be lost.
  6977. A JSON file is used to define the packages needed by a test. This file
  6978. must be in the same path as the file used to define the tests.
  6979. Furthermore, the filename must map directly to the test module name with
  6980. a ``.json`` extension.
  6981. The JSON file must include an object with the test name as keys of an
  6982. object or an array. This object (or array of objects) uses the following
  6983. data:
  6984. - "pkg" - A mandatory string that is the name of the package to be
  6985. installed.
  6986. - "rm" - An optional boolean, which defaults to "false", that specifies
  6987. to remove the package after the test.
  6988. - "extract" - An optional boolean, which defaults to "false", that
  6989. specifies if the package must be extracted from the package format.
  6990. When set to "true", the package is not automatically installed into
  6991. the DUT.
  6992. Following is an example JSON file that handles test "foo" installing
  6993. package "bar" and test "foobar" installing packages "foo" and "bar".
  6994. Once the test is complete, the packages are removed from the DUT.
  6995. ::
  6996. {
  6997. "foo": {
  6998. "pkg": "bar"
  6999. },
  7000. "foobar": [
  7001. {
  7002. "pkg": "foo",
  7003. "rm": true
  7004. },
  7005. {
  7006. "pkg": "bar",
  7007. "rm": true
  7008. }
  7009. ]
  7010. }
  7011. Debugging Tools and Techniques
  7012. ==============================
  7013. The exact method for debugging build failures depends on the nature of
  7014. the problem and on the system's area from which the bug originates.
  7015. Standard debugging practices such as comparison against the last known
  7016. working version with examination of the changes and the re-application
  7017. of steps to identify the one causing the problem are valid for the Yocto
  7018. Project just as they are for any other system. Even though it is
  7019. impossible to detail every possible potential failure, this section
  7020. provides some general tips to aid in debugging given a variety of
  7021. situations.
  7022. .. note::
  7023. A useful feature for debugging is the error reporting tool.
  7024. Configuring the Yocto Project to use this tool causes the
  7025. OpenEmbedded build system to produce error reporting commands as part
  7026. of the console output. You can enter the commands after the build
  7027. completes to log error information into a common database, that can
  7028. help you figure out what might be going wrong. For information on how
  7029. to enable and use this feature, see the
  7030. ":ref:`dev-manual/common-tasks:using the error reporting tool`"
  7031. section.
  7032. The following list shows the debugging topics in the remainder of this
  7033. section:
  7034. - "`Viewing Logs from Failed
  7035. Tasks <#dev-debugging-viewing-logs-from-failed-tasks>`__" describes
  7036. how to find and view logs from tasks that failed during the build
  7037. process.
  7038. - "`Viewing Variable
  7039. Values <#dev-debugging-viewing-variable-values>`__" describes how to
  7040. use the BitBake ``-e`` option to examine variable values after a
  7041. recipe has been parsed.
  7042. - ":ref:`dev-manual/common-tasks:viewing package information with \`\`oe-pkgdata-util\`\``"
  7043. describes how to use the ``oe-pkgdata-util`` utility to query
  7044. :term:`PKGDATA_DIR` and
  7045. display package-related information for built packages.
  7046. - "`Viewing Dependencies Between Recipes and
  7047. Tasks <#dev-viewing-dependencies-between-recipes-and-tasks>`__"
  7048. describes how to use the BitBake ``-g`` option to display recipe
  7049. dependency information used during the build.
  7050. - "`Viewing Task Variable
  7051. Dependencies <#dev-viewing-task-variable-dependencies>`__" describes
  7052. how to use the ``bitbake-dumpsig`` command in conjunction with key
  7053. subdirectories in the
  7054. :term:`Build Directory` to determine
  7055. variable dependencies.
  7056. - "`Running Specific Tasks <#dev-debugging-taskrunning>`__" describes
  7057. how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``)
  7058. to run specific tasks in the build chain. It can be useful to run
  7059. tasks "out-of-order" when trying isolate build issues.
  7060. - "`General BitBake Problems <#dev-debugging-bitbake>`__" describes how
  7061. to use BitBake's ``-D`` debug output option to reveal more about what
  7062. BitBake is doing during the build.
  7063. - "`Building with No Dependencies <#dev-debugging-buildfile>`__"
  7064. describes how to use the BitBake ``-b`` option to build a recipe
  7065. while ignoring dependencies.
  7066. - "`Recipe Logging Mechanisms <#recipe-logging-mechanisms>`__"
  7067. describes how to use the many recipe logging functions to produce
  7068. debugging output and report errors and warnings.
  7069. - "`Debugging Parallel Make Races <#debugging-parallel-make-races>`__"
  7070. describes how to debug situations where the build consists of several
  7071. parts that are run simultaneously and when the output or result of
  7072. one part is not ready for use with a different part of the build that
  7073. depends on that output.
  7074. - "`Debugging With the GNU Project Debugger (GDB)
  7075. Remotely <#platdev-gdb-remotedebug>`__" describes how to use GDB to
  7076. allow you to examine running programs, which can help you fix
  7077. problems.
  7078. - "`Debugging with the GNU Project Debugger (GDB) on the
  7079. Target <#debugging-with-the-gnu-project-debugger-gdb-on-the-target>`__"
  7080. describes how to use GDB directly on target hardware for debugging.
  7081. - "`Other Debugging Tips <#dev-other-debugging-others>`__" describes
  7082. miscellaneous debugging tips that can be useful.
  7083. Viewing Logs from Failed Tasks
  7084. ------------------------------
  7085. You can find the log for a task in the file
  7086. ``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`.
  7087. For example, the log for the
  7088. :ref:`ref-tasks-compile` task of the
  7089. QEMU minimal image for the x86 machine (``qemux86``) might be in
  7090. ``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``.
  7091. To see the commands :term:`BitBake` ran
  7092. to generate a log, look at the corresponding ``run.do_``\ `taskname` file
  7093. in the same directory.
  7094. ``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic
  7095. links to ``log.do_``\ `taskname`\ ``.``\ `pid` and
  7096. ``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had
  7097. when it ran. The symlinks always point to the files corresponding to the
  7098. most recent run.
  7099. Viewing Variable Values
  7100. -----------------------
  7101. Sometimes you need to know the value of a variable as a result of
  7102. BitBake's parsing step. This could be because some unexpected behavior
  7103. occurred in your project. Perhaps an attempt to :ref:`modify a variable
  7104. <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing
  7105. variables>` did not work out as expected.
  7106. BitBake's ``-e`` option is used to display variable values after
  7107. parsing. The following command displays the variable values after the
  7108. configuration files (i.e. ``local.conf``, ``bblayers.conf``,
  7109. ``bitbake.conf`` and so forth) have been parsed:
  7110. ::
  7111. $ bitbake -e
  7112. The following command displays variable values after a specific recipe has
  7113. been parsed. The variables include those from the configuration as well:
  7114. ::
  7115. $ bitbake -e recipename
  7116. .. note::
  7117. Each recipe has its own private set of variables (datastore).
  7118. Internally, after parsing the configuration, a copy of the resulting
  7119. datastore is made prior to parsing each recipe. This copying implies
  7120. that variables set in one recipe will not be visible to other
  7121. recipes.
  7122. Likewise, each task within a recipe gets a private datastore based on
  7123. the recipe datastore, which means that variables set within one task
  7124. will not be visible to other tasks.
  7125. In the output of ``bitbake -e``, each variable is preceded by a
  7126. description of how the variable got its value, including temporary
  7127. values that were later overridden. This description also includes
  7128. variable flags (varflags) set on the variable. The output can be very
  7129. helpful during debugging.
  7130. Variables that are exported to the environment are preceded by
  7131. ``export`` in the output of ``bitbake -e``. See the following example:
  7132. ::
  7133. export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
  7134. In addition to variable values, the output of the ``bitbake -e`` and
  7135. ``bitbake -e`` recipe commands includes the following information:
  7136. - The output starts with a tree listing all configuration files and
  7137. classes included globally, recursively listing the files they include
  7138. or inherit in turn. Much of the behavior of the OpenEmbedded build
  7139. system (including the behavior of the :ref:`ref-manual/tasks:normal recipe build tasks`) is
  7140. implemented in the
  7141. :ref:`base <ref-classes-base>` class and the
  7142. classes it inherits, rather than being built into BitBake itself.
  7143. - After the variable values, all functions appear in the output. For
  7144. shell functions, variables referenced within the function body are
  7145. expanded. If a function has been modified using overrides or using
  7146. override-style operators like ``_append`` and ``_prepend``, then the
  7147. final assembled function body appears in the output.
  7148. Viewing Package Information with ``oe-pkgdata-util``
  7149. ----------------------------------------------------
  7150. You can use the ``oe-pkgdata-util`` command-line utility to query
  7151. :term:`PKGDATA_DIR` and display
  7152. various package-related information. When you use the utility, you must
  7153. use it to view information on packages that have already been built.
  7154. Following are a few of the available ``oe-pkgdata-util`` subcommands.
  7155. .. note::
  7156. You can use the standard \* and ? globbing wildcards as part of
  7157. package names and paths.
  7158. - ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages
  7159. that have been built, optionally limiting the match to packages that
  7160. match pattern.
  7161. - ``oe-pkgdata-util list-pkg-files package ...``: Lists the
  7162. files and directories contained in the given packages.
  7163. .. note::
  7164. A different way to view the contents of a package is to look at
  7165. the
  7166. ``${``\ :term:`WORKDIR`\ ``}/packages-split``
  7167. directory of the recipe that generates the package. This directory
  7168. is created by the
  7169. :ref:`ref-tasks-package` task
  7170. and has one subdirectory for each package the recipe generates,
  7171. which contains the files stored in that package.
  7172. If you want to inspect the ``${WORKDIR}/packages-split``
  7173. directory, make sure that
  7174. :ref:`rm_work <ref-classes-rm-work>` is not
  7175. enabled when you build the recipe.
  7176. - ``oe-pkgdata-util find-path path ...``: Lists the names of
  7177. the packages that contain the given paths. For example, the following
  7178. tells us that ``/usr/share/man/man1/make.1`` is contained in the
  7179. ``make-doc`` package:
  7180. ::
  7181. $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
  7182. make-doc: /usr/share/man/man1/make.1
  7183. - ``oe-pkgdata-util lookup-recipe package ...``: Lists the name
  7184. of the recipes that produce the given packages.
  7185. For more information on the ``oe-pkgdata-util`` command, use the help
  7186. facility:
  7187. ::
  7188. $ oe-pkgdata-util --help
  7189. $ oe-pkgdata-util subcommand --help
  7190. Viewing Dependencies Between Recipes and Tasks
  7191. ----------------------------------------------
  7192. Sometimes it can be hard to see why BitBake wants to build other recipes
  7193. before the one you have specified. Dependency information can help you
  7194. understand why a recipe is built.
  7195. To generate dependency information for a recipe, run the following
  7196. command:
  7197. ::
  7198. $ bitbake -g recipename
  7199. This command writes the following files in the current directory:
  7200. - ``pn-buildlist``: A list of recipes/targets involved in building
  7201. `recipename`. "Involved" here means that at least one task from the
  7202. recipe needs to run when building `recipename` from scratch. Targets
  7203. that are in
  7204. :term:`ASSUME_PROVIDED`
  7205. are not listed.
  7206. - ``task-depends.dot``: A graph showing dependencies between tasks.
  7207. The graphs are in
  7208. `DOT <https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29>`__
  7209. format and can be converted to images (e.g. using the ``dot`` tool from
  7210. `Graphviz <https://www.graphviz.org/>`__).
  7211. .. note::
  7212. - DOT files use a plain text format. The graphs generated using the
  7213. ``bitbake -g`` command are often so large as to be difficult to
  7214. read without special pruning (e.g. with Bitbake's ``-I`` option)
  7215. and processing. Despite the form and size of the graphs, the
  7216. corresponding ``.dot`` files can still be possible to read and
  7217. provide useful information.
  7218. As an example, the ``task-depends.dot`` file contains lines such
  7219. as the following:
  7220. ::
  7221. "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
  7222. The above example line reveals that the
  7223. :ref:`ref-tasks-configure`
  7224. task in ``libxslt`` depends on the
  7225. :ref:`ref-tasks-populate_sysroot`
  7226. task in ``libxml2``, which is a normal
  7227. :term:`DEPENDS` dependency
  7228. between the two recipes.
  7229. - For an example of how ``.dot`` files can be processed, see the
  7230. ``scripts/contrib/graph-tool`` Python script, which finds and
  7231. displays paths between graph nodes.
  7232. You can use a different method to view dependency information by using
  7233. the following command:
  7234. ::
  7235. $ bitbake -g -u taskexp recipename
  7236. This command
  7237. displays a GUI window from which you can view build-time and runtime
  7238. dependencies for the recipes involved in building recipename.
  7239. Viewing Task Variable Dependencies
  7240. ----------------------------------
  7241. As mentioned in the
  7242. ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake
  7243. User Manual, BitBake tries to automatically determine what variables a
  7244. task depends on so that it can rerun the task if any values of the
  7245. variables change. This determination is usually reliable. However, if
  7246. you do things like construct variable names at runtime, then you might
  7247. have to manually declare dependencies on those variables using
  7248. ``vardeps`` as described in the
  7249. ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake
  7250. User Manual.
  7251. If you are unsure whether a variable dependency is being picked up
  7252. automatically for a given task, you can list the variable dependencies
  7253. BitBake has determined by doing the following:
  7254. 1. Build the recipe containing the task:
  7255. ::
  7256. $ bitbake recipename
  7257. 2. Inside the :term:`STAMPS_DIR`
  7258. directory, find the signature data (``sigdata``) file that
  7259. corresponds to the task. The ``sigdata`` files contain a pickled
  7260. Python database of all the metadata that went into creating the input
  7261. checksum for the task. As an example, for the
  7262. :ref:`ref-tasks-fetch` task of the
  7263. ``db`` recipe, the ``sigdata`` file might be found in the following
  7264. location:
  7265. ::
  7266. ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
  7267. For tasks that are accelerated through the shared state
  7268. (:ref:`sstate <overview-manual/concepts:shared state cache>`) cache, an
  7269. additional ``siginfo`` file is written into
  7270. :term:`SSTATE_DIR` along with
  7271. the cached task output. The ``siginfo`` files contain exactly the
  7272. same information as ``sigdata`` files.
  7273. 3. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here
  7274. is an example:
  7275. ::
  7276. $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
  7277. In the output of the above command, you will find a line like the
  7278. following, which lists all the (inferred) variable dependencies for
  7279. the task. This list also includes indirect dependencies from
  7280. variables depending on other variables, recursively.
  7281. ::
  7282. Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
  7283. .. note::
  7284. Functions (e.g. ``base_do_fetch``) also count as variable dependencies.
  7285. These functions in turn depend on the variables they reference.
  7286. The output of ``bitbake-dumpsig`` also includes the value each
  7287. variable had, a list of dependencies for each variable, and
  7288. :term:`bitbake:BB_HASHBASE_WHITELIST`
  7289. information.
  7290. There is also a ``bitbake-diffsigs`` command for comparing two
  7291. ``siginfo`` or ``sigdata`` files. This command can be helpful when
  7292. trying to figure out what changed between two versions of a task. If you
  7293. call ``bitbake-diffsigs`` with just one file, the command behaves like
  7294. ``bitbake-dumpsig``.
  7295. You can also use BitBake to dump out the signature construction
  7296. information without executing tasks by using either of the following
  7297. BitBake command-line options:
  7298. ::
  7299. ‐‐dump-signatures=SIGNATURE_HANDLER
  7300. -S SIGNATURE_HANDLER
  7301. .. note::
  7302. Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which
  7303. dump only the signature or compare the dumped signature with the cached one,
  7304. respectively.
  7305. Using BitBake with either of these options causes BitBake to dump out
  7306. ``sigdata`` files in the ``stamps`` directory for every task it would
  7307. have executed instead of building the specified target package.
  7308. Viewing Metadata Used to Create the Input Signature of a Shared State Task
  7309. --------------------------------------------------------------------------
  7310. Seeing what metadata went into creating the input signature of a shared
  7311. state (sstate) task can be a useful debugging aid. This information is
  7312. available in signature information (``siginfo``) files in
  7313. :term:`SSTATE_DIR`. For
  7314. information on how to view and interpret information in ``siginfo``
  7315. files, see the "`Viewing Task Variable
  7316. Dependencies <#dev-viewing-task-variable-dependencies>`__" section.
  7317. For conceptual information on shared state, see the
  7318. ":ref:`overview-manual/concepts:shared state`"
  7319. section in the Yocto Project Overview and Concepts Manual.
  7320. Invalidating Shared State to Force a Task to Run
  7321. ------------------------------------------------
  7322. The OpenEmbedded build system uses
  7323. :ref:`checksums <overview-manual/concepts:checksums (signatures)>` and
  7324. :ref:`overview-manual/concepts:shared state` cache to avoid unnecessarily
  7325. rebuilding tasks. Collectively, this scheme is known as "shared state
  7326. code".
  7327. As with all schemes, this one has some drawbacks. It is possible that
  7328. you could make implicit changes to your code that the checksum
  7329. calculations do not take into account. These implicit changes affect a
  7330. task's output but do not trigger the shared state code into rebuilding a
  7331. recipe. Consider an example during which a tool changes its output.
  7332. Assume that the output of ``rpmdeps`` changes. The result of the change
  7333. should be that all the ``package`` and ``package_write_rpm`` shared
  7334. state cache items become invalid. However, because the change to the
  7335. output is external to the code and therefore implicit, the associated
  7336. shared state cache items do not become invalidated. In this case, the
  7337. build process uses the cached items rather than running the task again.
  7338. Obviously, these types of implicit changes can cause problems.
  7339. To avoid these problems during the build, you need to understand the
  7340. effects of any changes you make. Realize that changes you make directly
  7341. to a function are automatically factored into the checksum calculation.
  7342. Thus, these explicit changes invalidate the associated area of shared
  7343. state cache. However, you need to be aware of any implicit changes that
  7344. are not obvious changes to the code and could affect the output of a
  7345. given task.
  7346. When you identify an implicit change, you can easily take steps to
  7347. invalidate the cache and force the tasks to run. The steps you can take
  7348. are as simple as changing a function's comments in the source code. For
  7349. example, to invalidate package shared state files, change the comment
  7350. statements of
  7351. :ref:`ref-tasks-package` or the
  7352. comments of one of the functions it calls. Even though the change is
  7353. purely cosmetic, it causes the checksum to be recalculated and forces
  7354. the build system to run the task again.
  7355. .. note::
  7356. For an example of a commit that makes a cosmetic change to invalidate
  7357. shared state, see this
  7358. :yocto_git:`commit </poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`.
  7359. Running Specific Tasks
  7360. ----------------------
  7361. Any given recipe consists of a set of tasks. The standard BitBake
  7362. behavior in most cases is: ``do_fetch``, ``do_unpack``, ``do_patch``,
  7363. ``do_configure``, ``do_compile``, ``do_install``, ``do_package``,
  7364. ``do_package_write_*``, and ``do_build``. The default task is
  7365. ``do_build`` and any tasks on which it depends build first. Some tasks,
  7366. such as ``do_devshell``, are not part of the default build chain. If you
  7367. wish to run a task that is not part of the default build chain, you can
  7368. use the ``-c`` option in BitBake. Here is an example:
  7369. ::
  7370. $ bitbake matchbox-desktop -c devshell
  7371. The ``-c`` option respects task dependencies, which means that all other
  7372. tasks (including tasks from other recipes) that the specified task
  7373. depends on will be run before the task. Even when you manually specify a
  7374. task to run with ``-c``, BitBake will only run the task if it considers
  7375. it "out of date". See the
  7376. ":ref:`overview-manual/concepts:stamp files and the rerunning of tasks`"
  7377. section in the Yocto Project Overview and Concepts Manual for how
  7378. BitBake determines whether a task is "out of date".
  7379. If you want to force an up-to-date task to be rerun (e.g. because you
  7380. made manual modifications to the recipe's
  7381. :term:`WORKDIR` that you want to try
  7382. out), then you can use the ``-f`` option.
  7383. .. note::
  7384. The reason ``-f`` is never required when running the
  7385. :ref:`ref-tasks-devshell` task is because the
  7386. [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ]
  7387. variable flag is already set for the task.
  7388. The following example shows one way you can use the ``-f`` option:
  7389. ::
  7390. $ bitbake matchbox-desktop
  7391. .
  7392. .
  7393. make some changes to the source code in the work directory
  7394. .
  7395. .
  7396. $ bitbake matchbox-desktop -c compile -f
  7397. $ bitbake matchbox-desktop
  7398. This sequence first builds and then recompiles ``matchbox-desktop``. The
  7399. last command reruns all tasks (basically the packaging tasks) after the
  7400. compile. BitBake recognizes that the ``do_compile`` task was rerun and
  7401. therefore understands that the other tasks also need to be run again.
  7402. Another, shorter way to rerun a task and all
  7403. :ref:`ref-manual/tasks:normal recipe build tasks`
  7404. that depend on it is to use the ``-C`` option.
  7405. .. note::
  7406. This option is upper-cased and is separate from the ``-c``
  7407. option, which is lower-cased.
  7408. Using this option invalidates the given task and then runs the
  7409. :ref:`ref-tasks-build` task, which is
  7410. the default task if no task is given, and the tasks on which it depends.
  7411. You could replace the final two commands in the previous example with
  7412. the following single command:
  7413. ::
  7414. $ bitbake matchbox-desktop -C compile
  7415. Internally, the ``-f`` and ``-C`` options work by tainting (modifying)
  7416. the input checksum of the specified task. This tainting indirectly
  7417. causes the task and its dependent tasks to be rerun through the normal
  7418. task dependency mechanisms.
  7419. .. note::
  7420. BitBake explicitly keeps track of which tasks have been tainted in
  7421. this fashion, and will print warnings such as the following for
  7422. builds involving such tasks:
  7423. .. code-block:: none
  7424. WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
  7425. The purpose of the warning is to let you know that the work directory
  7426. and build output might not be in the clean state they would be in for
  7427. a "normal" build, depending on what actions you took. To get rid of
  7428. such warnings, you can remove the work directory and rebuild the
  7429. recipe, as follows:
  7430. ::
  7431. $ bitbake matchbox-desktop -c clean
  7432. $ bitbake matchbox-desktop
  7433. You can view a list of tasks in a given package by running the
  7434. ``do_listtasks`` task as follows:
  7435. ::
  7436. $ bitbake matchbox-desktop -c listtasks
  7437. The results appear as output to the console and are also in
  7438. the file ``${WORKDIR}/temp/log.do_listtasks``.
  7439. General BitBake Problems
  7440. ------------------------
  7441. You can see debug output from BitBake by using the ``-D`` option. The
  7442. debug output gives more information about what BitBake is doing and the
  7443. reason behind it. Each ``-D`` option you use increases the logging
  7444. level. The most common usage is ``-DDD``.
  7445. The output from ``bitbake -DDD -v targetname`` can reveal why BitBake
  7446. chose a certain version of a package or why BitBake picked a certain
  7447. provider. This command could also help you in a situation where you
  7448. think BitBake did something unexpected.
  7449. Building with No Dependencies
  7450. -----------------------------
  7451. To build a specific recipe (``.bb`` file), you can use the following
  7452. command form:
  7453. ::
  7454. $ bitbake -b somepath/somerecipe.bb
  7455. This command form does
  7456. not check for dependencies. Consequently, you should use it only when
  7457. you know existing dependencies have been met.
  7458. .. note::
  7459. You can also specify fragments of the filename. In this case, BitBake
  7460. checks for a unique match.
  7461. Recipe Logging Mechanisms
  7462. -------------------------
  7463. The Yocto Project provides several logging functions for producing
  7464. debugging output and reporting errors and warnings. For Python
  7465. functions, the following logging functions exist. All of these functions
  7466. log to ``${T}/log.do_``\ `task`, and can also log to standard output
  7467. (stdout) with the right settings:
  7468. - ``bb.plain(msg)``: Writes msg as is to the log while also
  7469. logging to stdout.
  7470. - ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to
  7471. stdout if BitBake is called with "-v".
  7472. - ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the
  7473. log. Also logs to stdout if the log level is greater than or equal to
  7474. level. See the ":ref:`-D <bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax>`" option
  7475. in the BitBake User Manual for more information.
  7476. - ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also
  7477. logging to stdout.
  7478. - ``bb.error(msg)``: Writes "ERROR: msg" to the log while also
  7479. logging to standard out (stdout).
  7480. .. note::
  7481. Calling this function does not cause the task to fail.
  7482. - ``bb.fatal(``\ msg\ ``)``: This logging function is similar to
  7483. ``bb.error(``\ msg\ ``)`` but also causes the calling task to fail.
  7484. .. note::
  7485. ``bb.fatal()`` raises an exception, which means you do not need to put a
  7486. "return" statement after the function.
  7487. The same logging functions are also available in shell functions, under
  7488. the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``,
  7489. and ``bbfatal``. The
  7490. :ref:`logging <ref-classes-logging>` class
  7491. implements these functions. See that class in the ``meta/classes``
  7492. folder of the :term:`Source Directory` for information.
  7493. Logging With Python
  7494. ~~~~~~~~~~~~~~~~~~~
  7495. When creating recipes using Python and inserting code that handles build
  7496. logs, keep in mind the goal is to have informative logs while keeping
  7497. the console as "silent" as possible. Also, if you want status messages
  7498. in the log, use the "debug" loglevel.
  7499. Following is an example written in Python. The code handles logging for
  7500. a function that determines the number of tasks needed to be run. See the
  7501. ":ref:`ref-tasks-listtasks`"
  7502. section for additional information:
  7503. ::
  7504. python do_listtasks() {
  7505. bb.debug(2, "Starting to figure out the task list")
  7506. if noteworthy_condition:
  7507. bb.note("There are 47 tasks to run")
  7508. bb.debug(2, "Got to point xyz")
  7509. if warning_trigger:
  7510. bb.warn("Detected warning_trigger, this might be a problem later.")
  7511. if recoverable_error:
  7512. bb.error("Hit recoverable_error, you really need to fix this!")
  7513. if fatal_error:
  7514. bb.fatal("fatal_error detected, unable to print the task list")
  7515. bb.plain("The tasks present are abc")
  7516. bb.debug(2, "Finished figuring out the tasklist")
  7517. }
  7518. Logging With Bash
  7519. ~~~~~~~~~~~~~~~~~
  7520. When creating recipes using Bash and inserting code that handles build
  7521. logs, you have the same goals - informative with minimal console output.
  7522. The syntax you use for recipes written in Bash is similar to that of
  7523. recipes written in Python described in the previous section.
  7524. Following is an example written in Bash. The code logs the progress of
  7525. the ``do_my_function`` function.
  7526. ::
  7527. do_my_function() {
  7528. bbdebug 2 "Running do_my_function"
  7529. if [ exceptional_condition ]; then
  7530. bbnote "Hit exceptional_condition"
  7531. fi
  7532. bbdebug 2 "Got to point xyz"
  7533. if [ warning_trigger ]; then
  7534. bbwarn "Detected warning_trigger, this might cause a problem later."
  7535. fi
  7536. if [ recoverable_error ]; then
  7537. bberror "Hit recoverable_error, correcting"
  7538. fi
  7539. if [ fatal_error ]; then
  7540. bbfatal "fatal_error detected"
  7541. fi
  7542. bbdebug 2 "Completed do_my_function"
  7543. }
  7544. Debugging Parallel Make Races
  7545. -----------------------------
  7546. A parallel ``make`` race occurs when the build consists of several parts
  7547. that are run simultaneously and a situation occurs when the output or
  7548. result of one part is not ready for use with a different part of the
  7549. build that depends on that output. Parallel make races are annoying and
  7550. can sometimes be difficult to reproduce and fix. However, some simple
  7551. tips and tricks exist that can help you debug and fix them. This section
  7552. presents a real-world example of an error encountered on the Yocto
  7553. Project autobuilder and the process used to fix it.
  7554. .. note::
  7555. If you cannot properly fix a ``make`` race condition, you can work around it
  7556. by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST`
  7557. variables.
  7558. The Failure
  7559. ~~~~~~~~~~~
  7560. For this example, assume that you are building an image that depends on
  7561. the "neard" package. And, during the build, BitBake runs into problems
  7562. and creates the following output.
  7563. .. note::
  7564. This example log file has longer lines artificially broken to make
  7565. the listing easier to read.
  7566. If you examine the output or the log file, you see the failure during
  7567. ``make``:
  7568. .. code-block:: none
  7569. | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
  7570. | DEBUG: Executing shell function do_compile
  7571. | NOTE: make -j 16
  7572. | make --no-print-directory all-am
  7573. | /bin/mkdir -p include/near
  7574. | /bin/mkdir -p include/near
  7575. | /bin/mkdir -p include/near
  7576. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7577. 0.14-r0/neard-0.14/include/types.h include/near/types.h
  7578. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7579. 0.14-r0/neard-0.14/include/log.h include/near/log.h
  7580. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7581. 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
  7582. | /bin/mkdir -p include/near
  7583. | /bin/mkdir -p include/near
  7584. | /bin/mkdir -p include/near
  7585. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7586. 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
  7587. | /bin/mkdir -p include/near
  7588. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7589. 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
  7590. | /bin/mkdir -p include/near
  7591. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7592. 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
  7593. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7594. 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
  7595. | /bin/mkdir -p include/near
  7596. | /bin/mkdir -p include/near
  7597. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7598. 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
  7599. | /bin/mkdir -p include/near
  7600. | /bin/mkdir -p include/near
  7601. | /bin/mkdir -p include/near
  7602. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7603. 0.14-r0/neard-0.14/include/device.h include/near/device.h
  7604. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7605. 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
  7606. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7607. 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
  7608. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7609. 0.14-r0/neard-0.14/include/version.h include/near/version.h
  7610. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7611. 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
  7612. | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
  7613. | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
  7614. build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
  7615. yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
  7616. -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
  7617. lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
  7618. tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
  7619. nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
  7620. yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
  7621. -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
  7622. -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
  7623. -o tools/snep-send.o tools/snep-send.c
  7624. | In file included from tools/snep-send.c:16:0:
  7625. | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
  7626. | #include <near/dbus.h>
  7627. | ^
  7628. | compilation terminated.
  7629. | make[1]: *** [tools/snep-send.o] Error 1
  7630. | make[1]: *** Waiting for unfinished jobs....
  7631. | make: *** [all] Error 2
  7632. | ERROR: oe_runmake failed
  7633. Reproducing the Error
  7634. ~~~~~~~~~~~~~~~~~~~~~
  7635. Because race conditions are intermittent, they do not manifest
  7636. themselves every time you do the build. In fact, most times the build
  7637. will complete without problems even though the potential race condition
  7638. exists. Thus, once the error surfaces, you need a way to reproduce it.
  7639. In this example, compiling the "neard" package is causing the problem.
  7640. So the first thing to do is build "neard" locally. Before you start the
  7641. build, set the
  7642. :term:`PARALLEL_MAKE` variable
  7643. in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a
  7644. high value for ``PARALLEL_MAKE`` increases the chances of the race
  7645. condition showing up:
  7646. ::
  7647. $ bitbake neard
  7648. Once the local build for "neard" completes, start a ``devshell`` build:
  7649. ::
  7650. $ bitbake neard -c devshell
  7651. For information on how to use a
  7652. ``devshell``, see the "`Using a Development
  7653. Shell <#platdev-appdev-devshell>`__" section.
  7654. In the ``devshell``, do the following:
  7655. ::
  7656. $ make clean
  7657. $ make tools/snep-send.o
  7658. The ``devshell`` commands cause the failure to clearly
  7659. be visible. In this case, a missing dependency exists for the "neard"
  7660. Makefile target. Here is some abbreviated, sample output with the
  7661. missing dependency clearly visible at the end:
  7662. ::
  7663. i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
  7664. .
  7665. .
  7666. .
  7667. tools/snep-send.c
  7668. In file included from tools/snep-send.c:16:0:
  7669. tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
  7670. #include <near/dbus.h>
  7671. ^
  7672. compilation terminated.
  7673. make: *** [tools/snep-send.o] Error 1
  7674. $
  7675. Creating a Patch for the Fix
  7676. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7677. Because there is a missing dependency for the Makefile target, you need
  7678. to patch the ``Makefile.am`` file, which is generated from
  7679. ``Makefile.in``. You can use Quilt to create the patch:
  7680. ::
  7681. $ quilt new parallelmake.patch
  7682. Patch patches/parallelmake.patch is now on top
  7683. $ quilt add Makefile.am
  7684. File Makefile.am added to patch patches/parallelmake.patch
  7685. For more information on using Quilt, see the
  7686. "`Using Quilt in Your Workflow <#using-a-quilt-workflow>`__" section.
  7687. At this point you need to make the edits to ``Makefile.am`` to add the
  7688. missing dependency. For our example, you have to add the following line
  7689. to the file:
  7690. ::
  7691. tools/snep-send.$(OBJEXT): include/near/dbus.h
  7692. Once you have edited the file, use the ``refresh`` command to create the
  7693. patch:
  7694. ::
  7695. $ quilt refresh
  7696. Refreshed patch patches/parallelmake.patch
  7697. Once
  7698. the patch file exists, you need to add it back to the originating recipe
  7699. folder. Here is an example assuming a top-level
  7700. :term:`Source Directory` named ``poky``:
  7701. ::
  7702. $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
  7703. The final thing you need to do to implement the fix in the build is to
  7704. update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the
  7705. :term:`SRC_URI` statement includes
  7706. the patch file. The recipe file is in the folder above the patch. Here
  7707. is what the edited ``SRC_URI`` statement would look like:
  7708. ::
  7709. SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
  7710. file://neard.in \
  7711. file://neard.service.in \
  7712. file://parallelmake.patch \
  7713. "
  7714. With the patch complete and moved to the correct folder and the
  7715. ``SRC_URI`` statement updated, you can exit the ``devshell``:
  7716. ::
  7717. $ exit
  7718. Testing the Build
  7719. ~~~~~~~~~~~~~~~~~
  7720. With everything in place, you can get back to trying the build again
  7721. locally:
  7722. ::
  7723. $ bitbake neard
  7724. This build should succeed.
  7725. Now you can open up a ``devshell`` again and repeat the clean and make
  7726. operations as follows:
  7727. ::
  7728. $ bitbake neard -c devshell
  7729. $ make clean
  7730. $ make tools/snep-send.o
  7731. The build should work without issue.
  7732. As with all solved problems, if they originated upstream, you need to
  7733. submit the fix for the recipe in OE-Core and upstream so that the
  7734. problem is taken care of at its source. See the "`Submitting a Change to
  7735. the Yocto Project <#how-to-submit-a-change>`__" section for more
  7736. information.
  7737. Debugging With the GNU Project Debugger (GDB) Remotely
  7738. ------------------------------------------------------
  7739. GDB allows you to examine running programs, which in turn helps you to
  7740. understand and fix problems. It also allows you to perform post-mortem
  7741. style analysis of program crashes. GDB is available as a package within
  7742. the Yocto Project and is installed in SDK images by default. See the
  7743. ":ref:`ref-manual/images:Images`" chapter in the Yocto
  7744. Project Reference Manual for a description of these images. You can find
  7745. information on GDB at https://sourceware.org/gdb/.
  7746. .. note::
  7747. For best results, install debug (``-dbg``) packages for the applications you
  7748. are going to debug. Doing so makes extra debug symbols available that give
  7749. you more meaningful output.
  7750. Sometimes, due to memory or disk space constraints, it is not possible
  7751. to use GDB directly on the remote target to debug applications. These
  7752. constraints arise because GDB needs to load the debugging information
  7753. and the binaries of the process being debugged. Additionally, GDB needs
  7754. to perform many computations to locate information such as function
  7755. names, variable names and values, stack traces and so forth - even
  7756. before starting the debugging process. These extra computations place
  7757. more load on the target system and can alter the characteristics of the
  7758. program being debugged.
  7759. To help get past the previously mentioned constraints, you can use
  7760. gdbserver, which runs on the remote target and does not load any
  7761. debugging information from the debugged process. Instead, a GDB instance
  7762. processes the debugging information that is run on a remote computer -
  7763. the host GDB. The host GDB then sends control commands to gdbserver to
  7764. make it stop or start the debugged program, as well as read or write
  7765. memory regions of that debugged program. All the debugging information
  7766. loaded and processed as well as all the heavy debugging is done by the
  7767. host GDB. Offloading these processes gives the gdbserver running on the
  7768. target a chance to remain small and fast.
  7769. Because the host GDB is responsible for loading the debugging
  7770. information and for doing the necessary processing to make actual
  7771. debugging happen, you have to make sure the host can access the
  7772. unstripped binaries complete with their debugging information and also
  7773. be sure the target is compiled with no optimizations. The host GDB must
  7774. also have local access to all the libraries used by the debugged
  7775. program. Because gdbserver does not need any local debugging
  7776. information, the binaries on the remote target can remain stripped.
  7777. However, the binaries must also be compiled without optimization so they
  7778. match the host's binaries.
  7779. To remain consistent with GDB documentation and terminology, the binary
  7780. being debugged on the remote target machine is referred to as the
  7781. "inferior" binary. For documentation on GDB see the `GDB
  7782. site <https://sourceware.org/gdb/documentation/>`__.
  7783. The following steps show you how to debug using the GNU project
  7784. debugger.
  7785. 1. *Configure your build system to construct the companion debug
  7786. filesystem:*
  7787. In your ``local.conf`` file, set the following:
  7788. ::
  7789. IMAGE_GEN_DEBUGFS = "1"
  7790. IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
  7791. These options cause the
  7792. OpenEmbedded build system to generate a special companion filesystem
  7793. fragment, which contains the matching source and debug symbols to
  7794. your deployable filesystem. The build system does this by looking at
  7795. what is in the deployed filesystem, and pulling the corresponding
  7796. ``-dbg`` packages.
  7797. The companion debug filesystem is not a complete filesystem, but only
  7798. contains the debug fragments. This filesystem must be combined with
  7799. the full filesystem for debugging. Subsequent steps in this procedure
  7800. show how to combine the partial filesystem with the full filesystem.
  7801. 2. *Configure the system to include gdbserver in the target filesystem:*
  7802. Make the following addition in either your ``local.conf`` file or in
  7803. an image recipe:
  7804. ::
  7805. IMAGE_INSTALL_append = " gdbserver"
  7806. The change makes
  7807. sure the ``gdbserver`` package is included.
  7808. 3. *Build the environment:*
  7809. Use the following command to construct the image and the companion
  7810. Debug Filesystem:
  7811. ::
  7812. $ bitbake image
  7813. Build the cross GDB component and
  7814. make it available for debugging. Build the SDK that matches the
  7815. image. Building the SDK is best for a production build that can be
  7816. used later for debugging, especially during long term maintenance:
  7817. ::
  7818. $ bitbake -c populate_sdk image
  7819. Alternatively, you can build the minimal toolchain components that
  7820. match the target. Doing so creates a smaller than typical SDK and
  7821. only contains a minimal set of components with which to build simple
  7822. test applications, as well as run the debugger:
  7823. ::
  7824. $ bitbake meta-toolchain
  7825. A final method is to build Gdb itself within the build system:
  7826. ::
  7827. $ bitbake gdb-cross-<architecture>
  7828. Doing so produces a temporary copy of
  7829. ``cross-gdb`` you can use for debugging during development. While
  7830. this is the quickest approach, the two previous methods in this step
  7831. are better when considering long-term maintenance strategies.
  7832. .. note::
  7833. If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests
  7834. the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the
  7835. actual name you want to use.
  7836. 4. *Set up the* ``debugfs``\ *:*
  7837. Run the following commands to set up the ``debugfs``:
  7838. ::
  7839. $ mkdir debugfs
  7840. $ cd debugfs
  7841. $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image.rootfs.tar.bz2
  7842. $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image-dbg.rootfs.tar.bz2
  7843. 5. *Set up GDB:*
  7844. Install the SDK (if you built one) and then source the correct
  7845. environment file. Sourcing the environment file puts the SDK in your
  7846. ``PATH`` environment variable.
  7847. If you are using the build system, Gdb is located in
  7848. `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb``
  7849. 6. *Boot the target:*
  7850. For information on how to run QEMU, see the `QEMU
  7851. Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__.
  7852. .. note::
  7853. Be sure to verify that your host can access the target via TCP.
  7854. 7. *Debug a program:*
  7855. Debugging a program involves running gdbserver on the target and then
  7856. running Gdb on the host. The example in this step debugs ``gzip``:
  7857. .. code-block:: shell
  7858. root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
  7859. For
  7860. additional gdbserver options, see the `GDB Server
  7861. Documentation <https://www.gnu.org/software/gdb/documentation/>`__.
  7862. After running gdbserver on the target, you need to run Gdb on the
  7863. host and configure it and connect to the target. Use these commands:
  7864. ::
  7865. $ cd directory-holding-the-debugfs-directory
  7866. $ arch-gdb
  7867. (gdb) set sysroot debugfs
  7868. (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
  7869. (gdb) target remote IP-of-target:1234
  7870. At this
  7871. point, everything should automatically load (i.e. matching binaries,
  7872. symbols and headers).
  7873. .. note::
  7874. The Gdb ``set`` commands in the previous example can be placed into the
  7875. users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever
  7876. commands are in that file.
  7877. 8. *Deploying without a full image rebuild:*
  7878. In many cases, during development you want a quick method to deploy a
  7879. new binary to the target and debug it, without waiting for a full
  7880. image build.
  7881. One approach to solving this situation is to just build the component
  7882. you want to debug. Once you have built the component, copy the
  7883. executable directly to both the target and the host ``debugfs``.
  7884. If the binary is processed through the debug splitting in
  7885. OpenEmbedded, you should also copy the debug items (i.e. ``.debug``
  7886. contents and corresponding ``/usr/src/debug`` files) from the work
  7887. directory. Here is an example:
  7888. ::
  7889. $ bitbake bash
  7890. $ bitbake -c devshell bash
  7891. $ cd ..
  7892. $ scp packages-split/bash/bin/bash target:/bin/bash
  7893. $ cp -a packages-split/bash-dbg/\* path/debugfs
  7894. Debugging with the GNU Project Debugger (GDB) on the Target
  7895. -----------------------------------------------------------
  7896. The previous section addressed using GDB remotely for debugging
  7897. purposes, which is the most usual case due to the inherent hardware
  7898. limitations on many embedded devices. However, debugging in the target
  7899. hardware itself is also possible with more powerful devices. This
  7900. section describes what you need to do in order to support using GDB to
  7901. debug on the target hardware.
  7902. To support this kind of debugging, you need do the following:
  7903. - Ensure that GDB is on the target. You can do this by adding "gdb" to
  7904. :term:`IMAGE_INSTALL`:
  7905. ::
  7906. IMAGE_INSTALL_append = " gdb"
  7907. Alternatively, you can add "tools-debug" to :term:`IMAGE_FEATURES`:
  7908. ::
  7909. IMAGE_FEATURES_append = " tools-debug"
  7910. - Ensure that debug symbols are present. You can make sure these
  7911. symbols are present by installing ``-dbg``:
  7912. ::
  7913. IMAGE_INSTALL_append = "packagename-dbg"
  7914. Alternatively, you can do the following to include
  7915. all the debug symbols:
  7916. ::
  7917. IMAGE_FEATURES_append = " dbg-pkgs"
  7918. .. note::
  7919. To improve the debug information accuracy, you can reduce the level
  7920. of optimization used by the compiler. For example, when adding the
  7921. following line to your ``local.conf`` file, you will reduce optimization
  7922. from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION`
  7923. of "-O -fno-omit-frame-pointer":
  7924. ::
  7925. DEBUG_BUILD = "1"
  7926. Consider that this will reduce the application's performance and is
  7927. recommended only for debugging purposes.
  7928. Other Debugging Tips
  7929. --------------------
  7930. Here are some other tips that you might find useful:
  7931. - When adding new packages, it is worth watching for undesirable items
  7932. making their way into compiler command lines. For example, you do not
  7933. want references to local system files like ``/usr/lib/`` or
  7934. ``/usr/include/``.
  7935. - If you want to remove the ``psplash`` boot splashscreen, add
  7936. ``psplash=false`` to the kernel command line. Doing so prevents
  7937. ``psplash`` from loading and thus allows you to see the console. It
  7938. is also possible to switch out of the splashscreen by switching the
  7939. virtual console (e.g. Fn+Left or Fn+Right on a Zaurus).
  7940. - Removing :term:`TMPDIR` (usually
  7941. ``tmp/``, within the
  7942. :term:`Build Directory`) can often fix
  7943. temporary build issues. Removing ``TMPDIR`` is usually a relatively
  7944. cheap operation, because task output will be cached in
  7945. :term:`SSTATE_DIR` (usually
  7946. ``sstate-cache/``, which is also in the Build Directory).
  7947. .. note::
  7948. Removing ``TMPDIR`` might be a workaround rather than a fix.
  7949. Consequently, trying to determine the underlying cause of an issue before
  7950. removing the directory is a good idea.
  7951. - Understanding how a feature is used in practice within existing
  7952. recipes can be very helpful. It is recommended that you configure
  7953. some method that allows you to quickly search through files.
  7954. Using GNU Grep, you can use the following shell function to
  7955. recursively search through common recipe-related files, skipping
  7956. binary files, ``.git`` directories, and the Build Directory (assuming
  7957. its name starts with "build"):
  7958. ::
  7959. g() {
  7960. grep -Ir \
  7961. --exclude-dir=.git \
  7962. --exclude-dir='build*' \
  7963. --include='*.bb*' \
  7964. --include='*.inc*' \
  7965. --include='*.conf*' \
  7966. --include='*.py*' \
  7967. "$@"
  7968. }
  7969. Following are some usage examples:
  7970. ::
  7971. $ g FOO # Search recursively for "FOO"
  7972. $ g -i foo # Search recursively for "foo", ignoring case
  7973. $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
  7974. If figuring
  7975. out how some feature works requires a lot of searching, it might
  7976. indicate that the documentation should be extended or improved. In
  7977. such cases, consider filing a documentation bug using the Yocto
  7978. Project implementation of
  7979. :yocto_bugs:`Bugzilla <>`. For information on
  7980. how to submit a bug against the Yocto Project, see the Yocto Project
  7981. Bugzilla :yocto_wiki:`wiki page </Bugzilla_Configuration_and_Bug_Tracking>`
  7982. and the "`Submitting a Defect Against the Yocto
  7983. Project <#submitting-a-defect-against-the-yocto-project>`__" section.
  7984. .. note::
  7985. The manuals might not be the right place to document variables
  7986. that are purely internal and have a limited scope (e.g. internal
  7987. variables used to implement a single ``.bbclass`` file).
  7988. Making Changes to the Yocto Project
  7989. ===================================
  7990. Because the Yocto Project is an open-source, community-based project,
  7991. you can effect changes to the project. This section presents procedures
  7992. that show you how to submit a defect against the project and how to
  7993. submit a change.
  7994. Submitting a Defect Against the Yocto Project
  7995. ---------------------------------------------
  7996. Use the Yocto Project implementation of
  7997. `Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug)
  7998. against the Yocto Project. For additional information on this
  7999. implementation of Bugzilla see the ":ref:`Yocto Project
  8000. Bugzilla <resources-bugtracker>`" section in the
  8001. Yocto Project Reference Manual. For more detail on any of the following
  8002. steps, see the Yocto Project
  8003. :yocto_wiki:`Bugzilla wiki page </Bugzilla_Configuration_and_Bug_Tracking>`.
  8004. Use the following general steps to submit a bug:
  8005. 1. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`.
  8006. 2. Click "File a Bug" to enter a new bug.
  8007. 3. Choose the appropriate "Classification", "Product", and "Component"
  8008. for which the bug was found. Bugs for the Yocto Project fall into
  8009. one of several classifications, which in turn break down into
  8010. several products and components. For example, for a bug against the
  8011. ``meta-intel`` layer, you would choose "Build System, Metadata &
  8012. Runtime", "BSPs", and "bsps-meta-intel", respectively.
  8013. 4. Choose the "Version" of the Yocto Project for which you found the
  8014. bug (e.g. &DISTRO;).
  8015. 5. Determine and select the "Severity" of the bug. The severity
  8016. indicates how the bug impacted your work.
  8017. 6. Choose the "Hardware" that the bug impacts.
  8018. 7. Choose the "Architecture" that the bug impacts.
  8019. 8. Choose a "Documentation change" item for the bug. Fixing a bug might
  8020. or might not affect the Yocto Project documentation. If you are
  8021. unsure of the impact to the documentation, select "Don't Know".
  8022. 9. Provide a brief "Summary" of the bug. Try to limit your summary to
  8023. just a line or two and be sure to capture the essence of the bug.
  8024. 10. Provide a detailed "Description" of the bug. You should provide as
  8025. much detail as you can about the context, behavior, output, and so
  8026. forth that surrounds the bug. You can even attach supporting files
  8027. for output from logs by using the "Add an attachment" button.
  8028. 11. Click the "Submit Bug" button submit the bug. A new Bugzilla number
  8029. is assigned to the bug and the defect is logged in the bug tracking
  8030. system.
  8031. Once you file a bug, the bug is processed by the Yocto Project Bug
  8032. Triage Team and further details concerning the bug are assigned (e.g.
  8033. priority and owner). You are the "Submitter" of the bug and any further
  8034. categorization, progress, or comments on the bug result in Bugzilla
  8035. sending you an automated email concerning the particular change or
  8036. progress to the bug.
  8037. Submitting a Change to the Yocto Project
  8038. ----------------------------------------
  8039. Contributions to the Yocto Project and OpenEmbedded are very welcome.
  8040. Because the system is extremely configurable and flexible, we recognize
  8041. that developers will want to extend, configure or optimize it for their
  8042. specific uses.
  8043. The Yocto Project uses a mailing list and a patch-based workflow that is
  8044. similar to the Linux kernel but contains important differences. In
  8045. general, a mailing list exists through which you can submit patches. You
  8046. should send patches to the appropriate mailing list so that they can be
  8047. reviewed and merged by the appropriate maintainer. The specific mailing
  8048. list you need to use depends on the location of the code you are
  8049. changing. Each component (e.g. layer) should have a ``README`` file that
  8050. indicates where to send the changes and which process to follow.
  8051. You can send the patch to the mailing list using whichever approach you
  8052. feel comfortable with to generate the patch. Once sent, the patch is
  8053. usually reviewed by the community at large. If somebody has concerns
  8054. with the patch, they will usually voice their concern over the mailing
  8055. list. If a patch does not receive any negative reviews, the maintainer
  8056. of the affected layer typically takes the patch, tests it, and then
  8057. based on successful testing, merges the patch.
  8058. The "poky" repository, which is the Yocto Project's reference build
  8059. environment, is a hybrid repository that contains several individual
  8060. pieces (e.g. BitBake, Metadata, documentation, and so forth) built using
  8061. the combo-layer tool. The upstream location used for submitting changes
  8062. varies by component:
  8063. - *Core Metadata:* Send your patch to the
  8064. :oe_lists:`openembedded-core </g/openembedded-core>`
  8065. mailing list. For example, a change to anything under the ``meta`` or
  8066. ``scripts`` directories should be sent to this mailing list.
  8067. - *BitBake:* For changes to BitBake (i.e. anything under the
  8068. ``bitbake`` directory), send your patch to the
  8069. :oe_lists:`bitbake-devel </g/bitbake-devel>`
  8070. mailing list.
  8071. - *"meta-\*" trees:* These trees contain Metadata. Use the
  8072. :yocto_lists:`poky </g/poky>` mailing list.
  8073. - *Documentation*: For changes to the Yocto Project documentation, use the
  8074. :yocto_lists:`docs </g/docs>` mailing list.
  8075. For changes to other layers hosted in the Yocto Project source
  8076. repositories (i.e. ``yoctoproject.org``) and tools use the
  8077. :yocto_lists:`Yocto Project </g/yocto/>` general mailing list.
  8078. .. note::
  8079. Sometimes a layer's documentation specifies to use a particular
  8080. mailing list. If so, use that list.
  8081. For additional recipes that do not fit into the core Metadata, you
  8082. should determine which layer the recipe should go into and submit the
  8083. change in the manner recommended by the documentation (e.g. the
  8084. ``README`` file) supplied with the layer. If in doubt, please ask on the
  8085. Yocto general mailing list or on the openembedded-devel mailing list.
  8086. You can also push a change upstream and request a maintainer to pull the
  8087. change into the component's upstream repository. You do this by pushing
  8088. to a contribution repository that is upstream. See the
  8089. ":ref:`overview-manual/development-environment:git workflows and the yocto project`"
  8090. section in the Yocto Project Overview and Concepts Manual for additional
  8091. concepts on working in the Yocto Project development environment.
  8092. Maintainers commonly use ``-next`` branches to test submissions prior to
  8093. merging patches. Thus, you can get an idea of the status of a patch based on
  8094. whether the patch has been merged into one of these branches. The commonly
  8095. used testing branches for OpenEmbedded-Core are as follows:
  8096. - *openembedded-core "master-next" branch:* This branch is part of the
  8097. :oe_git:`openembedded-core </openembedded-core/>` repository and contains
  8098. proposed changes to the core metadata.
  8099. - *poky "master-next" branch:* This branch is part of the
  8100. :yocto_git:`poky </poky/>` repository and combines proposed
  8101. changes to bitbake, the core metadata and the poky distro.
  8102. Similarly, stable branches maintained by the project may have corresponding
  8103. ``-next`` branches which collect proposed changes. For example,
  8104. ``&DISTRO_NAME_NO_CAP;-next`` and ``&DISTRO_NAME_NO_CAP_MINUS_ONE;-next``
  8105. branches in both the "openembdedded-core" and "poky" repositories.
  8106. Other layers may have similar testing branches but there is no formal
  8107. requirement or standard for these so please check the documentation for the
  8108. layers you are contributing to.
  8109. The following sections provide procedures for submitting a change.
  8110. Preparing Changes for Submission
  8111. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8112. 1. *Make Your Changes Locally:* Make your changes in your local Git
  8113. repository. You should make small, controlled, isolated changes.
  8114. Keeping changes small and isolated aids review, makes
  8115. merging/rebasing easier and keeps the change history clean should
  8116. anyone need to refer to it in future.
  8117. 2. *Stage Your Changes:* Stage your changes by using the ``git add``
  8118. command on each file you changed.
  8119. 3. *Commit Your Changes:* Commit the change by using the ``git commit``
  8120. command. Make sure your commit information follows standards by
  8121. following these accepted conventions:
  8122. - Be sure to include a "Signed-off-by:" line in the same style as
  8123. required by the Linux kernel. Adding this line signifies that you,
  8124. the submitter, have agreed to the Developer's Certificate of
  8125. Origin 1.1 as follows:
  8126. .. code-block:: none
  8127. Developer's Certificate of Origin 1.1
  8128. By making a contribution to this project, I certify that:
  8129. (a) The contribution was created in whole or in part by me and I
  8130. have the right to submit it under the open source license
  8131. indicated in the file; or
  8132. (b) The contribution is based upon previous work that, to the best
  8133. of my knowledge, is covered under an appropriate open source
  8134. license and I have the right under that license to submit that
  8135. work with modifications, whether created in whole or in part
  8136. by me, under the same open source license (unless I am
  8137. permitted to submit under a different license), as indicated
  8138. in the file; or
  8139. (c) The contribution was provided directly to me by some other
  8140. person who certified (a), (b) or (c) and I have not modified
  8141. it.
  8142. (d) I understand and agree that this project and the contribution
  8143. are public and that a record of the contribution (including all
  8144. personal information I submit with it, including my sign-off) is
  8145. maintained indefinitely and may be redistributed consistent with
  8146. this project or the open source license(s) involved.
  8147. - Provide a single-line summary of the change and, if more
  8148. explanation is needed, provide more detail in the body of the
  8149. commit. This summary is typically viewable in the "shortlist" of
  8150. changes. Thus, providing something short and descriptive that
  8151. gives the reader a summary of the change is useful when viewing a
  8152. list of many commits. You should prefix this short description
  8153. with the recipe name (if changing a recipe), or else with the
  8154. short form path to the file being changed.
  8155. - For the body of the commit message, provide detailed information
  8156. that describes what you changed, why you made the change, and the
  8157. approach you used. It might also be helpful if you mention how you
  8158. tested the change. Provide as much detail as you can in the body
  8159. of the commit message.
  8160. .. note::
  8161. You do not need to provide a more detailed explanation of a
  8162. change if the change is minor to the point of the single line
  8163. summary providing all the information.
  8164. - If the change addresses a specific bug or issue that is associated
  8165. with a bug-tracking ID, include a reference to that ID in your
  8166. detailed description. For example, the Yocto Project uses a
  8167. specific convention for bug references - any commit that addresses
  8168. a specific bug should use the following form for the detailed
  8169. description. Be sure to use the actual bug-tracking ID from
  8170. Bugzilla for bug-id:
  8171. ::
  8172. Fixes [YOCTO #bug-id]
  8173. detailed description of change
  8174. Using Email to Submit a Patch
  8175. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8176. Depending on the components changed, you need to submit the email to a
  8177. specific mailing list. For some guidance on which mailing list to use,
  8178. see the `list <#figuring-out-the-mailing-list-to-use>`__ at the
  8179. beginning of this section. For a description of all the available
  8180. mailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the
  8181. Yocto Project Reference Manual.
  8182. Here is the general procedure on how to submit a patch through email
  8183. without using the scripts once the steps in
  8184. :ref:`dev-manual/common-tasks:preparing changes for submission` have been followed:
  8185. 1. *Format the Commit:* Format the commit into an email message. To
  8186. format commits, use the ``git format-patch`` command. When you
  8187. provide the command, you must include a revision list or a number of
  8188. patches as part of the command. For example, either of these two
  8189. commands takes your most recent single commit and formats it as an
  8190. email message in the current directory:
  8191. ::
  8192. $ git format-patch -1
  8193. or ::
  8194. $ git format-patch HEAD~
  8195. After the command is run, the current directory contains a numbered
  8196. ``.patch`` file for the commit.
  8197. If you provide several commits as part of the command, the
  8198. ``git format-patch`` command produces a series of numbered files in
  8199. the current directory – one for each commit. If you have more than
  8200. one patch, you should also use the ``--cover`` option with the
  8201. command, which generates a cover letter as the first "patch" in the
  8202. series. You can then edit the cover letter to provide a description
  8203. for the series of patches. For information on the
  8204. ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed
  8205. using the ``man git-format-patch`` command.
  8206. .. note::
  8207. If you are or will be a frequent contributor to the Yocto Project
  8208. or to OpenEmbedded, you might consider requesting a contrib area
  8209. and the necessary associated rights.
  8210. 2. *Send the patches via email:* Send the patches to the recipients and
  8211. relevant mailing lists by using the ``git send-email`` command.
  8212. .. note::
  8213. In order to use ``git send-email``, you must have the proper Git packages
  8214. installed on your host.
  8215. For Ubuntu, Debian, and Fedora the package is ``git-email``.
  8216. The ``git send-email`` command sends email by using a local or remote
  8217. Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or
  8218. through a direct ``smtp`` configuration in your Git ``~/.gitconfig``
  8219. file. If you are submitting patches through email only, it is very
  8220. important that you submit them without any whitespace or HTML
  8221. formatting that either you or your mailer introduces. The maintainer
  8222. that receives your patches needs to be able to save and apply them
  8223. directly from your emails. A good way to verify that what you are
  8224. sending will be applicable by the maintainer is to do a dry run and
  8225. send them to yourself and then save and apply them as the maintainer
  8226. would.
  8227. The ``git send-email`` command is the preferred method for sending
  8228. your patches using email since there is no risk of compromising
  8229. whitespace in the body of the message, which can occur when you use
  8230. your own mail client. The command also has several options that let
  8231. you specify recipients and perform further editing of the email
  8232. message. For information on how to use the ``git send-email``
  8233. command, see ``GIT-SEND-EMAIL(1)`` displayed using the
  8234. ``man git-send-email`` command.
  8235. The Yocto Project uses a `Patchwork instance <https://patchwork.openembedded.org/>`__
  8236. to track the status of patches submitted to the various mailing lists and to
  8237. support automated patch testing. Each submitted patch is checked for common
  8238. mistakes and deviations from the expected patch format and submitters are
  8239. notified by patchtest if such mistakes are found. This process helps to
  8240. reduce the burden of patch review on maintainers.
  8241. .. note::
  8242. This system is imperfect and changes can sometimes get lost in the flow.
  8243. Asking about the status of a patch or change is reasonable if the change
  8244. has been idle for a while with no feedback.
  8245. Using Scripts to Push a Change Upstream and Request a Pull
  8246. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8247. For larger patch series it is preferable to send a pull request which not
  8248. only includes the patch but also a pointer to a branch that can be pulled
  8249. from. This involves making a local branch for your changes, pushing this
  8250. branch to an accessible repository and then using the ``create-pull-request``
  8251. and ``send-pull-request`` scripts from openembedded-core to create and send a
  8252. patch series with a link to the branch for review.
  8253. Follow this procedure to push a change to an upstream "contrib" Git
  8254. repository once the steps in :ref:`dev-manual/common-tasks:preparing changes for submission` have
  8255. been followed:
  8256. .. note::
  8257. You can find general Git information on how to push a change upstream
  8258. in the
  8259. `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__.
  8260. 1. *Push Your Commits to a "Contrib" Upstream:* If you have arranged for
  8261. permissions to push to an upstream contrib repository, push the
  8262. change to that repository:
  8263. ::
  8264. $ git push upstream_remote_repo local_branch_name
  8265. For example, suppose you have permissions to push
  8266. into the upstream ``meta-intel-contrib`` repository and you are
  8267. working in a local branch named `your_name`\ ``/README``. The following
  8268. command pushes your local commits to the ``meta-intel-contrib``
  8269. upstream repository and puts the commit in a branch named
  8270. `your_name`\ ``/README``:
  8271. ::
  8272. $ git push meta-intel-contrib your_name/README
  8273. 2. *Determine Who to Notify:* Determine the maintainer or the mailing
  8274. list that you need to notify for the change.
  8275. Before submitting any change, you need to be sure who the maintainer
  8276. is or what mailing list that you need to notify. Use either these
  8277. methods to find out:
  8278. - *Maintenance File:* Examine the ``maintainers.inc`` file, which is
  8279. located in the :term:`Source Directory` at
  8280. ``meta/conf/distro/include``, to see who is responsible for code.
  8281. - *Search by File:* Using :ref:`overview-manual/development-environment:git`, you can
  8282. enter the following command to bring up a short list of all
  8283. commits against a specific file:
  8284. ::
  8285. git shortlog -- filename
  8286. Just provide the name of the file for which you are interested. The
  8287. information returned is not ordered by history but does include a
  8288. list of everyone who has committed grouped by name. From the list,
  8289. you can see who is responsible for the bulk of the changes against
  8290. the file.
  8291. - *Examine the List of Mailing Lists:* For a list of the Yocto
  8292. Project and related mailing lists, see the ":ref:`Mailing
  8293. lists <resources-mailinglist>`" section in
  8294. the Yocto Project Reference Manual.
  8295. 3. *Make a Pull Request:* Notify the maintainer or the mailing list that
  8296. you have pushed a change by making a pull request.
  8297. The Yocto Project provides two scripts that conveniently let you
  8298. generate and send pull requests to the Yocto Project. These scripts
  8299. are ``create-pull-request`` and ``send-pull-request``. You can find
  8300. these scripts in the ``scripts`` directory within the
  8301. :term:`Source Directory` (e.g.
  8302. ``~/poky/scripts``).
  8303. Using these scripts correctly formats the requests without
  8304. introducing any whitespace or HTML formatting. The maintainer that
  8305. receives your patches either directly or through the mailing list
  8306. needs to be able to save and apply them directly from your emails.
  8307. Using these scripts is the preferred method for sending patches.
  8308. First, create the pull request. For example, the following command
  8309. runs the script, specifies the upstream repository in the contrib
  8310. directory into which you pushed the change, and provides a subject
  8311. line in the created patch files:
  8312. ::
  8313. $ ~/poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
  8314. Running this script forms ``*.patch`` files in a folder named
  8315. ``pull-``\ `PID` in the current directory. One of the patch files is a
  8316. cover letter.
  8317. Before running the ``send-pull-request`` script, you must edit the
  8318. cover letter patch to insert information about your change. After
  8319. editing the cover letter, send the pull request. For example, the
  8320. following command runs the script and specifies the patch directory
  8321. and email address. In this example, the email address is a mailing
  8322. list:
  8323. ::
  8324. $ ~/poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
  8325. You need to follow the prompts as the script is interactive.
  8326. .. note::
  8327. For help on using these scripts, simply provide the ``-h``
  8328. argument as follows:
  8329. ::
  8330. $ poky/scripts/create-pull-request -h
  8331. $ poky/scripts/send-pull-request -h
  8332. Responding to Patch Review
  8333. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  8334. You may get feedback on your submitted patches from other community members
  8335. or from the automated patchtest service. If issues are identified in your
  8336. patch then it is usually necessary to address these before the patch will be
  8337. accepted into the project. In this case you should amend the patch according
  8338. to the feedback and submit an updated version to the relevant mailing list,
  8339. copying in the reviewers who provided feedback to the previous version of the
  8340. patch.
  8341. The patch should be amended using ``git commit --amend`` or perhaps ``git
  8342. rebase`` for more expert git users. You should also modify the ``[PATCH]``
  8343. tag in the email subject line when sending the revised patch to mark the new
  8344. iteration as ``[PATCH v2]``, ``[PATCH v3]``, etc as appropriate. This can be
  8345. done by passing the ``-v`` argument to ``git format-patch`` with a version
  8346. number.
  8347. Lastly please ensure that you also test your revised changes. In particular
  8348. please don't just edit the patch file written out by ``git format-patch`` and
  8349. resend it.
  8350. Submitting Changes to Stable Release Branches
  8351. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8352. The process for proposing changes to a Yocto Project stable branch differs
  8353. from the steps described above. Changes to a stable branch must address
  8354. identified bugs or CVEs and should be made carefully in order to avoid the
  8355. risk of introducing new bugs or breaking backwards compatibility. Typically
  8356. bug fixes must already be accepted into the master branch before they can be
  8357. backported to a stable branch unless the bug in question does not affect the
  8358. master branch or the fix on the master branch is unsuitable for backporting.
  8359. The list of stable branches along with the status and maintainer for each
  8360. branch can be obtained from the
  8361. :yocto_wiki:`Releases wiki page </Releases>`.
  8362. .. note::
  8363. Changes will not typically be accepted for branches which are marked as
  8364. End-Of-Life (EOL).
  8365. With this in mind, the steps to submit a change for a stable branch are as
  8366. follows:
  8367. 1. *Identify the bug or CVE to be fixed:* This information should be
  8368. collected so that it can be included in your submission.
  8369. 2. *Check if the fix is already present in the master branch:* This will
  8370. result in the most straightforward path into the stable branch for the
  8371. fix.
  8372. a. *If the fix is present in the master branch - Submit a backport request
  8373. by email:* You should send an email to the relevant stable branch
  8374. maintainer and the mailing list with details of the bug or CVE to be
  8375. fixed, the commit hash on the master branch that fixes the issue and
  8376. the stable branches which you would like this fix to be backported to.
  8377. b. *If the fix is not present in the master branch - Submit the fix to the
  8378. master branch first:* This will ensure that the fix passes through the
  8379. project's usual patch review and test processes before being accepted.
  8380. It will also ensure that bugs are not left unresolved in the master
  8381. branch itself. Once the fix is accepted in the master branch a backport
  8382. request can be submitted as above.
  8383. c. *If the fix is unsuitable for the master branch - Submit a patch
  8384. directly for the stable branch:* This method should be considered as a
  8385. last resort. It is typically necessary when the master branch is using
  8386. a newer version of the software which includes an upstream fix for the
  8387. issue or when the issue has been fixed on the master branch in a way
  8388. that introduces backwards incompatible changes. In this case follow the
  8389. steps in :ref:`dev-manual/common-tasks:preparing changes for submission` and
  8390. :ref:`dev-manual/common-tasks:using email to submit a patch` but modify the subject header of your patch
  8391. email to include the name of the stable branch which you are
  8392. targetting. This can be done using the ``--subject-prefix`` argument to
  8393. ``git format-patch``, for example to submit a patch to the dunfell
  8394. branch use
  8395. ``git format-patch --subject-prefix='&DISTRO_NAME_NO_CAP_MINUS_ONE;][PATCH' ...``.
  8396. Working With Licenses
  8397. =====================
  8398. As mentioned in the ":ref:`overview-manual/development-environment:licensing`"
  8399. section in the Yocto Project Overview and Concepts Manual, open source
  8400. projects are open to the public and they consequently have different
  8401. licensing structures in place. This section describes the mechanism by
  8402. which the :term:`OpenEmbedded Build System`
  8403. tracks changes to
  8404. licensing text and covers how to maintain open source license compliance
  8405. during your project's lifecycle. The section also describes how to
  8406. enable commercially licensed recipes, which by default are disabled.
  8407. Tracking License Changes
  8408. ------------------------
  8409. The license of an upstream project might change in the future. In order
  8410. to prevent these changes going unnoticed, the
  8411. :term:`LIC_FILES_CHKSUM`
  8412. variable tracks changes to the license text. The checksums are validated
  8413. at the end of the configure step, and if the checksums do not match, the
  8414. build will fail.
  8415. Specifying the ``LIC_FILES_CHKSUM`` Variable
  8416. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8417. The ``LIC_FILES_CHKSUM`` variable contains checksums of the license text
  8418. in the source code for the recipe. Following is an example of how to
  8419. specify ``LIC_FILES_CHKSUM``:
  8420. ::
  8421. LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
  8422. file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
  8423. file://licfile2.txt;endline=50;md5=zzzz \
  8424. ..."
  8425. .. note::
  8426. - When using "beginline" and "endline", realize that line numbering
  8427. begins with one and not zero. Also, the included lines are
  8428. inclusive (i.e. lines five through and including 29 in the
  8429. previous example for ``licfile1.txt``).
  8430. - When a license check fails, the selected license text is included
  8431. as part of the QA message. Using this output, you can determine
  8432. the exact start and finish for the needed license text.
  8433. The build system uses the :term:`S`
  8434. variable as the default directory when searching files listed in
  8435. ``LIC_FILES_CHKSUM``. The previous example employs the default
  8436. directory.
  8437. Consider this next example:
  8438. ::
  8439. LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
  8440. md5=bb14ed3c4cda583abc85401304b5cd4e"
  8441. LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
  8442. The first line locates a file in ``${S}/src/ls.c`` and isolates lines
  8443. five through 16 as license text. The second line refers to a file in
  8444. :term:`WORKDIR`.
  8445. Note that ``LIC_FILES_CHKSUM`` variable is mandatory for all recipes,
  8446. unless the ``LICENSE`` variable is set to "CLOSED".
  8447. Explanation of Syntax
  8448. ~~~~~~~~~~~~~~~~~~~~~
  8449. As mentioned in the previous section, the ``LIC_FILES_CHKSUM`` variable
  8450. lists all the important files that contain the license text for the
  8451. source code. It is possible to specify a checksum for an entire file, or
  8452. a specific section of a file (specified by beginning and ending line
  8453. numbers with the "beginline" and "endline" parameters, respectively).
  8454. The latter is useful for source files with a license notice header,
  8455. README documents, and so forth. If you do not use the "beginline"
  8456. parameter, then it is assumed that the text begins on the first line of
  8457. the file. Similarly, if you do not use the "endline" parameter, it is
  8458. assumed that the license text ends with the last line of the file.
  8459. The "md5" parameter stores the md5 checksum of the license text. If the
  8460. license text changes in any way as compared to this parameter then a
  8461. mismatch occurs. This mismatch triggers a build failure and notifies the
  8462. developer. Notification allows the developer to review and address the
  8463. license text changes. Also note that if a mismatch occurs during the
  8464. build, the correct md5 checksum is placed in the build log and can be
  8465. easily copied to the recipe.
  8466. There is no limit to how many files you can specify using the
  8467. ``LIC_FILES_CHKSUM`` variable. Generally, however, every project
  8468. requires a few specifications for license tracking. Many projects have a
  8469. "COPYING" file that stores the license information for all the source
  8470. code files. This practice allows you to just track the "COPYING" file as
  8471. long as it is kept up to date.
  8472. .. note::
  8473. - If you specify an empty or invalid "md5" parameter,
  8474. :term:`BitBake` returns an md5
  8475. mis-match error and displays the correct "md5" parameter value
  8476. during the build. The correct parameter is also captured in the
  8477. build log.
  8478. - If the whole file contains only license text, you do not need to
  8479. use the "beginline" and "endline" parameters.
  8480. Enabling Commercially Licensed Recipes
  8481. --------------------------------------
  8482. By default, the OpenEmbedded build system disables components that have
  8483. commercial or other special licensing requirements. Such requirements
  8484. are defined on a recipe-by-recipe basis through the
  8485. :term:`LICENSE_FLAGS` variable
  8486. definition in the affected recipe. For instance, the
  8487. ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe
  8488. contains the following statement:
  8489. ::
  8490. LICENSE_FLAGS = "commercial"
  8491. Here is a
  8492. slightly more complicated example that contains both an explicit recipe
  8493. name and version (after variable expansion):
  8494. ::
  8495. LICENSE_FLAGS = "license_${PN}_${PV}"
  8496. In order for a component restricted by a
  8497. ``LICENSE_FLAGS`` definition to be enabled and included in an image, it
  8498. needs to have a matching entry in the global
  8499. :term:`LICENSE_FLAGS_WHITELIST`
  8500. variable, which is a variable typically defined in your ``local.conf``
  8501. file. For example, to enable the
  8502. ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you
  8503. could add either the string "commercial_gst-plugins-ugly" or the more
  8504. general string "commercial" to ``LICENSE_FLAGS_WHITELIST``. See the
  8505. "`License Flag Matching <#license-flag-matching>`__" section for a full
  8506. explanation of how ``LICENSE_FLAGS`` matching works. Here is the
  8507. example:
  8508. ::
  8509. LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
  8510. Likewise, to additionally enable the package built from the recipe
  8511. containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that
  8512. the actual recipe name was ``emgd_1.10.bb``, the following string would
  8513. enable that package as well as the original ``gst-plugins-ugly``
  8514. package:
  8515. ::
  8516. LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
  8517. As a convenience, you do not need to specify the
  8518. complete license string in the whitelist for every package. You can use
  8519. an abbreviated form, which consists of just the first portion or
  8520. portions of the license string before the initial underscore character
  8521. or characters. A partial string will match any license that contains the
  8522. given string as the first portion of its license. For example, the
  8523. following whitelist string will also match both of the packages
  8524. previously mentioned as well as any other packages that have licenses
  8525. starting with "commercial" or "license".
  8526. ::
  8527. LICENSE_FLAGS_WHITELIST = "commercial license"
  8528. License Flag Matching
  8529. ~~~~~~~~~~~~~~~~~~~~~
  8530. License flag matching allows you to control what recipes the
  8531. OpenEmbedded build system includes in the build. Fundamentally, the
  8532. build system attempts to match ``LICENSE_FLAGS`` strings found in
  8533. recipes against ``LICENSE_FLAGS_WHITELIST`` strings found in the
  8534. whitelist. A match causes the build system to include a recipe in the
  8535. build, while failure to find a match causes the build system to exclude
  8536. a recipe.
  8537. In general, license flag matching is simple. However, understanding some
  8538. concepts will help you correctly and effectively use matching.
  8539. Before a flag defined by a particular recipe is tested against the
  8540. contents of the whitelist, the expanded string ``_${PN}`` is appended to
  8541. the flag. This expansion makes each ``LICENSE_FLAGS`` value
  8542. recipe-specific. After expansion, the string is then matched against the
  8543. whitelist. Thus, specifying ``LICENSE_FLAGS = "commercial"`` in recipe
  8544. "foo", for example, results in the string ``"commercial_foo"``. And, to
  8545. create a match, that string must appear in the whitelist.
  8546. Judicious use of the ``LICENSE_FLAGS`` strings and the contents of the
  8547. ``LICENSE_FLAGS_WHITELIST`` variable allows you a lot of flexibility for
  8548. including or excluding recipes based on licensing. For example, you can
  8549. broaden the matching capabilities by using license flags string subsets
  8550. in the whitelist.
  8551. .. note::
  8552. When using a string subset, be sure to use the part of the expanded
  8553. string that precedes the appended underscore character (e.g.
  8554. ``usethispart_1.3``, ``usethispart_1.4``, and so forth).
  8555. For example, simply specifying the string "commercial" in the whitelist
  8556. matches any expanded ``LICENSE_FLAGS`` definition that starts with the
  8557. string "commercial" such as "commercial_foo" and "commercial_bar", which
  8558. are the strings the build system automatically generates for
  8559. hypothetical recipes named "foo" and "bar" assuming those recipes simply
  8560. specify the following:
  8561. ::
  8562. LICENSE_FLAGS = "commercial"
  8563. Thus, you can choose
  8564. to exhaustively enumerate each license flag in the whitelist and allow
  8565. only specific recipes into the image, or you can use a string subset
  8566. that causes a broader range of matches to allow a range of recipes into
  8567. the image.
  8568. This scheme works even if the ``LICENSE_FLAGS`` string already has
  8569. ``_${PN}`` appended. For example, the build system turns the license
  8570. flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match
  8571. both the general "commercial" and the specific "commercial_1.2_foo"
  8572. strings found in the whitelist, as expected.
  8573. Here are some other scenarios:
  8574. - You can specify a versioned string in the recipe such as
  8575. "commercial_foo_1.2" in a "foo" recipe. The build system expands this
  8576. string to "commercial_foo_1.2_foo". Combine this license flag with a
  8577. whitelist that has the string "commercial" and you match the flag
  8578. along with any other flag that starts with the string "commercial".
  8579. - Under the same circumstances, you can use "commercial_foo" in the
  8580. whitelist and the build system not only matches "commercial_foo_1.2"
  8581. but also matches any license flag with the string "commercial_foo",
  8582. regardless of the version.
  8583. - You can be very specific and use both the package and version parts
  8584. in the whitelist (e.g. "commercial_foo_1.2") to specifically match a
  8585. versioned recipe.
  8586. Other Variables Related to Commercial Licenses
  8587. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8588. Other helpful variables related to commercial license handling exist and
  8589. are defined in the
  8590. ``poky/meta/conf/distro/include/default-distrovars.inc`` file:
  8591. ::
  8592. COMMERCIAL_AUDIO_PLUGINS ?= ""
  8593. COMMERCIAL_VIDEO_PLUGINS ?= ""
  8594. If you
  8595. want to enable these components, you can do so by making sure you have
  8596. statements similar to the following in your ``local.conf`` configuration
  8597. file:
  8598. ::
  8599. COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
  8600. gst-plugins-ugly-mpegaudioparse"
  8601. COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
  8602. gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
  8603. LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
  8604. Of course, you could also create a matching whitelist for those
  8605. components using the more general "commercial" in the whitelist, but
  8606. that would also enable all the other packages with ``LICENSE_FLAGS``
  8607. containing "commercial", which you may or may not want:
  8608. ::
  8609. LICENSE_FLAGS_WHITELIST = "commercial"
  8610. Specifying audio and video plugins as part of the
  8611. ``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements
  8612. (along with the enabling ``LICENSE_FLAGS_WHITELIST``) includes the
  8613. plugins or components into built images, thus adding support for media
  8614. formats or components.
  8615. Maintaining Open Source License Compliance During Your Product's Lifecycle
  8616. --------------------------------------------------------------------------
  8617. One of the concerns for a development organization using open source
  8618. software is how to maintain compliance with various open source
  8619. licensing during the lifecycle of the product. While this section does
  8620. not provide legal advice or comprehensively cover all scenarios, it does
  8621. present methods that you can use to assist you in meeting the compliance
  8622. requirements during a software release.
  8623. With hundreds of different open source licenses that the Yocto Project
  8624. tracks, it is difficult to know the requirements of each and every
  8625. license. However, the requirements of the major FLOSS licenses can begin
  8626. to be covered by assuming that three main areas of concern exist:
  8627. - Source code must be provided.
  8628. - License text for the software must be provided.
  8629. - Compilation scripts and modifications to the source code must be
  8630. provided.
  8631. - spdx files can be provided.
  8632. There are other requirements beyond the scope of these three and the
  8633. methods described in this section (e.g. the mechanism through which
  8634. source code is distributed).
  8635. As different organizations have different methods of complying with open
  8636. source licensing, this section is not meant to imply that there is only
  8637. one single way to meet your compliance obligations, but rather to
  8638. describe one method of achieving compliance. The remainder of this
  8639. section describes methods supported to meet the previously mentioned
  8640. three requirements. Once you take steps to meet these requirements, and
  8641. prior to releasing images, sources, and the build system, you should
  8642. audit all artifacts to ensure completeness.
  8643. .. note::
  8644. The Yocto Project generates a license manifest during image creation
  8645. that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp`
  8646. to assist with any audits.
  8647. Providing the Source Code
  8648. ~~~~~~~~~~~~~~~~~~~~~~~~~
  8649. Compliance activities should begin before you generate the final image.
  8650. The first thing you should look at is the requirement that tops the list
  8651. for most compliance groups - providing the source. The Yocto Project has
  8652. a few ways of meeting this requirement.
  8653. One of the easiest ways to meet this requirement is to provide the
  8654. entire :term:`DL_DIR` used by the
  8655. build. This method, however, has a few issues. The most obvious is the
  8656. size of the directory since it includes all sources used in the build
  8657. and not just the source used in the released image. It will include
  8658. toolchain source, and other artifacts, which you would not generally
  8659. release. However, the more serious issue for most companies is
  8660. accidental release of proprietary software. The Yocto Project provides
  8661. an :ref:`archiver <ref-classes-archiver>` class to
  8662. help avoid some of these concerns.
  8663. Before you employ ``DL_DIR`` or the ``archiver`` class, you need to
  8664. decide how you choose to provide source. The source ``archiver`` class
  8665. can generate tarballs and SRPMs and can create them with various levels
  8666. of compliance in mind.
  8667. One way of doing this (but certainly not the only way) is to release
  8668. just the source as a tarball. You can do this by adding the following to
  8669. the ``local.conf`` file found in the
  8670. :term:`Build Directory`:
  8671. ::
  8672. INHERIT += "archiver"
  8673. ARCHIVER_MODE[src] = "original"
  8674. During the creation of your
  8675. image, the source from all recipes that deploy packages to the image is
  8676. placed within subdirectories of ``DEPLOY_DIR/sources`` based on the
  8677. :term:`LICENSE` for each recipe.
  8678. Releasing the entire directory enables you to comply with requirements
  8679. concerning providing the unmodified source. It is important to note that
  8680. the size of the directory can get large.
  8681. A way to help mitigate the size issue is to only release tarballs for
  8682. licenses that require the release of source. Let us assume you are only
  8683. concerned with GPL code as identified by running the following script:
  8684. .. code-block:: shell
  8685. # Script to archive a subset of packages matching specific license(s)
  8686. # Source and license files are copied into sub folders of package folder
  8687. # Must be run from build folder
  8688. #!/bin/bash
  8689. src_release_dir="source-release"
  8690. mkdir -p $src_release_dir
  8691. for a in tmp/deploy/sources/*; do
  8692. for d in $a/*; do
  8693. # Get package name from path
  8694. p=`basename $d`
  8695. p=${p%-*}
  8696. p=${p%-*}
  8697. # Only archive GPL packages (update *GPL* regex for your license check)
  8698. numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
  8699. if [ $numfiles -gt 1 ]; then
  8700. echo Archiving $p
  8701. mkdir -p $src_release_dir/$p/source
  8702. cp $d/* $src_release_dir/$p/source 2> /dev/null
  8703. mkdir -p $src_release_dir/$p/license
  8704. cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
  8705. fi
  8706. done
  8707. done
  8708. At this point, you
  8709. could create a tarball from the ``gpl_source_release`` directory and
  8710. provide that to the end user. This method would be a step toward
  8711. achieving compliance with section 3a of GPLv2 and with section 6 of
  8712. GPLv3.
  8713. Providing License Text
  8714. ~~~~~~~~~~~~~~~~~~~~~~
  8715. One requirement that is often overlooked is inclusion of license text.
  8716. This requirement also needs to be dealt with prior to generating the
  8717. final image. Some licenses require the license text to accompany the
  8718. binary. You can achieve this by adding the following to your
  8719. ``local.conf`` file:
  8720. ::
  8721. COPY_LIC_MANIFEST = "1"
  8722. COPY_LIC_DIRS = "1"
  8723. LICENSE_CREATE_PACKAGE = "1"
  8724. Adding these statements to the
  8725. configuration file ensures that the licenses collected during package
  8726. generation are included on your image.
  8727. .. note::
  8728. Setting all three variables to "1" results in the image having two
  8729. copies of the same license file. One copy resides in
  8730. ``/usr/share/common-licenses`` and the other resides in
  8731. ``/usr/share/license``.
  8732. The reason for this behavior is because
  8733. :term:`COPY_LIC_DIRS` and
  8734. :term:`COPY_LIC_MANIFEST`
  8735. add a copy of the license when the image is built but do not offer a
  8736. path for adding licenses for newly installed packages to an image.
  8737. :term:`LICENSE_CREATE_PACKAGE`
  8738. adds a separate package and an upgrade path for adding licenses to an
  8739. image.
  8740. As the source ``archiver`` class has already archived the original
  8741. unmodified source that contains the license files, you would have
  8742. already met the requirements for inclusion of the license information
  8743. with source as defined by the GPL and other open source licenses.
  8744. Providing Compilation Scripts and Source Code Modifications
  8745. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8746. At this point, we have addressed all we need to prior to generating the
  8747. image. The next two requirements are addressed during the final
  8748. packaging of the release.
  8749. By releasing the version of the OpenEmbedded build system and the layers
  8750. used during the build, you will be providing both compilation scripts
  8751. and the source code modifications in one step.
  8752. If the deployment team has a :ref:`overview-manual/concepts:bsp layer`
  8753. and a distro layer, and those
  8754. those layers are used to patch, compile, package, or modify (in any way)
  8755. any open source software included in your released images, you might be
  8756. required to release those layers under section 3 of GPLv2 or section 1
  8757. of GPLv3. One way of doing that is with a clean checkout of the version
  8758. of the Yocto Project and layers used during your build. Here is an
  8759. example:
  8760. .. code-block:: shell
  8761. # We built using the dunfell branch of the poky repo
  8762. $ git clone -b dunfell git://git.yoctoproject.org/poky
  8763. $ cd poky
  8764. # We built using the release_branch for our layers
  8765. $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
  8766. $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
  8767. # clean up the .git repos
  8768. $ find . -name ".git" -type d -exec rm -rf {} \;
  8769. One
  8770. thing a development organization might want to consider for end-user
  8771. convenience is to modify ``meta-poky/conf/bblayers.conf.sample`` to
  8772. ensure that when the end user utilizes the released build system to
  8773. build an image, the development organization's layers are included in
  8774. the ``bblayers.conf`` file automatically:
  8775. ::
  8776. # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
  8777. # changes incompatibly
  8778. POKY_BBLAYERS_CONF_VERSION = "2"
  8779. BBPATH = "${TOPDIR}"
  8780. BBFILES ?= ""
  8781. BBLAYERS ?= " \
  8782. ##OEROOT##/meta \
  8783. ##OEROOT##/meta-poky \
  8784. ##OEROOT##/meta-yocto-bsp \
  8785. ##OEROOT##/meta-mylayer \
  8786. "
  8787. Creating and
  8788. providing an archive of the :term:`Metadata`
  8789. layers (recipes, configuration files, and so forth) enables you to meet
  8790. your requirements to include the scripts to control compilation as well
  8791. as any modifications to the original source.
  8792. Providing spdx files
  8793. ~~~~~~~~~~~~~~~~~~~~~~~~~
  8794. The spdx module has been integrated to a layer named meta-spdxscanner.
  8795. meta-spdxscanner provides several kinds of scanner. If you want to enable
  8796. this function, you have to follow the following steps:
  8797. 1. Add meta-spdxscanner layer into ``bblayers.conf``.
  8798. 2. Refer to the README in meta-spdxscanner to setup the environment (e.g,
  8799. setup a fossology server) needed for the scanner.
  8800. 3. Meta-spdxscanner provides several methods within the bbclass to create spdx files.
  8801. Please choose one that you want to use and enable the spdx task. You have to
  8802. add some config options in ``local.conf`` file in your :term:`Build
  8803. Directory`. The following is an example showing how to generate spdx files
  8804. during bitbake using the fossology-python.bbclass::
  8805. # Select fossology-python.bbclass.
  8806. INHERIT += "fossology-python"
  8807. # For fossology-python.bbclass, TOKEN is necessary, so, after setup a
  8808. # Fossology server, you have to create a token.
  8809. TOKEN = "eyJ0eXAiO..."
  8810. # The fossology server is necessary for fossology-python.bbclass.
  8811. FOSSOLOGY_SERVER = "http://xx.xx.xx.xx:8081/repo"
  8812. # If you want to upload the source code to a special folder:
  8813. FOLDER_NAME = "xxxx" //Optional
  8814. # If you don't want to put spdx files in tmp/deploy/spdx, you can enable:
  8815. SPDX_DEPLOY_DIR = "${DEPLOY_DIR}" //Optional
  8816. For more usage information refer to :yocto_git:`the meta-spdxscanner repository
  8817. </meta-spdxscanner/>`.
  8818. Copying Licenses that Do Not Exist
  8819. ----------------------------------
  8820. Some packages, such as the linux-firmware package, have many licenses
  8821. that are not in any way common. You can avoid adding a lot of these
  8822. types of common license files, which are only applicable to a specific
  8823. package, by using the
  8824. :term:`NO_GENERIC_LICENSE`
  8825. variable. Using this variable also avoids QA errors when you use a
  8826. non-common, non-CLOSED license in a recipe.
  8827. The following is an example that uses the ``LICENSE.Abilis.txt`` file as
  8828. the license from the fetched source:
  8829. ::
  8830. NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
  8831. Using the Error Reporting Tool
  8832. ==============================
  8833. The error reporting tool allows you to submit errors encountered during
  8834. builds to a central database. Outside of the build environment, you can
  8835. use a web interface to browse errors, view statistics, and query for
  8836. errors. The tool works using a client-server system where the client
  8837. portion is integrated with the installed Yocto Project
  8838. :term:`Source Directory` (e.g. ``poky``).
  8839. The server receives the information collected and saves it in a
  8840. database.
  8841. A live instance of the error reporting server exists at
  8842. https://errors.yoctoproject.org. This server exists so that when
  8843. you want to get help with build failures, you can submit all of the
  8844. information on the failure easily and then point to the URL in your bug
  8845. report or send an email to the mailing list.
  8846. .. note::
  8847. If you send error reports to this server, the reports become publicly
  8848. visible.
  8849. Enabling and Using the Tool
  8850. ---------------------------
  8851. By default, the error reporting tool is disabled. You can enable it by
  8852. inheriting the
  8853. :ref:`report-error <ref-classes-report-error>`
  8854. class by adding the following statement to the end of your
  8855. ``local.conf`` file in your
  8856. :term:`Build Directory`.
  8857. ::
  8858. INHERIT += "report-error"
  8859. By default, the error reporting feature stores information in
  8860. ``${``\ :term:`LOG_DIR`\ ``}/error-report``.
  8861. However, you can specify a directory to use by adding the following to
  8862. your ``local.conf`` file:
  8863. ::
  8864. ERR_REPORT_DIR = "path"
  8865. Enabling error
  8866. reporting causes the build process to collect the errors and store them
  8867. in a file as previously described. When the build system encounters an
  8868. error, it includes a command as part of the console output. You can run
  8869. the command to send the error file to the server. For example, the
  8870. following command sends the errors to an upstream server:
  8871. ::
  8872. $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
  8873. In the previous example, the errors are sent to a public database
  8874. available at https://errors.yoctoproject.org, which is used by the
  8875. entire community. If you specify a particular server, you can send the
  8876. errors to a different database. Use the following command for more
  8877. information on available options:
  8878. ::
  8879. $ send-error-report --help
  8880. When sending the error file, you are prompted to review the data being
  8881. sent as well as to provide a name and optional email address. Once you
  8882. satisfy these prompts, the command returns a link from the server that
  8883. corresponds to your entry in the database. For example, here is a
  8884. typical link: https://errors.yoctoproject.org/Errors/Details/9522/
  8885. Following the link takes you to a web interface where you can browse,
  8886. query the errors, and view statistics.
  8887. Disabling the Tool
  8888. ------------------
  8889. To disable the error reporting feature, simply remove or comment out the
  8890. following statement from the end of your ``local.conf`` file in your
  8891. :term:`Build Directory`.
  8892. ::
  8893. INHERIT += "report-error"
  8894. Setting Up Your Own Error Reporting Server
  8895. ------------------------------------------
  8896. If you want to set up your own error reporting server, you can obtain
  8897. the code from the Git repository at :yocto_git:`/error-report-web/`.
  8898. Instructions on how to set it up are in the README document.
  8899. Using Wayland and Weston
  8900. ========================
  8901. `Wayland <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)>`__
  8902. is a computer display server protocol that provides a method for
  8903. compositing window managers to communicate directly with applications
  8904. and video hardware and expects them to communicate with input hardware
  8905. using other libraries. Using Wayland with supporting targets can result
  8906. in better control over graphics frame rendering than an application
  8907. might otherwise achieve.
  8908. The Yocto Project provides the Wayland protocol libraries and the
  8909. reference
  8910. `Weston <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston>`__
  8911. compositor as part of its release. You can find the integrated packages
  8912. in the ``meta`` layer of the :term:`Source Directory`.
  8913. Specifically, you
  8914. can find the recipes that build both Wayland and Weston at
  8915. ``meta/recipes-graphics/wayland``.
  8916. You can build both the Wayland and Weston packages for use only with
  8917. targets that accept the `Mesa 3D and Direct Rendering
  8918. Infrastructure <https://en.wikipedia.org/wiki/Mesa_(computer_graphics)>`__,
  8919. which is also known as Mesa DRI. This implies that you cannot build and
  8920. use the packages if your target uses, for example, the Intel Embedded
  8921. Media and Graphics Driver (Intel EMGD) that overrides Mesa DRI.
  8922. .. note::
  8923. Due to lack of EGL support, Weston 1.0.3 will not run directly on the
  8924. emulated QEMU hardware. However, this version of Weston will run
  8925. under X emulation without issues.
  8926. This section describes what you need to do to implement Wayland and use
  8927. the Weston compositor when building an image for a supporting target.
  8928. Enabling Wayland in an Image
  8929. ----------------------------
  8930. To enable Wayland, you need to enable it to be built and enable it to be
  8931. included (installed) in the image.
  8932. Building Wayland
  8933. ~~~~~~~~~~~~~~~~
  8934. To cause Mesa to build the ``wayland-egl`` platform and Weston to build
  8935. Wayland with Kernel Mode Setting
  8936. (`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__)
  8937. support, include the "wayland" flag in the
  8938. :term:`DISTRO_FEATURES`
  8939. statement in your ``local.conf`` file:
  8940. ::
  8941. DISTRO_FEATURES_append = " wayland"
  8942. .. note::
  8943. If X11 has been enabled elsewhere, Weston will build Wayland with X11
  8944. support
  8945. Installing Wayland and Weston
  8946. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8947. To install the Wayland feature into an image, you must include the
  8948. following
  8949. :term:`CORE_IMAGE_EXTRA_INSTALL`
  8950. statement in your ``local.conf`` file:
  8951. ::
  8952. CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
  8953. Running Weston
  8954. --------------
  8955. To run Weston inside X11, enabling it as described earlier and building
  8956. a Sato image is sufficient. If you are running your image under Sato, a
  8957. Weston Launcher appears in the "Utility" category.
  8958. Alternatively, you can run Weston through the command-line interpretor
  8959. (CLI), which is better suited for development work. To run Weston under
  8960. the CLI, you need to do the following after your image is built:
  8961. 1. Run these commands to export ``XDG_RUNTIME_DIR``:
  8962. ::
  8963. mkdir -p /tmp/$USER-weston
  8964. chmod 0700 /tmp/$USER-weston
  8965. export XDG_RUNTIME_DIR=/tmp/$USER-weston
  8966. 2. Launch Weston in the shell:
  8967. ::
  8968. weston