common-tasks.rst 477 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779
  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. .. note::
  22. It is very easy to create your own layers to use with the OpenEmbedded
  23. build system, as the Yocto Project ships with tools that speed up creating
  24. layers. This section describes the steps you perform by hand to create
  25. layers so that you can better understand them. For information about the
  26. layer-creation tools, see the
  27. ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
  28. section in the Yocto Project Board Support Package (BSP) Developer's
  29. Guide and the ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
  30. section further down in this manual.
  31. Follow these general steps to create your layer without using tools:
  32. 1. *Check Existing Layers:* Before creating a new layer, you should be
  33. sure someone has not already created a layer containing the Metadata
  34. you need. You can see the :oe_layerindex:`OpenEmbedded Metadata Index <>`
  35. for a list of layers from the OpenEmbedded community that can be used in
  36. the Yocto Project. You could find a layer that is identical or close
  37. to what you need.
  38. 2. *Create a Directory:* Create the directory for your layer. When you
  39. create the layer, be sure to create the directory in an area not
  40. associated with the Yocto Project :term:`Source Directory`
  41. (e.g. the cloned ``poky`` repository).
  42. While not strictly required, prepend the name of the directory with
  43. the string "meta-". For example::
  44. meta-mylayer
  45. meta-GUI_xyz
  46. meta-mymachine
  47. With rare exceptions, a layer's name follows this form::
  48. meta-root_name
  49. Following this layer naming convention can save
  50. you trouble later when tools, components, or variables "assume" your
  51. layer name begins with "meta-". A notable example is in configuration
  52. files as shown in the following step where layer names without the
  53. "meta-" string are appended to several variables used in the
  54. configuration.
  55. 3. *Create a Layer Configuration File:* Inside your new layer folder,
  56. you need to create a ``conf/layer.conf`` file. It is easiest to take
  57. an existing layer configuration file and copy that to your layer's
  58. ``conf`` directory and then modify the file as needed.
  59. The ``meta-yocto-bsp/conf/layer.conf`` file in the Yocto Project
  60. :yocto_git:`Source Repositories </poky/tree/meta-yocto-bsp/conf>`
  61. demonstrates the required syntax. For your layer, you need to replace
  62. "yoctobsp" with a unique identifier for your layer (e.g. "machinexyz"
  63. for a layer named "meta-machinexyz")::
  64. # We have a conf and classes directory, add to BBPATH
  65. BBPATH .= ":${LAYERDIR}"
  66. # We have recipes-* directories, add to BBFILES
  67. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  68. ${LAYERDIR}/recipes-*/*/*.bbappend"
  69. BBFILE_COLLECTIONS += "yoctobsp"
  70. BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
  71. BBFILE_PRIORITY_yoctobsp = "5"
  72. LAYERVERSION_yoctobsp = "4"
  73. LAYERSERIES_COMPAT_yoctobsp = "dunfell"
  74. Following is an explanation of the layer configuration file:
  75. - :term:`BBPATH`: Adds the layer's
  76. root directory to BitBake's search path. Through the use of the
  77. :term:`BBPATH` variable, BitBake locates class files (``.bbclass``),
  78. configuration files, and files that are included with ``include``
  79. and ``require`` statements. For these cases, BitBake uses the
  80. first file that matches the name found in :term:`BBPATH`. This is
  81. similar to the way the ``PATH`` variable is used for binaries. It
  82. is recommended, therefore, that you use unique class and
  83. configuration filenames in your custom layer.
  84. - :term:`BBFILES`: Defines the
  85. location for all recipes in the layer.
  86. - :term:`BBFILE_COLLECTIONS`:
  87. Establishes the current layer through a unique identifier that is
  88. used throughout the OpenEmbedded build system to refer to the
  89. layer. In this example, the identifier "yoctobsp" is the
  90. representation for the container layer named "meta-yocto-bsp".
  91. - :term:`BBFILE_PATTERN`:
  92. Expands immediately during parsing to provide the directory of the
  93. layer.
  94. - :term:`BBFILE_PRIORITY`:
  95. Establishes a priority to use for recipes in the layer when the
  96. OpenEmbedded build finds recipes of the same name in different
  97. layers.
  98. - :term:`LAYERVERSION`:
  99. Establishes a version number for the layer. You can use this
  100. version number to specify this exact version of the layer as a
  101. dependency when using the
  102. :term:`LAYERDEPENDS`
  103. variable.
  104. - :term:`LAYERDEPENDS`:
  105. Lists all layers on which this layer depends (if any).
  106. - :term:`LAYERSERIES_COMPAT`:
  107. Lists the :yocto_wiki:`Yocto Project </Releases>`
  108. releases for which the current version is compatible. This
  109. variable is a good way to indicate if your particular layer is
  110. current.
  111. 4. *Add Content:* Depending on the type of layer, add the content. If
  112. the layer adds support for a machine, add the machine configuration
  113. in a ``conf/machine/`` file within the layer. If the layer adds
  114. distro policy, add the distro configuration in a ``conf/distro/``
  115. file within the layer. If the layer introduces new recipes, put the
  116. recipes you need in ``recipes-*`` subdirectories within the layer.
  117. .. note::
  118. For an explanation of layer hierarchy that is compliant with the
  119. Yocto Project, see the ":ref:`bsp-guide/bsp:example filesystem layout`"
  120. section in the Yocto Project Board Support Package (BSP) Developer's Guide.
  121. 5. *Optionally Test for Compatibility:* If you want permission to use
  122. the Yocto Project Compatibility logo with your layer or application
  123. that uses your layer, perform the steps to apply for compatibility.
  124. See the
  125. ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`"
  126. section for more information.
  127. Following Best Practices When Creating Layers
  128. ---------------------------------------------
  129. To create layers that are easier to maintain and that will not impact
  130. builds for other machines, you should consider the information in the
  131. following list:
  132. - *Avoid "Overlaying" Entire Recipes from Other Layers in Your
  133. Configuration:* In other words, do not copy an entire recipe into
  134. your layer and then modify it. Rather, use an append file
  135. (``.bbappend``) to override only those parts of the original recipe
  136. you need to modify.
  137. - *Avoid Duplicating Include Files:* Use append files (``.bbappend``)
  138. for each recipe that uses an include file. Or, if you are introducing
  139. a new recipe that requires the included file, use the path relative
  140. to the original layer directory to refer to the file. For example,
  141. use ``require recipes-core/``\ `package`\ ``/``\ `file`\ ``.inc`` instead
  142. of ``require`` `file`\ ``.inc``. If you're finding you have to overlay
  143. the include file, it could indicate a deficiency in the include file
  144. in the layer to which it originally belongs. If this is the case, you
  145. should try to address that deficiency instead of overlaying the
  146. include file. For example, you could address this by getting the
  147. maintainer of the include file to add a variable or variables to make
  148. it easy to override the parts needing to be overridden.
  149. - *Structure Your Layers:* Proper use of overrides within append files
  150. and placement of machine-specific files within your layer can ensure
  151. that a build is not using the wrong Metadata and negatively impacting
  152. a build for a different machine. Following are some examples:
  153. - *Modify Variables to Support a Different Machine:* Suppose you
  154. have a layer named ``meta-one`` that adds support for building
  155. machine "one". To do so, you use an append file named
  156. ``base-files.bbappend`` and create a dependency on "foo" by
  157. altering the :term:`DEPENDS`
  158. variable::
  159. DEPENDS = "foo"
  160. The dependency is created during any
  161. build that includes the layer ``meta-one``. However, you might not
  162. want this dependency for all machines. For example, suppose you
  163. are building for machine "two" but your ``bblayers.conf`` file has
  164. the ``meta-one`` layer included. During the build, the
  165. ``base-files`` for machine "two" will also have the dependency on
  166. ``foo``.
  167. To make sure your changes apply only when building machine "one",
  168. use a machine override with the :term:`DEPENDS` statement::
  169. DEPENDS:one = "foo"
  170. You should follow the same strategy when using ``:append``
  171. and ``:prepend`` operations::
  172. DEPENDS:append:one = " foo"
  173. DEPENDS:prepend:one = "foo "
  174. As an actual example, here's a
  175. snippet from the generic kernel include file ``linux-yocto.inc``,
  176. wherein the kernel compile and link options are adjusted in the
  177. case of a subset of the supported architectures::
  178. DEPENDS:append:aarch64 = " libgcc"
  179. KERNEL_CC:append:aarch64 = " ${TOOLCHAIN_OPTIONS}"
  180. KERNEL_LD:append:aarch64 = " ${TOOLCHAIN_OPTIONS}"
  181. DEPENDS:append:nios2 = " libgcc"
  182. KERNEL_CC:append:nios2 = " ${TOOLCHAIN_OPTIONS}"
  183. KERNEL_LD:append:nios2 = " ${TOOLCHAIN_OPTIONS}"
  184. DEPENDS:append:arc = " libgcc"
  185. KERNEL_CC:append:arc = " ${TOOLCHAIN_OPTIONS}"
  186. KERNEL_LD:append:arc = " ${TOOLCHAIN_OPTIONS}"
  187. KERNEL_FEATURES:append:qemuall=" features/debug/printk.scc"
  188. - *Place Machine-Specific Files in Machine-Specific Locations:* When
  189. you have a base recipe, such as ``base-files.bb``, that contains a
  190. :term:`SRC_URI` statement to a
  191. file, you can use an append file to cause the build to use your
  192. own version of the file. For example, an append file in your layer
  193. at ``meta-one/recipes-core/base-files/base-files.bbappend`` could
  194. extend :term:`FILESPATH` using :term:`FILESEXTRAPATHS` as follows::
  195. FILESEXTRAPATHS:prepend := "${THISDIR}/${BPN}:"
  196. The build for machine "one" will pick up your machine-specific file as
  197. long as you have the file in
  198. ``meta-one/recipes-core/base-files/base-files/``. However, if you
  199. are building for a different machine and the ``bblayers.conf``
  200. file includes the ``meta-one`` layer and the location of your
  201. machine-specific file is the first location where that file is
  202. found according to :term:`FILESPATH`, builds for all machines will
  203. also use that machine-specific file.
  204. You can make sure that a machine-specific file is used for a
  205. particular machine by putting the file in a subdirectory specific
  206. to the machine. For example, rather than placing the file in
  207. ``meta-one/recipes-core/base-files/base-files/`` as shown above,
  208. put it in ``meta-one/recipes-core/base-files/base-files/one/``.
  209. Not only does this make sure the file is used only when building
  210. for machine "one", but the build process locates the file more
  211. quickly.
  212. In summary, you need to place all files referenced from
  213. :term:`SRC_URI` in a machine-specific subdirectory within the layer in
  214. order to restrict those files to machine-specific builds.
  215. - *Perform Steps to Apply for Yocto Project Compatibility:* If you want
  216. permission to use the Yocto Project Compatibility logo with your
  217. layer or application that uses your layer, perform the steps to apply
  218. for compatibility. See the
  219. ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`"
  220. section for more information.
  221. - *Follow the Layer Naming Convention:* Store custom layers in a Git
  222. repository that use the ``meta-layer_name`` format.
  223. - *Group Your Layers Locally:* Clone your repository alongside other
  224. cloned ``meta`` directories from the :term:`Source Directory`.
  225. Making Sure Your Layer is Compatible With Yocto Project
  226. -------------------------------------------------------
  227. When you create a layer used with the Yocto Project, it is advantageous
  228. to make sure that the layer interacts well with existing Yocto Project
  229. layers (i.e. the layer is compatible with the Yocto Project). Ensuring
  230. compatibility makes the layer easy to be consumed by others in the Yocto
  231. Project community and could allow you permission to use the Yocto
  232. Project Compatible Logo.
  233. .. note::
  234. Only Yocto Project member organizations are permitted to use the
  235. Yocto Project Compatible Logo. The logo is not available for general
  236. use. For information on how to become a Yocto Project member
  237. organization, see the :yocto_home:`Yocto Project Website <>`.
  238. The Yocto Project Compatibility Program consists of a layer application
  239. process that requests permission to use the Yocto Project Compatibility
  240. Logo for your layer and application. The process consists of two parts:
  241. 1. Successfully passing a script (``yocto-check-layer``) that when run
  242. against your layer, tests it against constraints based on experiences
  243. of how layers have worked in the real world and where pitfalls have
  244. been found. Getting a "PASS" result from the script is required for
  245. successful compatibility registration.
  246. 2. Completion of an application acceptance form, which you can find at
  247. :yocto_home:`/webform/yocto-project-compatible-registration`.
  248. To be granted permission to use the logo, you need to satisfy the
  249. following:
  250. - Be able to check the box indicating that you got a "PASS" when
  251. running the script against your layer.
  252. - Answer "Yes" to the questions on the form or have an acceptable
  253. explanation for any questions answered "No".
  254. - Be a Yocto Project Member Organization.
  255. The remainder of this section presents information on the registration
  256. form and on the ``yocto-check-layer`` script.
  257. Yocto Project Compatible Program Application
  258. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  259. Use the form to apply for your layer's approval. Upon successful
  260. application, you can use the Yocto Project Compatibility Logo with your
  261. layer and the application that uses your layer.
  262. To access the form, use this link:
  263. :yocto_home:`/webform/yocto-project-compatible-registration`.
  264. Follow the instructions on the form to complete your application.
  265. The application consists of the following sections:
  266. - *Contact Information:* Provide your contact information as the fields
  267. require. Along with your information, provide the released versions
  268. of the Yocto Project for which your layer is compatible.
  269. - *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the
  270. items in the checklist. There is space at the bottom of the form for
  271. any explanations for items for which you answered "No".
  272. - *Recommendations:* Provide answers for the questions regarding Linux
  273. kernel use and build success.
  274. ``yocto-check-layer`` Script
  275. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  276. The ``yocto-check-layer`` script provides you a way to assess how
  277. compatible your layer is with the Yocto Project. You should run this
  278. script prior to using the form to apply for compatibility as described
  279. in the previous section. You need to achieve a "PASS" result in order to
  280. have your application form successfully processed.
  281. The script divides tests into three areas: COMMON, BSP, and DISTRO. For
  282. example, given a distribution layer (DISTRO), the layer must pass both
  283. the COMMON and DISTRO related tests. Furthermore, if your layer is a BSP
  284. layer, the layer must pass the COMMON and BSP set of tests.
  285. To execute the script, enter the following commands from your build
  286. directory::
  287. $ source oe-init-build-env
  288. $ yocto-check-layer your_layer_directory
  289. Be sure to provide the actual directory for your
  290. layer as part of the command.
  291. Entering the command causes the script to determine the type of layer
  292. and then to execute a set of specific tests against the layer. The
  293. following list overviews the test:
  294. - ``common.test_readme``: Tests if a ``README`` file exists in the
  295. layer and the file is not empty.
  296. - ``common.test_parse``: Tests to make sure that BitBake can parse the
  297. files without error (i.e. ``bitbake -p``).
  298. - ``common.test_show_environment``: Tests that the global or per-recipe
  299. environment is in order without errors (i.e. ``bitbake -e``).
  300. - ``common.test_world``: Verifies that ``bitbake world`` works.
  301. - ``common.test_signatures``: Tests to be sure that BSP and DISTRO
  302. layers do not come with recipes that change signatures.
  303. - ``common.test_layerseries_compat``: Verifies layer compatibility is
  304. set properly.
  305. - ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine
  306. configurations.
  307. - ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not
  308. set the machine when the layer is added.
  309. - ``bsp.test_machine_world``: Verifies that ``bitbake world`` works
  310. regardless of which machine is selected.
  311. - ``bsp.test_machine_signatures``: Verifies that building for a
  312. particular machine affects only the signature of tasks specific to
  313. that machine.
  314. - ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has
  315. distro configurations.
  316. - ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer
  317. does not set the distribution when the layer is added.
  318. Enabling Your Layer
  319. -------------------
  320. Before the OpenEmbedded build system can use your new layer, you need to
  321. enable it. To enable your layer, simply add your layer's path to the
  322. :term:`BBLAYERS` variable in your ``conf/bblayers.conf`` file, which is
  323. found in the :term:`Build Directory`.
  324. The following example shows how to enable your new
  325. ``meta-mylayer`` layer (note how your new layer exists outside of
  326. the official ``poky`` repository which you would have checked out earlier)::
  327. # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
  328. # changes incompatibly
  329. POKY_BBLAYERS_CONF_VERSION = "2"
  330. BBPATH = "${TOPDIR}"
  331. BBFILES ?= ""
  332. BBLAYERS ?= " \
  333. /home/user/poky/meta \
  334. /home/user/poky/meta-poky \
  335. /home/user/poky/meta-yocto-bsp \
  336. /home/user/mystuff/meta-mylayer \
  337. "
  338. BitBake parses each ``conf/layer.conf`` file from the top down as
  339. specified in the :term:`BBLAYERS` variable within the ``conf/bblayers.conf``
  340. file. During the processing of each ``conf/layer.conf`` file, BitBake
  341. adds the recipes, classes and configurations contained within the
  342. particular layer to the source directory.
  343. Appending Other Layers Metadata With Your Layer
  344. -----------------------------------------------
  345. A recipe that appends Metadata to another recipe is called a BitBake
  346. append file. A BitBake append file uses the ``.bbappend`` file type
  347. suffix, while the corresponding recipe to which Metadata is being
  348. appended uses the ``.bb`` file type suffix.
  349. You can use a ``.bbappend`` file in your layer to make additions or
  350. changes to the content of another layer's recipe without having to copy
  351. the other layer's recipe into your layer. Your ``.bbappend`` file
  352. resides in your layer, while the main ``.bb`` recipe file to which you
  353. are appending Metadata resides in a different layer.
  354. Being able to append information to an existing recipe not only avoids
  355. duplication, but also automatically applies recipe changes from a
  356. different layer into your layer. If you were copying recipes, you would
  357. have to manually merge changes as they occur.
  358. When you create an append file, you must use the same root name as the
  359. corresponding recipe file. For example, the append file
  360. ``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This
  361. means the original recipe and append filenames are version
  362. number-specific. If the corresponding recipe is renamed to update to a
  363. newer version, you must also rename and possibly update the
  364. corresponding ``.bbappend`` as well. During the build process, BitBake
  365. displays an error on starting if it detects a ``.bbappend`` file that
  366. does not have a corresponding recipe with a matching name. See the
  367. :term:`BB_DANGLINGAPPENDS_WARNONLY`
  368. variable for information on how to handle this error.
  369. Overlaying a File Using Your Layer
  370. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  371. As an example, consider the main formfactor recipe and a corresponding
  372. formfactor append file both from the :term:`Source Directory`.
  373. Here is the main
  374. formfactor recipe, which is named ``formfactor_0.0.bb`` and located in
  375. the "meta" layer at ``meta/recipes-bsp/formfactor``::
  376. SUMMARY = "Device formfactor information"
  377. DESCRIPTION = "A formfactor configuration file provides information about the \
  378. target hardware for which the image is being built and information that the \
  379. build system cannot obtain from other sources such as the kernel."
  380. SECTION = "base"
  381. LICENSE = "MIT"
  382. LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
  383. PR = "r45"
  384. SRC_URI = "file://config file://machconfig"
  385. S = "${WORKDIR}"
  386. PACKAGE_ARCH = "${MACHINE_ARCH}"
  387. INHIBIT_DEFAULT_DEPS = "1"
  388. do_install() {
  389. # Install file only if it has contents
  390. install -d ${D}${sysconfdir}/formfactor/
  391. install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
  392. if [ -s "${S}/machconfig" ]; then
  393. install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
  394. fi
  395. }
  396. In the main recipe, note the :term:`SRC_URI`
  397. variable, which tells the OpenEmbedded build system where to find files
  398. during the build.
  399. Following is the append file, which is named ``formfactor_0.0.bbappend``
  400. and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The
  401. file is in the layer at ``recipes-bsp/formfactor``::
  402. FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
  403. By default, the build system uses the
  404. :term:`FILESPATH` variable to
  405. locate files. This append file extends the locations by setting the
  406. :term:`FILESEXTRAPATHS`
  407. variable. Setting this variable in the ``.bbappend`` file is the most
  408. reliable and recommended method for adding directories to the search
  409. path used by the build system to find files.
  410. The statement in this example extends the directories to include
  411. ``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``,
  412. which resolves to a directory named ``formfactor`` in the same directory
  413. in which the append file resides (i.e.
  414. ``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must
  415. have the supporting directory structure set up that will contain any
  416. files or patches you will be including from the layer.
  417. Using the immediate expansion assignment operator ``:=`` is important
  418. because of the reference to :term:`THISDIR`. The trailing colon character is
  419. important as it ensures that items in the list remain colon-separated.
  420. .. note::
  421. BitBake automatically defines the :term:`THISDIR` variable. You should
  422. never set this variable yourself. Using ":prepend" as part of the
  423. :term:`FILESEXTRAPATHS` ensures your path will be searched prior to other
  424. paths in the final list.
  425. Also, not all append files add extra files. Many append files simply
  426. allow to add build options (e.g. ``systemd``). For these cases, your
  427. append file would not even use the :term:`FILESEXTRAPATHS` statement.
  428. The end result of this ``.bbappend`` file is that on a Raspberry Pi, where
  429. ``rpi`` will exist in the list of :term:`OVERRIDES`, the file
  430. ``meta-raspberrypi/recipes-bsp/formfactor/formfactor/rpi/machconfig`` will be
  431. used during :ref:`ref-tasks-fetch` and the test for a non-zero file size in
  432. :ref:`ref-tasks-install` will return true, and the file will be installed.
  433. Installing Additional Files Using Your Layer
  434. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  435. As another example, consider the main ``xserver-xf86-config`` recipe and a
  436. corresponding ``xserver-xf86-config`` append file both from the :term:`Source
  437. Directory`. Here is the main ``xserver-xf86-config`` recipe, which is named
  438. ``xserver-xf86-config_0.1.bb`` and located in the "meta" layer at
  439. ``meta/recipes-graphics/xorg-xserver``::
  440. SUMMARY = "X.Org X server configuration file"
  441. HOMEPAGE = "http://www.x.org"
  442. SECTION = "x11/base"
  443. LICENSE = "MIT"
  444. LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
  445. PR = "r33"
  446. SRC_URI = "file://xorg.conf"
  447. S = "${WORKDIR}"
  448. CONFFILES:${PN} = "${sysconfdir}/X11/xorg.conf"
  449. PACKAGE_ARCH = "${MACHINE_ARCH}"
  450. ALLOW_EMPTY:${PN} = "1"
  451. do_install () {
  452. if test -s ${WORKDIR}/xorg.conf; then
  453. install -d ${D}/${sysconfdir}/X11
  454. install -m 0644 ${WORKDIR}/xorg.conf ${D}/${sysconfdir}/X11/
  455. fi
  456. }
  457. Following is the append file, which is named ``xserver-xf86-config_%.bbappend``
  458. and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The
  459. file is in the layer at ``recipes-graphics/xorg-xserver``::
  460. FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
  461. SRC_URI:append:rpi = " \
  462. file://xorg.conf.d/98-pitft.conf \
  463. file://xorg.conf.d/99-calibration.conf \
  464. "
  465. do_install:append:rpi () {
  466. PITFT="${@bb.utils.contains("MACHINE_FEATURES", "pitft", "1", "0", d)}"
  467. if [ "${PITFT}" = "1" ]; then
  468. install -d ${D}/${sysconfdir}/X11/xorg.conf.d/
  469. install -m 0644 ${WORKDIR}/xorg.conf.d/98-pitft.conf ${D}/${sysconfdir}/X11/xorg.conf.d/
  470. install -m 0644 ${WORKDIR}/xorg.conf.d/99-calibration.conf ${D}/${sysconfdir}/X11/xorg.conf.d/
  471. fi
  472. }
  473. FILES:${PN}:append:rpi = " ${sysconfdir}/X11/xorg.conf.d/*"
  474. Building off of the previous example, we once again are setting the
  475. :term:`FILESEXTRAPATHS` variable. In this case we are also using
  476. :term:`SRC_URI` to list additional source files to use when ``rpi`` is found in
  477. the list of :term:`OVERRIDES`. The :ref:`ref-tasks-install` task will then perform a
  478. check for an additional :term:`MACHINE_FEATURES` that if set will cause these
  479. additional files to be installed. These additional files are listed in
  480. :term:`FILES` so that they will be packaged.
  481. Prioritizing Your Layer
  482. -----------------------
  483. Each layer is assigned a priority value. Priority values control which
  484. layer takes precedence if there are recipe files with the same name in
  485. multiple layers. For these cases, the recipe file from the layer with a
  486. higher priority number takes precedence. Priority values also affect the
  487. order in which multiple ``.bbappend`` files for the same recipe are
  488. applied. You can either specify the priority manually, or allow the
  489. build system to calculate it based on the layer's dependencies.
  490. To specify the layer's priority manually, use the
  491. :term:`BBFILE_PRIORITY`
  492. variable and append the layer's root name::
  493. BBFILE_PRIORITY_mylayer = "1"
  494. .. note::
  495. It is possible for a recipe with a lower version number
  496. :term:`PV` in a layer that has a higher
  497. priority to take precedence.
  498. Also, the layer priority does not currently affect the precedence
  499. order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake
  500. might address this.
  501. Managing Layers
  502. ---------------
  503. You can use the BitBake layer management tool ``bitbake-layers`` to
  504. provide a view into the structure of recipes across a multi-layer
  505. project. Being able to generate output that reports on configured layers
  506. with their paths and priorities and on ``.bbappend`` files and their
  507. applicable recipes can help to reveal potential problems.
  508. For help on the BitBake layer management tool, use the following
  509. command::
  510. $ bitbake-layers --help
  511. NOTE: Starting bitbake server...
  512. usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] <subcommand> ...
  513. BitBake layers utility
  514. optional arguments:
  515. -d, --debug Enable debug output
  516. -q, --quiet Print only errors
  517. -F, --force Force add without recipe parse verification
  518. --color COLOR Colorize output (where COLOR is auto, always, never)
  519. -h, --help show this help message and exit
  520. subcommands:
  521. <subcommand>
  522. layerindex-fetch Fetches a layer from a layer index along with its
  523. dependent layers, and adds them to conf/bblayers.conf.
  524. layerindex-show-depends
  525. Find layer dependencies from layer index.
  526. add-layer Add one or more layers to bblayers.conf.
  527. remove-layer Remove one or more layers from bblayers.conf.
  528. flatten flatten layer configuration into a separate output
  529. directory.
  530. show-layers show current configured layers.
  531. show-overlayed list overlayed recipes (where the same recipe exists
  532. in another layer)
  533. show-recipes list available recipes, showing the layer they are
  534. provided by
  535. show-appends list bbappend files and recipe files they apply to
  536. show-cross-depends Show dependencies between recipes that cross layer
  537. boundaries.
  538. create-layer Create a basic layer
  539. Use bitbake-layers <subcommand> --help to get help on a specific command
  540. The following list describes the available commands:
  541. - ``help:`` Displays general help or help on a specified command.
  542. - ``show-layers:`` Shows the current configured layers.
  543. - ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed
  544. when a recipe with the same name exists in another layer that has a
  545. higher layer priority.
  546. - ``show-recipes:`` Lists available recipes and the layers that
  547. provide them.
  548. - ``show-appends:`` Lists ``.bbappend`` files and the recipe files to
  549. which they apply.
  550. - ``show-cross-depends:`` Lists dependency relationships between
  551. recipes that cross layer boundaries.
  552. - ``add-layer:`` Adds a layer to ``bblayers.conf``.
  553. - ``remove-layer:`` Removes a layer from ``bblayers.conf``
  554. - ``flatten:`` Flattens the layer configuration into a separate
  555. output directory. Flattening your layer configuration builds a
  556. "flattened" directory that contains the contents of all layers, with
  557. any overlayed recipes removed and any ``.bbappend`` files appended to
  558. the corresponding recipes. You might have to perform some manual
  559. cleanup of the flattened layer as follows:
  560. - Non-recipe files (such as patches) are overwritten. The flatten
  561. command shows a warning for these files.
  562. - Anything beyond the normal layer setup has been added to the
  563. ``layer.conf`` file. Only the lowest priority layer's
  564. ``layer.conf`` is used.
  565. - Overridden and appended items from ``.bbappend`` files need to be
  566. cleaned up. The contents of each ``.bbappend`` end up in the
  567. flattened recipe. However, if there are appended or changed
  568. variable values, you need to tidy these up yourself. Consider the
  569. following example. Here, the ``bitbake-layers`` command adds the
  570. line ``#### bbappended ...`` so that you know where the following
  571. lines originate::
  572. ...
  573. DESCRIPTION = "A useful utility"
  574. ...
  575. EXTRA_OECONF = "--enable-something"
  576. ...
  577. #### bbappended from meta-anotherlayer ####
  578. DESCRIPTION = "Customized utility"
  579. EXTRA_OECONF += "--enable-somethingelse"
  580. Ideally, you would tidy up these utilities as follows::
  581. ...
  582. DESCRIPTION = "Customized utility"
  583. ...
  584. EXTRA_OECONF = "--enable-something --enable-somethingelse"
  585. ...
  586. - ``layerindex-fetch``: Fetches a layer from a layer index, along
  587. with its dependent layers, and adds the layers to the
  588. ``conf/bblayers.conf`` file.
  589. - ``layerindex-show-depends``: Finds layer dependencies from the
  590. layer index.
  591. - ``create-layer``: Creates a basic layer.
  592. Creating a General Layer Using the ``bitbake-layers`` Script
  593. ------------------------------------------------------------
  594. The ``bitbake-layers`` script with the ``create-layer`` subcommand
  595. simplifies creating a new general layer.
  596. .. note::
  597. - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`"
  598. section in the Yocto
  599. Project Board Specific (BSP) Developer's Guide.
  600. - In order to use a layer with the OpenEmbedded build system, you
  601. need to add the layer to your ``bblayers.conf`` configuration
  602. file. See the ":ref:`dev-manual/common-tasks:adding a layer using the \`\`bitbake-layers\`\` script`"
  603. section for more information.
  604. The default mode of the script's operation with this subcommand is to
  605. create a layer with the following:
  606. - A layer priority of 6.
  607. - A ``conf`` subdirectory that contains a ``layer.conf`` file.
  608. - A ``recipes-example`` subdirectory that contains a further
  609. subdirectory named ``example``, which contains an ``example.bb``
  610. recipe file.
  611. - A ``COPYING.MIT``, which is the license statement for the layer. The
  612. script assumes you want to use the MIT license, which is typical for
  613. most layers, for the contents of the layer itself.
  614. - A ``README`` file, which is a file describing the contents of your
  615. new layer.
  616. In its simplest form, you can use the following command form to create a
  617. layer. The command creates a layer whose name corresponds to
  618. "your_layer_name" in the current directory::
  619. $ bitbake-layers create-layer your_layer_name
  620. As an example, the following command creates a layer named ``meta-scottrif``
  621. in your home directory::
  622. $ cd /usr/home
  623. $ bitbake-layers create-layer meta-scottrif
  624. NOTE: Starting bitbake server...
  625. Add your new layer with 'bitbake-layers add-layer meta-scottrif'
  626. If you want to set the priority of the layer to other than the default
  627. value of "6", you can either use the ``--priority`` option or you
  628. can edit the
  629. :term:`BBFILE_PRIORITY` value
  630. in the ``conf/layer.conf`` after the script creates it. Furthermore, if
  631. you want to give the example recipe file some name other than the
  632. default, you can use the ``--example-recipe-name`` option.
  633. The easiest way to see how the ``bitbake-layers create-layer`` command
  634. works is to experiment with the script. You can also read the usage
  635. information by entering the following::
  636. $ bitbake-layers create-layer --help
  637. NOTE: Starting bitbake server...
  638. usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
  639. [--example-recipe-name EXAMPLERECIPE]
  640. layerdir
  641. Create a basic layer
  642. positional arguments:
  643. layerdir Layer directory to create
  644. optional arguments:
  645. -h, --help show this help message and exit
  646. --priority PRIORITY, -p PRIORITY
  647. Layer directory to create
  648. --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
  649. Filename of the example recipe
  650. Adding a Layer Using the ``bitbake-layers`` Script
  651. --------------------------------------------------
  652. Once you create your general layer, you must add it to your
  653. ``bblayers.conf`` file. Adding the layer to this configuration file
  654. makes the OpenEmbedded build system aware of your layer so that it can
  655. search it for metadata.
  656. Add your layer by using the ``bitbake-layers add-layer`` command::
  657. $ bitbake-layers add-layer your_layer_name
  658. Here is an example that adds a
  659. layer named ``meta-scottrif`` to the configuration file. Following the
  660. command that adds the layer is another ``bitbake-layers`` command that
  661. shows the layers that are in your ``bblayers.conf`` file::
  662. $ bitbake-layers add-layer meta-scottrif
  663. NOTE: Starting bitbake server...
  664. Parsing recipes: 100% |##########################################################| Time: 0:00:49
  665. Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
  666. $ bitbake-layers show-layers
  667. NOTE: Starting bitbake server...
  668. layer path priority
  669. ==========================================================================
  670. meta /home/scottrif/poky/meta 5
  671. meta-poky /home/scottrif/poky/meta-poky 5
  672. meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
  673. workspace /home/scottrif/poky/build/workspace 99
  674. meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
  675. Adding the layer to this file
  676. enables the build system to locate the layer during the build.
  677. .. note::
  678. During a build, the OpenEmbedded build system looks in the layers
  679. from the top of the list down to the bottom in that order.
  680. Customizing Images
  681. ==================
  682. You can customize images to satisfy particular requirements. This
  683. section describes several methods and provides guidelines for each.
  684. Customizing Images Using ``local.conf``
  685. ---------------------------------------
  686. Probably the easiest way to customize an image is to add a package by
  687. way of the ``local.conf`` configuration file. Because it is limited to
  688. local use, this method generally only allows you to add packages and is
  689. not as flexible as creating your own customized image. When you add
  690. packages using local variables this way, you need to realize that these
  691. variable changes are in effect for every build and consequently affect
  692. all images, which might not be what you require.
  693. To add a package to your image using the local configuration file, use
  694. the :term:`IMAGE_INSTALL` variable with the ``:append`` operator::
  695. IMAGE_INSTALL:append = " strace"
  696. Use of the syntax is important; specifically, the leading space
  697. after the opening quote and before the package name, which is
  698. ``strace`` in this example. This space is required since the ``:append``
  699. operator does not add the space.
  700. Furthermore, you must use ``:append`` instead of the ``+=`` operator if
  701. you want to avoid ordering issues. The reason for this is because doing
  702. so unconditionally appends to the variable and avoids ordering problems
  703. due to the variable being set in image recipes and ``.bbclass`` files
  704. with operators like ``?=``. Using ``:append`` ensures the operation
  705. takes effect.
  706. As shown in its simplest use, ``IMAGE_INSTALL:append`` affects all
  707. images. It is possible to extend the syntax so that the variable applies
  708. to a specific image only. Here is an example::
  709. IMAGE_INSTALL:append:pn-core-image-minimal = " strace"
  710. This example adds ``strace`` to the ``core-image-minimal`` image only.
  711. You can add packages using a similar approach through the
  712. :term:`CORE_IMAGE_EXTRA_INSTALL` variable. If you use this variable, only
  713. ``core-image-*`` images are affected.
  714. Customizing Images Using Custom ``IMAGE_FEATURES`` and ``EXTRA_IMAGE_FEATURES``
  715. -------------------------------------------------------------------------------
  716. Another method for customizing your image is to enable or disable
  717. high-level image features by using the
  718. :term:`IMAGE_FEATURES` and
  719. :term:`EXTRA_IMAGE_FEATURES`
  720. variables. Although the functions for both variables are nearly
  721. equivalent, best practices dictate using :term:`IMAGE_FEATURES` from within
  722. a recipe and using :term:`EXTRA_IMAGE_FEATURES` from within your
  723. ``local.conf`` file, which is found in the
  724. :term:`Build Directory`.
  725. To understand how these features work, the best reference is
  726. :ref:`meta/classes/image.bbclass <ref-classes-image>`.
  727. This class lists out the available
  728. :term:`IMAGE_FEATURES` of which most map to package groups while some, such
  729. as ``debug-tweaks`` and ``read-only-rootfs``, resolve as general
  730. configuration settings.
  731. In summary, the file looks at the contents of the :term:`IMAGE_FEATURES`
  732. variable and then maps or configures the feature accordingly. Based on
  733. this information, the build system automatically adds the appropriate
  734. packages or configurations to the
  735. :term:`IMAGE_INSTALL` variable.
  736. Effectively, you are enabling extra features by extending the class or
  737. creating a custom class for use with specialized image ``.bb`` files.
  738. Use the :term:`EXTRA_IMAGE_FEATURES` variable from within your local
  739. configuration file. Using a separate area from which to enable features
  740. with this variable helps you avoid overwriting the features in the image
  741. recipe that are enabled with :term:`IMAGE_FEATURES`. The value of
  742. :term:`EXTRA_IMAGE_FEATURES` is added to :term:`IMAGE_FEATURES` within
  743. ``meta/conf/bitbake.conf``.
  744. To illustrate how you can use these variables to modify your image,
  745. consider an example that selects the SSH server. The Yocto Project ships
  746. with two SSH servers you can use with your images: Dropbear and OpenSSH.
  747. Dropbear is a minimal SSH server appropriate for resource-constrained
  748. environments, while OpenSSH is a well-known standard SSH server
  749. implementation. By default, the ``core-image-sato`` image is configured
  750. to use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb``
  751. images both include OpenSSH. The ``core-image-minimal`` image does not
  752. contain an SSH server.
  753. You can customize your image and change these defaults. Edit the
  754. :term:`IMAGE_FEATURES` variable in your recipe or use the
  755. :term:`EXTRA_IMAGE_FEATURES` in your ``local.conf`` file so that it
  756. configures the image you are working with to include
  757. ``ssh-server-dropbear`` or ``ssh-server-openssh``.
  758. .. note::
  759. See the ":ref:`ref-manual/features:image features`" section in the Yocto
  760. Project Reference Manual for a complete list of image features that ship
  761. with the Yocto Project.
  762. Customizing Images Using Custom .bb Files
  763. -----------------------------------------
  764. You can also customize an image by creating a custom recipe that defines
  765. additional software as part of the image. The following example shows
  766. the form for the two lines you need::
  767. IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
  768. inherit core-image
  769. Defining the software using a custom recipe gives you total control over
  770. the contents of the image. It is important to use the correct names of
  771. packages in the :term:`IMAGE_INSTALL` variable. You must use the
  772. OpenEmbedded notation and not the Debian notation for the names (e.g.
  773. ``glibc-dev`` instead of ``libc6-dev``).
  774. The other method for creating a custom image is to base it on an
  775. existing image. For example, if you want to create an image based on
  776. ``core-image-sato`` but add the additional package ``strace`` to the
  777. image, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new
  778. ``.bb`` and add the following line to the end of the copy::
  779. IMAGE_INSTALL += "strace"
  780. Customizing Images Using Custom Package Groups
  781. ----------------------------------------------
  782. For complex custom images, the best approach for customizing an image is
  783. to create a custom package group recipe that is used to build the image
  784. or images. A good example of a package group recipe is
  785. ``meta/recipes-core/packagegroups/packagegroup-base.bb``.
  786. If you examine that recipe, you see that the :term:`PACKAGES` variable lists
  787. the package group packages to produce. The ``inherit packagegroup``
  788. statement sets appropriate default values and automatically adds
  789. ``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each
  790. package specified in the :term:`PACKAGES` statement.
  791. .. note::
  792. The ``inherit packagegroup`` line should be located near the top of the
  793. recipe, certainly before the :term:`PACKAGES` statement.
  794. For each package you specify in :term:`PACKAGES`, you can use :term:`RDEPENDS`
  795. and :term:`RRECOMMENDS` entries to provide a list of packages the parent
  796. task package should contain. You can see examples of these further down
  797. in the ``packagegroup-base.bb`` recipe.
  798. Here is a short, fabricated example showing the same basic pieces for a
  799. hypothetical packagegroup defined in ``packagegroup-custom.bb``, where
  800. the variable :term:`PN` is the standard way to abbreviate the reference to
  801. the full packagegroup name ``packagegroup-custom``::
  802. DESCRIPTION = "My Custom Package Groups"
  803. inherit packagegroup
  804. PACKAGES = "\
  805. ${PN}-apps \
  806. ${PN}-tools \
  807. "
  808. RDEPENDS:${PN}-apps = "\
  809. dropbear \
  810. portmap \
  811. psplash"
  812. RDEPENDS:${PN}-tools = "\
  813. oprofile \
  814. oprofileui-server \
  815. lttng-tools"
  816. RRECOMMENDS:${PN}-tools = "\
  817. kernel-module-oprofile"
  818. In the previous example, two package group packages are created with
  819. their dependencies and their recommended package dependencies listed:
  820. ``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To
  821. build an image using these package group packages, you need to add
  822. ``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to
  823. :term:`IMAGE_INSTALL`. For other forms of image dependencies see the other
  824. areas of this section.
  825. Customizing an Image Hostname
  826. -----------------------------
  827. By default, the configured hostname (i.e. ``/etc/hostname``) in an image
  828. is the same as the machine name. For example, if
  829. :term:`MACHINE` equals "qemux86", the
  830. configured hostname written to ``/etc/hostname`` is "qemux86".
  831. You can customize this name by altering the value of the "hostname"
  832. variable in the ``base-files`` recipe using either an append file or a
  833. configuration file. Use the following in an append file::
  834. hostname = "myhostname"
  835. Use the following in a configuration file::
  836. hostname:pn-base-files = "myhostname"
  837. Changing the default value of the variable "hostname" can be useful in
  838. certain situations. For example, suppose you need to do extensive
  839. testing on an image and you would like to easily identify the image
  840. under test from existing images with typical default hostnames. In this
  841. situation, you could change the default hostname to "testme", which
  842. results in all the images using the name "testme". Once testing is
  843. complete and you do not need to rebuild the image for test any longer,
  844. you can easily reset the default hostname.
  845. Another point of interest is that if you unset the variable, the image
  846. will have no default hostname in the filesystem. Here is an example that
  847. unsets the variable in a configuration file::
  848. hostname:pn-base-files = ""
  849. Having no default hostname in the filesystem is suitable for
  850. environments that use dynamic hostnames such as virtual machines.
  851. Writing a New Recipe
  852. ====================
  853. Recipes (``.bb`` files) are fundamental components in the Yocto Project
  854. environment. Each software component built by the OpenEmbedded build
  855. system requires a recipe to define the component. This section describes
  856. how to create, write, and test a new recipe.
  857. .. note::
  858. For information on variables that are useful for recipes and for
  859. information about recipe naming issues, see the
  860. ":ref:`ref-manual/varlocality:recipes`" section of the Yocto Project
  861. Reference Manual.
  862. Overview
  863. --------
  864. The following figure shows the basic process for creating a new recipe.
  865. The remainder of the section provides details for the steps.
  866. .. image:: figures/recipe-workflow.png
  867. :align: center
  868. Locate or Automatically Create a Base Recipe
  869. --------------------------------------------
  870. You can always write a recipe from scratch. However, there are three choices
  871. that can help you quickly get started with a new recipe:
  872. - ``devtool add``: A command that assists in creating a recipe and an
  873. environment conducive to development.
  874. - ``recipetool create``: A command provided by the Yocto Project that
  875. automates creation of a base recipe based on the source files.
  876. - *Existing Recipes:* Location and modification of an existing recipe
  877. that is similar in function to the recipe you need.
  878. .. note::
  879. For information on recipe syntax, see the
  880. ":ref:`dev-manual/common-tasks:recipe syntax`" section.
  881. Creating the Base Recipe Using ``devtool add``
  882. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  883. The ``devtool add`` command uses the same logic for auto-creating the
  884. recipe as ``recipetool create``, which is listed below. Additionally,
  885. however, ``devtool add`` sets up an environment that makes it easy for
  886. you to patch the source and to make changes to the recipe as is often
  887. necessary when adding a recipe to build a new piece of software to be
  888. included in a build.
  889. You can find a complete description of the ``devtool add`` command in
  890. the ":ref:`sdk-manual/extensible:a closer look at \`\`devtool add\`\``" section
  891. in the Yocto Project Application Development and the Extensible Software
  892. Development Kit (eSDK) manual.
  893. Creating the Base Recipe Using ``recipetool create``
  894. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  895. ``recipetool create`` automates creation of a base recipe given a set of
  896. source code files. As long as you can extract or point to the source
  897. files, the tool will construct a recipe and automatically configure all
  898. pre-build information into the recipe. For example, suppose you have an
  899. application that builds using Autotools. Creating the base recipe using
  900. ``recipetool`` results in a recipe that has the pre-build dependencies,
  901. license requirements, and checksums configured.
  902. To run the tool, you just need to be in your
  903. :term:`Build Directory` and have sourced the
  904. build environment setup script (i.e.
  905. :ref:`structure-core-script`).
  906. To get help on the tool, use the following command::
  907. $ recipetool -h
  908. NOTE: Starting bitbake server...
  909. usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ...
  910. OpenEmbedded recipe tool
  911. options:
  912. -d, --debug Enable debug output
  913. -q, --quiet Print only errors
  914. --color COLOR Colorize output (where COLOR is auto, always, never)
  915. -h, --help show this help message and exit
  916. subcommands:
  917. create Create a new recipe
  918. newappend Create a bbappend for the specified target in the specified
  919. layer
  920. setvar Set a variable within a recipe
  921. appendfile Create/update a bbappend to replace a target file
  922. appendsrcfiles Create/update a bbappend to add or replace source files
  923. appendsrcfile Create/update a bbappend to add or replace a source file
  924. Use recipetool <subcommand> --help to get help on a specific command
  925. Running ``recipetool create -o OUTFILE`` creates the base recipe and
  926. locates it properly in the layer that contains your source files.
  927. Following are some syntax examples:
  928. - Use this syntax to generate a recipe based on source. Once generated,
  929. the recipe resides in the existing source code layer::
  930. recipetool create -o OUTFILE source
  931. - Use this syntax to generate a recipe using code that
  932. you extract from source. The extracted code is placed in its own layer
  933. defined by :term:`EXTERNALSRC`.
  934. ::
  935. recipetool create -o OUTFILE -x EXTERNALSRC source
  936. - Use this syntax to generate a recipe based on source. The options
  937. direct ``recipetool`` to generate debugging information. Once generated,
  938. the recipe resides in the existing source code layer::
  939. recipetool create -d -o OUTFILE source
  940. Locating and Using a Similar Recipe
  941. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  942. Before writing a recipe from scratch, it is often useful to discover
  943. whether someone else has already written one that meets (or comes close
  944. to meeting) your needs. The Yocto Project and OpenEmbedded communities
  945. maintain many recipes that might be candidates for what you are doing.
  946. You can find a good central index of these recipes in the
  947. :oe_layerindex:`OpenEmbedded Layer Index <>`.
  948. Working from an existing recipe or a skeleton recipe is the best way to
  949. get started. Here are some points on both methods:
  950. - *Locate and modify a recipe that is close to what you want to do:*
  951. This method works when you are familiar with the current recipe
  952. space. The method does not work so well for those new to the Yocto
  953. Project or writing recipes.
  954. Some risks associated with this method are using a recipe that has
  955. areas totally unrelated to what you are trying to accomplish with
  956. your recipe, not recognizing areas of the recipe that you might have
  957. to add from scratch, and so forth. All these risks stem from
  958. unfamiliarity with the existing recipe space.
  959. - *Use and modify the following skeleton recipe:* If for some reason
  960. you do not want to use ``recipetool`` and you cannot find an existing
  961. recipe that is close to meeting your needs, you can use the following
  962. structure to provide the fundamental areas of a new recipe.
  963. ::
  964. DESCRIPTION = ""
  965. HOMEPAGE = ""
  966. LICENSE = ""
  967. SECTION = ""
  968. DEPENDS = ""
  969. LIC_FILES_CHKSUM = ""
  970. SRC_URI = ""
  971. Storing and Naming the Recipe
  972. -----------------------------
  973. Once you have your base recipe, you should put it in your own layer and
  974. name it appropriately. Locating it correctly ensures that the
  975. OpenEmbedded build system can find it when you use BitBake to process
  976. the recipe.
  977. - *Storing Your Recipe:* The OpenEmbedded build system locates your
  978. recipe through the layer's ``conf/layer.conf`` file and the
  979. :term:`BBFILES` variable. This
  980. variable sets up a path from which the build system can locate
  981. recipes. Here is the typical use::
  982. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  983. ${LAYERDIR}/recipes-*/*/*.bbappend"
  984. Consequently, you need to be sure you locate your new recipe inside
  985. your layer such that it can be found.
  986. You can find more information on how layers are structured in the
  987. ":ref:`dev-manual/common-tasks:understanding and creating layers`" section.
  988. - *Naming Your Recipe:* When you name your recipe, you need to follow
  989. this naming convention::
  990. basename_version.bb
  991. Use lower-cased characters and do not include the reserved suffixes
  992. ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use
  993. them as part of your recipe name unless the string applies). Here are some
  994. examples:
  995. .. code-block:: none
  996. cups_1.7.0.bb
  997. gawk_4.0.2.bb
  998. irssi_0.8.16-rc1.bb
  999. Running a Build on the Recipe
  1000. -----------------------------
  1001. Creating a new recipe is usually an iterative process that requires
  1002. using BitBake to process the recipe multiple times in order to
  1003. progressively discover and add information to the recipe file.
  1004. Assuming you have sourced the build environment setup script (i.e.
  1005. :ref:`structure-core-script`) and you are in
  1006. the :term:`Build Directory`, use
  1007. BitBake to process your recipe. All you need to provide is the
  1008. ``basename`` of the recipe as described in the previous section::
  1009. $ bitbake basename
  1010. During the build, the OpenEmbedded build system creates a temporary work
  1011. directory for each recipe
  1012. (``${``\ :term:`WORKDIR`\ ``}``)
  1013. where it keeps extracted source files, log files, intermediate
  1014. compilation and packaging files, and so forth.
  1015. The path to the per-recipe temporary work directory depends on the
  1016. context in which it is being built. The quickest way to find this path
  1017. is to have BitBake return it by running the following::
  1018. $ bitbake -e basename | grep ^WORKDIR=
  1019. As an example, assume a Source Directory
  1020. top-level folder named ``poky``, a default Build Directory at
  1021. ``poky/build``, and a ``qemux86-poky-linux`` machine target system.
  1022. Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this
  1023. case, the work directory the build system uses to build the package
  1024. would be as follows::
  1025. poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
  1026. Inside this directory you can find sub-directories such as ``image``,
  1027. ``packages-split``, and ``temp``. After the build, you can examine these
  1028. to determine how well the build went.
  1029. .. note::
  1030. You can find log files for each task in the recipe's ``temp``
  1031. directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``).
  1032. Log files are named ``log.taskname`` (e.g. ``log.do_configure``,
  1033. ``log.do_fetch``, and ``log.do_compile``).
  1034. You can find more information about the build process in
  1035. ":doc:`/overview-manual/development-environment`"
  1036. chapter of the Yocto Project Overview and Concepts Manual.
  1037. Fetching Code
  1038. -------------
  1039. The first thing your recipe must do is specify how to fetch the source
  1040. files. Fetching is controlled mainly through the
  1041. :term:`SRC_URI` variable. Your recipe
  1042. must have a :term:`SRC_URI` variable that points to where the source is
  1043. located. For a graphical representation of source locations, see the
  1044. ":ref:`overview-manual/concepts:sources`" section in
  1045. the Yocto Project Overview and Concepts Manual.
  1046. The :ref:`ref-tasks-fetch` task uses
  1047. the prefix of each entry in the :term:`SRC_URI` variable value to determine
  1048. which :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>` to use to get your
  1049. source files. It is the :term:`SRC_URI` variable that triggers the fetcher.
  1050. The :ref:`ref-tasks-patch` task uses
  1051. the variable after source is fetched to apply patches. The OpenEmbedded
  1052. build system uses
  1053. :term:`FILESOVERRIDES` for
  1054. scanning directory locations for local files in :term:`SRC_URI`.
  1055. The :term:`SRC_URI` variable in your recipe must define each unique location
  1056. for your source files. It is good practice to not hard-code version
  1057. numbers in a URL used in :term:`SRC_URI`. Rather than hard-code these
  1058. values, use ``${``\ :term:`PV`\ ``}``,
  1059. which causes the fetch process to use the version specified in the
  1060. recipe filename. Specifying the version in this manner means that
  1061. upgrading the recipe to a future version is as simple as renaming the
  1062. recipe to match the new version.
  1063. Here is a simple example from the
  1064. ``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source
  1065. comes from a single tarball. Notice the use of the
  1066. :term:`PV` variable::
  1067. SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \
  1068. Files mentioned in :term:`SRC_URI` whose names end in a typical archive
  1069. extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so
  1070. forth), are automatically extracted during the
  1071. :ref:`ref-tasks-unpack` task. For
  1072. another example that specifies these types of files, see the
  1073. ":ref:`dev-manual/common-tasks:autotooled package`" section.
  1074. Another way of specifying source is from an SCM. For Git repositories,
  1075. you must specify :term:`SRCREV` and you should specify :term:`PV` to include
  1076. the revision with :term:`SRCPV`. Here is an example from the recipe
  1077. ``meta/recipes-core/musl/gcompat_git.bb``::
  1078. SRC_URI = "git://git.adelielinux.org/adelie/gcompat.git;protocol=https;branch=current"
  1079. PV = "1.0.0+1.1+git${SRCPV}"
  1080. SRCREV = "af5a49e489fdc04b9cf02547650d7aeaccd43793"
  1081. If your :term:`SRC_URI` statement includes URLs pointing to individual files
  1082. fetched from a remote server other than a version control system,
  1083. BitBake attempts to verify the files against checksums defined in your
  1084. recipe to ensure they have not been tampered with or otherwise modified
  1085. since the recipe was written. Two checksums are used:
  1086. ``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``.
  1087. If your :term:`SRC_URI` variable points to more than a single URL (excluding
  1088. SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for
  1089. each URL. For these cases, you provide a name for each URL as part of
  1090. the :term:`SRC_URI` and then reference that name in the subsequent checksum
  1091. statements. Here is an example combining lines from the files
  1092. ``git.inc`` and ``git_2.24.1.bb``::
  1093. SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
  1094. ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages"
  1095. SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b"
  1096. SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02"
  1097. SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d"
  1098. SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230"
  1099. Proper values for ``md5`` and ``sha256`` checksums might be available
  1100. with other signatures on the download page for the upstream source (e.g.
  1101. ``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the
  1102. OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``,
  1103. you should verify all the signatures you find by hand.
  1104. If no :term:`SRC_URI` checksums are specified when you attempt to build the
  1105. recipe, or you provide an incorrect checksum, the build will produce an
  1106. error for each missing or incorrect checksum. As part of the error
  1107. message, the build system provides the checksum string corresponding to
  1108. the fetched file. Once you have the correct checksums, you can copy and
  1109. paste them into your recipe and then run the build again to continue.
  1110. .. note::
  1111. As mentioned, if the upstream source provides signatures for
  1112. verifying the downloaded source code, you should verify those
  1113. manually before setting the checksum values in the recipe and
  1114. continuing with the build.
  1115. This final example is a bit more complicated and is from the
  1116. ``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The
  1117. example's :term:`SRC_URI` statement identifies multiple files as the source
  1118. files for the recipe: a tarball, a patch file, a desktop file, and an
  1119. icon.
  1120. ::
  1121. SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
  1122. file://xwc.patch \
  1123. file://rxvt.desktop \
  1124. file://rxvt.png"
  1125. When you specify local files using the ``file://`` URI protocol, the
  1126. build system fetches files from the local machine. The path is relative
  1127. to the :term:`FILESPATH` variable
  1128. and searches specific directories in a certain order:
  1129. ``${``\ :term:`BP`\ ``}``,
  1130. ``${``\ :term:`BPN`\ ``}``, and
  1131. ``files``. The directories are assumed to be subdirectories of the
  1132. directory in which the recipe or append file resides. For another
  1133. example that specifies these types of files, see the
  1134. ":ref:`dev-manual/common-tasks:single .c file package (hello world!)`" section.
  1135. The previous example also specifies a patch file. Patch files are files
  1136. whose names usually end in ``.patch`` or ``.diff`` but can end with
  1137. compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example.
  1138. The build system automatically applies patches as described in the
  1139. ":ref:`dev-manual/common-tasks:patching code`" section.
  1140. Fetching Code Through Firewalls
  1141. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1142. Some users are behind firewalls and need to fetch code through a proxy.
  1143. See the ":doc:`/ref-manual/faq`" chapter for advice.
  1144. Limiting the Number of Parallel Connections
  1145. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1146. Some users are behind firewalls or use servers where the number of parallel
  1147. connections is limited. In such cases, you can limit the number of fetch
  1148. tasks being run in parallel by adding the following to your ``local.conf``
  1149. file::
  1150. do_fetch[number_threads] = "4"
  1151. Unpacking Code
  1152. --------------
  1153. During the build, the
  1154. :ref:`ref-tasks-unpack` task unpacks
  1155. the source with ``${``\ :term:`S`\ ``}``
  1156. pointing to where it is unpacked.
  1157. If you are fetching your source files from an upstream source archived
  1158. tarball and the tarball's internal structure matches the common
  1159. convention of a top-level subdirectory named
  1160. ``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``,
  1161. then you do not need to set :term:`S`. However, if :term:`SRC_URI` specifies to
  1162. fetch source from an archive that does not use this convention, or from
  1163. an SCM like Git or Subversion, your recipe needs to define :term:`S`.
  1164. If processing your recipe using BitBake successfully unpacks the source
  1165. files, you need to be sure that the directory pointed to by ``${S}``
  1166. matches the structure of the source.
  1167. Patching Code
  1168. -------------
  1169. Sometimes it is necessary to patch code after it has been fetched. Any
  1170. files mentioned in :term:`SRC_URI` whose names end in ``.patch`` or
  1171. ``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are
  1172. treated as patches. The
  1173. :ref:`ref-tasks-patch` task
  1174. automatically applies these patches.
  1175. The build system should be able to apply patches with the "-p1" option
  1176. (i.e. one directory level in the path will be stripped off). If your
  1177. patch needs to have more directory levels stripped off, specify the
  1178. number of levels using the "striplevel" option in the :term:`SRC_URI` entry
  1179. for the patch. Alternatively, if your patch needs to be applied in a
  1180. specific subdirectory that is not specified in the patch file, use the
  1181. "patchdir" option in the entry.
  1182. As with all local files referenced in
  1183. :term:`SRC_URI` using ``file://``,
  1184. you should place patch files in a directory next to the recipe either
  1185. named the same as the base name of the recipe
  1186. (:term:`BP` and
  1187. :term:`BPN`) or "files".
  1188. Licensing
  1189. ---------
  1190. Your recipe needs to have both the
  1191. :term:`LICENSE` and
  1192. :term:`LIC_FILES_CHKSUM`
  1193. variables:
  1194. - :term:`LICENSE`: This variable specifies the license for the software.
  1195. If you do not know the license under which the software you are
  1196. building is distributed, you should go to the source code and look
  1197. for that information. Typical files containing this information
  1198. include ``COPYING``, :term:`LICENSE`, and ``README`` files. You could
  1199. also find the information near the top of a source file. For example,
  1200. given a piece of software licensed under the GNU General Public
  1201. License version 2, you would set :term:`LICENSE` as follows::
  1202. LICENSE = "GPL-2.0-only"
  1203. The licenses you specify within :term:`LICENSE` can have any name as long
  1204. as you do not use spaces, since spaces are used as separators between
  1205. license names. For standard licenses, use the names of the files in
  1206. ``meta/files/common-licenses/`` or the :term:`SPDXLICENSEMAP` flag names
  1207. defined in ``meta/conf/licenses.conf``.
  1208. - :term:`LIC_FILES_CHKSUM`: The OpenEmbedded build system uses this
  1209. variable to make sure the license text has not changed. If it has,
  1210. the build produces an error and it affords you the chance to figure
  1211. it out and correct the problem.
  1212. You need to specify all applicable licensing files for the software.
  1213. At the end of the configuration step, the build process will compare
  1214. the checksums of the files to be sure the text has not changed. Any
  1215. differences result in an error with the message containing the
  1216. current checksum. For more explanation and examples of how to set the
  1217. :term:`LIC_FILES_CHKSUM` variable, see the
  1218. ":ref:`dev-manual/common-tasks:tracking license changes`" section.
  1219. To determine the correct checksum string, you can list the
  1220. appropriate files in the :term:`LIC_FILES_CHKSUM` variable with incorrect
  1221. md5 strings, attempt to build the software, and then note the
  1222. resulting error messages that will report the correct md5 strings.
  1223. See the ":ref:`dev-manual/common-tasks:fetching code`" section for
  1224. additional information.
  1225. Here is an example that assumes the software has a ``COPYING`` file::
  1226. LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
  1227. When you try to build the
  1228. software, the build system will produce an error and give you the
  1229. correct string that you can substitute into the recipe file for a
  1230. subsequent build.
  1231. Dependencies
  1232. ------------
  1233. Most software packages have a short list of other packages that they
  1234. require, which are called dependencies. These dependencies fall into two
  1235. main categories: build-time dependencies, which are required when the
  1236. software is built; and runtime dependencies, which are required to be
  1237. installed on the target in order for the software to run.
  1238. Within a recipe, you specify build-time dependencies using the
  1239. :term:`DEPENDS` variable. Although there are nuances,
  1240. items specified in :term:`DEPENDS` should be names of other
  1241. recipes. It is important that you specify all build-time dependencies
  1242. explicitly.
  1243. Another consideration is that configure scripts might automatically
  1244. check for optional dependencies and enable corresponding functionality
  1245. if those dependencies are found. If you wish to make a recipe that is
  1246. more generally useful (e.g. publish the recipe in a layer for others to
  1247. use), instead of hard-disabling the functionality, you can use the
  1248. :term:`PACKAGECONFIG` variable to allow functionality and the
  1249. corresponding dependencies to be enabled and disabled easily by other
  1250. users of the recipe.
  1251. Similar to build-time dependencies, you specify runtime dependencies
  1252. through a variable -
  1253. :term:`RDEPENDS`, which is
  1254. package-specific. All variables that are package-specific need to have
  1255. the name of the package added to the end as an override. Since the main
  1256. package for a recipe has the same name as the recipe, and the recipe's
  1257. name can be found through the
  1258. ``${``\ :term:`PN`\ ``}`` variable, then
  1259. you specify the dependencies for the main package by setting
  1260. ``RDEPENDS:${PN}``. If the package were named ``${PN}-tools``, then you
  1261. would set ``RDEPENDS:${PN}-tools``, and so forth.
  1262. Some runtime dependencies will be set automatically at packaging time.
  1263. These dependencies include any shared library dependencies (i.e. if a
  1264. package "example" contains "libexample" and another package "mypackage"
  1265. contains a binary that links to "libexample" then the OpenEmbedded build
  1266. system will automatically add a runtime dependency to "mypackage" on
  1267. "example"). See the
  1268. ":ref:`overview-manual/concepts:automatically added runtime dependencies`"
  1269. section in the Yocto Project Overview and Concepts Manual for further
  1270. details.
  1271. Configuring the Recipe
  1272. ----------------------
  1273. Most software provides some means of setting build-time configuration
  1274. options before compilation. Typically, setting these options is
  1275. accomplished by running a configure script with options, or by modifying
  1276. a build configuration file.
  1277. .. note::
  1278. As of Yocto Project Release 1.7, some of the core recipes that
  1279. package binary configuration scripts now disable the scripts due to
  1280. the scripts previously requiring error-prone path substitution. The
  1281. OpenEmbedded build system uses ``pkg-config`` now, which is much more
  1282. robust. You can find a list of the ``*-config`` scripts that are disabled
  1283. in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section
  1284. in the Yocto Project Reference Manual.
  1285. A major part of build-time configuration is about checking for
  1286. build-time dependencies and possibly enabling optional functionality as
  1287. a result. You need to specify any build-time dependencies for the
  1288. software you are building in your recipe's
  1289. :term:`DEPENDS` value, in terms of
  1290. other recipes that satisfy those dependencies. You can often find
  1291. build-time or runtime dependencies described in the software's
  1292. documentation.
  1293. The following list provides configuration items of note based on how
  1294. your software is built:
  1295. - *Autotools:* If your source files have a ``configure.ac`` file, then
  1296. your software is built using Autotools. If this is the case, you just
  1297. need to modify the configuration.
  1298. When using Autotools, your recipe needs to inherit the
  1299. :ref:`autotools <ref-classes-autotools>` class
  1300. and your recipe does not have to contain a
  1301. :ref:`ref-tasks-configure` task.
  1302. However, you might still want to make some adjustments. For example,
  1303. you can set
  1304. :term:`EXTRA_OECONF` or
  1305. :term:`PACKAGECONFIG_CONFARGS`
  1306. to pass any needed configure options that are specific to the recipe.
  1307. - *CMake:* If your source files have a ``CMakeLists.txt`` file, then
  1308. your software is built using CMake. If this is the case, you just
  1309. need to modify the configuration.
  1310. When you use CMake, your recipe needs to inherit the
  1311. :ref:`cmake <ref-classes-cmake>` class and your
  1312. recipe does not have to contain a
  1313. :ref:`ref-tasks-configure` task.
  1314. You can make some adjustments by setting
  1315. :term:`EXTRA_OECMAKE` to
  1316. pass any needed configure options that are specific to the recipe.
  1317. .. note::
  1318. If you need to install one or more custom CMake toolchain files
  1319. that are supplied by the application you are building, install the
  1320. files to ``${D}${datadir}/cmake/Modules`` during ``do_install``.
  1321. - *Other:* If your source files do not have a ``configure.ac`` or
  1322. ``CMakeLists.txt`` file, then your software is built using some
  1323. method other than Autotools or CMake. If this is the case, you
  1324. normally need to provide a
  1325. :ref:`ref-tasks-configure` task
  1326. in your recipe unless, of course, there is nothing to configure.
  1327. Even if your software is not being built by Autotools or CMake, you
  1328. still might not need to deal with any configuration issues. You need
  1329. to determine if configuration is even a required step. You might need
  1330. to modify a Makefile or some configuration file used for the build to
  1331. specify necessary build options. Or, perhaps you might need to run a
  1332. provided, custom configure script with the appropriate options.
  1333. For the case involving a custom configure script, you would run
  1334. ``./configure --help`` and look for the options you need to set.
  1335. Once configuration succeeds, it is always good practice to look at the
  1336. ``log.do_configure`` file to ensure that the appropriate options have
  1337. been enabled and no additional build-time dependencies need to be added
  1338. to :term:`DEPENDS`. For example, if the configure script reports that it
  1339. found something not mentioned in :term:`DEPENDS`, or that it did not find
  1340. something that it needed for some desired optional functionality, then
  1341. you would need to add those to :term:`DEPENDS`. Looking at the log might
  1342. also reveal items being checked for, enabled, or both that you do not
  1343. want, or items not being found that are in :term:`DEPENDS`, in which case
  1344. you would need to look at passing extra options to the configure script
  1345. as needed. For reference information on configure options specific to
  1346. the software you are building, you can consult the output of the
  1347. ``./configure --help`` command within ``${S}`` or consult the software's
  1348. upstream documentation.
  1349. Using Headers to Interface with Devices
  1350. ---------------------------------------
  1351. If your recipe builds an application that needs to communicate with some
  1352. device or needs an API into a custom kernel, you will need to provide
  1353. appropriate header files. Under no circumstances should you ever modify
  1354. the existing
  1355. ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file.
  1356. These headers are used to build ``libc`` and must not be compromised
  1357. with custom or machine-specific header information. If you customize
  1358. ``libc`` through modified headers all other applications that use
  1359. ``libc`` thus become affected.
  1360. .. note::
  1361. Never copy and customize the ``libc`` header file (i.e.
  1362. ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``).
  1363. The correct way to interface to a device or custom kernel is to use a
  1364. separate package that provides the additional headers for the driver or
  1365. other unique interfaces. When doing so, your application also becomes
  1366. responsible for creating a dependency on that specific provider.
  1367. Consider the following:
  1368. - Never modify ``linux-libc-headers.inc``. Consider that file to be
  1369. part of the ``libc`` system, and not something you use to access the
  1370. kernel directly. You should access ``libc`` through specific ``libc``
  1371. calls.
  1372. - Applications that must talk directly to devices should either provide
  1373. necessary headers themselves, or establish a dependency on a special
  1374. headers package that is specific to that driver.
  1375. For example, suppose you want to modify an existing header that adds I/O
  1376. control or network support. If the modifications are used by a small
  1377. number programs, providing a unique version of a header is easy and has
  1378. little impact. When doing so, bear in mind the guidelines in the
  1379. previous list.
  1380. .. note::
  1381. If for some reason your changes need to modify the behavior of the ``libc``,
  1382. and subsequently all other applications on the system, use a ``.bbappend``
  1383. to modify the ``linux-kernel-headers.inc`` file. However, take care to not
  1384. make the changes machine specific.
  1385. Consider a case where your kernel is older and you need an older
  1386. ``libc`` ABI. The headers installed by your recipe should still be a
  1387. standard mainline kernel, not your own custom one.
  1388. When you use custom kernel headers you need to get them from
  1389. :term:`STAGING_KERNEL_DIR`,
  1390. which is the directory with kernel headers that are required to build
  1391. out-of-tree modules. Your recipe will also need the following::
  1392. do_configure[depends] += "virtual/kernel:do_shared_workdir"
  1393. Compilation
  1394. -----------
  1395. During a build, the ``do_compile`` task happens after source is fetched,
  1396. unpacked, and configured. If the recipe passes through ``do_compile``
  1397. successfully, nothing needs to be done.
  1398. However, if the compile step fails, you need to diagnose the failure.
  1399. Here are some common issues that cause failures.
  1400. .. note::
  1401. For cases where improper paths are detected for configuration files
  1402. or for when libraries/headers cannot be found, be sure you are using
  1403. the more robust ``pkg-config``. See the note in section
  1404. ":ref:`dev-manual/common-tasks:Configuring the Recipe`" for additional information.
  1405. - *Parallel build failures:* These failures manifest themselves as
  1406. intermittent errors, or errors reporting that a file or directory
  1407. that should be created by some other part of the build process could
  1408. not be found. This type of failure can occur even if, upon
  1409. inspection, the file or directory does exist after the build has
  1410. failed, because that part of the build process happened in the wrong
  1411. order.
  1412. To fix the problem, you need to either satisfy the missing dependency
  1413. in the Makefile or whatever script produced the Makefile, or (as a
  1414. workaround) set :term:`PARALLEL_MAKE` to an empty string::
  1415. PARALLEL_MAKE = ""
  1416. For information on parallel Makefile issues, see the
  1417. ":ref:`dev-manual/common-tasks:debugging parallel make races`" section.
  1418. - *Improper host path usage:* This failure applies to recipes building
  1419. for the target or ``nativesdk`` only. The failure occurs when the
  1420. compilation process uses improper headers, libraries, or other files
  1421. from the host system when cross-compiling for the target.
  1422. To fix the problem, examine the ``log.do_compile`` file to identify
  1423. the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and
  1424. so forth) and then either add configure options, apply a patch, or do
  1425. both.
  1426. - *Failure to find required libraries/headers:* If a build-time
  1427. dependency is missing because it has not been declared in
  1428. :term:`DEPENDS`, or because the
  1429. dependency exists but the path used by the build process to find the
  1430. file is incorrect and the configure step did not detect it, the
  1431. compilation process could fail. For either of these failures, the
  1432. compilation process notes that files could not be found. In these
  1433. cases, you need to go back and add additional options to the
  1434. configure script as well as possibly add additional build-time
  1435. dependencies to :term:`DEPENDS`.
  1436. Occasionally, it is necessary to apply a patch to the source to
  1437. ensure the correct paths are used. If you need to specify paths to
  1438. find files staged into the sysroot from other recipes, use the
  1439. variables that the OpenEmbedded build system provides (e.g.
  1440. :term:`STAGING_BINDIR`, :term:`STAGING_INCDIR`, :term:`STAGING_DATADIR`, and so
  1441. forth).
  1442. Installing
  1443. ----------
  1444. During ``do_install``, the task copies the built files along with their
  1445. hierarchy to locations that would mirror their locations on the target
  1446. device. The installation process copies files from the
  1447. ``${``\ :term:`S`\ ``}``,
  1448. ``${``\ :term:`B`\ ``}``, and
  1449. ``${``\ :term:`WORKDIR`\ ``}``
  1450. directories to the ``${``\ :term:`D`\ ``}``
  1451. directory to create the structure as it should appear on the target
  1452. system.
  1453. How your software is built affects what you must do to be sure your
  1454. software is installed correctly. The following list describes what you
  1455. must do for installation depending on the type of build system used by
  1456. the software being built:
  1457. - *Autotools and CMake:* If the software your recipe is building uses
  1458. Autotools or CMake, the OpenEmbedded build system understands how to
  1459. install the software. Consequently, you do not have to have a
  1460. ``do_install`` task as part of your recipe. You just need to make
  1461. sure the install portion of the build completes with no issues.
  1462. However, if you wish to install additional files not already being
  1463. installed by ``make install``, you should do this using a
  1464. ``do_install:append`` function using the install command as described
  1465. in the "Manual" bulleted item later in this list.
  1466. - *Other (using* ``make install``\ *)*: You need to define a ``do_install``
  1467. function in your recipe. The function should call
  1468. ``oe_runmake install`` and will likely need to pass in the
  1469. destination directory as well. How you pass that path is dependent on
  1470. how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``,
  1471. ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth).
  1472. For an example recipe using ``make install``, see the
  1473. ":ref:`dev-manual/common-tasks:makefile-based package`" section.
  1474. - *Manual:* You need to define a ``do_install`` function in your
  1475. recipe. The function must first use ``install -d`` to create the
  1476. directories under
  1477. ``${``\ :term:`D`\ ``}``. Once the
  1478. directories exist, your function can use ``install`` to manually
  1479. install the built software into the directories.
  1480. You can find more information on ``install`` at
  1481. https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html.
  1482. For the scenarios that do not use Autotools or CMake, you need to track
  1483. the installation and diagnose and fix any issues until everything
  1484. installs correctly. You need to look in the default location of
  1485. ``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been
  1486. installed correctly.
  1487. .. note::
  1488. - During the installation process, you might need to modify some of
  1489. the installed files to suit the target layout. For example, you
  1490. might need to replace hard-coded paths in an initscript with
  1491. values of variables provided by the build system, such as
  1492. replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such
  1493. modifications during ``do_install``, be sure to modify the
  1494. destination file after copying rather than before copying.
  1495. Modifying after copying ensures that the build system can
  1496. re-execute ``do_install`` if needed.
  1497. - ``oe_runmake install``, which can be run directly or can be run
  1498. indirectly by the
  1499. :ref:`autotools <ref-classes-autotools>` and
  1500. :ref:`cmake <ref-classes-cmake>` classes,
  1501. runs ``make install`` in parallel. Sometimes, a Makefile can have
  1502. missing dependencies between targets that can result in race
  1503. conditions. If you experience intermittent failures during
  1504. ``do_install``, you might be able to work around them by disabling
  1505. parallel Makefile installs by adding the following to the recipe::
  1506. PARALLEL_MAKEINST = ""
  1507. See :term:`PARALLEL_MAKEINST` for additional information.
  1508. - If you need to install one or more custom CMake toolchain files
  1509. that are supplied by the application you are building, install the
  1510. files to ``${D}${datadir}/cmake/Modules`` during
  1511. :ref:`ref-tasks-install`.
  1512. Enabling System Services
  1513. ------------------------
  1514. If you want to install a service, which is a process that usually starts
  1515. on boot and runs in the background, then you must include some
  1516. additional definitions in your recipe.
  1517. If you are adding services and the service initialization script or the
  1518. service file itself is not installed, you must provide for that
  1519. installation in your recipe using a ``do_install:append`` function. If
  1520. your recipe already has a ``do_install`` function, update the function
  1521. near its end rather than adding an additional ``do_install:append``
  1522. function.
  1523. When you create the installation for your services, you need to
  1524. accomplish what is normally done by ``make install``. In other words,
  1525. make sure your installation arranges the output similar to how it is
  1526. arranged on the target system.
  1527. The OpenEmbedded build system provides support for starting services two
  1528. different ways:
  1529. - *SysVinit:* SysVinit is a system and service manager that manages the
  1530. init system used to control the very basic functions of your system.
  1531. The init program is the first program started by the Linux kernel
  1532. when the system boots. Init then controls the startup, running and
  1533. shutdown of all other programs.
  1534. To enable a service using SysVinit, your recipe needs to inherit the
  1535. :ref:`update-rc.d <ref-classes-update-rc.d>`
  1536. class. The class helps facilitate safely installing the package on
  1537. the target.
  1538. You will need to set the
  1539. :term:`INITSCRIPT_PACKAGES`,
  1540. :term:`INITSCRIPT_NAME`,
  1541. and
  1542. :term:`INITSCRIPT_PARAMS`
  1543. variables within your recipe.
  1544. - *systemd:* System Management Daemon (systemd) was designed to replace
  1545. SysVinit and to provide enhanced management of services. For more
  1546. information on systemd, see the systemd homepage at
  1547. https://freedesktop.org/wiki/Software/systemd/.
  1548. To enable a service using systemd, your recipe needs to inherit the
  1549. :ref:`systemd <ref-classes-systemd>` class. See
  1550. the ``systemd.bbclass`` file located in your :term:`Source Directory`
  1551. section for
  1552. more information.
  1553. Packaging
  1554. ---------
  1555. Successful packaging is a combination of automated processes performed
  1556. by the OpenEmbedded build system and some specific steps you need to
  1557. take. The following list describes the process:
  1558. - *Splitting Files*: The ``do_package`` task splits the files produced
  1559. by the recipe into logical components. Even software that produces a
  1560. single binary might still have debug symbols, documentation, and
  1561. other logical components that should be split out. The ``do_package``
  1562. task ensures that files are split up and packaged correctly.
  1563. - *Running QA Checks*: The
  1564. :ref:`insane <ref-classes-insane>` class adds a
  1565. step to the package generation process so that output quality
  1566. assurance checks are generated by the OpenEmbedded build system. This
  1567. step performs a range of checks to be sure the build's output is free
  1568. of common problems that show up during runtime. For information on
  1569. these checks, see the
  1570. :ref:`insane <ref-classes-insane>` class and
  1571. the ":ref:`ref-manual/qa-checks:qa error and warning messages`"
  1572. chapter in the Yocto Project Reference Manual.
  1573. - *Hand-Checking Your Packages*: After you build your software, you
  1574. need to be sure your packages are correct. Examine the
  1575. ``${``\ :term:`WORKDIR`\ ``}/packages-split``
  1576. directory and make sure files are where you expect them to be. If you
  1577. discover problems, you can set
  1578. :term:`PACKAGES`,
  1579. :term:`FILES`,
  1580. ``do_install(:append)``, and so forth as needed.
  1581. - *Splitting an Application into Multiple Packages*: If you need to
  1582. split an application into several packages, see the
  1583. ":ref:`dev-manual/common-tasks:splitting an application into multiple packages`"
  1584. section for an example.
  1585. - *Installing a Post-Installation Script*: For an example showing how
  1586. to install a post-installation script, see the
  1587. ":ref:`dev-manual/common-tasks:post-installation scripts`" section.
  1588. - *Marking Package Architecture*: Depending on what your recipe is
  1589. building and how it is configured, it might be important to mark the
  1590. packages produced as being specific to a particular machine, or to
  1591. mark them as not being specific to a particular machine or
  1592. architecture at all.
  1593. By default, packages apply to any machine with the same architecture
  1594. as the target machine. When a recipe produces packages that are
  1595. machine-specific (e.g. the
  1596. :term:`MACHINE` value is passed
  1597. into the configure script or a patch is applied only for a particular
  1598. machine), you should mark them as such by adding the following to the
  1599. recipe::
  1600. PACKAGE_ARCH = "${MACHINE_ARCH}"
  1601. On the other hand, if the recipe produces packages that do not
  1602. contain anything specific to the target machine or architecture at
  1603. all (e.g. recipes that simply package script files or configuration
  1604. files), you should use the
  1605. :ref:`allarch <ref-classes-allarch>` class to
  1606. do this for you by adding this to your recipe::
  1607. inherit allarch
  1608. Ensuring that the package architecture is correct is not critical
  1609. while you are doing the first few builds of your recipe. However, it
  1610. is important in order to ensure that your recipe rebuilds (or does
  1611. not rebuild) appropriately in response to changes in configuration,
  1612. and to ensure that you get the appropriate packages installed on the
  1613. target machine, particularly if you run separate builds for more than
  1614. one target machine.
  1615. Sharing Files Between Recipes
  1616. -----------------------------
  1617. Recipes often need to use files provided by other recipes on the build
  1618. host. For example, an application linking to a common library needs
  1619. access to the library itself and its associated headers. The way this
  1620. access is accomplished is by populating a sysroot with files. Each
  1621. recipe has two sysroots in its work directory, one for target files
  1622. (``recipe-sysroot``) and one for files that are native to the build host
  1623. (``recipe-sysroot-native``).
  1624. .. note::
  1625. You could find the term "staging" used within the Yocto project
  1626. regarding files populating sysroots (e.g. the :term:`STAGING_DIR`
  1627. variable).
  1628. Recipes should never populate the sysroot directly (i.e. write files
  1629. into sysroot). Instead, files should be installed into standard
  1630. locations during the
  1631. :ref:`ref-tasks-install` task within
  1632. the ``${``\ :term:`D`\ ``}`` directory. The
  1633. reason for this limitation is that almost all files that populate the
  1634. sysroot are cataloged in manifests in order to ensure the files can be
  1635. removed later when a recipe is either modified or removed. Thus, the
  1636. sysroot is able to remain free from stale files.
  1637. A subset of the files installed by the :ref:`ref-tasks-install` task are
  1638. used by the :ref:`ref-tasks-populate_sysroot` task as defined by the the
  1639. :term:`SYSROOT_DIRS` variable to automatically populate the sysroot. It
  1640. is possible to modify the list of directories that populate the sysroot.
  1641. The following example shows how you could add the ``/opt`` directory to
  1642. the list of directories within a recipe::
  1643. SYSROOT_DIRS += "/opt"
  1644. .. note::
  1645. The `/sysroot-only` is to be used by recipes that generate artifacts
  1646. that are not included in the target filesystem, allowing them to share
  1647. these artifacts without needing to use the :term:`DEPLOY_DIR`.
  1648. For a more complete description of the :ref:`ref-tasks-populate_sysroot`
  1649. task and its associated functions, see the
  1650. :ref:`staging <ref-classes-staging>` class.
  1651. Using Virtual Providers
  1652. -----------------------
  1653. Prior to a build, if you know that several different recipes provide the
  1654. same functionality, you can use a virtual provider (i.e. ``virtual/*``)
  1655. as a placeholder for the actual provider. The actual provider is
  1656. determined at build-time.
  1657. A common scenario where a virtual provider is used would be for the
  1658. kernel recipe. Suppose you have three kernel recipes whose
  1659. :term:`PN` values map to ``kernel-big``,
  1660. ``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes
  1661. in some way uses a :term:`PROVIDES`
  1662. statement that essentially identifies itself as being able to provide
  1663. ``virtual/kernel``. Here is one way through the
  1664. :ref:`kernel <ref-classes-kernel>` class::
  1665. PROVIDES += "virtual/kernel"
  1666. Any recipe that inherits the :ref:`kernel <ref-classes-kernel>` class is
  1667. going to utilize a :term:`PROVIDES` statement that identifies that recipe as
  1668. being able to provide the ``virtual/kernel`` item.
  1669. Now comes the time to actually build an image and you need a kernel
  1670. recipe, but which one? You can configure your build to call out the
  1671. kernel recipe you want by using the :term:`PREFERRED_PROVIDER` variable. As
  1672. an example, consider the :yocto_git:`x86-base.inc
  1673. </poky/tree/meta/conf/machine/include/x86/x86-base.inc>` include file, which is a
  1674. machine (i.e. :term:`MACHINE`) configuration file. This include file is the
  1675. reason all x86-based machines use the ``linux-yocto`` kernel. Here are the
  1676. relevant lines from the include file::
  1677. PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
  1678. PREFERRED_VERSION_linux-yocto ??= "4.15%"
  1679. When you use a virtual provider, you do not have to "hard code" a recipe
  1680. name as a build dependency. You can use the
  1681. :term:`DEPENDS` variable to state the
  1682. build is dependent on ``virtual/kernel`` for example::
  1683. DEPENDS = "virtual/kernel"
  1684. During the build, the OpenEmbedded build system picks
  1685. the correct recipe needed for the ``virtual/kernel`` dependency based on
  1686. the :term:`PREFERRED_PROVIDER` variable. If you want to use the small kernel
  1687. mentioned at the beginning of this section, configure your build as
  1688. follows::
  1689. PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
  1690. .. note::
  1691. Any recipe that :term:`PROVIDES` a ``virtual/*`` item that is ultimately not
  1692. selected through :term:`PREFERRED_PROVIDER` does not get built. Preventing these
  1693. recipes from building is usually the desired behavior since this mechanism's
  1694. purpose is to select between mutually exclusive alternative providers.
  1695. The following lists specific examples of virtual providers:
  1696. - ``virtual/kernel``: Provides the name of the kernel recipe to use
  1697. when building a kernel image.
  1698. - ``virtual/bootloader``: Provides the name of the bootloader to use
  1699. when building an image.
  1700. - ``virtual/libgbm``: Provides ``gbm.pc``.
  1701. - ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``.
  1702. - ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL).
  1703. - ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM).
  1704. - ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2).
  1705. .. note::
  1706. Virtual providers only apply to build time dependencies specified with
  1707. :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime
  1708. dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`.
  1709. Properly Versioning Pre-Release Recipes
  1710. ---------------------------------------
  1711. Sometimes the name of a recipe can lead to versioning problems when the
  1712. recipe is upgraded to a final release. For example, consider the
  1713. ``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in
  1714. the ":ref:`dev-manual/common-tasks:storing and naming the recipe`" section.
  1715. This recipe is at a release candidate stage (i.e. "rc1"). When the recipe is
  1716. released, the recipe filename becomes ``irssi_0.8.16.bb``. The version
  1717. change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the
  1718. build system and package managers, so the resulting packages will not
  1719. correctly trigger an upgrade.
  1720. In order to ensure the versions compare properly, the recommended
  1721. convention is to set :term:`PV` within the
  1722. recipe to "previous_version+current_version". You can use an additional
  1723. variable so that you can use the current version elsewhere. Here is an
  1724. example::
  1725. REALPV = "0.8.16-rc1"
  1726. PV = "0.8.15+${REALPV}"
  1727. Post-Installation Scripts
  1728. -------------------------
  1729. Post-installation scripts run immediately after installing a package on
  1730. the target or during image creation when a package is included in an
  1731. image. To add a post-installation script to a package, add a
  1732. ``pkg_postinst:``\ `PACKAGENAME`\ ``()`` function to the recipe file
  1733. (``.bb``) and replace `PACKAGENAME` with the name of the package you want
  1734. to attach to the ``postinst`` script. To apply the post-installation
  1735. script to the main package for the recipe, which is usually what is
  1736. required, specify
  1737. ``${``\ :term:`PN`\ ``}`` in place of
  1738. PACKAGENAME.
  1739. A post-installation function has the following structure::
  1740. pkg_postinst:PACKAGENAME() {
  1741. # Commands to carry out
  1742. }
  1743. The script defined in the post-installation function is called when the
  1744. root filesystem is created. If the script succeeds, the package is
  1745. marked as installed.
  1746. .. note::
  1747. Any RPM post-installation script that runs on the target should
  1748. return a 0 exit code. RPM does not allow non-zero exit codes for
  1749. these scripts, and the RPM package manager will cause the package to
  1750. fail installation on the target.
  1751. Sometimes it is necessary for the execution of a post-installation
  1752. script to be delayed until the first boot. For example, the script might
  1753. need to be executed on the device itself. To delay script execution
  1754. until boot time, you must explicitly mark post installs to defer to the
  1755. target. You can use ``pkg_postinst_ontarget()`` or call
  1756. ``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any
  1757. failure of a ``pkg_postinst()`` script (including exit 1) triggers an
  1758. error during the
  1759. :ref:`ref-tasks-rootfs` task.
  1760. If you have recipes that use ``pkg_postinst`` function and they require
  1761. the use of non-standard native tools that have dependencies during
  1762. root filesystem construction, you need to use the
  1763. :term:`PACKAGE_WRITE_DEPS`
  1764. variable in your recipe to list these tools. If you do not use this
  1765. variable, the tools might be missing and execution of the
  1766. post-installation script is deferred until first boot. Deferring the
  1767. script to the first boot is undesirable and impossible for read-only
  1768. root filesystems.
  1769. .. note::
  1770. There is equivalent support for pre-install, pre-uninstall, and post-uninstall
  1771. scripts by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``,
  1772. respectively. These scrips work in exactly the same way as does
  1773. ``pkg_postinst`` with the exception that they run at different times. Also,
  1774. because of when they run, they are not applicable to being run at image
  1775. creation time like ``pkg_postinst``.
  1776. Testing
  1777. -------
  1778. The final step for completing your recipe is to be sure that the
  1779. software you built runs correctly. To accomplish runtime testing, add
  1780. the build's output packages to your image and test them on the target.
  1781. For information on how to customize your image by adding specific
  1782. packages, see ":ref:`dev-manual/common-tasks:customizing images`" section.
  1783. Examples
  1784. --------
  1785. To help summarize how to write a recipe, this section provides some
  1786. examples given various scenarios:
  1787. - Recipes that use local files
  1788. - Using an Autotooled package
  1789. - Using a Makefile-based package
  1790. - Splitting an application into multiple packages
  1791. - Adding binaries to an image
  1792. Single .c File Package (Hello World!)
  1793. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1794. Building an application from a single file that is stored locally (e.g.
  1795. under ``files``) requires a recipe that has the file listed in the
  1796. :term:`SRC_URI` variable. Additionally, you need to manually write the
  1797. ``do_compile`` and ``do_install`` tasks. The :term:`S` variable defines the
  1798. directory containing the source code, which is set to
  1799. :term:`WORKDIR` in this case - the
  1800. directory BitBake uses for the build.
  1801. ::
  1802. SUMMARY = "Simple helloworld application"
  1803. SECTION = "examples"
  1804. LICENSE = "MIT"
  1805. LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
  1806. SRC_URI = "file://helloworld.c"
  1807. S = "${WORKDIR}"
  1808. do_compile() {
  1809. ${CC} ${LDFLAGS} helloworld.c -o helloworld
  1810. }
  1811. do_install() {
  1812. install -d ${D}${bindir}
  1813. install -m 0755 helloworld ${D}${bindir}
  1814. }
  1815. By default, the ``helloworld``, ``helloworld-dbg``, and
  1816. ``helloworld-dev`` packages are built. For information on how to
  1817. customize the packaging process, see the
  1818. ":ref:`dev-manual/common-tasks:splitting an application into multiple packages`"
  1819. section.
  1820. Autotooled Package
  1821. ~~~~~~~~~~~~~~~~~~
  1822. Applications that use Autotools such as ``autoconf`` and ``automake``
  1823. require a recipe that has a source archive listed in :term:`SRC_URI` and
  1824. also inherit the
  1825. :ref:`autotools <ref-classes-autotools>` class,
  1826. which contains the definitions of all the steps needed to build an
  1827. Autotool-based application. The result of the build is automatically
  1828. packaged. And, if the application uses NLS for localization, packages
  1829. with local information are generated (one package per language).
  1830. Following is one example: (``hello_2.3.bb``)
  1831. ::
  1832. SUMMARY = "GNU Helloworld application"
  1833. SECTION = "examples"
  1834. LICENSE = "GPL-2.0-or-later"
  1835. LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
  1836. SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
  1837. inherit autotools gettext
  1838. The variable :term:`LIC_FILES_CHKSUM` is used to track source license
  1839. changes as described in the
  1840. ":ref:`dev-manual/common-tasks:tracking license changes`" section in
  1841. the Yocto Project Overview and Concepts Manual. You can quickly create
  1842. Autotool-based recipes in a manner similar to the previous example.
  1843. Makefile-Based Package
  1844. ~~~~~~~~~~~~~~~~~~~~~~
  1845. Applications that use GNU ``make`` also require a recipe that has the
  1846. source archive listed in :term:`SRC_URI`. You do not need to add a
  1847. ``do_compile`` step since by default BitBake starts the ``make`` command
  1848. to compile the application. If you need additional ``make`` options, you
  1849. should store them in the
  1850. :term:`EXTRA_OEMAKE` or
  1851. :term:`PACKAGECONFIG_CONFARGS`
  1852. variables. BitBake passes these options into the GNU ``make``
  1853. invocation. Note that a ``do_install`` task is still required.
  1854. Otherwise, BitBake runs an empty ``do_install`` task by default.
  1855. Some applications might require extra parameters to be passed to the
  1856. compiler. For example, the application might need an additional header
  1857. path. You can accomplish this by adding to the :term:`CFLAGS` variable. The
  1858. following example shows this::
  1859. CFLAGS:prepend = "-I ${S}/include "
  1860. In the following example, ``lz4`` is a makefile-based package::
  1861. SUMMARY = "Extremely Fast Compression algorithm"
  1862. DESCRIPTION = "LZ4 is a very fast lossless compression algorithm, providing compression speed at 400 MB/s per core, scalable with multi-cores CPU. It also features an extremely fast decoder, with speed in multiple GB/s per core, typically reaching RAM speed limits on multi-core systems."
  1863. HOMEPAGE = "https://github.com/lz4/lz4"
  1864. LICENSE = "BSD-2-Clause | GPL-2.0-only"
  1865. LIC_FILES_CHKSUM = "file://lib/LICENSE;md5=ebc2ea4814a64de7708f1571904b32cc \
  1866. file://programs/COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \
  1867. file://LICENSE;md5=d57c0d21cb917fb4e0af2454aa48b956 \
  1868. "
  1869. PE = "1"
  1870. SRCREV = "d44371841a2f1728a3f36839fd4b7e872d0927d3"
  1871. SRC_URI = "git://github.com/lz4/lz4.git;branch=release;protocol=https \
  1872. file://CVE-2021-3520.patch \
  1873. "
  1874. UPSTREAM_CHECK_GITTAGREGEX = "v(?P<pver>.*)"
  1875. S = "${WORKDIR}/git"
  1876. # Fixed in r118, which is larger than the current version.
  1877. CVE_CHECK_IGNORE += "CVE-2014-4715"
  1878. EXTRA_OEMAKE = "PREFIX=${prefix} CC='${CC}' CFLAGS='${CFLAGS}' DESTDIR=${D} LIBDIR=${libdir} INCLUDEDIR=${includedir} BUILD_STATIC=no"
  1879. do_install() {
  1880. oe_runmake install
  1881. }
  1882. BBCLASSEXTEND = "native nativesdk"
  1883. Splitting an Application into Multiple Packages
  1884. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1885. You can use the variables :term:`PACKAGES` and :term:`FILES` to split an
  1886. application into multiple packages.
  1887. Following is an example that uses the ``libxpm`` recipe. By default,
  1888. this recipe generates a single package that contains the library along
  1889. with a few binaries. You can modify the recipe to split the binaries
  1890. into separate packages::
  1891. require xorg-lib-common.inc
  1892. SUMMARY = "Xpm: X Pixmap extension library"
  1893. LICENSE = "MIT"
  1894. LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
  1895. DEPENDS += "libxext libsm libxt"
  1896. PE = "1"
  1897. XORG_PN = "libXpm"
  1898. PACKAGES =+ "sxpm cxpm"
  1899. FILES:cxpm = "${bindir}/cxpm"
  1900. FILES:sxpm = "${bindir}/sxpm"
  1901. In the previous example, we want to ship the ``sxpm`` and ``cxpm``
  1902. binaries in separate packages. Since ``bindir`` would be packaged into
  1903. the main :term:`PN` package by default, we prepend the :term:`PACKAGES` variable
  1904. so additional package names are added to the start of list. This results
  1905. in the extra ``FILES:*`` variables then containing information that
  1906. define which files and directories go into which packages. Files
  1907. included by earlier packages are skipped by latter packages. Thus, the
  1908. main :term:`PN` package does not include the above listed files.
  1909. Packaging Externally Produced Binaries
  1910. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1911. Sometimes, you need to add pre-compiled binaries to an image. For
  1912. example, suppose that there are binaries for proprietary code,
  1913. created by a particular division of a company. Your part of the company
  1914. needs to use those binaries as part of an image that you are building
  1915. using the OpenEmbedded build system. Since you only have the binaries
  1916. and not the source code, you cannot use a typical recipe that expects to
  1917. fetch the source specified in
  1918. :term:`SRC_URI` and then compile it.
  1919. One method is to package the binaries and then install them as part of
  1920. the image. Generally, it is not a good idea to package binaries since,
  1921. among other things, it can hinder the ability to reproduce builds and
  1922. could lead to compatibility problems with ABI in the future. However,
  1923. sometimes you have no choice.
  1924. The easiest solution is to create a recipe that uses the
  1925. :ref:`bin_package <ref-classes-bin-package>` class
  1926. and to be sure that you are using default locations for build artifacts.
  1927. In most cases, the :ref:`bin_package <ref-classes-bin-package>` class handles "skipping" the
  1928. configure and compile steps as well as sets things up to grab packages
  1929. from the appropriate area. In particular, this class sets ``noexec`` on
  1930. both the :ref:`ref-tasks-configure`
  1931. and :ref:`ref-tasks-compile` tasks,
  1932. sets ``FILES:${PN}`` to "/" so that it picks up all files, and sets up a
  1933. :ref:`ref-tasks-install` task, which
  1934. effectively copies all files from ``${S}`` to ``${D}``. The
  1935. :ref:`bin_package <ref-classes-bin-package>` class works well when the files extracted into ``${S}``
  1936. are already laid out in the way they should be laid out on the target.
  1937. For more information on these variables, see the
  1938. :term:`FILES`,
  1939. :term:`PN`,
  1940. :term:`S`, and
  1941. :term:`D` variables in the Yocto Project
  1942. Reference Manual's variable glossary.
  1943. .. note::
  1944. - Using :term:`DEPENDS` is a good
  1945. idea even for components distributed in binary form, and is often
  1946. necessary for shared libraries. For a shared library, listing the
  1947. library dependencies in :term:`DEPENDS` makes sure that the libraries
  1948. are available in the staging sysroot when other recipes link
  1949. against the library, which might be necessary for successful
  1950. linking.
  1951. - Using :term:`DEPENDS` also allows runtime dependencies between
  1952. packages to be added automatically. See the
  1953. ":ref:`overview-manual/concepts:automatically added runtime dependencies`"
  1954. section in the Yocto Project Overview and Concepts Manual for more
  1955. information.
  1956. If you cannot use the :ref:`bin_package <ref-classes-bin-package>` class, you need to be sure you are
  1957. doing the following:
  1958. - Create a recipe where the
  1959. :ref:`ref-tasks-configure` and
  1960. :ref:`ref-tasks-compile` tasks do
  1961. nothing: It is usually sufficient to just not define these tasks in
  1962. the recipe, because the default implementations do nothing unless a
  1963. Makefile is found in
  1964. ``${``\ :term:`S`\ ``}``.
  1965. If ``${S}`` might contain a Makefile, or if you inherit some class
  1966. that replaces ``do_configure`` and ``do_compile`` with custom
  1967. versions, then you can use the
  1968. ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]``
  1969. flag to turn the tasks into no-ops, as follows::
  1970. do_configure[noexec] = "1"
  1971. do_compile[noexec] = "1"
  1972. Unlike
  1973. :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`,
  1974. using the flag preserves the dependency chain from the
  1975. :ref:`ref-tasks-fetch`,
  1976. :ref:`ref-tasks-unpack`, and
  1977. :ref:`ref-tasks-patch` tasks to the
  1978. :ref:`ref-tasks-install` task.
  1979. - Make sure your ``do_install`` task installs the binaries
  1980. appropriately.
  1981. - Ensure that you set up :term:`FILES`
  1982. (usually
  1983. ``FILES:${``\ :term:`PN`\ ``}``) to
  1984. point to the files you have installed, which of course depends on
  1985. where you have installed them and whether those files are in
  1986. different locations than the defaults.
  1987. Following Recipe Style Guidelines
  1988. ---------------------------------
  1989. When writing recipes, it is good to conform to existing style
  1990. guidelines. The :oe_wiki:`OpenEmbedded Styleguide </Styleguide>` wiki page
  1991. provides rough guidelines for preferred recipe style.
  1992. It is common for existing recipes to deviate a bit from this style.
  1993. However, aiming for at least a consistent style is a good idea. Some
  1994. practices, such as omitting spaces around ``=`` operators in assignments
  1995. or ordering recipe components in an erratic way, are widely seen as poor
  1996. style.
  1997. Recipe Syntax
  1998. -------------
  1999. Understanding recipe file syntax is important for writing recipes. The
  2000. following list overviews the basic items that make up a BitBake recipe
  2001. file. For more complete BitBake syntax descriptions, see the
  2002. ":doc:`bitbake-user-manual/bitbake-user-manual-metadata`"
  2003. chapter of the BitBake User Manual.
  2004. - *Variable Assignments and Manipulations:* Variable assignments allow
  2005. a value to be assigned to a variable. The assignment can be static
  2006. text or might include the contents of other variables. In addition to
  2007. the assignment, appending and prepending operations are also
  2008. supported.
  2009. The following example shows some of the ways you can use variables in
  2010. recipes::
  2011. S = "${WORKDIR}/postfix-${PV}"
  2012. CFLAGS += "-DNO_ASM"
  2013. SRC_URI:append = " file://fixup.patch"
  2014. - *Functions:* Functions provide a series of actions to be performed.
  2015. You usually use functions to override the default implementation of a
  2016. task function or to complement a default function (i.e. append or
  2017. prepend to an existing function). Standard functions use ``sh`` shell
  2018. syntax, although access to OpenEmbedded variables and internal
  2019. methods are also available.
  2020. Here is an example function from the ``sed`` recipe::
  2021. do_install () {
  2022. autotools_do_install
  2023. install -d ${D}${base_bindir}
  2024. mv ${D}${bindir}/sed ${D}${base_bindir}/sed
  2025. rmdir ${D}${bindir}/
  2026. }
  2027. It is
  2028. also possible to implement new functions that are called between
  2029. existing tasks as long as the new functions are not replacing or
  2030. complementing the default functions. You can implement functions in
  2031. Python instead of shell. Both of these options are not seen in the
  2032. majority of recipes.
  2033. - *Keywords:* BitBake recipes use only a few keywords. You use keywords
  2034. to include common functions (``inherit``), load parts of a recipe
  2035. from other files (``include`` and ``require``) and export variables
  2036. to the environment (``export``).
  2037. The following example shows the use of some of these keywords::
  2038. export POSTCONF = "${STAGING_BINDIR}/postconf"
  2039. inherit autoconf
  2040. require otherfile.inc
  2041. - *Comments (#):* Any lines that begin with the hash character (``#``)
  2042. are treated as comment lines and are ignored::
  2043. # This is a comment
  2044. This next list summarizes the most important and most commonly used
  2045. parts of the recipe syntax. For more information on these parts of the
  2046. syntax, you can reference the
  2047. :doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata` chapter
  2048. in the BitBake User Manual.
  2049. - *Line Continuation (\\):* Use the backward slash (``\``) character to
  2050. split a statement over multiple lines. Place the slash character at
  2051. the end of the line that is to be continued on the next line::
  2052. VAR = "A really long \
  2053. line"
  2054. .. note::
  2055. You cannot have any characters including spaces or tabs after the
  2056. slash character.
  2057. - *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to
  2058. access the contents of a variable::
  2059. SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
  2060. .. note::
  2061. It is important to understand that the value of a variable
  2062. expressed in this form does not get substituted automatically. The
  2063. expansion of these expressions happens on-demand later (e.g.
  2064. usually when a function that makes reference to the variable
  2065. executes). This behavior ensures that the values are most
  2066. appropriate for the context in which they are finally used. On the
  2067. rare occasion that you do need the variable expression to be
  2068. expanded immediately, you can use the
  2069. :=
  2070. operator instead of
  2071. =
  2072. when you make the assignment, but this is not generally needed.
  2073. - *Quote All Assignments ("value"):* Use double quotes around values in
  2074. all variable assignments (e.g. ``"value"``). Following is an example::
  2075. VAR1 = "${OTHERVAR}"
  2076. VAR2 = "The version is ${PV}"
  2077. - *Conditional Assignment (?=):* Conditional assignment is used to
  2078. assign a value to a variable, but only when the variable is currently
  2079. unset. Use the question mark followed by the equal sign (``?=``) to
  2080. make a "soft" assignment used for conditional assignment. Typically,
  2081. "soft" assignments are used in the ``local.conf`` file for variables
  2082. that are allowed to come through from the external environment.
  2083. Here is an example where ``VAR1`` is set to "New value" if it is
  2084. currently empty. However, if ``VAR1`` has already been set, it
  2085. remains unchanged::
  2086. VAR1 ?= "New value"
  2087. In this next example, ``VAR1`` is left with the value "Original value"::
  2088. VAR1 = "Original value"
  2089. VAR1 ?= "New value"
  2090. - *Appending (+=):* Use the plus character followed by the equals sign
  2091. (``+=``) to append values to existing variables.
  2092. .. note::
  2093. This operator adds a space between the existing content of the
  2094. variable and the new content.
  2095. Here is an example::
  2096. SRC_URI += "file://fix-makefile.patch"
  2097. - *Prepending (=+):* Use the equals sign followed by the plus character
  2098. (``=+``) to prepend values to existing variables.
  2099. .. note::
  2100. This operator adds a space between the new content and the
  2101. existing content of the variable.
  2102. Here is an example::
  2103. VAR =+ "Starts"
  2104. - *Appending (:append):* Use the ``:append`` operator to append values
  2105. to existing variables. This operator does not add any additional
  2106. space. Also, the operator is applied after all the ``+=``, and ``=+``
  2107. operators have been applied and after all ``=`` assignments have
  2108. occurred.
  2109. The following example shows the space being explicitly added to the
  2110. start to ensure the appended value is not merged with the existing
  2111. value::
  2112. SRC_URI:append = " file://fix-makefile.patch"
  2113. You can also use
  2114. the ``:append`` operator with overrides, which results in the actions
  2115. only being performed for the specified target or machine::
  2116. SRC_URI:append:sh4 = " file://fix-makefile.patch"
  2117. - *Prepending (:prepend):* Use the ``:prepend`` operator to prepend
  2118. values to existing variables. This operator does not add any
  2119. additional space. Also, the operator is applied after all the ``+=``,
  2120. and ``=+`` operators have been applied and after all ``=``
  2121. assignments have occurred.
  2122. The following example shows the space being explicitly added to the
  2123. end to ensure the prepended value is not merged with the existing
  2124. value::
  2125. CFLAGS:prepend = "-I${S}/myincludes "
  2126. You can also use the
  2127. ``:prepend`` operator with overrides, which results in the actions
  2128. only being performed for the specified target or machine::
  2129. CFLAGS:prepend:sh4 = "-I${S}/myincludes "
  2130. - *Overrides:* You can use overrides to set a value conditionally,
  2131. typically based on how the recipe is being built. For example, to set
  2132. the :term:`KBRANCH` variable's
  2133. value to "standard/base" for any target
  2134. :term:`MACHINE`, except for
  2135. qemuarm where it should be set to "standard/arm-versatile-926ejs",
  2136. you would do the following::
  2137. KBRANCH = "standard/base"
  2138. KBRANCH:qemuarm = "standard/arm-versatile-926ejs"
  2139. Overrides are also used to separate
  2140. alternate values of a variable in other situations. For example, when
  2141. setting variables such as
  2142. :term:`FILES` and
  2143. :term:`RDEPENDS` that are
  2144. specific to individual packages produced by a recipe, you should
  2145. always use an override that specifies the name of the package.
  2146. - *Indentation:* Use spaces for indentation rather than tabs. For
  2147. shell functions, both currently work. However, it is a policy
  2148. decision of the Yocto Project to use tabs in shell functions. Realize
  2149. that some layers have a policy to use spaces for all indentation.
  2150. - *Using Python for Complex Operations:* For more advanced processing,
  2151. it is possible to use Python code during variable assignments (e.g.
  2152. search and replacement on a variable).
  2153. You indicate Python code using the ``${@python_code}`` syntax for the
  2154. variable assignment::
  2155. SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
  2156. - *Shell Function Syntax:* Write shell functions as if you were writing
  2157. a shell script when you describe a list of actions to take. You
  2158. should ensure that your script works with a generic ``sh`` and that
  2159. it does not require any ``bash`` or other shell-specific
  2160. functionality. The same considerations apply to various system
  2161. utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you
  2162. might wish to use. If in doubt, you should check with multiple
  2163. implementations - including those from BusyBox.
  2164. Adding a New Machine
  2165. ====================
  2166. Adding a new machine to the Yocto Project is a straightforward process.
  2167. This section describes how to add machines that are similar to those
  2168. that the Yocto Project already supports.
  2169. .. note::
  2170. Although well within the capabilities of the Yocto Project, adding a
  2171. totally new architecture might require changes to ``gcc``/``glibc``
  2172. and to the site information, which is beyond the scope of this
  2173. manual.
  2174. For a complete example that shows how to add a new machine, see the
  2175. ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
  2176. section in the Yocto Project Board Support Package (BSP) Developer's
  2177. Guide.
  2178. Adding the Machine Configuration File
  2179. -------------------------------------
  2180. To add a new machine, you need to add a new machine configuration file
  2181. to the layer's ``conf/machine`` directory. This configuration file
  2182. provides details about the device you are adding.
  2183. The OpenEmbedded build system uses the root name of the machine
  2184. configuration file to reference the new machine. For example, given a
  2185. machine configuration file named ``crownbay.conf``, the build system
  2186. recognizes the machine as "crownbay".
  2187. The most important variables you must set in your machine configuration
  2188. file or include from a lower-level configuration file are as follows:
  2189. - :term:`TARGET_ARCH` (e.g. "arm")
  2190. - ``PREFERRED_PROVIDER_virtual/kernel``
  2191. - :term:`MACHINE_FEATURES` (e.g. "apm screen wifi")
  2192. You might also need these variables:
  2193. - :term:`SERIAL_CONSOLES` (e.g. "115200;ttyS0 115200;ttyS1")
  2194. - :term:`KERNEL_IMAGETYPE` (e.g. "zImage")
  2195. - :term:`IMAGE_FSTYPES` (e.g. "tar.gz jffs2")
  2196. You can find full details on these variables in the reference section.
  2197. You can leverage existing machine ``.conf`` files from
  2198. ``meta-yocto-bsp/conf/machine/``.
  2199. Adding a Kernel for the Machine
  2200. -------------------------------
  2201. The OpenEmbedded build system needs to be able to build a kernel for the
  2202. machine. You need to either create a new kernel recipe for this machine,
  2203. or extend an existing kernel recipe. You can find several kernel recipe
  2204. examples in the Source Directory at ``meta/recipes-kernel/linux`` that
  2205. you can use as references.
  2206. If you are creating a new kernel recipe, normal recipe-writing rules
  2207. apply for setting up a :term:`SRC_URI`. Thus, you need to specify any
  2208. necessary patches and set :term:`S` to point at the source code. You need to
  2209. create a ``do_configure`` task that configures the unpacked kernel with
  2210. a ``defconfig`` file. You can do this by using a ``make defconfig``
  2211. command or, more commonly, by copying in a suitable ``defconfig`` file
  2212. and then running ``make oldconfig``. By making use of ``inherit kernel``
  2213. and potentially some of the ``linux-*.inc`` files, most other
  2214. functionality is centralized and the defaults of the class normally work
  2215. well.
  2216. If you are extending an existing kernel recipe, it is usually a matter
  2217. of adding a suitable ``defconfig`` file. The file needs to be added into
  2218. a location similar to ``defconfig`` files used for other machines in a
  2219. given kernel recipe. A possible way to do this is by listing the file in
  2220. the :term:`SRC_URI` and adding the machine to the expression in
  2221. :term:`COMPATIBLE_MACHINE`::
  2222. COMPATIBLE_MACHINE = '(qemux86|qemumips)'
  2223. For more information on ``defconfig`` files, see the
  2224. ":ref:`kernel-dev/common:changing the configuration`"
  2225. section in the Yocto Project Linux Kernel Development Manual.
  2226. Adding a Formfactor Configuration File
  2227. --------------------------------------
  2228. A formfactor configuration file provides information about the target
  2229. hardware for which the image is being built and information that the
  2230. build system cannot obtain from other sources such as the kernel. Some
  2231. examples of information contained in a formfactor configuration file
  2232. include framebuffer orientation, whether or not the system has a
  2233. keyboard, the positioning of the keyboard in relation to the screen, and
  2234. the screen resolution.
  2235. The build system uses reasonable defaults in most cases. However, if
  2236. customization is necessary, you need to create a ``machconfig`` file in
  2237. the ``meta/recipes-bsp/formfactor/files`` directory. This directory
  2238. contains directories for specific machines such as ``qemuarm`` and
  2239. ``qemux86``. For information about the settings available and the
  2240. defaults, see the ``meta/recipes-bsp/formfactor/files/config`` file
  2241. found in the same area.
  2242. Following is an example for "qemuarm" machine::
  2243. HAVE_TOUCHSCREEN=1
  2244. HAVE_KEYBOARD=1
  2245. DISPLAY_CAN_ROTATE=0
  2246. DISPLAY_ORIENTATION=0
  2247. #DISPLAY_WIDTH_PIXELS=640
  2248. #DISPLAY_HEIGHT_PIXELS=480
  2249. #DISPLAY_BPP=16
  2250. DISPLAY_DPI=150
  2251. DISPLAY_SUBPIXEL_ORDER=vrgb
  2252. Upgrading Recipes
  2253. =================
  2254. Over time, upstream developers publish new versions for software built
  2255. by layer recipes. It is recommended to keep recipes up-to-date with
  2256. upstream version releases.
  2257. While there are several methods to upgrade a recipe, you might
  2258. consider checking on the upgrade status of a recipe first. You can do so
  2259. using the ``devtool check-upgrade-status`` command. See the
  2260. ":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`"
  2261. section in the Yocto Project Reference Manual for more information.
  2262. The remainder of this section describes three ways you can upgrade a
  2263. recipe. You can use the Automated Upgrade Helper (AUH) to set up
  2264. automatic version upgrades. Alternatively, you can use
  2265. ``devtool upgrade`` to set up semi-automatic version upgrades. Finally,
  2266. you can manually upgrade a recipe by editing the recipe itself.
  2267. Using the Auto Upgrade Helper (AUH)
  2268. -----------------------------------
  2269. The AUH utility works in conjunction with the OpenEmbedded build system
  2270. in order to automatically generate upgrades for recipes based on new
  2271. versions being published upstream. Use AUH when you want to create a
  2272. service that performs the upgrades automatically and optionally sends
  2273. you an email with the results.
  2274. AUH allows you to update several recipes with a single use. You can also
  2275. optionally perform build and integration tests using images with the
  2276. results saved to your hard drive and emails of results optionally sent
  2277. to recipe maintainers. Finally, AUH creates Git commits with appropriate
  2278. commit messages in the layer's tree for the changes made to recipes.
  2279. .. note::
  2280. In some conditions, you should not use AUH to upgrade recipes
  2281. and should instead use either ``devtool upgrade`` or upgrade your
  2282. recipes manually:
  2283. - When AUH cannot complete the upgrade sequence. This situation
  2284. usually results because custom patches carried by the recipe
  2285. cannot be automatically rebased to the new version. In this case,
  2286. ``devtool upgrade`` allows you to manually resolve conflicts.
  2287. - When for any reason you want fuller control over the upgrade
  2288. process. For example, when you want special arrangements for
  2289. testing.
  2290. The following steps describe how to set up the AUH utility:
  2291. 1. *Be Sure the Development Host is Set Up:* You need to be sure that
  2292. your development host is set up to use the Yocto Project. For
  2293. information on how to set up your host, see the
  2294. ":ref:`dev-manual/start:Preparing the Build Host`" section.
  2295. 2. *Make Sure Git is Configured:* The AUH utility requires Git to be
  2296. configured because AUH uses Git to save upgrades. Thus, you must have
  2297. Git user and email configured. The following command shows your
  2298. configurations::
  2299. $ git config --list
  2300. If you do not have the user and
  2301. email configured, you can use the following commands to do so::
  2302. $ git config --global user.name some_name
  2303. $ git config --global user.email username@domain.com
  2304. 3. *Clone the AUH Repository:* To use AUH, you must clone the repository
  2305. onto your development host. The following command uses Git to create
  2306. a local copy of the repository on your system::
  2307. $ git clone git://git.yoctoproject.org/auto-upgrade-helper
  2308. Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done.
  2309. remote: Compressing objects: 100% (300/300), done.
  2310. remote: Total 768 (delta 499), reused 703 (delta 434)
  2311. Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
  2312. Resolving deltas: 100% (499/499), done.
  2313. Checking connectivity... done.
  2314. AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or
  2315. :term:`Poky` repositories.
  2316. 4. *Create a Dedicated Build Directory:* Run the
  2317. :ref:`structure-core-script`
  2318. script to create a fresh build directory that you use exclusively for
  2319. running the AUH utility::
  2320. $ cd poky
  2321. $ source oe-init-build-env your_AUH_build_directory
  2322. Re-using an existing build directory and its configurations is not
  2323. recommended as existing settings could cause AUH to fail or behave
  2324. undesirably.
  2325. 5. *Make Configurations in Your Local Configuration File:* Several
  2326. settings are needed in the ``local.conf`` file in the build
  2327. directory you just created for AUH. Make these following
  2328. configurations:
  2329. - If you want to enable :ref:`Build
  2330. History <dev-manual/common-tasks:maintaining build output quality>`,
  2331. which is optional, you need the following lines in the
  2332. ``conf/local.conf`` file::
  2333. INHERIT =+ "buildhistory"
  2334. BUILDHISTORY_COMMIT = "1"
  2335. With this configuration and a successful
  2336. upgrade, a build history "diff" file appears in the
  2337. ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in
  2338. your build directory.
  2339. - If you want to enable testing through the
  2340. :ref:`testimage <ref-classes-testimage*>`
  2341. class, which is optional, you need to have the following set in
  2342. your ``conf/local.conf`` file::
  2343. INHERIT += "testimage"
  2344. .. note::
  2345. If your distro does not enable by default ptest, which Poky
  2346. does, you need the following in your ``local.conf`` file::
  2347. DISTRO_FEATURES:append = " ptest"
  2348. 6. *Optionally Start a vncserver:* If you are running in a server
  2349. without an X11 session, you need to start a vncserver::
  2350. $ vncserver :1
  2351. $ export DISPLAY=:1
  2352. 7. *Create and Edit an AUH Configuration File:* You need to have the
  2353. ``upgrade-helper/upgrade-helper.conf`` configuration file in your
  2354. build directory. You can find a sample configuration file in the
  2355. :yocto_git:`AUH source repository </auto-upgrade-helper/tree/>`.
  2356. Read through the sample file and make configurations as needed. For
  2357. example, if you enabled build history in your ``local.conf`` as
  2358. described earlier, you must enable it in ``upgrade-helper.conf``.
  2359. Also, if you are using the default ``maintainers.inc`` file supplied
  2360. with Poky and located in ``meta-yocto`` and you do not set a
  2361. "maintainers_whitelist" or "global_maintainer_override" in the
  2362. ``upgrade-helper.conf`` configuration, and you specify "-e all" on
  2363. the AUH command-line, the utility automatically sends out emails to
  2364. all the default maintainers. Please avoid this.
  2365. This next set of examples describes how to use the AUH:
  2366. - *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the
  2367. following form::
  2368. $ upgrade-helper.py recipe_name
  2369. For example, this command upgrades the ``xmodmap`` recipe::
  2370. $ upgrade-helper.py xmodmap
  2371. - *Upgrading a Specific Recipe to a Particular Version:* To upgrade a
  2372. specific recipe to a particular version, use the following form::
  2373. $ upgrade-helper.py recipe_name -t version
  2374. For example, this command upgrades the ``xmodmap`` recipe to version 1.2.3::
  2375. $ upgrade-helper.py xmodmap -t 1.2.3
  2376. - *Upgrading all Recipes to the Latest Versions and Suppressing Email
  2377. Notifications:* To upgrade all recipes to their most recent versions
  2378. and suppress the email notifications, use the following command::
  2379. $ upgrade-helper.py all
  2380. - *Upgrading all Recipes to the Latest Versions and Send Email
  2381. Notifications:* To upgrade all recipes to their most recent versions
  2382. and send email messages to maintainers for each attempted recipe as
  2383. well as a status email, use the following command::
  2384. $ upgrade-helper.py -e all
  2385. Once you have run the AUH utility, you can find the results in the AUH
  2386. build directory::
  2387. ${BUILDDIR}/upgrade-helper/timestamp
  2388. The AUH utility
  2389. also creates recipe update commits from successful upgrade attempts in
  2390. the layer tree.
  2391. You can easily set up to run the AUH utility on a regular basis by using
  2392. a cron job. See the
  2393. :yocto_git:`weeklyjob.sh </auto-upgrade-helper/tree/weeklyjob.sh>`
  2394. file distributed with the utility for an example.
  2395. Using ``devtool upgrade``
  2396. -------------------------
  2397. As mentioned earlier, an alternative method for upgrading recipes to
  2398. newer versions is to use
  2399. :doc:`devtool upgrade </ref-manual/devtool-reference>`.
  2400. You can read about ``devtool upgrade`` in general in the
  2401. ":ref:`sdk-manual/extensible:use \`\`devtool upgrade\`\` to create a version of the recipe that supports a newer version of the software`"
  2402. section in the Yocto Project Application Development and the Extensible
  2403. Software Development Kit (eSDK) Manual.
  2404. To see all the command-line options available with ``devtool upgrade``,
  2405. use the following help command::
  2406. $ devtool upgrade -h
  2407. If you want to find out what version a recipe is currently at upstream
  2408. without any attempt to upgrade your local version of the recipe, you can
  2409. use the following command::
  2410. $ devtool latest-version recipe_name
  2411. As mentioned in the previous section describing AUH, ``devtool upgrade``
  2412. works in a less-automated manner than AUH. Specifically,
  2413. ``devtool upgrade`` only works on a single recipe that you name on the
  2414. command line, cannot perform build and integration testing using images,
  2415. and does not automatically generate commits for changes in the source
  2416. tree. Despite all these "limitations", ``devtool upgrade`` updates the
  2417. recipe file to the new upstream version and attempts to rebase custom
  2418. patches contained by the recipe as needed.
  2419. .. note::
  2420. AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat
  2421. of a "wrapper" application for ``devtool upgrade``.
  2422. A typical scenario involves having used Git to clone an upstream
  2423. repository that you use during build operations. Because you have built the
  2424. recipe in the past, the layer is likely added to your
  2425. configuration already. If for some reason, the layer is not added, you
  2426. could add it easily using the
  2427. ":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`"
  2428. script. For example, suppose you use the ``nano.bb`` recipe from the
  2429. ``meta-oe`` layer in the ``meta-openembedded`` repository. For this
  2430. example, assume that the layer has been cloned into following area::
  2431. /home/scottrif/meta-openembedded
  2432. The following command from your
  2433. :term:`Build Directory` adds the layer to
  2434. your build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``)::
  2435. $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
  2436. NOTE: Starting bitbake server...
  2437. Parsing recipes: 100% |##########################################| Time: 0:00:55
  2438. Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
  2439. Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
  2440. Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
  2441. Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
  2442. Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
  2443. For this example, assume that the ``nano.bb`` recipe that
  2444. is upstream has a 2.9.3 version number. However, the version in the
  2445. local repository is 2.7.4. The following command from your build
  2446. directory automatically upgrades the recipe for you:
  2447. .. note::
  2448. Using the ``-V`` option is not necessary. Omitting the version number causes
  2449. ``devtool upgrade`` to upgrade the recipe to the most recent version.
  2450. ::
  2451. $ devtool upgrade nano -V 2.9.3
  2452. NOTE: Starting bitbake server...
  2453. NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
  2454. Parsing recipes: 100% |##########################################| Time: 0:00:46
  2455. Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
  2456. NOTE: Extracting current version source...
  2457. NOTE: Resolving any missing task queue dependencies
  2458. .
  2459. .
  2460. .
  2461. NOTE: Executing SetScene Tasks
  2462. NOTE: Executing RunQueue Tasks
  2463. NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
  2464. Adding changed files: 100% |#####################################| Time: 0:00:00
  2465. NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
  2466. NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
  2467. Continuing with this example, you can use ``devtool build`` to build the
  2468. newly upgraded recipe::
  2469. $ devtool build nano
  2470. NOTE: Starting bitbake server...
  2471. Loading cache: 100% |################################################################################################| Time: 0:00:01
  2472. Loaded 2040 entries from dependency cache.
  2473. Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
  2474. Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
  2475. NOTE: Resolving any missing task queue dependencies
  2476. .
  2477. .
  2478. .
  2479. NOTE: Executing SetScene Tasks
  2480. NOTE: Executing RunQueue Tasks
  2481. NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
  2482. NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
  2483. Within the ``devtool upgrade`` workflow, you can
  2484. deploy and test your rebuilt software. For this example,
  2485. however, running ``devtool finish`` cleans up the workspace once the
  2486. source in your workspace is clean. This usually means using Git to stage
  2487. and submit commits for the changes generated by the upgrade process.
  2488. Once the tree is clean, you can clean things up in this example with the
  2489. following command from the ``${BUILDDIR}/workspace/sources/nano``
  2490. directory::
  2491. $ devtool finish nano meta-oe
  2492. NOTE: Starting bitbake server...
  2493. Loading cache: 100% |################################################################################################| Time: 0:00:00
  2494. Loaded 2040 entries from dependency cache.
  2495. Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
  2496. Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
  2497. NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
  2498. NOTE: Updating recipe nano_2.9.3.bb
  2499. NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
  2500. NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
  2501. NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
  2502. Using the ``devtool finish`` command cleans up the workspace and creates a patch
  2503. file based on your commits. The tool puts all patch files back into the
  2504. source directory in a sub-directory named ``nano`` in this case.
  2505. Manually Upgrading a Recipe
  2506. ---------------------------
  2507. If for some reason you choose not to upgrade recipes using
  2508. :ref:`dev-manual/common-tasks:Using the Auto Upgrade Helper (AUH)` or
  2509. by :ref:`dev-manual/common-tasks:Using \`\`devtool upgrade\`\``,
  2510. you can manually edit the recipe files to upgrade the versions.
  2511. .. note::
  2512. Manually updating multiple recipes scales poorly and involves many
  2513. steps. The recommendation to upgrade recipe versions is through AUH
  2514. or ``devtool upgrade``, both of which automate some steps and provide
  2515. guidance for others needed for the manual process.
  2516. To manually upgrade recipe versions, follow these general steps:
  2517. 1. *Change the Version:* Rename the recipe such that the version (i.e.
  2518. the :term:`PV` part of the recipe name)
  2519. changes appropriately. If the version is not part of the recipe name,
  2520. change the value as it is set for :term:`PV` within the recipe itself.
  2521. 2. *Update* :term:`SRCREV` *if Needed*: If the source code your recipe builds
  2522. is fetched from Git or some other version control system, update
  2523. :term:`SRCREV` to point to the
  2524. commit hash that matches the new version.
  2525. 3. *Build the Software:* Try to build the recipe using BitBake. Typical
  2526. build failures include the following:
  2527. - License statements were updated for the new version. For this
  2528. case, you need to review any changes to the license and update the
  2529. values of :term:`LICENSE` and
  2530. :term:`LIC_FILES_CHKSUM`
  2531. as needed.
  2532. .. note::
  2533. License changes are often inconsequential. For example, the
  2534. license text's copyright year might have changed.
  2535. - Custom patches carried by the older version of the recipe might
  2536. fail to apply to the new version. For these cases, you need to
  2537. review the failures. Patches might not be necessary for the new
  2538. version of the software if the upgraded version has fixed those
  2539. issues. If a patch is necessary and failing, you need to rebase it
  2540. into the new version.
  2541. 4. *Optionally Attempt to Build for Several Architectures:* Once you
  2542. successfully build the new software for a given architecture, you
  2543. could test the build for other architectures by changing the
  2544. :term:`MACHINE` variable and
  2545. rebuilding the software. This optional step is especially important
  2546. if the recipe is to be released publicly.
  2547. 5. *Check the Upstream Change Log or Release Notes:* Checking both these
  2548. reveals if there are new features that could break
  2549. backwards-compatibility. If so, you need to take steps to mitigate or
  2550. eliminate that situation.
  2551. 6. *Optionally Create a Bootable Image and Test:* If you want, you can
  2552. test the new software by booting it onto actual hardware.
  2553. 7. *Create a Commit with the Change in the Layer Repository:* After all
  2554. builds work and any testing is successful, you can create commits for
  2555. any changes in the layer holding your upgraded recipe.
  2556. Finding Temporary Source Code
  2557. =============================
  2558. You might find it helpful during development to modify the temporary
  2559. source code used by recipes to build packages. For example, suppose you
  2560. are developing a patch and you need to experiment a bit to figure out
  2561. your solution. After you have initially built the package, you can
  2562. iteratively tweak the source code, which is located in the
  2563. :term:`Build Directory`, and then you can
  2564. force a re-compile and quickly test your altered code. Once you settle
  2565. on a solution, you can then preserve your changes in the form of
  2566. patches.
  2567. During a build, the unpacked temporary source code used by recipes to
  2568. build packages is available in the Build Directory as defined by the
  2569. :term:`S` variable. Below is the default
  2570. value for the :term:`S` variable as defined in the
  2571. ``meta/conf/bitbake.conf`` configuration file in the
  2572. :term:`Source Directory`::
  2573. S = "${WORKDIR}/${BP}"
  2574. You should be aware that many recipes override the
  2575. :term:`S` variable. For example, recipes that fetch their source from Git
  2576. usually set :term:`S` to ``${WORKDIR}/git``.
  2577. .. note::
  2578. The :term:`BP` represents the base recipe name, which consists of the name
  2579. and version::
  2580. BP = "${BPN}-${PV}"
  2581. The path to the work directory for the recipe
  2582. (:term:`WORKDIR`) is defined as
  2583. follows::
  2584. ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
  2585. The actual directory depends on several things:
  2586. - :term:`TMPDIR`: The top-level build
  2587. output directory.
  2588. - :term:`MULTIMACH_TARGET_SYS`:
  2589. The target system identifier.
  2590. - :term:`PN`: The recipe name.
  2591. - :term:`EXTENDPE`: The epoch - (if
  2592. :term:`PE` is not specified, which is
  2593. usually the case for most recipes, then :term:`EXTENDPE` is blank).
  2594. - :term:`PV`: The recipe version.
  2595. - :term:`PR`: The recipe revision.
  2596. As an example, assume a Source Directory top-level folder named
  2597. ``poky``, a default Build Directory at ``poky/build``, and a
  2598. ``qemux86-poky-linux`` machine target system. Furthermore, suppose your
  2599. recipe is named ``foo_1.3.0.bb``. In this case, the work directory the
  2600. build system uses to build the package would be as follows::
  2601. poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
  2602. Using Quilt in Your Workflow
  2603. ============================
  2604. `Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool
  2605. that allows you to capture source code changes without having a clean
  2606. source tree. This section outlines the typical workflow you can use to
  2607. modify source code, test changes, and then preserve the changes in the
  2608. form of a patch all using Quilt.
  2609. .. note::
  2610. With regard to preserving changes to source files, if you clean a
  2611. recipe or have ``rm_work`` enabled, the
  2612. :ref:`devtool workflow <sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow>`
  2613. as described in the Yocto Project Application Development and the
  2614. Extensible Software Development Kit (eSDK) manual is a safer
  2615. development flow than the flow that uses Quilt.
  2616. Follow these general steps:
  2617. 1. *Find the Source Code:* Temporary source code used by the
  2618. OpenEmbedded build system is kept in the
  2619. :term:`Build Directory`. See the
  2620. ":ref:`dev-manual/common-tasks:finding temporary source code`" section to
  2621. learn how to locate the directory that has the temporary source code for a
  2622. particular package.
  2623. 2. *Change Your Working Directory:* You need to be in the directory that
  2624. has the temporary source code. That directory is defined by the
  2625. :term:`S` variable.
  2626. 3. *Create a New Patch:* Before modifying source code, you need to
  2627. create a new patch. To create a new patch file, use ``quilt new`` as
  2628. below::
  2629. $ quilt new my_changes.patch
  2630. 4. *Notify Quilt and Add Files:* After creating the patch, you need to
  2631. notify Quilt about the files you plan to edit. You notify Quilt by
  2632. adding the files to the patch you just created::
  2633. $ quilt add file1.c file2.c file3.c
  2634. 5. *Edit the Files:* Make your changes in the source code to the files
  2635. you added to the patch.
  2636. 6. *Test Your Changes:* Once you have modified the source code, the
  2637. easiest way to test your changes is by calling the ``do_compile``
  2638. task as shown in the following example::
  2639. $ bitbake -c compile -f package
  2640. The ``-f`` or ``--force`` option forces the specified task to
  2641. execute. If you find problems with your code, you can just keep
  2642. editing and re-testing iteratively until things work as expected.
  2643. .. note::
  2644. All the modifications you make to the temporary source code disappear
  2645. once you run the ``do_clean`` or ``do_cleanall`` tasks using BitBake
  2646. (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``).
  2647. Modifications will also disappear if you use the ``rm_work`` feature as
  2648. described in the
  2649. ":ref:`dev-manual/common-tasks:conserving disk space during builds`"
  2650. section.
  2651. 7. *Generate the Patch:* Once your changes work as expected, you need to
  2652. use Quilt to generate the final patch that contains all your
  2653. modifications.
  2654. ::
  2655. $ quilt refresh
  2656. At this point, the
  2657. ``my_changes.patch`` file has all your edits made to the ``file1.c``,
  2658. ``file2.c``, and ``file3.c`` files.
  2659. You can find the resulting patch file in the ``patches/``
  2660. subdirectory of the source (:term:`S`) directory.
  2661. 8. *Copy the Patch File:* For simplicity, copy the patch file into a
  2662. directory named ``files``, which you can create in the same directory
  2663. that holds the recipe (``.bb``) file or the append (``.bbappend``)
  2664. file. Placing the patch here guarantees that the OpenEmbedded build
  2665. system will find the patch. Next, add the patch into the :term:`SRC_URI`
  2666. of the recipe. Here is an example::
  2667. SRC_URI += "file://my_changes.patch"
  2668. Using a Development Shell
  2669. =========================
  2670. When debugging certain commands or even when just editing packages,
  2671. ``devshell`` can be a useful tool. When you invoke ``devshell``, all
  2672. tasks up to and including
  2673. :ref:`ref-tasks-patch` are run for the
  2674. specified target. Then, a new terminal is opened and you are placed in
  2675. ``${``\ :term:`S`\ ``}``, the source
  2676. directory. In the new terminal, all the OpenEmbedded build-related
  2677. environment variables are still defined so you can use commands such as
  2678. ``configure`` and ``make``. The commands execute just as if the
  2679. OpenEmbedded build system were executing them. Consequently, working
  2680. this way can be helpful when debugging a build or preparing software to
  2681. be used with the OpenEmbedded build system.
  2682. Following is an example that uses ``devshell`` on a target named
  2683. ``matchbox-desktop``::
  2684. $ bitbake matchbox-desktop -c devshell
  2685. This command spawns a terminal with a shell prompt within the
  2686. OpenEmbedded build environment. The
  2687. :term:`OE_TERMINAL` variable
  2688. controls what type of shell is opened.
  2689. For spawned terminals, the following occurs:
  2690. - The ``PATH`` variable includes the cross-toolchain.
  2691. - The ``pkgconfig`` variables find the correct ``.pc`` files.
  2692. - The ``configure`` command finds the Yocto Project site files as well
  2693. as any other necessary files.
  2694. Within this environment, you can run configure or compile commands as if
  2695. they were being run by the OpenEmbedded build system itself. As noted
  2696. earlier, the working directory also automatically changes to the Source
  2697. Directory (:term:`S`).
  2698. To manually run a specific task using ``devshell``, run the
  2699. corresponding ``run.*`` script in the
  2700. ``${``\ :term:`WORKDIR`\ ``}/temp``
  2701. directory (e.g., ``run.do_configure.``\ `pid`). If a task's script does
  2702. not exist, which would be the case if the task was skipped by way of the
  2703. sstate cache, you can create the task by first running it outside of the
  2704. ``devshell``::
  2705. $ bitbake -c task
  2706. .. note::
  2707. - Execution of a task's ``run.*`` script and BitBake's execution of
  2708. a task are identical. In other words, running the script re-runs
  2709. the task just as it would be run using the ``bitbake -c`` command.
  2710. - Any ``run.*`` file that does not have a ``.pid`` extension is a
  2711. symbolic link (symlink) to the most recent version of that file.
  2712. Remember, that the ``devshell`` is a mechanism that allows you to get
  2713. into the BitBake task execution environment. And as such, all commands
  2714. must be called just as BitBake would call them. That means you need to
  2715. provide the appropriate options for cross-compilation and so forth as
  2716. applicable.
  2717. When you are finished using ``devshell``, exit the shell or close the
  2718. terminal window.
  2719. .. note::
  2720. - It is worth remembering that when using ``devshell`` you need to
  2721. use the full compiler name such as ``arm-poky-linux-gnueabi-gcc``
  2722. instead of just using ``gcc``. The same applies to other
  2723. applications such as ``binutils``, ``libtool`` and so forth.
  2724. BitBake sets up environment variables such as :term:`CC` to assist
  2725. applications, such as ``make`` to find the correct tools.
  2726. - It is also worth noting that ``devshell`` still works over X11
  2727. forwarding and similar situations.
  2728. Using a Python Development Shell
  2729. ================================
  2730. Similar to working within a development shell as described in the
  2731. previous section, you can also spawn and work within an interactive
  2732. Python development shell. When debugging certain commands or even when
  2733. just editing packages, ``pydevshell`` can be a useful tool. When you
  2734. invoke the ``pydevshell`` task, all tasks up to and including
  2735. :ref:`ref-tasks-patch` are run for the
  2736. specified target. Then a new terminal is opened. Additionally, key
  2737. Python objects and code are available in the same way they are to
  2738. BitBake tasks, in particular, the data store 'd'. So, commands such as
  2739. the following are useful when exploring the data store and running
  2740. functions::
  2741. pydevshell> d.getVar("STAGING_DIR")
  2742. '/media/build1/poky/build/tmp/sysroots'
  2743. pydevshell> d.getVar("STAGING_DIR", False)
  2744. '${TMPDIR}/sysroots'
  2745. pydevshell> d.setVar("FOO", "bar")
  2746. pydevshell> d.getVar("FOO")
  2747. 'bar'
  2748. pydevshell> d.delVar("FOO")
  2749. pydevshell> d.getVar("FOO")
  2750. pydevshell> bb.build.exec_func("do_unpack", d)
  2751. pydevshell>
  2752. The commands execute just as if the OpenEmbedded build
  2753. system were executing them. Consequently, working this way can be
  2754. helpful when debugging a build or preparing software to be used with the
  2755. OpenEmbedded build system.
  2756. Following is an example that uses ``pydevshell`` on a target named
  2757. ``matchbox-desktop``::
  2758. $ bitbake matchbox-desktop -c pydevshell
  2759. This command spawns a terminal and places you in an interactive Python
  2760. interpreter within the OpenEmbedded build environment. The
  2761. :term:`OE_TERMINAL` variable
  2762. controls what type of shell is opened.
  2763. When you are finished using ``pydevshell``, you can exit the shell
  2764. either by using Ctrl+d or closing the terminal window.
  2765. Building
  2766. ========
  2767. This section describes various build procedures, such as the steps
  2768. needed for a simple build, building a target for multiple configurations,
  2769. generating an image for more than one machine, and so forth.
  2770. Building a Simple Image
  2771. -----------------------
  2772. In the development environment, you need to build an image whenever you
  2773. change hardware support, add or change system libraries, or add or
  2774. change services that have dependencies. There are several methods that allow
  2775. you to build an image within the Yocto Project. This section presents
  2776. the basic steps you need to build a simple image using BitBake from a
  2777. build host running Linux.
  2778. .. note::
  2779. - For information on how to build an image using
  2780. :term:`Toaster`, see the
  2781. :doc:`/toaster-manual/index`.
  2782. - For information on how to use ``devtool`` to build images, see the
  2783. ":ref:`sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow`"
  2784. section in the Yocto Project Application Development and the
  2785. Extensible Software Development Kit (eSDK) manual.
  2786. - For a quick example on how to build an image using the
  2787. OpenEmbedded build system, see the
  2788. :doc:`/brief-yoctoprojectqs/index` document.
  2789. The build process creates an entire Linux distribution from source and
  2790. places it in your :term:`Build Directory` under
  2791. ``tmp/deploy/images``. For detailed information on the build process
  2792. using BitBake, see the ":ref:`overview-manual/concepts:images`" section in the
  2793. Yocto Project Overview and Concepts Manual.
  2794. The following figure and list overviews the build process:
  2795. .. image:: figures/bitbake-build-flow.png
  2796. :align: center
  2797. 1. *Set up Your Host Development System to Support Development Using the
  2798. Yocto Project*: See the ":doc:`start`" section for options on how to get a
  2799. build host ready to use the Yocto Project.
  2800. 2. *Initialize the Build Environment:* Initialize the build environment
  2801. by sourcing the build environment script (i.e.
  2802. :ref:`structure-core-script`)::
  2803. $ source oe-init-build-env [build_dir]
  2804. When you use the initialization script, the OpenEmbedded build system
  2805. uses ``build`` as the default :term:`Build Directory` in your current work
  2806. directory. You can use a `build_dir` argument with the script to
  2807. specify a different build directory.
  2808. .. note::
  2809. A common practice is to use a different Build Directory for
  2810. different targets; for example, ``~/build/x86`` for a ``qemux86``
  2811. target, and ``~/build/arm`` for a ``qemuarm`` target. In any
  2812. event, it's typically cleaner to locate the build directory
  2813. somewhere outside of your source directory.
  2814. 3. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the
  2815. ``conf/local.conf`` configuration file, which is found in the Build
  2816. Directory, is set up how you want it. This file defines many aspects
  2817. of the build environment including the target machine architecture
  2818. through the :term:`MACHINE` variable, the packaging format used during
  2819. the build
  2820. (:term:`PACKAGE_CLASSES`),
  2821. and a centralized tarball download directory through the
  2822. :term:`DL_DIR` variable.
  2823. 4. *Build the Image:* Build the image using the ``bitbake`` command::
  2824. $ bitbake target
  2825. .. note::
  2826. For information on BitBake, see the :doc:`bitbake:index`.
  2827. The target is the name of the recipe you want to build. Common
  2828. targets are the images in ``meta/recipes-core/images``,
  2829. ``meta/recipes-sato/images``, and so forth all found in the
  2830. :term:`Source Directory`. Alternatively, the target
  2831. can be the name of a recipe for a specific piece of software such as
  2832. BusyBox. For more details about the images the OpenEmbedded build
  2833. system supports, see the
  2834. ":ref:`ref-manual/images:Images`" chapter in the Yocto
  2835. Project Reference Manual.
  2836. As an example, the following command builds the
  2837. ``core-image-minimal`` image::
  2838. $ bitbake core-image-minimal
  2839. Once an
  2840. image has been built, it often needs to be installed. The images and
  2841. kernels built by the OpenEmbedded build system are placed in the
  2842. Build Directory in ``tmp/deploy/images``. For information on how to
  2843. run pre-built images such as ``qemux86`` and ``qemuarm``, see the
  2844. :doc:`/sdk-manual/index` manual. For
  2845. information about how to install these images, see the documentation
  2846. for your particular board or machine.
  2847. Building Images for Multiple Targets Using Multiple Configurations
  2848. ------------------------------------------------------------------
  2849. You can use a single ``bitbake`` command to build multiple images or
  2850. packages for different targets where each image or package requires a
  2851. different configuration (multiple configuration builds). The builds, in
  2852. this scenario, are sometimes referred to as "multiconfigs", and this
  2853. section uses that term throughout.
  2854. This section describes how to set up for multiple configuration builds
  2855. and how to account for cross-build dependencies between the
  2856. multiconfigs.
  2857. Setting Up and Running a Multiple Configuration Build
  2858. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2859. To accomplish a multiple configuration build, you must define each
  2860. target's configuration separately using a parallel configuration file in
  2861. the :term:`Build Directory`, and you
  2862. must follow a required file hierarchy. Additionally, you must enable the
  2863. multiple configuration builds in your ``local.conf`` file.
  2864. Follow these steps to set up and execute multiple configuration builds:
  2865. - *Create Separate Configuration Files*: You need to create a single
  2866. configuration file for each build target (each multiconfig).
  2867. Minimally, each configuration file must define the machine and the
  2868. temporary directory BitBake uses for the build. Suggested practice
  2869. dictates that you do not overlap the temporary directories used
  2870. during the builds. However, it is possible that you can share the
  2871. temporary directory
  2872. (:term:`TMPDIR`). For example,
  2873. consider a scenario with two different multiconfigs for the same
  2874. :term:`MACHINE`: "qemux86" built
  2875. for two distributions such as "poky" and "poky-lsb". In this case,
  2876. you might want to use the same :term:`TMPDIR`.
  2877. Here is an example showing the minimal statements needed in a
  2878. configuration file for a "qemux86" target whose temporary build
  2879. directory is ``tmpmultix86``::
  2880. MACHINE = "qemux86"
  2881. TMPDIR = "${TOPDIR}/tmpmultix86"
  2882. The location for these multiconfig configuration files is specific.
  2883. They must reside in the current build directory in a sub-directory of
  2884. ``conf`` named ``multiconfig``. Following is an example that defines
  2885. two configuration files for the "x86" and "arm" multiconfigs:
  2886. .. image:: figures/multiconfig_files.png
  2887. :align: center
  2888. The reason for this required file hierarchy is because the :term:`BBPATH`
  2889. variable is not constructed until the layers are parsed.
  2890. Consequently, using the configuration file as a pre-configuration
  2891. file is not possible unless it is located in the current working
  2892. directory.
  2893. - *Add the BitBake Multi-configuration Variable to the Local
  2894. Configuration File*: Use the
  2895. :term:`BBMULTICONFIG`
  2896. variable in your ``conf/local.conf`` configuration file to specify
  2897. each multiconfig. Continuing with the example from the previous
  2898. figure, the :term:`BBMULTICONFIG` variable needs to enable two
  2899. multiconfigs: "x86" and "arm" by specifying each configuration file::
  2900. BBMULTICONFIG = "x86 arm"
  2901. .. note::
  2902. A "default" configuration already exists by definition. This
  2903. configuration is named: "" (i.e. empty string) and is defined by
  2904. the variables coming from your ``local.conf``
  2905. file. Consequently, the previous example actually adds two
  2906. additional configurations to your build: "arm" and "x86" along
  2907. with "".
  2908. - *Launch BitBake*: Use the following BitBake command form to launch
  2909. the multiple configuration build::
  2910. $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ]
  2911. For the example in this section, the following command applies::
  2912. $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base
  2913. The previous BitBake command builds a ``core-image-minimal`` image
  2914. that is configured through the ``x86.conf`` configuration file, a
  2915. ``core-image-sato`` image that is configured through the ``arm.conf``
  2916. configuration file and a ``core-image-base`` that is configured
  2917. through your ``local.conf`` configuration file.
  2918. .. note::
  2919. Support for multiple configuration builds in the Yocto Project &DISTRO;
  2920. (&DISTRO_NAME;) Release does not include Shared State (sstate)
  2921. optimizations. Consequently, if a build uses the same object twice
  2922. in, for example, two different :term:`TMPDIR`
  2923. directories, the build either loads from an existing sstate cache for
  2924. that build at the start or builds the object fresh.
  2925. Enabling Multiple Configuration Build Dependencies
  2926. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2927. Sometimes dependencies can exist between targets (multiconfigs) in a
  2928. multiple configuration build. For example, suppose that in order to
  2929. build a ``core-image-sato`` image for an "x86" multiconfig, the root
  2930. filesystem of an "arm" multiconfig must exist. This dependency is
  2931. essentially that the
  2932. :ref:`ref-tasks-image` task in the
  2933. ``core-image-sato`` recipe depends on the completion of the
  2934. :ref:`ref-tasks-rootfs` task of the
  2935. ``core-image-minimal`` recipe.
  2936. To enable dependencies in a multiple configuration build, you must
  2937. declare the dependencies in the recipe using the following statement
  2938. form::
  2939. task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend"
  2940. To better show how to use this statement, consider the example scenario
  2941. from the first paragraph of this section. The following statement needs
  2942. to be added to the recipe that builds the ``core-image-sato`` image::
  2943. do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs"
  2944. In this example, the `from_multiconfig` is "x86". The `to_multiconfig` is "arm". The
  2945. task on which the ``do_image`` task in the recipe depends is the
  2946. ``do_rootfs`` task from the ``core-image-minimal`` recipe associated
  2947. with the "arm" multiconfig.
  2948. Once you set up this dependency, you can build the "x86" multiconfig
  2949. using a BitBake command as follows::
  2950. $ bitbake mc:x86:core-image-sato
  2951. This command executes all the tasks needed to create the
  2952. ``core-image-sato`` image for the "x86" multiconfig. Because of the
  2953. dependency, BitBake also executes through the ``do_rootfs`` task for the
  2954. "arm" multiconfig build.
  2955. Having a recipe depend on the root filesystem of another build might not
  2956. seem that useful. Consider this change to the statement in the
  2957. ``core-image-sato`` recipe::
  2958. do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image"
  2959. In this case, BitBake must
  2960. create the ``core-image-minimal`` image for the "arm" build since the
  2961. "x86" build depends on it.
  2962. Because "x86" and "arm" are enabled for multiple configuration builds
  2963. and have separate configuration files, BitBake places the artifacts for
  2964. each build in the respective temporary build directories (i.e.
  2965. :term:`TMPDIR`).
  2966. Building an Initial RAM Filesystem (initramfs) Image
  2967. ----------------------------------------------------
  2968. An initial RAM filesystem (initramfs) image provides a temporary root
  2969. filesystem used for early system initialization (e.g. loading of modules
  2970. needed to locate and mount the "real" root filesystem).
  2971. .. note::
  2972. The initramfs image is the successor of initial RAM disk (initrd). It
  2973. is a "copy in and out" (cpio) archive of the initial filesystem that
  2974. gets loaded into memory during the Linux startup process. Because
  2975. Linux uses the contents of the archive during initialization, the
  2976. initramfs image needs to contain all of the device drivers and tools
  2977. needed to mount the final root filesystem.
  2978. Follow these steps to create an initramfs image:
  2979. 1. *Create the initramfs Image Recipe:* You can reference the
  2980. ``core-image-minimal-initramfs.bb`` recipe found in the
  2981. ``meta/recipes-core`` directory of the :term:`Source Directory`
  2982. as an example
  2983. from which to work.
  2984. 2. *Decide if You Need to Bundle the initramfs Image Into the Kernel
  2985. Image:* If you want the initramfs image that is built to be bundled
  2986. in with the kernel image, set the
  2987. :term:`INITRAMFS_IMAGE_BUNDLE`
  2988. variable to "1" in your ``local.conf`` configuration file and set the
  2989. :term:`INITRAMFS_IMAGE`
  2990. variable in the recipe that builds the kernel image.
  2991. .. note::
  2992. It is recommended that you bundle the initramfs image with the
  2993. kernel image to avoid circular dependencies between the kernel
  2994. recipe and the initramfs recipe should the initramfs image include
  2995. kernel modules.
  2996. Setting the :term:`INITRAMFS_IMAGE_BUNDLE` flag causes the initramfs
  2997. image to be unpacked into the ``${B}/usr/`` directory. The unpacked
  2998. initramfs image is then passed to the kernel's ``Makefile`` using the
  2999. :term:`CONFIG_INITRAMFS_SOURCE`
  3000. variable, allowing the initramfs image to be built into the kernel
  3001. normally.
  3002. .. note::
  3003. Bundling the initramfs with the kernel conflates the code in the initramfs
  3004. with the GPLv2 licensed Linux kernel binary. Thus only GPLv2 compatible
  3005. software may be part of a bundled initramfs.
  3006. .. note::
  3007. If you choose to not bundle the initramfs image with the kernel
  3008. image, you are essentially using an
  3009. `Initial RAM Disk (initrd) <https://en.wikipedia.org/wiki/Initrd>`__.
  3010. Creating an initrd is handled primarily through the :term:`INITRD_IMAGE`,
  3011. ``INITRD_LIVE``, and ``INITRD_IMAGE_LIVE`` variables. For more
  3012. information, see the :ref:`ref-classes-image-live` file.
  3013. 3. *Optionally Add Items to the initramfs Image Through the initramfs
  3014. Image Recipe:* If you add items to the initramfs image by way of its
  3015. recipe, you should use
  3016. :term:`PACKAGE_INSTALL`
  3017. rather than
  3018. :term:`IMAGE_INSTALL`.
  3019. :term:`PACKAGE_INSTALL` gives more direct control of what is added to the
  3020. image as compared to the defaults you might not necessarily want that
  3021. are set by the :ref:`image <ref-classes-image>`
  3022. or :ref:`core-image <ref-classes-core-image>`
  3023. classes.
  3024. 4. *Build the Kernel Image and the initramfs Image:* Build your kernel
  3025. image using BitBake. Because the initramfs image recipe is a
  3026. dependency of the kernel image, the initramfs image is built as well
  3027. and bundled with the kernel image if you used the
  3028. :term:`INITRAMFS_IMAGE_BUNDLE`
  3029. variable described earlier.
  3030. Bundling an Initramfs Image From a Separate Multiconfig
  3031. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3032. There may be a case where we want to build an initramfs image which does not
  3033. inherit the same distro policy as our main image, for example, we may want
  3034. our main image to use ``TCLIBC="glibc"``, but to use ``TCLIBC="musl"`` in our initramfs
  3035. image to keep a smaller footprint. However, by performing the steps mentioned
  3036. above the initramfs image will inherit ``TCLIBC="glibc"`` without allowing us
  3037. to override it.
  3038. To achieve this, you need to perform some additional steps:
  3039. 1. *Create a multiconfig for your initramfs image:* You can perform the steps
  3040. on ":ref:`dev-manual/common-tasks:building images for multiple targets using multiple configurations`" to create a separate multiconfig.
  3041. For the sake of simplicity let's assume such multiconfig is called: ``initramfscfg.conf`` and
  3042. contains the variables::
  3043. TMPDIR="${TOPDIR}/tmp-initramfscfg"
  3044. TCLIBC="musl"
  3045. 2. *Set additional initramfs variables on your main configuration:*
  3046. Additionally, on your main configuration (``local.conf``) you need to set the
  3047. variables::
  3048. INITRAMFS_MULTICONFIG = "initramfscfg"
  3049. INITRAMFS_DEPLOY_DIR_IMAGE = "${TOPDIR}/tmp-initramfscfg/deploy/images/${MACHINE}"
  3050. The variables :term:`INITRAMFS_MULTICONFIG` and :term:`INITRAMFS_DEPLOY_DIR_IMAGE`
  3051. are used to create a multiconfig dependency from the kernel to the :term:`INITRAMFS_IMAGE`
  3052. to be built coming from the ``initramfscfg`` multiconfig, and to let the
  3053. buildsystem know where the :term:`INITRAMFS_IMAGE` will be located.
  3054. Building a system with such configuration will build the kernel using the
  3055. main configuration but the ``do_bundle_initramfs`` task will grab the
  3056. selected :term:`INITRAMFS_IMAGE` from :term:`INITRAMFS_DEPLOY_DIR_IMAGE`
  3057. instead, resulting in a musl based initramfs image bundled in the kernel
  3058. but a glibc based main image.
  3059. The same is applicable to avoid inheriting :term:`DISTRO_FEATURES` on :term:`INITRAMFS_IMAGE`
  3060. or to build a different :term:`DISTRO` for it such as ``poky-tiny``.
  3061. Building a Tiny System
  3062. ----------------------
  3063. Very small distributions have some significant advantages such as
  3064. requiring less on-die or in-package memory (cheaper), better performance
  3065. through efficient cache usage, lower power requirements due to less
  3066. memory, faster boot times, and reduced development overhead. Some
  3067. real-world examples where a very small distribution gives you distinct
  3068. advantages are digital cameras, medical devices, and small headless
  3069. systems.
  3070. This section presents information that shows you how you can trim your
  3071. distribution to even smaller sizes than the ``poky-tiny`` distribution,
  3072. which is around 5 Mbytes, that can be built out-of-the-box using the
  3073. Yocto Project.
  3074. Tiny System Overview
  3075. ~~~~~~~~~~~~~~~~~~~~
  3076. The following list presents the overall steps you need to consider and
  3077. perform to create distributions with smaller root filesystems, achieve
  3078. faster boot times, maintain your critical functionality, and avoid
  3079. initial RAM disks:
  3080. - :ref:`Determine your goals and guiding principles
  3081. <dev-manual/common-tasks:goals and guiding principles>`
  3082. - :ref:`dev-manual/common-tasks:understand what contributes to your image size`
  3083. - :ref:`Reduce the size of the root filesystem
  3084. <dev-manual/common-tasks:trim the root filesystem>`
  3085. - :ref:`Reduce the size of the kernel <dev-manual/common-tasks:trim the kernel>`
  3086. - :ref:`dev-manual/common-tasks:remove package management requirements`
  3087. - :ref:`dev-manual/common-tasks:look for other ways to minimize size`
  3088. - :ref:`dev-manual/common-tasks:iterate on the process`
  3089. Goals and Guiding Principles
  3090. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3091. Before you can reach your destination, you need to know where you are
  3092. going. Here is an example list that you can use as a guide when creating
  3093. very small distributions:
  3094. - Determine how much space you need (e.g. a kernel that is 1 Mbyte or
  3095. less and a root filesystem that is 3 Mbytes or less).
  3096. - Find the areas that are currently taking 90% of the space and
  3097. concentrate on reducing those areas.
  3098. - Do not create any difficult "hacks" to achieve your goals.
  3099. - Leverage the device-specific options.
  3100. - Work in a separate layer so that you keep changes isolated. For
  3101. information on how to create layers, see the
  3102. ":ref:`dev-manual/common-tasks:understanding and creating layers`" section.
  3103. Understand What Contributes to Your Image Size
  3104. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3105. It is easiest to have something to start with when creating your own
  3106. distribution. You can use the Yocto Project out-of-the-box to create the
  3107. ``poky-tiny`` distribution. Ultimately, you will want to make changes in
  3108. your own distribution that are likely modeled after ``poky-tiny``.
  3109. .. note::
  3110. To use ``poky-tiny`` in your build, set the :term:`DISTRO` variable in your
  3111. ``local.conf`` file to "poky-tiny" as described in the
  3112. ":ref:`dev-manual/common-tasks:creating your own distribution`"
  3113. section.
  3114. Understanding some memory concepts will help you reduce the system size.
  3115. Memory consists of static, dynamic, and temporary memory. Static memory
  3116. is the TEXT (code), DATA (initialized data in the code), and BSS
  3117. (uninitialized data) sections. Dynamic memory represents memory that is
  3118. allocated at runtime: stacks, hash tables, and so forth. Temporary
  3119. memory is recovered after the boot process. This memory consists of
  3120. memory used for decompressing the kernel and for the ``__init__``
  3121. functions.
  3122. To help you see where you currently are with kernel and root filesystem
  3123. sizes, you can use two tools found in the :term:`Source Directory`
  3124. in the
  3125. ``scripts/tiny/`` directory:
  3126. - ``ksize.py``: Reports component sizes for the kernel build objects.
  3127. - ``dirsize.py``: Reports component sizes for the root filesystem.
  3128. This next tool and command help you organize configuration fragments and
  3129. view file dependencies in a human-readable form:
  3130. - ``merge_config.sh``: Helps you manage configuration files and
  3131. fragments within the kernel. With this tool, you can merge individual
  3132. configuration fragments together. The tool allows you to make
  3133. overrides and warns you of any missing configuration options. The
  3134. tool is ideal for allowing you to iterate on configurations, create
  3135. minimal configurations, and create configuration files for different
  3136. machines without having to duplicate your process.
  3137. The ``merge_config.sh`` script is part of the Linux Yocto kernel Git
  3138. repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``,
  3139. ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig``
  3140. directory.
  3141. For more information on configuration fragments, see the
  3142. ":ref:`kernel-dev/common:creating configuration fragments`"
  3143. section in the Yocto Project Linux Kernel Development Manual.
  3144. - ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command
  3145. with these options brings up a Dependency Explorer from which you can
  3146. view file dependencies. Understanding these dependencies allows you
  3147. to make informed decisions when cutting out various pieces of the
  3148. kernel and root filesystem.
  3149. Trim the Root Filesystem
  3150. ~~~~~~~~~~~~~~~~~~~~~~~~
  3151. The root filesystem is made up of packages for booting, libraries, and
  3152. applications. To change things, you can configure how the packaging
  3153. happens, which changes the way you build them. You can also modify the
  3154. filesystem itself or select a different filesystem.
  3155. First, find out what is hogging your root filesystem by running the
  3156. ``dirsize.py`` script from your root directory::
  3157. $ cd root-directory-of-image
  3158. $ dirsize.py 100000 > dirsize-100k.log
  3159. $ cat dirsize-100k.log
  3160. You can apply a filter to the script to ignore files
  3161. under a certain size. The previous example filters out any files below
  3162. 100 Kbytes. The sizes reported by the tool are uncompressed, and thus
  3163. will be smaller by a relatively constant factor in a compressed root
  3164. filesystem. When you examine your log file, you can focus on areas of
  3165. the root filesystem that take up large amounts of memory.
  3166. You need to be sure that what you eliminate does not cripple the
  3167. functionality you need. One way to see how packages relate to each other
  3168. is by using the Dependency Explorer UI with the BitBake command::
  3169. $ cd image-directory
  3170. $ bitbake -u taskexp -g image
  3171. Use the interface to
  3172. select potential packages you wish to eliminate and see their dependency
  3173. relationships.
  3174. When deciding how to reduce the size, get rid of packages that result in
  3175. minimal impact on the feature set. For example, you might not need a VGA
  3176. display. Or, you might be able to get by with ``devtmpfs`` and ``mdev``
  3177. instead of ``udev``.
  3178. Use your ``local.conf`` file to make changes. For example, to eliminate
  3179. ``udev`` and ``glib``, set the following in the local configuration
  3180. file::
  3181. VIRTUAL-RUNTIME_dev_manager = ""
  3182. Finally, you should consider exactly the type of root filesystem you
  3183. need to meet your needs while also reducing its size. For example,
  3184. consider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an
  3185. ``initramfs`` using ``initramfs``. Be aware that ``ext3`` requires a 1
  3186. Mbyte journal. If you are okay with running read-only, you do not need
  3187. this journal.
  3188. .. note::
  3189. After each round of elimination, you need to rebuild your system and
  3190. then use the tools to see the effects of your reductions.
  3191. Trim the Kernel
  3192. ~~~~~~~~~~~~~~~
  3193. The kernel is built by including policies for hardware-independent
  3194. aspects. What subsystems do you enable? For what architecture are you
  3195. building? Which drivers do you build by default?
  3196. .. note::
  3197. You can modify the kernel source if you want to help with boot time.
  3198. Run the ``ksize.py`` script from the top-level Linux build directory to
  3199. get an idea of what is making up the kernel::
  3200. $ cd top-level-linux-build-directory
  3201. $ ksize.py > ksize.log
  3202. $ cat ksize.log
  3203. When you examine the log, you will see how much space is taken up with
  3204. the built-in ``.o`` files for drivers, networking, core kernel files,
  3205. filesystem, sound, and so forth. The sizes reported by the tool are
  3206. uncompressed, and thus will be smaller by a relatively constant factor
  3207. in a compressed kernel image. Look to reduce the areas that are large
  3208. and taking up around the "90% rule."
  3209. To examine, or drill down, into any particular area, use the ``-d``
  3210. option with the script::
  3211. $ ksize.py -d > ksize.log
  3212. Using this option
  3213. breaks out the individual file information for each area of the kernel
  3214. (e.g. drivers, networking, and so forth).
  3215. Use your log file to see what you can eliminate from the kernel based on
  3216. features you can let go. For example, if you are not going to need
  3217. sound, you do not need any drivers that support sound.
  3218. After figuring out what to eliminate, you need to reconfigure the kernel
  3219. to reflect those changes during the next build. You could run
  3220. ``menuconfig`` and make all your changes at once. However, that makes it
  3221. difficult to see the effects of your individual eliminations and also
  3222. makes it difficult to replicate the changes for perhaps another target
  3223. device. A better method is to start with no configurations using
  3224. ``allnoconfig``, create configuration fragments for individual changes,
  3225. and then manage the fragments into a single configuration file using
  3226. ``merge_config.sh``. The tool makes it easy for you to iterate using the
  3227. configuration change and build cycle.
  3228. Each time you make configuration changes, you need to rebuild the kernel
  3229. and check to see what impact your changes had on the overall size.
  3230. Remove Package Management Requirements
  3231. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3232. Packaging requirements add size to the image. One way to reduce the size
  3233. of the image is to remove all the packaging requirements from the image.
  3234. This reduction includes both removing the package manager and its unique
  3235. dependencies as well as removing the package management data itself.
  3236. To eliminate all the packaging requirements for an image, be sure that
  3237. "package-management" is not part of your
  3238. :term:`IMAGE_FEATURES`
  3239. statement for the image. When you remove this feature, you are removing
  3240. the package manager as well as its dependencies from the root
  3241. filesystem.
  3242. Look for Other Ways to Minimize Size
  3243. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3244. Depending on your particular circumstances, other areas that you can
  3245. trim likely exist. The key to finding these areas is through tools and
  3246. methods described here combined with experimentation and iteration. Here
  3247. are a couple of areas to experiment with:
  3248. - ``glibc``: In general, follow this process:
  3249. 1. Remove ``glibc`` features from
  3250. :term:`DISTRO_FEATURES`
  3251. that you think you do not need.
  3252. 2. Build your distribution.
  3253. 3. If the build fails due to missing symbols in a package, determine
  3254. if you can reconfigure the package to not need those features. For
  3255. example, change the configuration to not support wide character
  3256. support as is done for ``ncurses``. Or, if support for those
  3257. characters is needed, determine what ``glibc`` features provide
  3258. the support and restore the configuration.
  3259. 4. Rebuild and repeat the process.
  3260. - ``busybox``: For BusyBox, use a process similar as described for
  3261. ``glibc``. A difference is you will need to boot the resulting system
  3262. to see if you are able to do everything you expect from the running
  3263. system. You need to be sure to integrate configuration fragments into
  3264. Busybox because BusyBox handles its own core features and then allows
  3265. you to add configuration fragments on top.
  3266. Iterate on the Process
  3267. ~~~~~~~~~~~~~~~~~~~~~~
  3268. If you have not reached your goals on system size, you need to iterate
  3269. on the process. The process is the same. Use the tools and see just what
  3270. is taking up 90% of the root filesystem and the kernel. Decide what you
  3271. can eliminate without limiting your device beyond what you need.
  3272. Depending on your system, a good place to look might be Busybox, which
  3273. provides a stripped down version of Unix tools in a single, executable
  3274. file. You might be able to drop virtual terminal services or perhaps
  3275. ipv6.
  3276. Building Images for More than One Machine
  3277. -----------------------------------------
  3278. A common scenario developers face is creating images for several
  3279. different machines that use the same software environment. In this
  3280. situation, it is tempting to set the tunings and optimization flags for
  3281. each build specifically for the targeted hardware (i.e. "maxing out" the
  3282. tunings). Doing so can considerably add to build times and package feed
  3283. maintenance collectively for the machines. For example, selecting tunes
  3284. that are extremely specific to a CPU core used in a system might enable
  3285. some micro optimizations in GCC for that particular system but would
  3286. otherwise not gain you much of a performance difference across the other
  3287. systems as compared to using a more general tuning across all the builds
  3288. (e.g. setting :term:`DEFAULTTUNE`
  3289. specifically for each machine's build). Rather than "max out" each
  3290. build's tunings, you can take steps that cause the OpenEmbedded build
  3291. system to reuse software across the various machines where it makes
  3292. sense.
  3293. If build speed and package feed maintenance are considerations, you
  3294. should consider the points in this section that can help you optimize
  3295. your tunings to best consider build times and package feed maintenance.
  3296. - *Share the Build Directory:* If at all possible, share the
  3297. :term:`TMPDIR` across builds. The
  3298. Yocto Project supports switching between different
  3299. :term:`MACHINE` values in the same
  3300. :term:`TMPDIR`. This practice is well supported and regularly used by
  3301. developers when building for multiple machines. When you use the same
  3302. :term:`TMPDIR` for multiple machine builds, the OpenEmbedded build system
  3303. can reuse the existing native and often cross-recipes for multiple
  3304. machines. Thus, build time decreases.
  3305. .. note::
  3306. If :term:`DISTRO` settings change or fundamental configuration settings
  3307. such as the filesystem layout, you need to work with a clean :term:`TMPDIR`.
  3308. Sharing :term:`TMPDIR` under these circumstances might work but since it is
  3309. not guaranteed, you should use a clean :term:`TMPDIR`.
  3310. - *Enable the Appropriate Package Architecture:* By default, the
  3311. OpenEmbedded build system enables three levels of package
  3312. architectures: "all", "tune" or "package", and "machine". Any given
  3313. recipe usually selects one of these package architectures (types) for
  3314. its output. Depending for what a given recipe creates packages,
  3315. making sure you enable the appropriate package architecture can
  3316. directly impact the build time.
  3317. A recipe that just generates scripts can enable "all" architecture
  3318. because there are no binaries to build. To specifically enable "all"
  3319. architecture, be sure your recipe inherits the
  3320. :ref:`allarch <ref-classes-allarch>` class.
  3321. This class is useful for "all" architectures because it configures
  3322. many variables so packages can be used across multiple architectures.
  3323. If your recipe needs to generate packages that are machine-specific
  3324. or when one of the build or runtime dependencies is already
  3325. machine-architecture dependent, which makes your recipe also
  3326. machine-architecture dependent, make sure your recipe enables the
  3327. "machine" package architecture through the
  3328. :term:`MACHINE_ARCH`
  3329. variable::
  3330. PACKAGE_ARCH = "${MACHINE_ARCH}"
  3331. When you do not
  3332. specifically enable a package architecture through the
  3333. :term:`PACKAGE_ARCH`, The
  3334. OpenEmbedded build system defaults to the
  3335. :term:`TUNE_PKGARCH` setting::
  3336. PACKAGE_ARCH = "${TUNE_PKGARCH}"
  3337. - *Choose a Generic Tuning File if Possible:* Some tunes are more
  3338. generic and can run on multiple targets (e.g. an ``armv5`` set of
  3339. packages could run on ``armv6`` and ``armv7`` processors in most
  3340. cases). Similarly, ``i486`` binaries could work on ``i586`` and
  3341. higher processors. You should realize, however, that advances on
  3342. newer processor versions would not be used.
  3343. If you select the same tune for several different machines, the
  3344. OpenEmbedded build system reuses software previously built, thus
  3345. speeding up the overall build time. Realize that even though a new
  3346. sysroot for each machine is generated, the software is not recompiled
  3347. and only one package feed exists.
  3348. - *Manage Granular Level Packaging:* Sometimes there are cases where
  3349. injecting another level of package architecture beyond the three
  3350. higher levels noted earlier can be useful. For example, consider how
  3351. NXP (formerly Freescale) allows for the easy reuse of binary packages
  3352. in their layer
  3353. :yocto_git:`meta-freescale </meta-freescale/>`.
  3354. In this example, the
  3355. :yocto_git:`fsl-dynamic-packagearch </meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass>`
  3356. class shares GPU packages for i.MX53 boards because all boards share
  3357. the AMD GPU. The i.MX6-based boards can do the same because all
  3358. boards share the Vivante GPU. This class inspects the BitBake
  3359. datastore to identify if the package provides or depends on one of
  3360. the sub-architecture values. If so, the class sets the
  3361. :term:`PACKAGE_ARCH` value
  3362. based on the ``MACHINE_SUBARCH`` value. If the package does not
  3363. provide or depend on one of the sub-architecture values but it
  3364. matches a value in the machine-specific filter, it sets
  3365. :term:`MACHINE_ARCH`. This
  3366. behavior reduces the number of packages built and saves build time by
  3367. reusing binaries.
  3368. - *Use Tools to Debug Issues:* Sometimes you can run into situations
  3369. where software is being rebuilt when you think it should not be. For
  3370. example, the OpenEmbedded build system might not be using shared
  3371. state between machines when you think it should be. These types of
  3372. situations are usually due to references to machine-specific
  3373. variables such as :term:`MACHINE`,
  3374. :term:`SERIAL_CONSOLES`,
  3375. :term:`XSERVER`,
  3376. :term:`MACHINE_FEATURES`,
  3377. and so forth in code that is supposed to only be tune-specific or
  3378. when the recipe depends
  3379. (:term:`DEPENDS`,
  3380. :term:`RDEPENDS`,
  3381. :term:`RRECOMMENDS`,
  3382. :term:`RSUGGESTS`, and so forth)
  3383. on some other recipe that already has
  3384. :term:`PACKAGE_ARCH` defined
  3385. as "${MACHINE_ARCH}".
  3386. .. note::
  3387. Patches to fix any issues identified are most welcome as these
  3388. issues occasionally do occur.
  3389. For such cases, you can use some tools to help you sort out the
  3390. situation:
  3391. - ``state-diff-machines.sh``*:* You can find this tool in the
  3392. ``scripts`` directory of the Source Repositories. See the comments
  3393. in the script for information on how to use the tool.
  3394. - *BitBake's "-S printdiff" Option:* Using this option causes
  3395. BitBake to try to establish the closest signature match it can
  3396. (e.g. in the shared state cache) and then run ``bitbake-diffsigs``
  3397. over the matches to determine the stamps and delta where these two
  3398. stamp trees diverge.
  3399. Building Software from an External Source
  3400. -----------------------------------------
  3401. By default, the OpenEmbedded build system uses the
  3402. :term:`Build Directory` when building source
  3403. code. The build process involves fetching the source files, unpacking
  3404. them, and then patching them if necessary before the build takes place.
  3405. There are situations where you might want to build software from source
  3406. files that are external to and thus outside of the OpenEmbedded build
  3407. system. For example, suppose you have a project that includes a new BSP
  3408. with a heavily customized kernel. And, you want to minimize exposing the
  3409. build system to the development team so that they can focus on their
  3410. project and maintain everyone's workflow as much as possible. In this
  3411. case, you want a kernel source directory on the development machine
  3412. where the development occurs. You want the recipe's
  3413. :term:`SRC_URI` variable to point to
  3414. the external directory and use it as is, not copy it.
  3415. To build from software that comes from an external source, all you need
  3416. to do is inherit the
  3417. :ref:`externalsrc <ref-classes-externalsrc>` class
  3418. and then set the
  3419. :term:`EXTERNALSRC` variable to
  3420. point to your external source code. Here are the statements to put in
  3421. your ``local.conf`` file::
  3422. INHERIT += "externalsrc"
  3423. EXTERNALSRC:pn-myrecipe = "path-to-your-source-tree"
  3424. This next example shows how to accomplish the same thing by setting
  3425. :term:`EXTERNALSRC` in the recipe itself or in the recipe's append file::
  3426. EXTERNALSRC = "path"
  3427. EXTERNALSRC_BUILD = "path"
  3428. .. note::
  3429. In order for these settings to take effect, you must globally or
  3430. locally inherit the :ref:`externalsrc <ref-classes-externalsrc>`
  3431. class.
  3432. By default, :ref:`ref-classes-externalsrc` builds the source code in a
  3433. directory separate from the external source directory as specified by
  3434. :term:`EXTERNALSRC`. If you need
  3435. to have the source built in the same directory in which it resides, or
  3436. some other nominated directory, you can set
  3437. :term:`EXTERNALSRC_BUILD`
  3438. to point to that directory::
  3439. EXTERNALSRC_BUILD:pn-myrecipe = "path-to-your-source-tree"
  3440. Replicating a Build Offline
  3441. ---------------------------
  3442. It can be useful to take a "snapshot" of upstream sources used in a
  3443. build and then use that "snapshot" later to replicate the build offline.
  3444. To do so, you need to first prepare and populate your downloads
  3445. directory your "snapshot" of files. Once your downloads directory is
  3446. ready, you can use it at any time and from any machine to replicate your
  3447. build.
  3448. Follow these steps to populate your Downloads directory:
  3449. 1. *Create a Clean Downloads Directory:* Start with an empty downloads
  3450. directory (:term:`DL_DIR`). You
  3451. start with an empty downloads directory by either removing the files
  3452. in the existing directory or by setting :term:`DL_DIR` to point to either
  3453. an empty location or one that does not yet exist.
  3454. 2. *Generate Tarballs of the Source Git Repositories:* Edit your
  3455. ``local.conf`` configuration file as follows::
  3456. DL_DIR = "/home/your-download-dir/"
  3457. BB_GENERATE_MIRROR_TARBALLS = "1"
  3458. During
  3459. the fetch process in the next step, BitBake gathers the source files
  3460. and creates tarballs in the directory pointed to by :term:`DL_DIR`. See
  3461. the
  3462. :term:`BB_GENERATE_MIRROR_TARBALLS`
  3463. variable for more information.
  3464. 3. *Populate Your Downloads Directory Without Building:* Use BitBake to
  3465. fetch your sources but inhibit the build::
  3466. $ bitbake target --runonly=fetch
  3467. The downloads directory (i.e. ``${DL_DIR}``) now has
  3468. a "snapshot" of the source files in the form of tarballs, which can
  3469. be used for the build.
  3470. 4. *Optionally Remove Any Git or other SCM Subdirectories From the
  3471. Downloads Directory:* If you want, you can clean up your downloads
  3472. directory by removing any Git or other Source Control Management
  3473. (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs
  3474. already contain these subdirectories.
  3475. Once your downloads directory has everything it needs regarding source
  3476. files, you can create your "own-mirror" and build your target.
  3477. Understand that you can use the files to build the target offline from
  3478. any machine and at any time.
  3479. Follow these steps to build your target using the files in the downloads
  3480. directory:
  3481. 1. *Using Local Files Only:* Inside your ``local.conf`` file, add the
  3482. :term:`SOURCE_MIRROR_URL` variable, inherit the
  3483. :ref:`own-mirrors <ref-classes-own-mirrors>` class, and use the
  3484. :term:`BB_NO_NETWORK` variable to your ``local.conf``.
  3485. ::
  3486. SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/"
  3487. INHERIT += "own-mirrors"
  3488. BB_NO_NETWORK = "1"
  3489. The :term:`SOURCE_MIRROR_URL` and :ref:`own-mirrors <ref-classes-own-mirrors>`
  3490. class set up the system to use the downloads directory as your "own
  3491. mirror". Using the :term:`BB_NO_NETWORK` variable makes sure that
  3492. BitBake's fetching process in step 3 stays local, which means files
  3493. from your "own-mirror" are used.
  3494. 2. *Start With a Clean Build:* You can start with a clean build by
  3495. removing the
  3496. ``${``\ :term:`TMPDIR`\ ``}``
  3497. directory or using a new :term:`Build Directory`.
  3498. 3. *Build Your Target:* Use BitBake to build your target::
  3499. $ bitbake target
  3500. The build completes using the known local "snapshot" of source
  3501. files from your mirror. The resulting tarballs for your "snapshot" of
  3502. source files are in the downloads directory.
  3503. .. note::
  3504. The offline build does not work if recipes attempt to find the
  3505. latest version of software by setting
  3506. :term:`SRCREV` to
  3507. ``${``\ :term:`AUTOREV`\ ``}``::
  3508. SRCREV = "${AUTOREV}"
  3509. When a recipe sets :term:`SRCREV` to
  3510. ``${``\ :term:`AUTOREV`\ ``}``, the build system accesses the network in an
  3511. attempt to determine the latest version of software from the SCM.
  3512. Typically, recipes that use :term:`AUTOREV` are custom or modified
  3513. recipes. Recipes that reside in public repositories usually do not
  3514. use :term:`AUTOREV`.
  3515. If you do have recipes that use :term:`AUTOREV`, you can take steps to
  3516. still use the recipes in an offline build. Do the following:
  3517. 1. Use a configuration generated by enabling :ref:`build
  3518. history <dev-manual/common-tasks:maintaining build output quality>`.
  3519. 2. Use the ``buildhistory-collect-srcrevs`` command to collect the
  3520. stored :term:`SRCREV` values from the build's history. For more
  3521. information on collecting these values, see the
  3522. ":ref:`dev-manual/common-tasks:build history package information`"
  3523. section.
  3524. 3. Once you have the correct source revisions, you can modify
  3525. those recipes to set :term:`SRCREV` to specific versions of the
  3526. software.
  3527. Speeding Up a Build
  3528. ===================
  3529. Build time can be an issue. By default, the build system uses simple
  3530. controls to try and maximize build efficiency. In general, the default
  3531. settings for all the following variables result in the most efficient
  3532. build times when dealing with single socket systems (i.e. a single CPU).
  3533. If you have multiple CPUs, you might try increasing the default values
  3534. to gain more speed. See the descriptions in the glossary for each
  3535. variable for more information:
  3536. - :term:`BB_NUMBER_THREADS`:
  3537. The maximum number of threads BitBake simultaneously executes.
  3538. - :term:`BB_NUMBER_PARSE_THREADS`:
  3539. The number of threads BitBake uses during parsing.
  3540. - :term:`PARALLEL_MAKE`: Extra
  3541. options passed to the ``make`` command during the
  3542. :ref:`ref-tasks-compile` task in
  3543. order to specify parallel compilation on the local build host.
  3544. - :term:`PARALLEL_MAKEINST`:
  3545. Extra options passed to the ``make`` command during the
  3546. :ref:`ref-tasks-install` task in
  3547. order to specify parallel installation on the local build host.
  3548. As mentioned, these variables all scale to the number of processor cores
  3549. available on the build system. For single socket systems, this
  3550. auto-scaling ensures that the build system fundamentally takes advantage
  3551. of potential parallel operations during the build based on the build
  3552. machine's capabilities.
  3553. Following are additional factors that can affect build speed:
  3554. - File system type: The file system type that the build is being
  3555. performed on can also influence performance. Using ``ext4`` is
  3556. recommended as compared to ``ext2`` and ``ext3`` due to ``ext4``
  3557. improved features such as extents.
  3558. - Disabling the updating of access time using ``noatime``: The
  3559. ``noatime`` mount option prevents the build system from updating file
  3560. and directory access times.
  3561. - Setting a longer commit: Using the "commit=" mount option increases
  3562. the interval in seconds between disk cache writes. Changing this
  3563. interval from the five second default to something longer increases
  3564. the risk of data loss but decreases the need to write to the disk,
  3565. thus increasing the build performance.
  3566. - Choosing the packaging backend: Of the available packaging backends,
  3567. IPK is the fastest. Additionally, selecting a singular packaging
  3568. backend also helps.
  3569. - Using ``tmpfs`` for :term:`TMPDIR`
  3570. as a temporary file system: While this can help speed up the build,
  3571. the benefits are limited due to the compiler using ``-pipe``. The
  3572. build system goes to some lengths to avoid ``sync()`` calls into the
  3573. file system on the principle that if there was a significant failure,
  3574. the :term:`Build Directory`
  3575. contents could easily be rebuilt.
  3576. - Inheriting the
  3577. :ref:`rm_work <ref-classes-rm-work>` class:
  3578. Inheriting this class has shown to speed up builds due to
  3579. significantly lower amounts of data stored in the data cache as well
  3580. as on disk. Inheriting this class also makes cleanup of
  3581. :term:`TMPDIR` faster, at the
  3582. expense of being easily able to dive into the source code. File
  3583. system maintainers have recommended that the fastest way to clean up
  3584. large numbers of files is to reformat partitions rather than delete
  3585. files due to the linear nature of partitions. This, of course,
  3586. assumes you structure the disk partitions and file systems in a way
  3587. that this is practical.
  3588. Aside from the previous list, you should keep some trade offs in mind
  3589. that can help you speed up the build:
  3590. - Remove items from
  3591. :term:`DISTRO_FEATURES`
  3592. that you might not need.
  3593. - Exclude debug symbols and other debug information: If you do not need
  3594. these symbols and other debug information, disabling the ``*-dbg``
  3595. package generation can speed up the build. You can disable this
  3596. generation by setting the
  3597. :term:`INHIBIT_PACKAGE_DEBUG_SPLIT`
  3598. variable to "1".
  3599. - Disable static library generation for recipes derived from
  3600. ``autoconf`` or ``libtool``: Following is an example showing how to
  3601. disable static libraries and still provide an override to handle
  3602. exceptions::
  3603. STATICLIBCONF = "--disable-static"
  3604. STATICLIBCONF:sqlite3-native = ""
  3605. EXTRA_OECONF += "${STATICLIBCONF}"
  3606. .. note::
  3607. - Some recipes need static libraries in order to work correctly
  3608. (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides,
  3609. as in the previous example, account for these kinds of
  3610. exceptions.
  3611. - Some packages have packaging code that assumes the presence of
  3612. the static libraries. If so, you might need to exclude them as
  3613. well.
  3614. Working With Libraries
  3615. ======================
  3616. Libraries are an integral part of your system. This section describes
  3617. some common practices you might find helpful when working with libraries
  3618. to build your system:
  3619. - :ref:`How to include static library files
  3620. <dev-manual/common-tasks:including static library files>`
  3621. - :ref:`How to use the Multilib feature to combine multiple versions of
  3622. library files into a single image
  3623. <dev-manual/common-tasks:combining multiple versions of library files into one image>`
  3624. - :ref:`How to install multiple versions of the same library in parallel on
  3625. the same system
  3626. <dev-manual/common-tasks:installing multiple versions of the same library>`
  3627. Including Static Library Files
  3628. ------------------------------
  3629. If you are building a library and the library offers static linking, you
  3630. can control which static library files (``*.a`` files) get included in
  3631. the built library.
  3632. The :term:`PACKAGES` and
  3633. :term:`FILES:* <FILES>` variables in the
  3634. ``meta/conf/bitbake.conf`` configuration file define how files installed
  3635. by the ``do_install`` task are packaged. By default, the :term:`PACKAGES`
  3636. variable includes ``${PN}-staticdev``, which represents all static
  3637. library files.
  3638. .. note::
  3639. Some previously released versions of the Yocto Project defined the
  3640. static library files through ``${PN}-dev``.
  3641. Following is part of the BitBake configuration file, where you can see
  3642. how the static library files are defined::
  3643. PACKAGE_BEFORE_PN ?= ""
  3644. PACKAGES = "${PN}-src ${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
  3645. PACKAGES_DYNAMIC = "^${PN}-locale-.*"
  3646. FILES = ""
  3647. FILES:${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
  3648. ${sysconfdir} ${sharedstatedir} ${localstatedir} \
  3649. ${base_bindir}/* ${base_sbindir}/* \
  3650. ${base_libdir}/*${SOLIBS} \
  3651. ${base_prefix}/lib/udev ${prefix}/lib/udev \
  3652. ${base_libdir}/udev ${libdir}/udev \
  3653. ${datadir}/${BPN} ${libdir}/${BPN}/* \
  3654. ${datadir}/pixmaps ${datadir}/applications \
  3655. ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
  3656. ${libdir}/bonobo/servers"
  3657. FILES:${PN}-bin = "${bindir}/* ${sbindir}/*"
  3658. FILES:${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
  3659. ${datadir}/gnome/help"
  3660. SECTION:${PN}-doc = "doc"
  3661. FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
  3662. FILES:${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
  3663. ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
  3664. ${datadir}/aclocal ${base_libdir}/*.o \
  3665. ${libdir}/${BPN}/*.la ${base_libdir}/*.la \
  3666. ${libdir}/cmake ${datadir}/cmake"
  3667. SECTION:${PN}-dev = "devel"
  3668. ALLOW_EMPTY:${PN}-dev = "1"
  3669. RDEPENDS:${PN}-dev = "${PN} (= ${EXTENDPKGV})"
  3670. FILES:${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
  3671. SECTION:${PN}-staticdev = "devel"
  3672. RDEPENDS:${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
  3673. Combining Multiple Versions of Library Files into One Image
  3674. -----------------------------------------------------------
  3675. The build system offers the ability to build libraries with different
  3676. target optimizations or architecture formats and combine these together
  3677. into one system image. You can link different binaries in the image
  3678. against the different libraries as needed for specific use cases. This
  3679. feature is called "Multilib".
  3680. An example would be where you have most of a system compiled in 32-bit
  3681. mode using 32-bit libraries, but you have something large, like a
  3682. database engine, that needs to be a 64-bit application and uses 64-bit
  3683. libraries. Multilib allows you to get the best of both 32-bit and 64-bit
  3684. libraries.
  3685. While the Multilib feature is most commonly used for 32 and 64-bit
  3686. differences, the approach the build system uses facilitates different
  3687. target optimizations. You could compile some binaries to use one set of
  3688. libraries and other binaries to use a different set of libraries. The
  3689. libraries could differ in architecture, compiler options, or other
  3690. optimizations.
  3691. There are several examples in the ``meta-skeleton`` layer found in the
  3692. :term:`Source Directory`:
  3693. - :oe_git:`conf/multilib-example.conf </openembedded-core/tree/meta-skeleton/conf/multilib-example.conf>`
  3694. configuration file.
  3695. - :oe_git:`conf/multilib-example2.conf </openembedded-core/tree/meta-skeleton/conf/multilib-example2.conf>`
  3696. configuration file.
  3697. - :oe_git:`recipes-multilib/images/core-image-multilib-example.bb </openembedded-core/tree/meta-skeleton/recipes-multilib/images/core-image-multilib-example.bb>`
  3698. recipe
  3699. Preparing to Use Multilib
  3700. ~~~~~~~~~~~~~~~~~~~~~~~~~
  3701. User-specific requirements drive the Multilib feature. Consequently,
  3702. there is no one "out-of-the-box" configuration that would
  3703. meet your needs.
  3704. In order to enable Multilib, you first need to ensure your recipe is
  3705. extended to support multiple libraries. Many standard recipes are
  3706. already extended and support multiple libraries. You can check in the
  3707. ``meta/conf/multilib.conf`` configuration file in the
  3708. :term:`Source Directory` to see how this is
  3709. done using the
  3710. :term:`BBCLASSEXTEND` variable.
  3711. Eventually, all recipes will be covered and this list will not be
  3712. needed.
  3713. For the most part, the :ref:`Multilib <ref-classes-multilib*>`
  3714. class extension works automatically to
  3715. extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where
  3716. :term:`MLPREFIX` is the particular multilib (e.g. "lib32-" or "lib64-").
  3717. Standard variables such as
  3718. :term:`DEPENDS`,
  3719. :term:`RDEPENDS`,
  3720. :term:`RPROVIDES`,
  3721. :term:`RRECOMMENDS`,
  3722. :term:`PACKAGES`, and
  3723. :term:`PACKAGES_DYNAMIC` are
  3724. automatically extended by the system. If you are extending any manual
  3725. code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure
  3726. those names are extended correctly.
  3727. Using Multilib
  3728. ~~~~~~~~~~~~~~
  3729. After you have set up the recipes, you need to define the actual
  3730. combination of multiple libraries you want to build. You accomplish this
  3731. through your ``local.conf`` configuration file in the
  3732. :term:`Build Directory`. An example
  3733. configuration would be as follows::
  3734. MACHINE = "qemux86-64"
  3735. require conf/multilib.conf
  3736. MULTILIBS = "multilib:lib32"
  3737. DEFAULTTUNE:virtclass-multilib-lib32 = "x86"
  3738. IMAGE_INSTALL:append = "lib32-glib-2.0"
  3739. This example enables an additional library named
  3740. ``lib32`` alongside the normal target packages. When combining these
  3741. "lib32" alternatives, the example uses "x86" for tuning. For information
  3742. on this particular tuning, see
  3743. ``meta/conf/machine/include/ia32/arch-ia32.inc``.
  3744. The example then includes ``lib32-glib-2.0`` in all the images, which
  3745. illustrates one method of including a multiple library dependency. You
  3746. can use a normal image build to include this dependency, for example::
  3747. $ bitbake core-image-sato
  3748. You can also build Multilib packages
  3749. specifically with a command like this::
  3750. $ bitbake lib32-glib-2.0
  3751. Additional Implementation Details
  3752. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3753. There are generic implementation details as well as details that are specific to
  3754. package management systems. Following are implementation details
  3755. that exist regardless of the package management system:
  3756. - The typical convention used for the class extension code as used by
  3757. Multilib assumes that all package names specified in
  3758. :term:`PACKAGES` that contain
  3759. ``${PN}`` have ``${PN}`` at the start of the name. When that
  3760. convention is not followed and ``${PN}`` appears at the middle or the
  3761. end of a name, problems occur.
  3762. - The :term:`TARGET_VENDOR`
  3763. value under Multilib will be extended to "-vendormlmultilib" (e.g.
  3764. "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this
  3765. slightly unwieldy contraction is that any "-" characters in the
  3766. vendor string presently break Autoconf's ``config.sub``, and other
  3767. separators are problematic for different reasons.
  3768. Here are the implementation details for the RPM Package Management System:
  3769. - A unique architecture is defined for the Multilib packages, along
  3770. with creating a unique deploy folder under ``tmp/deploy/rpm`` in the
  3771. :term:`Build Directory`. For
  3772. example, consider ``lib32`` in a ``qemux86-64`` image. The possible
  3773. architectures in the system are "all", "qemux86_64",
  3774. "lib32:qemux86_64", and "lib32:x86".
  3775. - The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM
  3776. packaging. The naming for a normal RPM package and a Multilib RPM
  3777. package in a ``qemux86-64`` system resolves to something similar to
  3778. ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``,
  3779. respectively.
  3780. - When installing a Multilib image, the RPM backend first installs the
  3781. base image and then installs the Multilib libraries.
  3782. - The build system relies on RPM to resolve the identical files in the
  3783. two (or more) Multilib packages.
  3784. Here are the implementation details for the IPK Package Management System:
  3785. - The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK
  3786. packaging. The naming for a normal RPM package and a Multilib IPK
  3787. package in a ``qemux86-64`` system resolves to something like
  3788. ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw:x86.ipk``,
  3789. respectively.
  3790. - The IPK deploy folder is not modified with ``${MLPREFIX}`` because
  3791. packages with and without the Multilib feature can exist in the same
  3792. folder due to the ``${PN}`` differences.
  3793. - IPK defines a sanity check for Multilib installation using certain
  3794. rules for file comparison, overridden, etc.
  3795. Installing Multiple Versions of the Same Library
  3796. ------------------------------------------------
  3797. There are be situations where you need to install and use multiple versions
  3798. of the same library on the same system at the same time. This
  3799. almost always happens when a library API changes and you have
  3800. multiple pieces of software that depend on the separate versions of the
  3801. library. To accommodate these situations, you can install multiple
  3802. versions of the same library in parallel on the same system.
  3803. The process is straightforward as long as the libraries use proper
  3804. versioning. With properly versioned libraries, all you need to do to
  3805. individually specify the libraries is create separate, appropriately
  3806. named recipes where the :term:`PN` part of
  3807. the name includes a portion that differentiates each library version
  3808. (e.g. the major part of the version number). Thus, instead of having a
  3809. single recipe that loads one version of a library (e.g. ``clutter``),
  3810. you provide multiple recipes that result in different versions of the
  3811. libraries you want. As an example, the following two recipes would allow
  3812. the two separate versions of the ``clutter`` library to co-exist on the
  3813. same system:
  3814. .. code-block:: none
  3815. clutter-1.6_1.6.20.bb
  3816. clutter-1.8_1.8.4.bb
  3817. Additionally, if
  3818. you have other recipes that depend on a given library, you need to use
  3819. the :term:`DEPENDS` variable to
  3820. create the dependency. Continuing with the same example, if you want to
  3821. have a recipe depend on the 1.8 version of the ``clutter`` library, use
  3822. the following in your recipe::
  3823. DEPENDS = "clutter-1.8"
  3824. Working with Pre-Built Libraries
  3825. ================================
  3826. Introduction
  3827. -------------
  3828. Some library vendors do not release source code for their software but do
  3829. release pre-built binaries. When shared libraries are built, they should
  3830. be versioned (see `this article
  3831. <https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html>`__
  3832. for some background), but sometimes this is not done.
  3833. To summarize, a versioned library must meet two conditions:
  3834. #. The filename must have the version appended, for example: ``libfoo.so.1.2.3``.
  3835. #. The library must have the ELF tag ``SONAME`` set to the major version
  3836. of the library, for example: ``libfoo.so.1``. You can check this by
  3837. running ``readelf -d filename | grep SONAME``.
  3838. This section shows how to deal with both versioned and unversioned
  3839. pre-built libraries.
  3840. Versioned Libraries
  3841. -------------------
  3842. In this example we work with pre-built libraries for the FT4222H USB I/O chip.
  3843. Libraries are built for several target architecture variants and packaged in
  3844. an archive as follows::
  3845. ├── build-arm-hisiv300
  3846. │   └── libft4222.so.1.4.4.44
  3847. ├── build-arm-v5-sf
  3848. │   └── libft4222.so.1.4.4.44
  3849. ├── build-arm-v6-hf
  3850. │   └── libft4222.so.1.4.4.44
  3851. ├── build-arm-v7-hf
  3852. │   └── libft4222.so.1.4.4.44
  3853. ├── build-arm-v8
  3854. │   └── libft4222.so.1.4.4.44
  3855. ├── build-i386
  3856. │   └── libft4222.so.1.4.4.44
  3857. ├── build-i486
  3858. │   └── libft4222.so.1.4.4.44
  3859. ├── build-mips-eglibc-hf
  3860. │   └── libft4222.so.1.4.4.44
  3861. ├── build-pentium
  3862. │   └── libft4222.so.1.4.4.44
  3863. ├── build-x86_64
  3864. │   └── libft4222.so.1.4.4.44
  3865. ├── examples
  3866. │   ├── get-version.c
  3867. │   ├── i2cm.c
  3868. │   ├── spim.c
  3869. │   └── spis.c
  3870. ├── ftd2xx.h
  3871. ├── install4222.sh
  3872. ├── libft4222.h
  3873. ├── ReadMe.txt
  3874. └── WinTypes.h
  3875. To write a recipe to use such a library in your system:
  3876. - The vendor will probably have a proprietary licence, so set
  3877. :term:`LICENSE_FLAGS` in your recipe.
  3878. - The vendor provides a tarball containing libraries so set :term:`SRC_URI`
  3879. appropriately.
  3880. - Set :term:`COMPATIBLE_HOST` so that the recipe cannot be used with an
  3881. unsupported architecture. In the following example, we only support the 32
  3882. and 64 bit variants of the ``x86`` architecture.
  3883. - As the vendor provides versioned libraries, we can use ``oe_soinstall``
  3884. from :ref:`ref-classes-utils` to install the shared library and create
  3885. symbolic links. If the vendor does not do this, we need to follow the
  3886. non-versioned library guidelines in the next section.
  3887. - As the vendor likely used :term:`LDFLAGS` different from those in your Yocto
  3888. Project build, disable the corresponding checks by adding ``ldflags``
  3889. to :term:`INSANE_SKIP`.
  3890. - The vendor will typically ship release builds without debugging symbols.
  3891. Avoid errors by preventing the packaging task from stripping out the symbols
  3892. and adding them to a separate debug package. This is done by setting the
  3893. ``INHIBIT_`` flags shown below.
  3894. The complete recipe would look like this::
  3895. SUMMARY = "FTDI FT4222H Library"
  3896. SECTION = "libs"
  3897. LICENSE_FLAGS = "ftdi"
  3898. LICENSE = "CLOSED"
  3899. COMPATIBLE_HOST = "(i.86|x86_64).*-linux"
  3900. # Sources available in a .tgz file in .zip archive
  3901. # at https://ftdichip.com/wp-content/uploads/2021/01/libft4222-linux-1.4.4.44.zip
  3902. # Found on https://ftdichip.com/software-examples/ft4222h-software-examples/
  3903. # Since dealing with this particular type of archive is out of topic here,
  3904. # we use a local link.
  3905. SRC_URI = "file://libft4222-linux-${PV}.tgz"
  3906. S = "${WORKDIR}"
  3907. ARCH_DIR:x86-64 = "build-x86_64"
  3908. ARCH_DIR:i586 = "build-i386"
  3909. ARCH_DIR:i686 = "build-i386"
  3910. INSANE_SKIP:${PN} = "ldflags"
  3911. INHIBIT_PACKAGE_STRIP = "1"
  3912. INHIBIT_SYSROOT_STRIP = "1"
  3913. INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
  3914. do_install () {
  3915. install -m 0755 -d ${D}${libdir}
  3916. oe_soinstall ${S}/${ARCH_DIR}/libft4222.so.${PV} ${D}${libdir}
  3917. install -d ${D}${includedir}
  3918. install -m 0755 ${S}/*.h ${D}${includedir}
  3919. }
  3920. If the precompiled binaries are not statically linked and have dependencies on
  3921. other libraries, then by adding those libraries to :term:`DEPENDS`, the linking
  3922. can be examined and the appropriate :term:`RDEPENDS` automatically added.
  3923. Non-Versioned Libraries
  3924. -----------------------
  3925. Some Background
  3926. ~~~~~~~~~~~~~~~
  3927. Libraries in Linux systems are generally versioned so that it is possible
  3928. to have multiple versions of the same library installed, which eases upgrades
  3929. and support for older software. For example, suppose that in a versioned
  3930. library, an actual library is called ``libfoo.so.1.2``, a symbolic link named
  3931. ``libfoo.so.1`` points to ``libfoo.so.1.2``, and a symbolic link named
  3932. ``libfoo.so`` points to ``libfoo.so.1.2``. Given these conditions, when you
  3933. link a binary against a library, you typically provide the unversioned file
  3934. name (i.e. ``-lfoo`` to the linker). However, the linker follows the symbolic
  3935. link and actually links against the versioned filename. The unversioned symbolic
  3936. link is only used at development time. Consequently, the library is packaged
  3937. along with the headers in the development package ``${PN}-dev`` along with the
  3938. actual library and versioned symbolic links in ``${PN}``. Because versioned
  3939. libraries are far more common than unversioned libraries, the default packaging
  3940. rules assume versioned libraries.
  3941. Yocto Library Packaging Overview
  3942. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3943. It follows that packaging an unversioned library requires a bit of work in the
  3944. recipe. By default, ``libfoo.so`` gets packaged into ``${PN}-dev``, which
  3945. triggers a QA warning that a non-symlink library is in a ``-dev`` package,
  3946. and binaries in the same recipe link to the library in ``${PN}-dev``,
  3947. which triggers more QA warnings. To solve this problem, you need to package the
  3948. unversioned library into ``${PN}`` where it belongs. The following are the abridged
  3949. default :term:`FILES` variables in ``bitbake.conf``::
  3950. SOLIBS = ".so.*"
  3951. SOLIBSDEV = ".so"
  3952. FILES_${PN} = "... ${libdir}/lib*${SOLIBS} ..."
  3953. FILES_SOLIBSDEV ?= "... ${libdir}/lib*${SOLIBSDEV} ..."
  3954. FILES_${PN}-dev = "... ${FILES_SOLIBSDEV} ..."
  3955. :term:`SOLIBS` defines a pattern that matches real shared object libraries.
  3956. :term:`SOLIBSDEV` matches the development form (unversioned symlink). These two
  3957. variables are then used in ``FILES:${PN}`` and ``FILES:${PN}-dev``, which puts
  3958. the real libraries into ``${PN}`` and the unversioned symbolic link into ``${PN}-dev``.
  3959. To package unversioned libraries, you need to modify the variables in the recipe
  3960. as follows::
  3961. SOLIBS = ".so"
  3962. FILES_SOLIBSDEV = ""
  3963. The modifications cause the ``.so`` file to be the real library
  3964. and unset :term:`FILES_SOLIBSDEV` so that no libraries get packaged into
  3965. ``${PN}-dev``. The changes are required because unless :term:`PACKAGES` is changed,
  3966. ``${PN}-dev`` collects files before `${PN}`. ``${PN}-dev`` must not collect any of
  3967. the files you want in ``${PN}``.
  3968. Finally, loadable modules, essentially unversioned libraries that are linked
  3969. at runtime using ``dlopen()`` instead of at build time, should generally be
  3970. installed in a private directory. However, if they are installed in ``${libdir}``,
  3971. then the modules can be treated as unversioned libraries.
  3972. Example
  3973. ~~~~~~~
  3974. The example below installs an unversioned x86-64 pre-built library named
  3975. ``libfoo.so``. The :term:`COMPATIBLE_HOST` variable limits recipes to the
  3976. x86-64 architecture while the :term:`INSANE_SKIP`, :term:`INHIBIT_PACKAGE_STRIP`
  3977. and :term:`INHIBIT_SYSROOT_STRIP` variables are all set as in the above
  3978. versioned library example. The "magic" is setting the :term:`SOLIBS` and
  3979. :term:`FILES_SOLIBSDEV` variables as explained above::
  3980. SUMMARY = "libfoo sample recipe"
  3981. SECTION = "libs"
  3982. LICENSE = "CLOSED"
  3983. SRC_URI = "file://libfoo.so"
  3984. COMPATIBLE_HOST = "x86_64.*-linux"
  3985. INSANE_SKIP:${PN} = "ldflags"
  3986. INHIBIT_PACKAGE_STRIP = "1"
  3987. INHIBIT_SYSROOT_STRIP = "1"
  3988. SOLIBS = ".so"
  3989. FILES_SOLIBSDEV = ""
  3990. do_install () {
  3991. install -d ${D}${libdir}
  3992. install -m 0755 ${WORKDIR}/libfoo.so ${D}${libdir}
  3993. }
  3994. Using x32 psABI
  3995. ===============
  3996. x32 processor-specific Application Binary Interface (`x32
  3997. psABI <https://software.intel.com/en-us/node/628948>`__) is a native
  3998. 32-bit processor-specific ABI for Intel 64 (x86-64) architectures. An
  3999. ABI defines the calling conventions between functions in a processing
  4000. environment. The interface determines what registers are used and what
  4001. the sizes are for various C data types.
  4002. Some processing environments prefer using 32-bit applications even when
  4003. running on Intel 64-bit platforms. Consider the i386 psABI, which is a
  4004. very old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not
  4005. provide efficient use and access of the Intel 64-bit processor
  4006. resources, leaving the system underutilized. Now consider the x86_64
  4007. psABI. This ABI is newer and uses 64-bits for data sizes and program
  4008. pointers. The extra bits increase the footprint size of the programs,
  4009. libraries, and also increases the memory and file system size
  4010. requirements. Executing under the x32 psABI enables user programs to
  4011. utilize CPU and system resources more efficiently while keeping the
  4012. memory footprint of the applications low. Extra bits are used for
  4013. registers but not for addressing mechanisms.
  4014. The Yocto Project supports the final specifications of x32 psABI as
  4015. follows:
  4016. - You can create packages and images in x32 psABI format on x86_64
  4017. architecture targets.
  4018. - You can successfully build recipes with the x32 toolchain.
  4019. - You can create and boot ``core-image-minimal`` and
  4020. ``core-image-sato`` images.
  4021. - There is RPM Package Manager (RPM) support for x32 binaries.
  4022. - There is support for large images.
  4023. To use the x32 psABI, you need to edit your ``conf/local.conf``
  4024. configuration file as follows::
  4025. MACHINE = "qemux86-64"
  4026. DEFAULTTUNE = "x86-64-x32"
  4027. baselib = "${@d.getVar('BASE_LIB:tune-' + (d.getVar('DEFAULTTUNE') \
  4028. or 'INVALID')) or 'lib'}"
  4029. Once you have set
  4030. up your configuration file, use BitBake to build an image that supports
  4031. the x32 psABI. Here is an example::
  4032. $ bitbake core-image-sato
  4033. Enabling GObject Introspection Support
  4034. ======================================
  4035. `GObject introspection <https://gi.readthedocs.io/en/latest/>`__
  4036. is the standard mechanism for accessing GObject-based software from
  4037. runtime environments. GObject is a feature of the GLib library that
  4038. provides an object framework for the GNOME desktop and related software.
  4039. GObject Introspection adds information to GObject that allows objects
  4040. created within it to be represented across different programming
  4041. languages. If you want to construct GStreamer pipelines using Python, or
  4042. control UPnP infrastructure using Javascript and GUPnP, GObject
  4043. introspection is the only way to do it.
  4044. This section describes the Yocto Project support for generating and
  4045. packaging GObject introspection data. GObject introspection data is a
  4046. description of the API provided by libraries built on top of the GLib
  4047. framework, and, in particular, that framework's GObject mechanism.
  4048. GObject Introspection Repository (GIR) files go to ``-dev`` packages,
  4049. ``typelib`` files go to main packages as they are packaged together with
  4050. libraries that are introspected.
  4051. The data is generated when building such a library, by linking the
  4052. library with a small executable binary that asks the library to describe
  4053. itself, and then executing the binary and processing its output.
  4054. Generating this data in a cross-compilation environment is difficult
  4055. because the library is produced for the target architecture, but its
  4056. code needs to be executed on the build host. This problem is solved with
  4057. the OpenEmbedded build system by running the code through QEMU, which
  4058. allows precisely that. Unfortunately, QEMU does not always work
  4059. perfectly as mentioned in the ":ref:`dev-manual/common-tasks:known issues`"
  4060. section.
  4061. Enabling the Generation of Introspection Data
  4062. ---------------------------------------------
  4063. Enabling the generation of introspection data (GIR files) in your
  4064. library package involves the following:
  4065. 1. Inherit the
  4066. :ref:`gobject-introspection <ref-classes-gobject-introspection>`
  4067. class.
  4068. 2. Make sure introspection is not disabled anywhere in the recipe or
  4069. from anything the recipe includes. Also, make sure that
  4070. "gobject-introspection-data" is not in
  4071. :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
  4072. and that "qemu-usermode" is not in
  4073. :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
  4074. In either of these conditions, nothing will happen.
  4075. 3. Try to build the recipe. If you encounter build errors that look like
  4076. something is unable to find ``.so`` libraries, check where these
  4077. libraries are located in the source tree and add the following to the
  4078. recipe::
  4079. GIR_EXTRA_LIBS_PATH = "${B}/something/.libs"
  4080. .. note::
  4081. See recipes in the ``oe-core`` repository that use that
  4082. :term:`GIR_EXTRA_LIBS_PATH` variable as an example.
  4083. 4. Look for any other errors, which probably mean that introspection
  4084. support in a package is not entirely standard, and thus breaks down
  4085. in a cross-compilation environment. For such cases, custom-made fixes
  4086. are needed. A good place to ask and receive help in these cases is
  4087. the :ref:`Yocto Project mailing
  4088. lists <resources-mailinglist>`.
  4089. .. note::
  4090. Using a library that no longer builds against the latest Yocto
  4091. Project release and prints introspection related errors is a good
  4092. candidate for the previous procedure.
  4093. Disabling the Generation of Introspection Data
  4094. ----------------------------------------------
  4095. You might find that you do not want to generate introspection data. Or,
  4096. perhaps QEMU does not work on your build host and target architecture
  4097. combination. If so, you can use either of the following methods to
  4098. disable GIR file generations:
  4099. - Add the following to your distro configuration::
  4100. DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
  4101. Adding this statement disables generating introspection data using
  4102. QEMU but will still enable building introspection tools and libraries
  4103. (i.e. building them does not require the use of QEMU).
  4104. - Add the following to your machine configuration::
  4105. MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
  4106. Adding this statement disables the use of QEMU when building packages for your
  4107. machine. Currently, this feature is used only by introspection
  4108. recipes and has the same effect as the previously described option.
  4109. .. note::
  4110. Future releases of the Yocto Project might have other features
  4111. affected by this option.
  4112. If you disable introspection data, you can still obtain it through other
  4113. means such as copying the data from a suitable sysroot, or by generating
  4114. it on the target hardware. The OpenEmbedded build system does not
  4115. currently provide specific support for these techniques.
  4116. Testing that Introspection Works in an Image
  4117. --------------------------------------------
  4118. Use the following procedure to test if generating introspection data is
  4119. working in an image:
  4120. 1. Make sure that "gobject-introspection-data" is not in
  4121. :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
  4122. and that "qemu-usermode" is not in
  4123. :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
  4124. 2. Build ``core-image-sato``.
  4125. 3. Launch a Terminal and then start Python in the terminal.
  4126. 4. Enter the following in the terminal::
  4127. >>> from gi.repository import GLib
  4128. >>> GLib.get_host_name()
  4129. 5. For something a little more advanced, enter the following see:
  4130. https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html
  4131. Known Issues
  4132. ------------
  4133. Here are know issues in GObject Introspection Support:
  4134. - ``qemu-ppc64`` immediately crashes. Consequently, you cannot build
  4135. introspection data on that architecture.
  4136. - x32 is not supported by QEMU. Consequently, introspection data is
  4137. disabled.
  4138. - musl causes transient GLib binaries to crash on assertion failures.
  4139. Consequently, generating introspection data is disabled.
  4140. - Because QEMU is not able to run the binaries correctly, introspection
  4141. is disabled for some specific packages under specific architectures
  4142. (e.g. ``gcr``, ``libsecret``, and ``webkit``).
  4143. - QEMU usermode might not work properly when running 64-bit binaries
  4144. under 32-bit host machines. In particular, "qemumips64" is known to
  4145. not work under i686.
  4146. Optionally Using an External Toolchain
  4147. ======================================
  4148. You might want to use an external toolchain as part of your development.
  4149. If this is the case, the fundamental steps you need to accomplish are as
  4150. follows:
  4151. - Understand where the installed toolchain resides. For cases where you
  4152. need to build the external toolchain, you would need to take separate
  4153. steps to build and install the toolchain.
  4154. - Make sure you add the layer that contains the toolchain to your
  4155. ``bblayers.conf`` file through the
  4156. :term:`BBLAYERS` variable.
  4157. - Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file
  4158. to the location in which you installed the toolchain.
  4159. A good example of an external toolchain used with the Yocto Project is
  4160. Mentor Graphics Sourcery G++ Toolchain. You can see information on how
  4161. to use that particular layer in the ``README`` file at
  4162. https://github.com/MentorEmbedded/meta-sourcery/. You can find
  4163. further information by reading about the
  4164. :term:`TCMODE` variable in the Yocto
  4165. Project Reference Manual's variable glossary.
  4166. Creating Partitioned Images Using Wic
  4167. =====================================
  4168. Creating an image for a particular hardware target using the
  4169. OpenEmbedded build system does not necessarily mean you can boot that
  4170. image as is on your device. Physical devices accept and boot images in
  4171. various ways depending on the specifics of the device. Usually,
  4172. information about the hardware can tell you what image format the device
  4173. requires. Should your device require multiple partitions on an SD card,
  4174. flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to
  4175. create the properly partitioned image.
  4176. The ``wic`` command generates partitioned images from existing
  4177. OpenEmbedded build artifacts. Image generation is driven by partitioning
  4178. commands contained in an OpenEmbedded kickstart file (``.wks``)
  4179. specified either directly on the command line or as one of a selection
  4180. of canned kickstart files as shown with the ``wic list images`` command
  4181. in the
  4182. ":ref:`dev-manual/common-tasks:generate an image using an existing kickstart file`"
  4183. section. When you apply the command to a given set of build artifacts, the
  4184. result is an image or set of images that can be directly written onto media and
  4185. used on a particular system.
  4186. .. note::
  4187. For a kickstart file reference, see the
  4188. ":ref:`ref-manual/kickstart:openembedded kickstart (\`\`.wks\`\`) reference`"
  4189. Chapter in the Yocto Project Reference Manual.
  4190. The ``wic`` command and the infrastructure it is based on is by
  4191. definition incomplete. The purpose of the command is to allow the
  4192. generation of customized images, and as such, was designed to be
  4193. completely extensible through a plugin interface. See the
  4194. ":ref:`dev-manual/common-tasks:using the wic plugin interface`" section
  4195. for information on these plugins.
  4196. This section provides some background information on Wic, describes what
  4197. you need to have in place to run the tool, provides instruction on how
  4198. to use the Wic utility, provides information on using the Wic plugins
  4199. interface, and provides several examples that show how to use Wic.
  4200. Background
  4201. ----------
  4202. This section provides some background on the Wic utility. While none of
  4203. this information is required to use Wic, you might find it interesting.
  4204. - The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The
  4205. "oe" diphthong in "oeic" was promoted to the letter "w", because
  4206. "oeic" is both difficult to remember and to pronounce.
  4207. - Wic is loosely based on the Meego Image Creator (``mic``) framework.
  4208. The Wic implementation has been heavily modified to make direct use
  4209. of OpenEmbedded build artifacts instead of package installation and
  4210. configuration, which are already incorporated within the OpenEmbedded
  4211. artifacts.
  4212. - Wic is a completely independent standalone utility that initially
  4213. provides easier-to-use and more flexible replacements for an existing
  4214. functionality in OE-Core's
  4215. :ref:`image-live <ref-classes-image-live>`
  4216. class. The difference between Wic and those examples is that with Wic
  4217. the functionality of those scripts is implemented by a
  4218. general-purpose partitioning language, which is based on Redhat
  4219. kickstart syntax.
  4220. Requirements
  4221. ------------
  4222. In order to use the Wic utility with the OpenEmbedded Build system, your
  4223. system needs to meet the following requirements:
  4224. - The Linux distribution on your development host must support the
  4225. Yocto Project. See the ":ref:`detailed-supported-distros`"
  4226. section in the Yocto Project Reference Manual for the list of
  4227. distributions that support the Yocto Project.
  4228. - The standard system utilities, such as ``cp``, must be installed on
  4229. your development host system.
  4230. - You must have sourced the build environment setup script (i.e.
  4231. :ref:`structure-core-script`) found in the
  4232. :term:`Build Directory`.
  4233. - You need to have the build artifacts already available, which
  4234. typically means that you must have already created an image using the
  4235. OpenEmbedded build system (e.g. ``core-image-minimal``). While it
  4236. might seem redundant to generate an image in order to create an image
  4237. using Wic, the current version of Wic requires the artifacts in the
  4238. form generated by the OpenEmbedded build system.
  4239. - You must build several native tools, which are built to run on the
  4240. build system::
  4241. $ bitbake parted-native dosfstools-native mtools-native
  4242. - Include "wic" as part of the
  4243. :term:`IMAGE_FSTYPES`
  4244. variable.
  4245. - Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>`
  4246. as part of the :term:`WKS_FILE` variable
  4247. Getting Help
  4248. ------------
  4249. You can get general help for the ``wic`` command by entering the ``wic``
  4250. command by itself or by entering the command with a help argument as
  4251. follows::
  4252. $ wic -h
  4253. $ wic --help
  4254. $ wic help
  4255. Currently, Wic supports seven commands: ``cp``, ``create``, ``help``,
  4256. ``list``, ``ls``, ``rm``, and ``write``. You can get help for all these
  4257. commands except "help" by using the following form::
  4258. $ wic help command
  4259. For example, the following command returns help for the ``write``
  4260. command::
  4261. $ wic help write
  4262. Wic supports help for three topics: ``overview``, ``plugins``, and
  4263. ``kickstart``. You can get help for any topic using the following form::
  4264. $ wic help topic
  4265. For example, the following returns overview help for Wic::
  4266. $ wic help overview
  4267. There is one additional level of help for Wic. You can get help on
  4268. individual images through the ``list`` command. You can use the ``list``
  4269. command to return the available Wic images as follows::
  4270. $ wic list images
  4271. genericx86 Create an EFI disk image for genericx86*
  4272. edgerouter Create SD card image for Edgerouter
  4273. beaglebone-yocto Create SD card image for Beaglebone
  4274. qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
  4275. systemd-bootdisk Create an EFI disk image with systemd-boot
  4276. mkhybridiso Create a hybrid ISO image
  4277. mkefidisk Create an EFI disk image
  4278. sdimage-bootpart Create SD card image with a boot partition
  4279. directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
  4280. directdisk Create a 'pcbios' direct disk image
  4281. directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
  4282. qemuriscv Create qcow2 image for RISC-V QEMU machines
  4283. directdisk-gpt Create a 'pcbios' direct disk image
  4284. efi-bootdisk
  4285. Once you know the list of available
  4286. Wic images, you can use ``help`` with the command to get help on a
  4287. particular image. For example, the following command returns help on the
  4288. "beaglebone-yocto" image::
  4289. $ wic list beaglebone-yocto help
  4290. Creates a partitioned SD card image for Beaglebone.
  4291. Boot files are located in the first vfat partition.
  4292. Operational Modes
  4293. -----------------
  4294. You can use Wic in two different modes, depending on how much control
  4295. you need for specifying the OpenEmbedded build artifacts that are used
  4296. for creating the image: Raw and Cooked:
  4297. - *Raw Mode:* You explicitly specify build artifacts through Wic
  4298. command-line arguments.
  4299. - *Cooked Mode:* The current
  4300. :term:`MACHINE` setting and image
  4301. name are used to automatically locate and provide the build
  4302. artifacts. You just supply a kickstart file and the name of the image
  4303. from which to use artifacts.
  4304. Regardless of the mode you use, you need to have the build artifacts
  4305. ready and available.
  4306. Raw Mode
  4307. ~~~~~~~~
  4308. Running Wic in raw mode allows you to specify all the partitions through
  4309. the ``wic`` command line. The primary use for raw mode is if you have
  4310. built your kernel outside of the Yocto Project
  4311. :term:`Build Directory`. In other words, you
  4312. can point to arbitrary kernel, root filesystem locations, and so forth.
  4313. Contrast this behavior with cooked mode where Wic looks in the Build
  4314. Directory (e.g. ``tmp/deploy/images/``\ machine).
  4315. The general form of the ``wic`` command in raw mode is::
  4316. $ wic create wks_file options ...
  4317. Where:
  4318. wks_file:
  4319. An OpenEmbedded kickstart file. You can provide
  4320. your own custom file or use a file from a set of
  4321. existing files as described by further options.
  4322. optional arguments:
  4323. -h, --help show this help message and exit
  4324. -o OUTDIR, --outdir OUTDIR
  4325. name of directory to create image in
  4326. -e IMAGE_NAME, --image-name IMAGE_NAME
  4327. name of the image to use the artifacts from e.g. core-
  4328. image-sato
  4329. -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR
  4330. path to the /rootfs dir to use as the .wks rootfs
  4331. source
  4332. -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR
  4333. path to the dir containing the boot artifacts (e.g.
  4334. /EFI or /syslinux dirs) to use as the .wks bootimg
  4335. source
  4336. -k KERNEL_DIR, --kernel-dir KERNEL_DIR
  4337. path to the dir containing the kernel to use in the
  4338. .wks bootimg
  4339. -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT
  4340. path to the native sysroot containing the tools to use
  4341. to build the image
  4342. -s, --skip-build-check
  4343. skip the build check
  4344. -f, --build-rootfs build rootfs
  4345. -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
  4346. compress image with specified compressor
  4347. -m, --bmap generate .bmap
  4348. --no-fstab-update Do not change fstab file.
  4349. -v VARS_DIR, --vars VARS_DIR
  4350. directory with <image>.env files that store bitbake
  4351. variables
  4352. -D, --debug output debug information
  4353. .. note::
  4354. You do not need root privileges to run Wic. In fact, you should not
  4355. run as root when using the utility.
  4356. Cooked Mode
  4357. ~~~~~~~~~~~
  4358. Running Wic in cooked mode leverages off artifacts in the Build
  4359. Directory. In other words, you do not have to specify kernel or root
  4360. filesystem locations as part of the command. All you need to provide is
  4361. a kickstart file and the name of the image from which to use artifacts
  4362. by using the "-e" option. Wic looks in the Build Directory (e.g.
  4363. ``tmp/deploy/images/``\ machine) for artifacts.
  4364. The general form of the ``wic`` command using Cooked Mode is as follows::
  4365. $ wic create wks_file -e IMAGE_NAME
  4366. Where:
  4367. wks_file:
  4368. An OpenEmbedded kickstart file. You can provide
  4369. your own custom file or use a file from a set of
  4370. existing files provided with the Yocto Project
  4371. release.
  4372. required argument:
  4373. -e IMAGE_NAME, --image-name IMAGE_NAME
  4374. name of the image to use the artifacts from e.g. core-
  4375. image-sato
  4376. Using an Existing Kickstart File
  4377. --------------------------------
  4378. If you do not want to create your own kickstart file, you can use an
  4379. existing file provided by the Wic installation. As shipped, kickstart
  4380. files can be found in the :ref:`overview-manual/development-environment:yocto project source repositories` in the
  4381. following two locations::
  4382. poky/meta-yocto-bsp/wic
  4383. poky/scripts/lib/wic/canned-wks
  4384. Use the following command to list the available kickstart files::
  4385. $ wic list images
  4386. genericx86 Create an EFI disk image for genericx86*
  4387. beaglebone-yocto Create SD card image for Beaglebone
  4388. edgerouter Create SD card image for Edgerouter
  4389. qemux86-directdisk Create a QEMU machine 'pcbios' direct disk image
  4390. directdisk-gpt Create a 'pcbios' direct disk image
  4391. mkefidisk Create an EFI disk image
  4392. directdisk Create a 'pcbios' direct disk image
  4393. systemd-bootdisk Create an EFI disk image with systemd-boot
  4394. mkhybridiso Create a hybrid ISO image
  4395. sdimage-bootpart Create SD card image with a boot partition
  4396. directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
  4397. directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
  4398. When you use an existing file, you
  4399. do not have to use the ``.wks`` extension. Here is an example in Raw
  4400. Mode that uses the ``directdisk`` file::
  4401. $ wic create directdisk -r rootfs_dir -b bootimg_dir \
  4402. -k kernel_dir -n native_sysroot
  4403. Here are the actual partition language commands used in the
  4404. ``genericx86.wks`` file to generate an image::
  4405. # short-description: Create an EFI disk image for genericx86*
  4406. # long-description: Creates a partitioned EFI disk image for genericx86* machines
  4407. part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
  4408. part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
  4409. part swap --ondisk sda --size 44 --label swap1 --fstype=swap
  4410. bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
  4411. Using the Wic Plugin Interface
  4412. ------------------------------
  4413. You can extend and specialize Wic functionality by using Wic plugins.
  4414. This section explains the Wic plugin interface.
  4415. .. note::
  4416. Wic plugins consist of "source" and "imager" plugins. Imager plugins
  4417. are beyond the scope of this section.
  4418. Source plugins provide a mechanism to customize partition content during
  4419. the Wic image generation process. You can use source plugins to map
  4420. values that you specify using ``--source`` commands in kickstart files
  4421. (i.e. ``*.wks``) to a plugin implementation used to populate a given
  4422. partition.
  4423. .. note::
  4424. If you use plugins that have build-time dependencies (e.g. native
  4425. tools, bootloaders, and so forth) when building a Wic image, you need
  4426. to specify those dependencies using the :term:`WKS_FILE_DEPENDS`
  4427. variable.
  4428. Source plugins are subclasses defined in plugin files. As shipped, the
  4429. Yocto Project provides several plugin files. You can see the source
  4430. plugin files that ship with the Yocto Project
  4431. :yocto_git:`here </poky/tree/scripts/lib/wic/plugins/source>`.
  4432. Each of these plugin files contains source plugins that are designed to
  4433. populate a specific Wic image partition.
  4434. Source plugins are subclasses of the ``SourcePlugin`` class, which is
  4435. defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example,
  4436. the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py``
  4437. file is a subclass of the ``SourcePlugin`` class, which is found in the
  4438. ``pluginbase.py`` file.
  4439. You can also implement source plugins in a layer outside of the Source
  4440. Repositories (external layer). To do so, be sure that your plugin files
  4441. are located in a directory whose path is
  4442. ``scripts/lib/wic/plugins/source/`` within your external layer. When the
  4443. plugin files are located there, the source plugins they contain are made
  4444. available to Wic.
  4445. When the Wic implementation needs to invoke a partition-specific
  4446. implementation, it looks for the plugin with the same name as the
  4447. ``--source`` parameter used in the kickstart file given to that
  4448. partition. For example, if the partition is set up using the following
  4449. command in a kickstart file::
  4450. part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
  4451. The methods defined as class
  4452. members of the matching source plugin (i.e. ``bootimg-pcbios``) in the
  4453. ``bootimg-pcbios.py`` plugin file are used.
  4454. To be more concrete, here is the corresponding plugin definition from
  4455. the ``bootimg-pcbios.py`` file for the previous command along with an
  4456. example method called by the Wic implementation when it needs to prepare
  4457. a partition using an implementation-specific function::
  4458. .
  4459. .
  4460. .
  4461. class BootimgPcbiosPlugin(SourcePlugin):
  4462. """
  4463. Create MBR boot partition and install syslinux on it.
  4464. """
  4465. name = 'bootimg-pcbios'
  4466. .
  4467. .
  4468. .
  4469. @classmethod
  4470. def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
  4471. oe_builddir, bootimg_dir, kernel_dir,
  4472. rootfs_dir, native_sysroot):
  4473. """
  4474. Called to do the actual content population for a partition i.e. it
  4475. 'prepares' the partition to be incorporated into the image.
  4476. In this case, prepare content for legacy bios boot partition.
  4477. """
  4478. .
  4479. .
  4480. .
  4481. If a
  4482. subclass (plugin) itself does not implement a particular function, Wic
  4483. locates and uses the default version in the superclass. It is for this
  4484. reason that all source plugins are derived from the ``SourcePlugin``
  4485. class.
  4486. The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines
  4487. a set of methods that source plugins can implement or override. Any
  4488. plugins (subclass of ``SourcePlugin``) that do not implement a
  4489. particular method inherit the implementation of the method from the
  4490. ``SourcePlugin`` class. For more information, see the ``SourcePlugin``
  4491. class in the ``pluginbase.py`` file for details:
  4492. The following list describes the methods implemented in the
  4493. ``SourcePlugin`` class:
  4494. - ``do_prepare_partition()``: Called to populate a partition with
  4495. actual content. In other words, the method prepares the final
  4496. partition image that is incorporated into the disk image.
  4497. - ``do_configure_partition()``: Called before
  4498. ``do_prepare_partition()`` to create custom configuration files for a
  4499. partition (e.g. syslinux or grub configuration files).
  4500. - ``do_install_disk()``: Called after all partitions have been
  4501. prepared and assembled into a disk image. This method provides a hook
  4502. to allow finalization of a disk image (e.g. writing an MBR).
  4503. - ``do_stage_partition()``: Special content-staging hook called
  4504. before ``do_prepare_partition()``. This method is normally empty.
  4505. Typically, a partition just uses the passed-in parameters (e.g. the
  4506. unmodified value of ``bootimg_dir``). However, in some cases, things
  4507. might need to be more tailored. As an example, certain files might
  4508. additionally need to be taken from ``bootimg_dir + /boot``. This hook
  4509. allows those files to be staged in a customized fashion.
  4510. .. note::
  4511. ``get_bitbake_var()`` allows you to access non-standard variables that
  4512. you might want to use for this behavior.
  4513. You can extend the source plugin mechanism. To add more hooks, create
  4514. more source plugin methods within ``SourcePlugin`` and the corresponding
  4515. derived subclasses. The code that calls the plugin methods uses the
  4516. ``plugin.get_source_plugin_methods()`` function to find the method or
  4517. methods needed by the call. Retrieval of those methods is accomplished
  4518. by filling up a dict with keys that contain the method names of
  4519. interest. On success, these will be filled in with the actual methods.
  4520. See the Wic implementation for examples and details.
  4521. Wic Examples
  4522. ------------
  4523. This section provides several examples that show how to use the Wic
  4524. utility. All the examples assume the list of requirements in the
  4525. ":ref:`dev-manual/common-tasks:requirements`" section have been met. The
  4526. examples assume the previously generated image is
  4527. ``core-image-minimal``.
  4528. Generate an Image using an Existing Kickstart File
  4529. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4530. This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart
  4531. file::
  4532. $ wic create mkefidisk -e core-image-minimal
  4533. INFO: Building wic-tools...
  4534. .
  4535. .
  4536. .
  4537. INFO: The new image(s) can be found here:
  4538. ./mkefidisk-201804191017-sda.direct
  4539. The following build artifacts were used to create the image(s):
  4540. ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
  4541. BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
  4542. KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86
  4543. NATIVE_SYSROOT: /home/stephano/yocto/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4544. INFO: The image(s) were created using OE kickstart file:
  4545. /home/stephano/yocto/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
  4546. The previous example shows the easiest way to create an image by running
  4547. in cooked mode and supplying a kickstart file and the "-e" option to
  4548. point to the existing build artifacts. Your ``local.conf`` file needs to
  4549. have the :term:`MACHINE` variable set
  4550. to the machine you are using, which is "qemux86" in this example.
  4551. Once the image builds, the output provides image location, artifact use,
  4552. and kickstart file information.
  4553. .. note::
  4554. You should always verify the details provided in the output to make
  4555. sure that the image was indeed created exactly as expected.
  4556. Continuing with the example, you can now write the image from the Build
  4557. Directory onto a USB stick, or whatever media for which you built your
  4558. image, and boot from the media. You can write the image by using
  4559. ``bmaptool`` or ``dd``::
  4560. $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX
  4561. or ::
  4562. $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX
  4563. .. note::
  4564. For more information on how to use the ``bmaptool``
  4565. to flash a device with an image, see the
  4566. ":ref:`dev-manual/common-tasks:flashing images using \`\`bmaptool\`\``"
  4567. section.
  4568. Using a Modified Kickstart File
  4569. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4570. Because partitioned image creation is driven by the kickstart file, it
  4571. is easy to affect image creation by changing the parameters in the file.
  4572. This next example demonstrates that through modification of the
  4573. ``directdisk-gpt`` kickstart file.
  4574. As mentioned earlier, you can use the command ``wic list images`` to
  4575. show the list of existing kickstart files. The directory in which the
  4576. ``directdisk-gpt.wks`` file resides is
  4577. ``scripts/lib/image/canned-wks/``, which is located in the
  4578. :term:`Source Directory` (e.g. ``poky``).
  4579. Because available files reside in this directory, you can create and add
  4580. your own custom files to the directory. Subsequent use of the
  4581. ``wic list images`` command would then include your kickstart files.
  4582. In this example, the existing ``directdisk-gpt`` file already does most
  4583. of what is needed. However, for the hardware in this example, the image
  4584. will need to boot from ``sdb`` instead of ``sda``, which is what the
  4585. ``directdisk-gpt`` kickstart file uses.
  4586. The example begins by making a copy of the ``directdisk-gpt.wks`` file
  4587. in the ``scripts/lib/image/canned-wks`` directory and then by changing
  4588. the lines that specify the target disk from which to boot.
  4589. ::
  4590. $ cp /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
  4591. /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
  4592. Next, the example modifies the ``directdisksdb-gpt.wks`` file and
  4593. changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The
  4594. example changes the following two lines and leaves the remaining lines
  4595. untouched::
  4596. part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
  4597. part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
  4598. Once the lines are changed, the
  4599. example generates the ``directdisksdb-gpt`` image. The command points
  4600. the process at the ``core-image-minimal`` artifacts for the Next Unit of
  4601. Computing (nuc) :term:`MACHINE` the
  4602. ``local.conf``.
  4603. ::
  4604. $ wic create directdisksdb-gpt -e core-image-minimal
  4605. INFO: Building wic-tools...
  4606. .
  4607. .
  4608. .
  4609. Initialising tasks: 100% |#######################################| Time: 0:00:01
  4610. NOTE: Executing SetScene Tasks
  4611. NOTE: Executing RunQueue Tasks
  4612. NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
  4613. INFO: Creating image(s)...
  4614. INFO: The new image(s) can be found here:
  4615. ./directdisksdb-gpt-201710090938-sdb.direct
  4616. The following build artifacts were used to create the image(s):
  4617. ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
  4618. BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
  4619. KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86
  4620. NATIVE_SYSROOT: /home/stephano/yocto/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4621. INFO: The image(s) were created using OE kickstart file:
  4622. /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
  4623. Continuing with the example, you can now directly ``dd`` the image to a
  4624. USB stick, or whatever media for which you built your image, and boot
  4625. the resulting media::
  4626. $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
  4627. 140966+0 records in
  4628. 140966+0 records out
  4629. 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
  4630. $ sudo eject /dev/sdb
  4631. Using a Modified Kickstart File and Running in Raw Mode
  4632. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4633. This next example manually specifies each build artifact (runs in Raw
  4634. Mode) and uses a modified kickstart file. The example also uses the
  4635. ``-o`` option to cause Wic to create the output somewhere other than the
  4636. default output directory, which is the current directory::
  4637. $ wic create test.wks -o /home/stephano/testwic \
  4638. --rootfs-dir /home/stephano/yocto/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
  4639. --bootimg-dir /home/stephano/yocto/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
  4640. --kernel-dir /home/stephano/yocto/build/tmp/deploy/images/qemux86 \
  4641. --native-sysroot /home/stephano/yocto/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4642. INFO: Creating image(s)...
  4643. INFO: The new image(s) can be found here:
  4644. /home/stephano/testwic/test-201710091445-sdb.direct
  4645. The following build artifacts were used to create the image(s):
  4646. ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
  4647. BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
  4648. KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86
  4649. NATIVE_SYSROOT: /home/stephano/yocto/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4650. INFO: The image(s) were created using OE kickstart file:
  4651. test.wks
  4652. For this example,
  4653. :term:`MACHINE` did not have to be
  4654. specified in the ``local.conf`` file since the artifact is manually
  4655. specified.
  4656. Using Wic to Manipulate an Image
  4657. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4658. Wic image manipulation allows you to shorten turnaround time during
  4659. image development. For example, you can use Wic to delete the kernel
  4660. partition of a Wic image and then insert a newly built kernel. This
  4661. saves you time from having to rebuild the entire image each time you
  4662. modify the kernel.
  4663. .. note::
  4664. In order to use Wic to manipulate a Wic image as in this example,
  4665. your development machine must have the ``mtools`` package installed.
  4666. The following example examines the contents of the Wic image, deletes
  4667. the existing kernel, and then inserts a new kernel:
  4668. 1. *List the Partitions:* Use the ``wic ls`` command to list all the
  4669. partitions in the Wic image::
  4670. $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
  4671. Num Start End Size Fstype
  4672. 1 1048576 25041919 23993344 fat16
  4673. 2 25165824 72157183 46991360 ext4
  4674. The previous output shows two partitions in the
  4675. ``core-image-minimal-qemux86.wic`` image.
  4676. 2. *Examine a Particular Partition:* Use the ``wic ls`` command again
  4677. but in a different form to examine a particular partition.
  4678. .. note::
  4679. You can get command usage on any Wic command using the following
  4680. form::
  4681. $ wic help command
  4682. For example, the following command shows you the various ways to
  4683. use the
  4684. wic ls
  4685. command::
  4686. $ wic help ls
  4687. The following command shows what is in partition one::
  4688. $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
  4689. Volume in drive : is boot
  4690. Volume Serial Number is E894-1809
  4691. Directory for ::/
  4692. libcom32 c32 186500 2017-10-09 16:06
  4693. libutil c32 24148 2017-10-09 16:06
  4694. syslinux cfg 220 2017-10-09 16:06
  4695. vesamenu c32 27104 2017-10-09 16:06
  4696. vmlinuz 6904608 2017-10-09 16:06
  4697. 5 files 7 142 580 bytes
  4698. 16 582 656 bytes free
  4699. The previous output shows five files, with the
  4700. ``vmlinuz`` being the kernel.
  4701. .. note::
  4702. If you see the following error, you need to update or create a
  4703. ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1"
  4704. in the file. Then, run the Wic command again::
  4705. ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
  4706. output: Total number of sectors (47824) not a multiple of sectors per track (32)!
  4707. Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
  4708. 3. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the
  4709. ``vmlinuz`` file (kernel)::
  4710. $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
  4711. 4. *Add In the New Kernel:* Use the ``wic cp`` command to add the
  4712. updated kernel to the Wic image. Depending on how you built your
  4713. kernel, it could be in different places. If you used ``devtool`` and
  4714. an SDK to build your kernel, it resides in the ``tmp/work`` directory
  4715. of the extensible SDK. If you used ``make`` to build the kernel, the
  4716. kernel will be in the ``workspace/sources`` area.
  4717. The following example assumes ``devtool`` was used to build the
  4718. kernel::
  4719. $ wic 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 \
  4720. poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
  4721. Once the new kernel is added back into the image, you can use the
  4722. ``dd`` command or :ref:`bmaptool
  4723. <dev-manual/common-tasks:flashing images using \`\`bmaptool\`\`>`
  4724. to flash your wic image onto an SD card or USB stick and test your
  4725. target.
  4726. .. note::
  4727. Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``.
  4728. Flashing Images Using ``bmaptool``
  4729. ==================================
  4730. A fast and easy way to flash an image to a bootable device is to use
  4731. Bmaptool, which is integrated into the OpenEmbedded build system.
  4732. Bmaptool is a generic tool that creates a file's block map (bmap) and
  4733. then uses that map to copy the file. As compared to traditional tools
  4734. such as dd or cp, Bmaptool can copy (or flash) large files like raw
  4735. system image files much faster.
  4736. .. note::
  4737. - If you are using Ubuntu or Debian distributions, you can install
  4738. the ``bmap-tools`` package using the following command and then
  4739. use the tool without specifying ``PATH`` even from the root
  4740. account::
  4741. $ sudo apt install bmap-tools
  4742. - If you are unable to install the ``bmap-tools`` package, you will
  4743. need to build Bmaptool before using it. Use the following command::
  4744. $ bitbake bmap-tools-native
  4745. Following, is an example that shows how to flash a Wic image. Realize
  4746. that while this example uses a Wic image, you can use Bmaptool to flash
  4747. any type of image. Use these steps to flash an image using Bmaptool:
  4748. 1. *Update your local.conf File:* You need to have the following set
  4749. in your ``local.conf`` file before building your image::
  4750. IMAGE_FSTYPES += "wic wic.bmap"
  4751. 2. *Get Your Image:* Either have your image ready (pre-built with the
  4752. :term:`IMAGE_FSTYPES`
  4753. setting previously mentioned) or take the step to build the image::
  4754. $ bitbake image
  4755. 3. *Flash the Device:* Flash the device with the image by using Bmaptool
  4756. depending on your particular setup. The following commands assume the
  4757. image resides in the Build Directory's ``deploy/images/`` area:
  4758. - If you have write access to the media, use this command form::
  4759. $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
  4760. - If you do not have write access to the media, set your permissions
  4761. first and then use the same command form::
  4762. $ sudo chmod 666 /dev/sdX
  4763. $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
  4764. For help on the ``bmaptool`` command, use the following command::
  4765. $ bmaptool --help
  4766. Making Images More Secure
  4767. =========================
  4768. Security is of increasing concern for embedded devices. Consider the
  4769. issues and problems discussed in just this sampling of work found across
  4770. the Internet:
  4771. - *"*\ `Security Risks of Embedded
  4772. Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"*
  4773. by Bruce Schneier
  4774. - *"*\ `Internet Census
  4775. 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna
  4776. Botnet
  4777. - *"*\ `Security Issues for Embedded
  4778. Devices <https://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"*
  4779. by Jake Edge
  4780. When securing your image is of concern, there are steps, tools, and
  4781. variables that you can consider to help you reach the security goals you
  4782. need for your particular device. Not all situations are identical when
  4783. it comes to making an image secure. Consequently, this section provides
  4784. some guidance and suggestions for consideration when you want to make
  4785. your image more secure.
  4786. .. note::
  4787. Because the security requirements and risks are different for every
  4788. type of device, this section cannot provide a complete reference on
  4789. securing your custom OS. It is strongly recommended that you also
  4790. consult other sources of information on embedded Linux system
  4791. hardening and on security.
  4792. General Considerations
  4793. ----------------------
  4794. There are general considerations that help you create more secure images.
  4795. You should consider the following suggestions to make your device
  4796. more secure:
  4797. - Scan additional code you are adding to the system (e.g. application
  4798. code) by using static analysis tools. Look for buffer overflows and
  4799. other potential security problems.
  4800. - Pay particular attention to the security for any web-based
  4801. administration interface.
  4802. Web interfaces typically need to perform administrative functions and
  4803. tend to need to run with elevated privileges. Thus, the consequences
  4804. resulting from the interface's security becoming compromised can be
  4805. serious. Look for common web vulnerabilities such as
  4806. cross-site-scripting (XSS), unvalidated inputs, and so forth.
  4807. As with system passwords, the default credentials for accessing a
  4808. web-based interface should not be the same across all devices. This
  4809. is particularly true if the interface is enabled by default as it can
  4810. be assumed that many end-users will not change the credentials.
  4811. - Ensure you can update the software on the device to mitigate
  4812. vulnerabilities discovered in the future. This consideration
  4813. especially applies when your device is network-enabled.
  4814. - Ensure you remove or disable debugging functionality before producing
  4815. the final image. For information on how to do this, see the
  4816. ":ref:`dev-manual/common-tasks:considerations specific to the openembedded build system`"
  4817. section.
  4818. - Ensure you have no network services listening that are not needed.
  4819. - Remove any software from the image that is not needed.
  4820. - Enable hardware support for secure boot functionality when your
  4821. device supports this functionality.
  4822. Security Flags
  4823. --------------
  4824. The Yocto Project has security flags that you can enable that help make
  4825. your build output more secure. The security flags are in the
  4826. ``meta/conf/distro/include/security_flags.inc`` file in your
  4827. :term:`Source Directory` (e.g. ``poky``).
  4828. .. note::
  4829. Depending on the recipe, certain security flags are enabled and
  4830. disabled by default.
  4831. Use the following line in your ``local.conf`` file or in your custom
  4832. distribution configuration file to enable the security compiler and
  4833. linker flags for your build::
  4834. require conf/distro/include/security_flags.inc
  4835. Considerations Specific to the OpenEmbedded Build System
  4836. --------------------------------------------------------
  4837. You can take some steps that are specific to the OpenEmbedded build
  4838. system to make your images more secure:
  4839. - Ensure "debug-tweaks" is not one of your selected
  4840. :term:`IMAGE_FEATURES`.
  4841. When creating a new project, the default is to provide you with an
  4842. initial ``local.conf`` file that enables this feature using the
  4843. :term:`EXTRA_IMAGE_FEATURES`
  4844. variable with the line::
  4845. EXTRA_IMAGE_FEATURES = "debug-tweaks"
  4846. To disable that feature, simply comment out that line in your
  4847. ``local.conf`` file, or make sure :term:`IMAGE_FEATURES` does not contain
  4848. "debug-tweaks" before producing your final image. Among other things,
  4849. leaving this in place sets the root password as blank, which makes
  4850. logging in for debugging or inspection easy during development but
  4851. also means anyone can easily log in during production.
  4852. - It is possible to set a root password for the image and also to set
  4853. passwords for any extra users you might add (e.g. administrative or
  4854. service type users). When you set up passwords for multiple images or
  4855. users, you should not duplicate passwords.
  4856. To set up passwords, use the
  4857. :ref:`extrausers <ref-classes-extrausers>`
  4858. class, which is the preferred method. For an example on how to set up
  4859. both root and user passwords, see the
  4860. ":ref:`ref-classes-extrausers`" section.
  4861. .. note::
  4862. When adding extra user accounts or setting a root password, be
  4863. cautious about setting the same password on every device. If you
  4864. do this, and the password you have set is exposed, then every
  4865. device is now potentially compromised. If you need this access but
  4866. want to ensure security, consider setting a different, random
  4867. password for each device. Typically, you do this as a separate
  4868. step after you deploy the image onto the device.
  4869. - Consider enabling a Mandatory Access Control (MAC) framework such as
  4870. SMACK or SELinux and tuning it appropriately for your device's usage.
  4871. You can find more information in the
  4872. :yocto_git:`meta-selinux </meta-selinux/>` layer.
  4873. Tools for Hardening Your Image
  4874. ------------------------------
  4875. The Yocto Project provides tools for making your image more secure. You
  4876. can find these tools in the ``meta-security`` layer of the
  4877. :yocto_git:`Yocto Project Source Repositories <>`.
  4878. Creating Your Own Distribution
  4879. ==============================
  4880. When you build an image using the Yocto Project and do not alter any
  4881. distribution :term:`Metadata`, you are
  4882. creating a Poky distribution. If you wish to gain more control over
  4883. package alternative selections, compile-time options, and other
  4884. low-level configurations, you can create your own distribution.
  4885. To create your own distribution, the basic steps consist of creating
  4886. your own distribution layer, creating your own distribution
  4887. configuration file, and then adding any needed code and Metadata to the
  4888. layer. The following steps provide some more detail:
  4889. - *Create a layer for your new distro:* Create your distribution layer
  4890. so that you can keep your Metadata and code for the distribution
  4891. separate. It is strongly recommended that you create and use your own
  4892. layer for configuration and code. Using your own layer as compared to
  4893. just placing configurations in a ``local.conf`` configuration file
  4894. makes it easier to reproduce the same build configuration when using
  4895. multiple build machines. See the
  4896. ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
  4897. section for information on how to quickly set up a layer.
  4898. - *Create the distribution configuration file:* The distribution
  4899. configuration file needs to be created in the ``conf/distro``
  4900. directory of your layer. You need to name it using your distribution
  4901. name (e.g. ``mydistro.conf``).
  4902. .. note::
  4903. The :term:`DISTRO` variable in your ``local.conf`` file determines the
  4904. name of your distribution.
  4905. You can split out parts of your configuration file into include files
  4906. and then "require" them from within your distribution configuration
  4907. file. Be sure to place the include files in the
  4908. ``conf/distro/include`` directory of your layer. A common example
  4909. usage of include files would be to separate out the selection of
  4910. desired version and revisions for individual recipes.
  4911. Your configuration file needs to set the following required
  4912. variables:
  4913. - :term:`DISTRO_NAME`
  4914. - :term:`DISTRO_VERSION`
  4915. These following variables are optional and you typically set them
  4916. from the distribution configuration file:
  4917. - :term:`DISTRO_FEATURES`
  4918. - :term:`DISTRO_EXTRA_RDEPENDS`
  4919. - :term:`DISTRO_EXTRA_RRECOMMENDS`
  4920. - :term:`TCLIBC`
  4921. .. tip::
  4922. If you want to base your distribution configuration file on the
  4923. very basic configuration from OE-Core, you can use
  4924. ``conf/distro/defaultsetup.conf`` as a reference and just include
  4925. variables that differ as compared to ``defaultsetup.conf``.
  4926. Alternatively, you can create a distribution configuration file
  4927. from scratch using the ``defaultsetup.conf`` file or configuration files
  4928. from another distribution such as Poky as a reference.
  4929. - *Provide miscellaneous variables:* Be sure to define any other
  4930. variables for which you want to create a default or enforce as part
  4931. of the distribution configuration. You can include nearly any
  4932. variable from the ``local.conf`` file. The variables you use are not
  4933. limited to the list in the previous bulleted item.
  4934. - *Point to Your distribution configuration file:* In your
  4935. ``local.conf`` file in the :term:`Build Directory`,
  4936. set your
  4937. :term:`DISTRO` variable to point to
  4938. your distribution's configuration file. For example, if your
  4939. distribution's configuration file is named ``mydistro.conf``, then
  4940. you point to it as follows::
  4941. DISTRO = "mydistro"
  4942. - *Add more to the layer if necessary:* Use your layer to hold other
  4943. information needed for the distribution:
  4944. - Add recipes for installing distro-specific configuration files
  4945. that are not already installed by another recipe. If you have
  4946. distro-specific configuration files that are included by an
  4947. existing recipe, you should add an append file (``.bbappend``) for
  4948. those. For general information and recommendations on how to add
  4949. recipes to your layer, see the
  4950. ":ref:`dev-manual/common-tasks:creating your own layer`" and
  4951. ":ref:`dev-manual/common-tasks:following best practices when creating layers`"
  4952. sections.
  4953. - Add any image recipes that are specific to your distribution.
  4954. - Add a ``psplash`` append file for a branded splash screen. For
  4955. information on append files, see the
  4956. ":ref:`dev-manual/common-tasks:appending other layers metadata with your layer`"
  4957. section.
  4958. - Add any other append files to make custom changes that are
  4959. specific to individual recipes.
  4960. Creating a Custom Template Configuration Directory
  4961. ==================================================
  4962. If you are producing your own customized version of the build system for
  4963. use by other users, you might want to customize the message shown by the
  4964. setup script or you might want to change the template configuration
  4965. files (i.e. ``local.conf`` and ``bblayers.conf``) that are created in a
  4966. new build directory.
  4967. The OpenEmbedded build system uses the environment variable
  4968. ``TEMPLATECONF`` to locate the directory from which it gathers
  4969. configuration information that ultimately ends up in the
  4970. :term:`Build Directory` ``conf`` directory.
  4971. By default, ``TEMPLATECONF`` is set as follows in the ``poky``
  4972. repository::
  4973. TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
  4974. This is the
  4975. directory used by the build system to find templates from which to build
  4976. some key configuration files. If you look at this directory, you will
  4977. see the ``bblayers.conf.sample``, ``local.conf.sample``, and
  4978. ``conf-notes.txt`` files. The build system uses these files to form the
  4979. respective ``bblayers.conf`` file, ``local.conf`` file, and display the
  4980. list of BitBake targets when running the setup script.
  4981. To override these default configuration files with configurations you
  4982. want used within every new Build Directory, simply set the
  4983. ``TEMPLATECONF`` variable to your directory. The ``TEMPLATECONF``
  4984. variable is set in the ``.templateconf`` file, which is in the top-level
  4985. :term:`Source Directory` folder
  4986. (e.g. ``poky``). Edit the ``.templateconf`` so that it can locate your
  4987. directory.
  4988. Best practices dictate that you should keep your template configuration
  4989. directory in your custom distribution layer. For example, suppose you
  4990. have a layer named ``meta-mylayer`` located in your home directory and
  4991. you want your template configuration directory named ``myconf``.
  4992. Changing the ``.templateconf`` as follows causes the OpenEmbedded build
  4993. system to look in your directory and base its configuration files on the
  4994. ``*.sample`` configuration files it finds. The final configuration files
  4995. (i.e. ``local.conf`` and ``bblayers.conf`` ultimately still end up in
  4996. your Build Directory, but they are based on your ``*.sample`` files.
  4997. ::
  4998. TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
  4999. Aside from the ``*.sample`` configuration files, the ``conf-notes.txt``
  5000. also resides in the default ``meta-poky/conf`` directory. The script
  5001. that sets up the build environment (i.e.
  5002. :ref:`structure-core-script`) uses this file to
  5003. display BitBake targets as part of the script output. Customizing this
  5004. ``conf-notes.txt`` file is a good way to make sure your list of custom
  5005. targets appears as part of the script's output.
  5006. Here is the default list of targets displayed as a result of running
  5007. either of the setup scripts::
  5008. You can now run 'bitbake <target>'
  5009. Common targets are:
  5010. core-image-minimal
  5011. core-image-sato
  5012. meta-toolchain
  5013. meta-ide-support
  5014. Changing the listed common targets is as easy as editing your version of
  5015. ``conf-notes.txt`` in your custom template configuration directory and
  5016. making sure you have ``TEMPLATECONF`` set to your directory.
  5017. Conserving Disk Space
  5018. =====================
  5019. Conserving Disk Space During Builds
  5020. -----------------------------------
  5021. To help conserve disk space during builds, you can add the following
  5022. statement to your project's ``local.conf`` configuration file found in
  5023. the :term:`Build Directory`::
  5024. INHERIT += "rm_work"
  5025. Adding this statement deletes the work directory used for
  5026. building a recipe once the recipe is built. For more information on
  5027. "rm_work", see the
  5028. :ref:`rm_work <ref-classes-rm-work>` class in the
  5029. Yocto Project Reference Manual.
  5030. Purging Duplicate Shared State Cache Files
  5031. -------------------------------------------
  5032. After multiple build iterations, the Shared State (sstate) cache can contain
  5033. duplicate cache files for a given package, while only the most recent one
  5034. is likely to be reusable. The following command purges all but the
  5035. newest sstate cache file for each package::
  5036. sstate-cache-management.sh --remove-duplicated --cache-dir=build/sstate-cache
  5037. This command will ask you to confirm the deletions it identifies.
  5038. Note::
  5039. The duplicated sstate cache files of one package must have the same
  5040. architecture, which means that sstate cache files with multiple
  5041. architectures are not considered as duplicate.
  5042. Run ``sstate-cache-management.sh`` for more details about this script.
  5043. Working with Packages
  5044. =====================
  5045. This section describes a few tasks that involve packages:
  5046. - :ref:`dev-manual/common-tasks:excluding packages from an image`
  5047. - :ref:`dev-manual/common-tasks:incrementing a package version`
  5048. - :ref:`dev-manual/common-tasks:handling optional module packaging`
  5049. - :ref:`dev-manual/common-tasks:using runtime package management`
  5050. - :ref:`dev-manual/common-tasks:generating and using signed packages`
  5051. - :ref:`Setting up and running package test
  5052. (ptest) <dev-manual/common-tasks:testing packages with ptest>`
  5053. - :ref:`dev-manual/common-tasks:creating node package manager (npm) packages`
  5054. - :ref:`dev-manual/common-tasks:adding custom metadata to packages`
  5055. Excluding Packages from an Image
  5056. --------------------------------
  5057. You might find it necessary to prevent specific packages from being
  5058. installed into an image. If so, you can use several variables to direct
  5059. the build system to essentially ignore installing recommended packages
  5060. or to not install a package at all.
  5061. The following list introduces variables you can use to prevent packages
  5062. from being installed into your image. Each of these variables only works
  5063. with IPK and RPM package types, not for Debian packages.
  5064. Also, you can use these variables from your ``local.conf`` file
  5065. or attach them to a specific image recipe by using a recipe name
  5066. override. For more detail on the variables, see the descriptions in the
  5067. Yocto Project Reference Manual's glossary chapter.
  5068. - :term:`BAD_RECOMMENDATIONS`:
  5069. Use this variable to specify "recommended-only" packages that you do
  5070. not want installed.
  5071. - :term:`NO_RECOMMENDATIONS`:
  5072. Use this variable to prevent all "recommended-only" packages from
  5073. being installed.
  5074. - :term:`PACKAGE_EXCLUDE`:
  5075. Use this variable to prevent specific packages from being installed
  5076. regardless of whether they are "recommended-only" or not. You need to
  5077. realize that the build process could fail with an error when you
  5078. prevent the installation of a package whose presence is required by
  5079. an installed package.
  5080. Incrementing a Package Version
  5081. ------------------------------
  5082. This section provides some background on how binary package versioning
  5083. is accomplished and presents some of the services, variables, and
  5084. terminology involved.
  5085. In order to understand binary package versioning, you need to consider
  5086. the following:
  5087. - Binary Package: The binary package that is eventually built and
  5088. installed into an image.
  5089. - Binary Package Version: The binary package version is composed of two
  5090. components - a version and a revision.
  5091. .. note::
  5092. Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved
  5093. but this discussion for the most part ignores :term:`PE`.
  5094. The version and revision are taken from the
  5095. :term:`PV` and
  5096. :term:`PR` variables, respectively.
  5097. - :term:`PV`: The recipe version. :term:`PV` represents the version of the
  5098. software being packaged. Do not confuse :term:`PV` with the binary
  5099. package version.
  5100. - :term:`PR`: The recipe revision.
  5101. - :term:`SRCPV`: The OpenEmbedded
  5102. build system uses this string to help define the value of :term:`PV` when
  5103. the source code revision needs to be included in it.
  5104. - :yocto_wiki:`PR Service </PR_Service>`: A
  5105. network-based service that helps automate keeping package feeds
  5106. compatible with existing package manager applications such as RPM,
  5107. APT, and OPKG.
  5108. Whenever the binary package content changes, the binary package version
  5109. must change. Changing the binary package version is accomplished by
  5110. changing or "bumping" the :term:`PR` and/or :term:`PV` values. Increasing these
  5111. values occurs one of two ways:
  5112. - Automatically using a Package Revision Service (PR Service).
  5113. - Manually incrementing the :term:`PR` and/or :term:`PV` variables.
  5114. Given a primary challenge of any build system and its users is how to
  5115. maintain a package feed that is compatible with existing package manager
  5116. applications such as RPM, APT, and OPKG, using an automated system is
  5117. much preferred over a manual system. In either system, the main
  5118. requirement is that binary package version numbering increases in a
  5119. linear fashion and that there is a number of version components that
  5120. support that linear progression. For information on how to ensure
  5121. package revisioning remains linear, see the
  5122. ":ref:`dev-manual/common-tasks:automatically incrementing a package version number`"
  5123. section.
  5124. The following three sections provide related information on the PR
  5125. Service, the manual method for "bumping" :term:`PR` and/or :term:`PV`, and on
  5126. how to ensure binary package revisioning remains linear.
  5127. Working With a PR Service
  5128. ~~~~~~~~~~~~~~~~~~~~~~~~~
  5129. As mentioned, attempting to maintain revision numbers in the
  5130. :term:`Metadata` is error prone, inaccurate,
  5131. and causes problems for people submitting recipes. Conversely, the PR
  5132. Service automatically generates increasing numbers, particularly the
  5133. revision field, which removes the human element.
  5134. .. note::
  5135. For additional information on using a PR Service, you can see the
  5136. :yocto_wiki:`PR Service </PR_Service>` wiki page.
  5137. The Yocto Project uses variables in order of decreasing priority to
  5138. facilitate revision numbering (i.e.
  5139. :term:`PE`,
  5140. :term:`PV`, and
  5141. :term:`PR` for epoch, version, and
  5142. revision, respectively). The values are highly dependent on the policies
  5143. and procedures of a given distribution and package feed.
  5144. Because the OpenEmbedded build system uses
  5145. ":ref:`signatures <overview-manual/concepts:checksums (signatures)>`", which are
  5146. unique to a given build, the build system knows when to rebuild
  5147. packages. All the inputs into a given task are represented by a
  5148. signature, which can trigger a rebuild when different. Thus, the build
  5149. system itself does not rely on the :term:`PR`, :term:`PV`, and :term:`PE` numbers to
  5150. trigger a rebuild. The signatures, however, can be used to generate
  5151. these values.
  5152. The PR Service works with both ``OEBasic`` and ``OEBasicHash``
  5153. generators. The value of :term:`PR` bumps when the checksum changes and the
  5154. different generator mechanisms change signatures under different
  5155. circumstances.
  5156. As implemented, the build system includes values from the PR Service
  5157. into the :term:`PR` field as an addition using the form "``.x``" so ``r0``
  5158. becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing
  5159. :term:`PR` values to be used for whatever reasons, which include manual
  5160. :term:`PR` bumps, should it be necessary.
  5161. By default, the PR Service is not enabled or running. Thus, the packages
  5162. generated are just "self consistent". The build system adds and removes
  5163. packages and there are no guarantees about upgrade paths but images will
  5164. be consistent and correct with the latest changes.
  5165. The simplest form for a PR Service is for a single host
  5166. development system that builds the package feed (building system). For
  5167. this scenario, you can enable a local PR Service by setting
  5168. :term:`PRSERV_HOST` in your
  5169. ``local.conf`` file in the :term:`Build Directory`::
  5170. PRSERV_HOST = "localhost:0"
  5171. Once the service is started, packages will automatically
  5172. get increasing :term:`PR` values and BitBake takes care of starting and
  5173. stopping the server.
  5174. If you have a more complex setup where multiple host development systems
  5175. work against a common, shared package feed, you have a single PR Service
  5176. running and it is connected to each building system. For this scenario,
  5177. you need to start the PR Service using the ``bitbake-prserv`` command::
  5178. bitbake-prserv --host ip --port port --start
  5179. In addition to
  5180. hand-starting the service, you need to update the ``local.conf`` file of
  5181. each building system as described earlier so each system points to the
  5182. server and port.
  5183. It is also recommended you use build history, which adds some sanity
  5184. checks to binary package versions, in conjunction with the server that
  5185. is running the PR Service. To enable build history, add the following to
  5186. each building system's ``local.conf`` file::
  5187. # It is recommended to activate "buildhistory" for testing the PR service
  5188. INHERIT += "buildhistory"
  5189. BUILDHISTORY_COMMIT = "1"
  5190. For information on build
  5191. history, see the
  5192. ":ref:`dev-manual/common-tasks:maintaining build output quality`" section.
  5193. .. note::
  5194. The OpenEmbedded build system does not maintain :term:`PR` information as
  5195. part of the shared state (sstate) packages. If you maintain an sstate
  5196. feed, it's expected that either all your building systems that
  5197. contribute to the sstate feed use a shared PR Service, or you do not
  5198. run a PR Service on any of your building systems. Having some systems
  5199. use a PR Service while others do not leads to obvious problems.
  5200. For more information on shared state, see the
  5201. ":ref:`overview-manual/concepts:shared state cache`"
  5202. section in the Yocto Project Overview and Concepts Manual.
  5203. Manually Bumping PR
  5204. ~~~~~~~~~~~~~~~~~~~
  5205. The alternative to setting up a PR Service is to manually "bump" the
  5206. :term:`PR` variable.
  5207. If a committed change results in changing the package output, then the
  5208. value of the PR variable needs to be increased (or "bumped") as part of
  5209. that commit. For new recipes you should add the :term:`PR` variable and set
  5210. its initial value equal to "r0", which is the default. Even though the
  5211. default value is "r0", the practice of adding it to a new recipe makes
  5212. it harder to forget to bump the variable when you make changes to the
  5213. recipe in future.
  5214. If you are sharing a common ``.inc`` file with multiple recipes, you can
  5215. also use the :term:`INC_PR` variable to ensure that the recipes sharing the
  5216. ``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The
  5217. ``.inc`` file must set :term:`INC_PR` (initially to "r0"), and all recipes
  5218. referring to it should set :term:`PR` to "${INC_PR}.0" initially,
  5219. incrementing the last number when the recipe is changed. If the ``.inc``
  5220. file is changed then its :term:`INC_PR` should be incremented.
  5221. When upgrading the version of a binary package, assuming the :term:`PV`
  5222. changes, the :term:`PR` variable should be reset to "r0" (or "${INC_PR}.0"
  5223. if you are using :term:`INC_PR`).
  5224. Usually, version increases occur only to binary packages. However, if
  5225. for some reason :term:`PV` changes but does not increase, you can increase
  5226. the :term:`PE` variable (Package Epoch). The :term:`PE` variable defaults to
  5227. "0".
  5228. Binary package version numbering strives to follow the `Debian Version
  5229. Field Policy
  5230. Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__.
  5231. These guidelines define how versions are compared and what "increasing"
  5232. a version means.
  5233. Automatically Incrementing a Package Version Number
  5234. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5235. When fetching a repository, BitBake uses the
  5236. :term:`SRCREV` variable to determine
  5237. the specific source code revision from which to build. You set the
  5238. :term:`SRCREV` variable to
  5239. :term:`AUTOREV` to cause the
  5240. OpenEmbedded build system to automatically use the latest revision of
  5241. the software::
  5242. SRCREV = "${AUTOREV}"
  5243. Furthermore, you need to reference :term:`SRCPV` in :term:`PV` in order to
  5244. automatically update the version whenever the revision of the source
  5245. code changes. Here is an example::
  5246. PV = "1.0+git${SRCPV}"
  5247. The OpenEmbedded build system substitutes :term:`SRCPV` with the following:
  5248. .. code-block:: none
  5249. AUTOINC+source_code_revision
  5250. The build system replaces the ``AUTOINC``
  5251. with a number. The number used depends on the state of the PR Service:
  5252. - If PR Service is enabled, the build system increments the number,
  5253. which is similar to the behavior of
  5254. :term:`PR`. This behavior results in
  5255. linearly increasing package versions, which is desirable. Here is an
  5256. example:
  5257. .. code-block:: none
  5258. hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
  5259. hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
  5260. - If PR Service is not enabled, the build system replaces the
  5261. ``AUTOINC`` placeholder with zero (i.e. "0"). This results in
  5262. changing the package version since the source revision is included.
  5263. However, package versions are not increased linearly. Here is an
  5264. example:
  5265. .. code-block:: none
  5266. hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
  5267. hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
  5268. In summary, the OpenEmbedded build system does not track the history of
  5269. binary package versions for this purpose. ``AUTOINC``, in this case, is
  5270. comparable to :term:`PR`. If PR server is not enabled, ``AUTOINC`` in the
  5271. package version is simply replaced by "0". If PR server is enabled, the
  5272. build system keeps track of the package versions and bumps the number
  5273. when the package revision changes.
  5274. Handling Optional Module Packaging
  5275. ----------------------------------
  5276. Many pieces of software split functionality into optional modules (or
  5277. plugins) and the plugins that are built might depend on configuration
  5278. options. To avoid having to duplicate the logic that determines what
  5279. modules are available in your recipe or to avoid having to package each
  5280. module by hand, the OpenEmbedded build system provides functionality to
  5281. handle module packaging dynamically.
  5282. To handle optional module packaging, you need to do two things:
  5283. - Ensure the module packaging is actually done.
  5284. - Ensure that any dependencies on optional modules from other recipes
  5285. are satisfied by your recipe.
  5286. Making Sure the Packaging is Done
  5287. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5288. To ensure the module packaging actually gets done, you use the
  5289. ``do_split_packages`` function within the ``populate_packages`` Python
  5290. function in your recipe. The ``do_split_packages`` function searches for
  5291. a pattern of files or directories under a specified path and creates a
  5292. package for each one it finds by appending to the
  5293. :term:`PACKAGES` variable and
  5294. setting the appropriate values for ``FILES:packagename``,
  5295. ``RDEPENDS:packagename``, ``DESCRIPTION:packagename``, and so forth.
  5296. Here is an example from the ``lighttpd`` recipe::
  5297. python populate_packages:prepend () {
  5298. lighttpd_libdir = d.expand('${libdir}')
  5299. do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$',
  5300. 'lighttpd-module-%s', 'Lighttpd module for %s',
  5301. extra_depends='')
  5302. }
  5303. The previous example specifies a number of things in the call to
  5304. ``do_split_packages``.
  5305. - A directory within the files installed by your recipe through
  5306. ``do_install`` in which to search.
  5307. - A regular expression used to match module files in that directory. In
  5308. the example, note the parentheses () that mark the part of the
  5309. expression from which the module name should be derived.
  5310. - A pattern to use for the package names.
  5311. - A description for each package.
  5312. - An empty string for ``extra_depends``, which disables the default
  5313. dependency on the main ``lighttpd`` package. Thus, if a file in
  5314. ``${libdir}`` called ``mod_alias.so`` is found, a package called
  5315. ``lighttpd-module-alias`` is created for it and the
  5316. :term:`DESCRIPTION` is set to
  5317. "Lighttpd module for alias".
  5318. Often, packaging modules is as simple as the previous example. However,
  5319. there are more advanced options that you can use within
  5320. ``do_split_packages`` to modify its behavior. And, if you need to, you
  5321. can add more logic by specifying a hook function that is called for each
  5322. package. It is also perfectly acceptable to call ``do_split_packages``
  5323. multiple times if you have more than one set of modules to package.
  5324. For more examples that show how to use ``do_split_packages``, see the
  5325. ``connman.inc`` file in the ``meta/recipes-connectivity/connman/``
  5326. directory of the ``poky`` :ref:`source repository <overview-manual/development-environment:yocto project source repositories>`. You can
  5327. also find examples in ``meta/classes/kernel.bbclass``.
  5328. Following is a reference that shows ``do_split_packages`` mandatory and
  5329. optional arguments::
  5330. Mandatory arguments
  5331. root
  5332. The path in which to search
  5333. file_regex
  5334. Regular expression to match searched files.
  5335. Use parentheses () to mark the part of this
  5336. expression that should be used to derive the
  5337. module name (to be substituted where %s is
  5338. used in other function arguments as noted below)
  5339. output_pattern
  5340. Pattern to use for the package names. Must
  5341. include %s.
  5342. description
  5343. Description to set for each package. Must
  5344. include %s.
  5345. Optional arguments
  5346. postinst
  5347. Postinstall script to use for all packages
  5348. (as a string)
  5349. recursive
  5350. True to perform a recursive search - default
  5351. False
  5352. hook
  5353. A hook function to be called for every match.
  5354. The function will be called with the following
  5355. arguments (in the order listed):
  5356. f
  5357. Full path to the file/directory match
  5358. pkg
  5359. The package name
  5360. file_regex
  5361. As above
  5362. output_pattern
  5363. As above
  5364. modulename
  5365. The module name derived using file_regex
  5366. extra_depends
  5367. Extra runtime dependencies (RDEPENDS) to be
  5368. set for all packages. The default value of None
  5369. causes a dependency on the main package
  5370. (${PN}) - if you do not want this, pass empty
  5371. string '' for this parameter.
  5372. aux_files_pattern
  5373. Extra item(s) to be added to FILES for each
  5374. package. Can be a single string item or a list
  5375. of strings for multiple items. Must include %s.
  5376. postrm
  5377. postrm script to use for all packages (as a
  5378. string)
  5379. allow_dirs
  5380. True to allow directories to be matched -
  5381. default False
  5382. prepend
  5383. If True, prepend created packages to PACKAGES
  5384. instead of the default False which appends them
  5385. match_path
  5386. match file_regex on the whole relative path to
  5387. the root rather than just the filename
  5388. aux_files_pattern_verbatim
  5389. Extra item(s) to be added to FILES for each
  5390. package, using the actual derived module name
  5391. rather than converting it to something legal
  5392. for a package name. Can be a single string item
  5393. or a list of strings for multiple items. Must
  5394. include %s.
  5395. allow_links
  5396. True to allow symlinks to be matched - default
  5397. False
  5398. summary
  5399. Summary to set for each package. Must include %s;
  5400. defaults to description if not set.
  5401. Satisfying Dependencies
  5402. ~~~~~~~~~~~~~~~~~~~~~~~
  5403. The second part for handling optional module packaging is to ensure that
  5404. any dependencies on optional modules from other recipes are satisfied by
  5405. your recipe. You can be sure these dependencies are satisfied by using
  5406. the :term:`PACKAGES_DYNAMIC`
  5407. variable. Here is an example that continues with the ``lighttpd`` recipe
  5408. shown earlier::
  5409. PACKAGES_DYNAMIC = "lighttpd-module-.*"
  5410. The name
  5411. specified in the regular expression can of course be anything. In this
  5412. example, it is ``lighttpd-module-`` and is specified as the prefix to
  5413. ensure that any :term:`RDEPENDS` and
  5414. :term:`RRECOMMENDS` on a package
  5415. name starting with the prefix are satisfied during build time. If you
  5416. are using ``do_split_packages`` as described in the previous section,
  5417. the value you put in :term:`PACKAGES_DYNAMIC` should correspond to the name
  5418. pattern specified in the call to ``do_split_packages``.
  5419. Using Runtime Package Management
  5420. --------------------------------
  5421. During a build, BitBake always transforms a recipe into one or more
  5422. packages. For example, BitBake takes the ``bash`` recipe and produces a
  5423. number of packages (e.g. ``bash``, ``bash-bashbug``,
  5424. ``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``,
  5425. ``bash-completion-extra``, ``bash-dbg``, and so forth). Not all
  5426. generated packages are included in an image.
  5427. In several situations, you might need to update, add, remove, or query
  5428. the packages on a target device at runtime (i.e. without having to
  5429. generate a new image). Examples of such situations include:
  5430. - You want to provide in-the-field updates to deployed devices (e.g.
  5431. security updates).
  5432. - You want to have a fast turn-around development cycle for one or more
  5433. applications that run on your device.
  5434. - You want to temporarily install the "debug" packages of various
  5435. applications on your device so that debugging can be greatly improved
  5436. by allowing access to symbols and source debugging.
  5437. - You want to deploy a more minimal package selection of your device
  5438. but allow in-the-field updates to add a larger selection for
  5439. customization.
  5440. In all these situations, you have something similar to a more
  5441. traditional Linux distribution in that in-field devices are able to
  5442. receive pre-compiled packages from a server for installation or update.
  5443. Being able to install these packages on a running, in-field device is
  5444. what is termed "runtime package management".
  5445. In order to use runtime package management, you need a host or server
  5446. machine that serves up the pre-compiled packages plus the required
  5447. metadata. You also need package manipulation tools on the target. The
  5448. build machine is a likely candidate to act as the server. However, that
  5449. machine does not necessarily have to be the package server. The build
  5450. machine could push its artifacts to another machine that acts as the
  5451. server (e.g. Internet-facing). In fact, doing so is advantageous for a
  5452. production environment as getting the packages away from the development
  5453. system's build directory prevents accidental overwrites.
  5454. A simple build that targets just one device produces more than one
  5455. package database. In other words, the packages produced by a build are
  5456. separated out into a couple of different package groupings based on
  5457. criteria such as the target's CPU architecture, the target board, or the
  5458. C library used on the target. For example, a build targeting the
  5459. ``qemux86`` device produces the following three package databases:
  5460. ``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86``
  5461. device to be aware of all the packages that were available to it, you
  5462. would need to point it to each of these databases individually. In a
  5463. similar way, a traditional Linux distribution usually is configured to
  5464. be aware of a number of software repositories from which it retrieves
  5465. packages.
  5466. Using runtime package management is completely optional and not required
  5467. for a successful build or deployment in any way. But if you want to make
  5468. use of runtime package management, you need to do a couple things above
  5469. and beyond the basics. The remainder of this section describes what you
  5470. need to do.
  5471. Build Considerations
  5472. ~~~~~~~~~~~~~~~~~~~~
  5473. This section describes build considerations of which you need to be
  5474. aware in order to provide support for runtime package management.
  5475. When BitBake generates packages, it needs to know what format or formats
  5476. to use. In your configuration, you use the
  5477. :term:`PACKAGE_CLASSES`
  5478. variable to specify the format:
  5479. 1. Open the ``local.conf`` file inside your
  5480. :term:`Build Directory` (e.g.
  5481. ``poky/build/conf/local.conf``).
  5482. 2. Select the desired package format as follows::
  5483. PACKAGE_CLASSES ?= "package_packageformat"
  5484. where packageformat can be "ipk", "rpm",
  5485. "deb", or "tar" which are the supported package formats.
  5486. .. note::
  5487. Because the Yocto Project supports four different package formats,
  5488. you can set the variable with more than one argument. However, the
  5489. OpenEmbedded build system only uses the first argument when
  5490. creating an image or Software Development Kit (SDK).
  5491. If you would like your image to start off with a basic package database
  5492. containing the packages in your current build as well as to have the
  5493. relevant tools available on the target for runtime package management,
  5494. you can include "package-management" in the
  5495. :term:`IMAGE_FEATURES`
  5496. variable. Including "package-management" in this configuration variable
  5497. ensures that when the image is assembled for your target, the image
  5498. includes the currently-known package databases as well as the
  5499. target-specific tools required for runtime package management to be
  5500. performed on the target. However, this is not strictly necessary. You
  5501. could start your image off without any databases but only include the
  5502. required on-target package tool(s). As an example, you could include
  5503. "opkg" in your
  5504. :term:`IMAGE_INSTALL` variable
  5505. if you are using the IPK package format. You can then initialize your
  5506. target's package database(s) later once your image is up and running.
  5507. Whenever you perform any sort of build step that can potentially
  5508. generate a package or modify existing package, it is always a good idea
  5509. to re-generate the package index after the build by using the following
  5510. command::
  5511. $ bitbake package-index
  5512. It might be tempting to build the
  5513. package and the package index at the same time with a command such as
  5514. the following::
  5515. $ bitbake some-package package-index
  5516. Do not do this as
  5517. BitBake does not schedule the package index for after the completion of
  5518. the package you are building. Consequently, you cannot be sure of the
  5519. package index including information for the package you just built.
  5520. Thus, be sure to run the package update step separately after building
  5521. any packages.
  5522. You can use the
  5523. :term:`PACKAGE_FEED_ARCHS`,
  5524. :term:`PACKAGE_FEED_BASE_PATHS`,
  5525. and
  5526. :term:`PACKAGE_FEED_URIS`
  5527. variables to pre-configure target images to use a package feed. If you
  5528. do not define these variables, then manual steps as described in the
  5529. subsequent sections are necessary to configure the target. You should
  5530. set these variables before building the image in order to produce a
  5531. correctly configured image.
  5532. When your build is complete, your packages reside in the
  5533. ``${TMPDIR}/deploy/packageformat`` directory. For example, if
  5534. ``${``\ :term:`TMPDIR`\ ``}`` is
  5535. ``tmp`` and your selected package type is RPM, then your RPM packages
  5536. are available in ``tmp/deploy/rpm``.
  5537. Host or Server Machine Setup
  5538. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5539. Although other protocols are possible, a server using HTTP typically
  5540. serves packages. If you want to use HTTP, then set up and configure a
  5541. web server such as Apache 2, lighttpd, or Python web server on the
  5542. machine serving the packages.
  5543. To keep things simple, this section describes how to set up a
  5544. Python web server to share package feeds from the developer's
  5545. machine. Although this server might not be the best for a production
  5546. environment, the setup is simple and straight forward. Should you want
  5547. to use a different server more suited for production (e.g. Apache 2,
  5548. Lighttpd, or Nginx), take the appropriate steps to do so.
  5549. From within the build directory where you have built an image based on
  5550. your packaging choice (i.e. the
  5551. :term:`PACKAGE_CLASSES`
  5552. setting), simply start the server. The following example assumes a build
  5553. directory of ``poky/build/tmp/deploy/rpm`` and a :term:`PACKAGE_CLASSES`
  5554. setting of "package_rpm"::
  5555. $ cd poky/build/tmp/deploy/rpm
  5556. $ python3 -m http.server
  5557. Target Setup
  5558. ~~~~~~~~~~~~
  5559. Setting up the target differs depending on the package management
  5560. system. This section provides information for RPM, IPK, and DEB.
  5561. Using RPM
  5562. ^^^^^^^^^
  5563. The `Dandified Packaging
  5564. Tool <https://en.wikipedia.org/wiki/DNF_(software)>`__ (DNF) performs
  5565. runtime package management of RPM packages. In order to use DNF for
  5566. runtime package management, you must perform an initial setup on the
  5567. target machine for cases where the ``PACKAGE_FEED_*`` variables were not
  5568. set as part of the image that is running on the target. This means if
  5569. you built your image and did not use these variables as part of the
  5570. build and your image is now running on the target, you need to perform
  5571. the steps in this section if you want to use runtime package management.
  5572. .. note::
  5573. For information on the ``PACKAGE_FEED_*`` variables, see
  5574. :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and
  5575. :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables
  5576. glossary.
  5577. On the target, you must inform DNF that package databases are available.
  5578. You do this by creating a file named
  5579. ``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``.
  5580. As an example, assume the target is able to use the following package
  5581. databases: ``all``, ``i586``, and ``qemux86`` from a server named
  5582. ``my.server``. The specifics for setting up the web server are up to
  5583. you. The critical requirement is that the URIs in the target repository
  5584. configuration point to the correct remote location for the feeds.
  5585. .. note::
  5586. For development purposes, you can point the web server to the build
  5587. system's ``deploy`` directory. However, for production use, it is better to
  5588. copy the package directories to a location outside of the build area and use
  5589. that location. Doing so avoids situations where the build system
  5590. overwrites or changes the ``deploy`` directory.
  5591. When telling DNF where to look for the package databases, you must
  5592. declare individual locations per architecture or a single location used
  5593. for all architectures. You cannot do both:
  5594. - *Create an Explicit List of Architectures:* Define individual base
  5595. URLs to identify where each package database is located:
  5596. .. code-block:: none
  5597. [oe-packages]
  5598. baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
  5599. This example
  5600. informs DNF about individual package databases for all three
  5601. architectures.
  5602. - *Create a Single (Full) Package Index:* Define a single base URL that
  5603. identifies where a full package database is located::
  5604. [oe-packages]
  5605. baseurl=http://my.server/rpm
  5606. This example informs DNF about a single
  5607. package database that contains all the package index information for
  5608. all supported architectures.
  5609. Once you have informed DNF where to find the package databases, you need
  5610. to fetch them:
  5611. .. code-block:: none
  5612. # dnf makecache
  5613. DNF is now able to find, install, and
  5614. upgrade packages from the specified repository or repositories.
  5615. .. note::
  5616. See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for
  5617. additional information.
  5618. Using IPK
  5619. ^^^^^^^^^
  5620. The ``opkg`` application performs runtime package management of IPK
  5621. packages. You must perform an initial setup for ``opkg`` on the target
  5622. machine if the
  5623. :term:`PACKAGE_FEED_ARCHS`,
  5624. :term:`PACKAGE_FEED_BASE_PATHS`,
  5625. and
  5626. :term:`PACKAGE_FEED_URIS`
  5627. variables have not been set or the target image was built before the
  5628. variables were set.
  5629. The ``opkg`` application uses configuration files to find available
  5630. package databases. Thus, you need to create a configuration file inside
  5631. the ``/etc/opkg/`` directory, which informs ``opkg`` of any repository
  5632. you want to use.
  5633. As an example, suppose you are serving packages from a ``ipk/``
  5634. directory containing the ``i586``, ``all``, and ``qemux86`` databases
  5635. through an HTTP server named ``my.server``. On the target, create a
  5636. configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/``
  5637. directory containing the following:
  5638. .. code-block:: none
  5639. src/gz all http://my.server/ipk/all
  5640. src/gz i586 http://my.server/ipk/i586
  5641. src/gz qemux86 http://my.server/ipk/qemux86
  5642. Next, instruct ``opkg`` to fetch the
  5643. repository information:
  5644. .. code-block:: none
  5645. # opkg update
  5646. The ``opkg`` application is now able to find, install, and upgrade packages
  5647. from the specified repository.
  5648. Using DEB
  5649. ^^^^^^^^^
  5650. The ``apt`` application performs runtime package management of DEB
  5651. packages. This application uses a source list file to find available
  5652. package databases. You must perform an initial setup for ``apt`` on the
  5653. target machine if the
  5654. :term:`PACKAGE_FEED_ARCHS`,
  5655. :term:`PACKAGE_FEED_BASE_PATHS`,
  5656. and
  5657. :term:`PACKAGE_FEED_URIS`
  5658. variables have not been set or the target image was built before the
  5659. variables were set.
  5660. To inform ``apt`` of the repository you want to use, you might create a
  5661. list file (e.g. ``my_repo.list``) inside the
  5662. ``/etc/apt/sources.list.d/`` directory. As an example, suppose you are
  5663. serving packages from a ``deb/`` directory containing the ``i586``,
  5664. ``all``, and ``qemux86`` databases through an HTTP server named
  5665. ``my.server``. The list file should contain:
  5666. .. code-block:: none
  5667. deb http://my.server/deb/all ./
  5668. deb http://my.server/deb/i586 ./
  5669. deb http://my.server/deb/qemux86 ./
  5670. Next, instruct the ``apt`` application
  5671. to fetch the repository information:
  5672. .. code-block:: none
  5673. $ sudo apt update
  5674. After this step,
  5675. ``apt`` is able to find, install, and upgrade packages from the
  5676. specified repository.
  5677. Generating and Using Signed Packages
  5678. ------------------------------------
  5679. In order to add security to RPM packages used during a build, you can
  5680. take steps to securely sign them. Once a signature is verified, the
  5681. OpenEmbedded build system can use the package in the build. If security
  5682. fails for a signed package, the build system stops the build.
  5683. This section describes how to sign RPM packages during a build and how
  5684. to use signed package feeds (repositories) when doing a build.
  5685. Signing RPM Packages
  5686. ~~~~~~~~~~~~~~~~~~~~
  5687. To enable signing RPM packages, you must set up the following
  5688. configurations in either your ``local.config`` or ``distro.config``
  5689. file::
  5690. # Inherit sign_rpm.bbclass to enable signing functionality
  5691. INHERIT += " sign_rpm"
  5692. # Define the GPG key that will be used for signing.
  5693. RPM_GPG_NAME = "key_name"
  5694. # Provide passphrase for the key
  5695. RPM_GPG_PASSPHRASE = "passphrase"
  5696. .. note::
  5697. Be sure to supply appropriate values for both `key_name` and
  5698. `passphrase`.
  5699. Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in
  5700. the previous example, two optional variables related to signing are available:
  5701. - *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed
  5702. when the package is signed.
  5703. - *GPG_PATH:* Specifies the ``gpg`` home directory used when the
  5704. package is signed.
  5705. Processing Package Feeds
  5706. ~~~~~~~~~~~~~~~~~~~~~~~~
  5707. In addition to being able to sign RPM packages, you can also enable
  5708. signed package feeds for IPK and RPM packages.
  5709. The steps you need to take to enable signed package feed use are similar
  5710. to the steps used to sign RPM packages. You must define the following in
  5711. your ``local.config`` or ``distro.config`` file::
  5712. INHERIT += "sign_package_feed"
  5713. PACKAGE_FEED_GPG_NAME = "key_name"
  5714. PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase"
  5715. For signed package feeds, the passphrase must be specified in a separate file,
  5716. which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE``
  5717. variable. Regarding security, keeping a plain text passphrase out of the
  5718. configuration is more secure.
  5719. Aside from the ``PACKAGE_FEED_GPG_NAME`` and
  5720. ``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables
  5721. related to signed package feeds are available:
  5722. - *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed
  5723. when the package is signed.
  5724. - *GPG_PATH:* Specifies the ``gpg`` home directory used when the
  5725. package is signed.
  5726. - *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg``
  5727. signature. This variable applies only to RPM and IPK package feeds.
  5728. Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are
  5729. "ASC", which is the default and specifies ascii armored, and "BIN",
  5730. which specifies binary.
  5731. Testing Packages With ptest
  5732. ---------------------------
  5733. A Package Test (ptest) runs tests against packages built by the
  5734. OpenEmbedded build system on the target machine. A ptest contains at
  5735. least two items: the actual test, and a shell script (``run-ptest``)
  5736. that starts the test. The shell script that starts the test must not
  5737. contain the actual test - the script only starts the test. On the other
  5738. hand, the test can be anything from a simple shell script that runs a
  5739. binary and checks the output to an elaborate system of test binaries and
  5740. data files.
  5741. The test generates output in the format used by Automake::
  5742. result: testname
  5743. where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and
  5744. the testname can be any identifying string.
  5745. For a list of Yocto Project recipes that are already enabled with ptest,
  5746. see the :yocto_wiki:`Ptest </Ptest>` wiki page.
  5747. .. note::
  5748. A recipe is "ptest-enabled" if it inherits the
  5749. :ref:`ptest <ref-classes-ptest>` class.
  5750. Adding ptest to Your Build
  5751. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  5752. To add package testing to your build, add the
  5753. :term:`DISTRO_FEATURES` and
  5754. :term:`EXTRA_IMAGE_FEATURES`
  5755. variables to your ``local.conf`` file, which is found in the
  5756. :term:`Build Directory`::
  5757. DISTRO_FEATURES:append = " ptest"
  5758. EXTRA_IMAGE_FEATURES += "ptest-pkgs"
  5759. Once your build is complete, the ptest files are installed into the
  5760. ``/usr/lib/package/ptest`` directory within the image, where ``package``
  5761. is the name of the package.
  5762. Running ptest
  5763. ~~~~~~~~~~~~~
  5764. The ``ptest-runner`` package installs a shell script that loops through
  5765. all installed ptest test suites and runs them in sequence. Consequently,
  5766. you might want to add this package to your image.
  5767. Getting Your Package Ready
  5768. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  5769. In order to enable a recipe to run installed ptests on target hardware,
  5770. you need to prepare the recipes that build the packages you want to
  5771. test. Here is what you have to do for each recipe:
  5772. - *Be sure the recipe inherits
  5773. the* :ref:`ptest <ref-classes-ptest>` *class:*
  5774. Include the following line in each recipe::
  5775. inherit ptest
  5776. - *Create run-ptest:* This script starts your test. Locate the
  5777. script where you will refer to it using
  5778. :term:`SRC_URI`. Here is an
  5779. example that starts a test for ``dbus``::
  5780. #!/bin/sh
  5781. cd test
  5782. make -k runtest-TESTS
  5783. - *Ensure dependencies are met:* If the test adds build or runtime
  5784. dependencies that normally do not exist for the package (such as
  5785. requiring "make" to run the test suite), use the
  5786. :term:`DEPENDS` and
  5787. :term:`RDEPENDS` variables in
  5788. your recipe in order for the package to meet the dependencies. Here
  5789. is an example where the package has a runtime dependency on "make"::
  5790. RDEPENDS:${PN}-ptest += "make"
  5791. - *Add a function to build the test suite:* Not many packages support
  5792. cross-compilation of their test suites. Consequently, you usually
  5793. need to add a cross-compilation function to the package.
  5794. Many packages based on Automake compile and run the test suite by
  5795. using a single command such as ``make check``. However, the host
  5796. ``make check`` builds and runs on the same computer, while
  5797. cross-compiling requires that the package is built on the host but
  5798. executed for the target architecture (though often, as in the case
  5799. for ptest, the execution occurs on the host). The built version of
  5800. Automake that ships with the Yocto Project includes a patch that
  5801. separates building and execution. Consequently, packages that use the
  5802. unaltered, patched version of ``make check`` automatically
  5803. cross-compiles.
  5804. Regardless, you still must add a ``do_compile_ptest`` function to
  5805. build the test suite. Add a function similar to the following to your
  5806. recipe::
  5807. do_compile_ptest() {
  5808. oe_runmake buildtest-TESTS
  5809. }
  5810. - *Ensure special configurations are set:* If the package requires
  5811. special configurations prior to compiling the test code, you must
  5812. insert a ``do_configure_ptest`` function into the recipe.
  5813. - *Install the test suite:* The ``ptest`` class automatically copies
  5814. the file ``run-ptest`` to the target and then runs make
  5815. ``install-ptest`` to run the tests. If this is not enough, you need
  5816. to create a ``do_install_ptest`` function and make sure it gets
  5817. called after the "make install-ptest" completes.
  5818. Creating Node Package Manager (NPM) Packages
  5819. --------------------------------------------
  5820. `NPM <https://en.wikipedia.org/wiki/Npm_(software)>`__ is a package
  5821. manager for the JavaScript programming language. The Yocto Project
  5822. supports the NPM :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>`. You can
  5823. use this fetcher in combination with
  5824. :doc:`devtool </ref-manual/devtool-reference>` to create
  5825. recipes that produce NPM packages.
  5826. There are two workflows that allow you to create NPM packages using
  5827. ``devtool``: the NPM registry modules method and the NPM project code
  5828. method.
  5829. .. note::
  5830. While it is possible to create NPM recipes manually, using
  5831. ``devtool`` is far simpler.
  5832. Additionally, some requirements and caveats exist.
  5833. Requirements and Caveats
  5834. ~~~~~~~~~~~~~~~~~~~~~~~~
  5835. You need to be aware of the following before using ``devtool`` to create
  5836. NPM packages:
  5837. - Of the two methods that you can use ``devtool`` to create NPM
  5838. packages, the registry approach is slightly simpler. However, you
  5839. might consider the project approach because you do not have to
  5840. publish your module in the NPM registry
  5841. (`npm-registry <https://docs.npmjs.com/misc/registry>`_), which
  5842. is NPM's public registry.
  5843. - Be familiar with
  5844. :doc:`devtool </ref-manual/devtool-reference>`.
  5845. - The NPM host tools need the native ``nodejs-npm`` package, which is
  5846. part of the OpenEmbedded environment. You need to get the package by
  5847. cloning the https://github.com/openembedded/meta-openembedded
  5848. repository out of GitHub. Be sure to add the path to your local copy
  5849. to your ``bblayers.conf`` file.
  5850. - ``devtool`` cannot detect native libraries in module dependencies.
  5851. Consequently, you must manually add packages to your recipe.
  5852. - While deploying NPM packages, ``devtool`` cannot determine which
  5853. dependent packages are missing on the target (e.g. the node runtime
  5854. ``nodejs``). Consequently, you need to find out what files are
  5855. missing and be sure they are on the target.
  5856. - Although you might not need NPM to run your node package, it is
  5857. useful to have NPM on your target. The NPM package name is
  5858. ``nodejs-npm``.
  5859. Using the Registry Modules Method
  5860. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5861. This section presents an example that uses the ``cute-files`` module,
  5862. which is a file browser web application.
  5863. .. note::
  5864. You must know the ``cute-files`` module version.
  5865. The first thing you need to do is use ``devtool`` and the NPM fetcher to
  5866. create the recipe::
  5867. $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2"
  5868. The
  5869. ``devtool add`` command runs ``recipetool create`` and uses the same
  5870. fetch URI to download each dependency and capture license details where
  5871. possible. The result is a generated recipe.
  5872. The recipe file is fairly simple and contains every license that
  5873. ``recipetool`` finds and includes the licenses in the recipe's
  5874. :term:`LIC_FILES_CHKSUM`
  5875. variables. You need to examine the variables and look for those with
  5876. "unknown" in the :term:`LICENSE`
  5877. field. You need to track down the license information for "unknown"
  5878. modules and manually add the information to the recipe.
  5879. ``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap
  5880. files capture the version of all dependent modules. Many packages do not
  5881. provide shrinkwrap files. ``recipetool`` create a shrinkwrap file as it
  5882. runs.
  5883. .. note::
  5884. A package is created for each sub-module. This policy is the only
  5885. practical way to have the licenses for all of the dependencies
  5886. represented in the license manifest of the image.
  5887. The ``devtool edit-recipe`` command lets you take a look at the recipe::
  5888. $ devtool edit-recipe cute-files
  5889. SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
  5890. LICENSE = "MIT & ISC & Unknown"
  5891. LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
  5892. file://node_modules/toidentifier/LICENSE;md5=1a261071a044d02eb6f2bb47f51a3502 \
  5893. file://node_modules/debug/LICENSE;md5=ddd815a475e7338b0be7a14d8ee35a99 \
  5894. ...
  5895. SRC_URI = " \
  5896. npm://registry.npmjs.org/;package=cute-files;version=${PV} \
  5897. npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
  5898. "
  5899. S = "${WORKDIR}/npm"
  5900. inherit npm
  5901. LICENSE:${PN} = "MIT"
  5902. LICENSE:${PN}-accepts = "MIT"
  5903. LICENSE:${PN}-array-flatten = "MIT"
  5904. ...
  5905. LICENSE:${PN}-vary = "MIT"
  5906. Here are three key points in the previous example:
  5907. - :term:`SRC_URI` uses the NPM
  5908. scheme so that the NPM fetcher is used.
  5909. - ``recipetool`` collects all the license information. If a
  5910. sub-module's license is unavailable, the sub-module's name appears in
  5911. the comments.
  5912. - The ``inherit npm`` statement causes the
  5913. :ref:`npm <ref-classes-npm>` class to package
  5914. up all the modules.
  5915. You can run the following command to build the ``cute-files`` package::
  5916. $ devtool build cute-files
  5917. Remember that ``nodejs`` must be installed on
  5918. the target before your package.
  5919. Assuming 192.168.7.2 for the target's IP address, use the following
  5920. command to deploy your package::
  5921. $ devtool deploy-target -s cute-files root@192.168.7.2
  5922. Once the package is installed on the target, you can
  5923. test the application:
  5924. .. note::
  5925. Because of a known issue, you cannot simply run ``cute-files`` as you would
  5926. if you had run ``npm install``.
  5927. ::
  5928. $ cd /usr/lib/node_modules/cute-files
  5929. $ node cute-files.js
  5930. On a browser,
  5931. go to ``http://192.168.7.2:3000`` and you see the following:
  5932. .. image:: figures/cute-files-npm-example.png
  5933. :align: center
  5934. You can find the recipe in ``workspace/recipes/cute-files``. You can use
  5935. the recipe in any layer you choose.
  5936. Using the NPM Projects Code Method
  5937. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5938. Although it is useful to package modules already in the NPM registry,
  5939. adding ``node.js`` projects under development is a more common developer
  5940. use case.
  5941. This section covers the NPM projects code method, which is very similar
  5942. to the "registry" approach described in the previous section. In the NPM
  5943. projects method, you provide ``devtool`` with an URL that points to the
  5944. source files.
  5945. Replicating the same example, (i.e. ``cute-files``) use the following
  5946. command::
  5947. $ devtool add https://github.com/martinaglv/cute-files.git
  5948. The
  5949. recipe this command generates is very similar to the recipe created in
  5950. the previous section. However, the :term:`SRC_URI` looks like the following::
  5951. SRC_URI = " \
  5952. git://github.com/martinaglv/cute-files.git;protocol=https \
  5953. npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
  5954. "
  5955. In this example,
  5956. the main module is taken from the Git repository and dependencies are
  5957. taken from the NPM registry. Other than those differences, the recipe is
  5958. basically the same between the two methods. You can build and deploy the
  5959. package exactly as described in the previous section that uses the
  5960. registry modules method.
  5961. Adding custom metadata to packages
  5962. ----------------------------------
  5963. The variable
  5964. :term:`PACKAGE_ADD_METADATA`
  5965. can be used to add additional metadata to packages. This is reflected in
  5966. the package control/spec file. To take the ipk format for example, the
  5967. CONTROL file stored inside would contain the additional metadata as
  5968. additional lines.
  5969. The variable can be used in multiple ways, including using suffixes to
  5970. set it for a specific package type and/or package. Note that the order
  5971. of precedence is the same as this list:
  5972. - ``PACKAGE_ADD_METADATA_<PKGTYPE>:<PN>``
  5973. - ``PACKAGE_ADD_METADATA_<PKGTYPE>``
  5974. - ``PACKAGE_ADD_METADATA:<PN>``
  5975. - :term:`PACKAGE_ADD_METADATA`
  5976. `<PKGTYPE>` is a parameter and expected to be a distinct name of specific
  5977. package type:
  5978. - IPK for .ipk packages
  5979. - DEB for .deb packages
  5980. - RPM for .rpm packages
  5981. `<PN>` is a parameter and expected to be a package name.
  5982. The variable can contain multiple [one-line] metadata fields separated
  5983. by the literal sequence '\\n'. The separator can be redefined using the
  5984. variable flag ``separator``.
  5985. Here is an example that adds two custom fields for ipk
  5986. packages::
  5987. PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets"
  5988. Efficiently Fetching Source Files During a Build
  5989. ================================================
  5990. The OpenEmbedded build system works with source files located through
  5991. the :term:`SRC_URI` variable. When
  5992. you build something using BitBake, a big part of the operation is
  5993. locating and downloading all the source tarballs. For images,
  5994. downloading all the source for various packages can take a significant
  5995. amount of time.
  5996. This section shows you how you can use mirrors to speed up fetching
  5997. source files and how you can pre-fetch files all of which leads to more
  5998. efficient use of resources and time.
  5999. Setting up Effective Mirrors
  6000. ----------------------------
  6001. A good deal that goes into a Yocto Project build is simply downloading
  6002. all of the source tarballs. Maybe you have been working with another
  6003. build system for which you have built up a
  6004. sizable directory of source tarballs. Or, perhaps someone else has such
  6005. a directory for which you have read access. If so, you can save time by
  6006. adding statements to your configuration file so that the build process
  6007. checks local directories first for existing tarballs before checking the
  6008. Internet.
  6009. Here is an efficient way to set it up in your ``local.conf`` file::
  6010. SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
  6011. INHERIT += "own-mirrors"
  6012. BB_GENERATE_MIRROR_TARBALLS = "1"
  6013. # BB_NO_NETWORK = "1"
  6014. In the previous example, the
  6015. :term:`BB_GENERATE_MIRROR_TARBALLS`
  6016. variable causes the OpenEmbedded build system to generate tarballs of
  6017. the Git repositories and store them in the
  6018. :term:`DL_DIR` directory. Due to
  6019. performance reasons, generating and storing these tarballs is not the
  6020. build system's default behavior.
  6021. You can also use the
  6022. :term:`PREMIRRORS` variable. For
  6023. an example, see the variable's glossary entry in the Yocto Project
  6024. Reference Manual.
  6025. Getting Source Files and Suppressing the Build
  6026. ----------------------------------------------
  6027. Another technique you can use to ready yourself for a successive string
  6028. of build operations, is to pre-fetch all the source files without
  6029. actually starting a build. This technique lets you work through any
  6030. download issues and ultimately gathers all the source files into your
  6031. download directory :ref:`structure-build-downloads`,
  6032. which is located with :term:`DL_DIR`.
  6033. Use the following BitBake command form to fetch all the necessary
  6034. sources without starting the build::
  6035. $ bitbake target --runall=fetch
  6036. This
  6037. variation of the BitBake command guarantees that you have all the
  6038. sources for that BitBake target should you disconnect from the Internet
  6039. and want to do the build later offline.
  6040. Selecting an Initialization Manager
  6041. ===================================
  6042. By default, the Yocto Project uses SysVinit as the initialization
  6043. manager. However, there is also support for systemd, which is a full
  6044. replacement for init with parallel starting of services, reduced shell
  6045. overhead and other features that are used by many distributions.
  6046. Within the system, SysVinit treats system components as services. These
  6047. services are maintained as shell scripts stored in the ``/etc/init.d/``
  6048. directory. Services organize into different run levels. This
  6049. organization is maintained by putting links to the services in the
  6050. ``/etc/rcN.d/`` directories, where `N/` is one of the following options:
  6051. "S", "0", "1", "2", "3", "4", "5", or "6".
  6052. .. note::
  6053. Each runlevel has a dependency on the previous runlevel. This
  6054. dependency allows the services to work properly.
  6055. In comparison, systemd treats components as units. Using units is a
  6056. broader concept as compared to using a service. A unit includes several
  6057. different types of entities. Service is one of the types of entities.
  6058. The runlevel concept in SysVinit corresponds to the concept of a target
  6059. in systemd, where target is also a type of supported unit.
  6060. In a SysVinit-based system, services load sequentially (i.e. one by one)
  6061. during init and parallelization is not supported. With systemd, services
  6062. start in parallel. Needless to say, the method can have an impact on
  6063. system startup performance.
  6064. If you want to use SysVinit, you do not have to do anything. But, if you
  6065. want to use systemd, you must take some steps as described in the
  6066. following sections.
  6067. Using systemd Exclusively
  6068. -------------------------
  6069. Set these variables in your distribution configuration file as follows::
  6070. DISTRO_FEATURES:append = " systemd"
  6071. VIRTUAL-RUNTIME_init_manager = "systemd"
  6072. You can also prevent the SysVinit distribution feature from
  6073. being automatically enabled as follows::
  6074. DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
  6075. Doing so removes any
  6076. redundant SysVinit scripts.
  6077. To remove initscripts from your image altogether, set this variable
  6078. also::
  6079. VIRTUAL-RUNTIME_initscripts = ""
  6080. For information on the backfill variable, see
  6081. :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`.
  6082. Using systemd for the Main Image and Using SysVinit for the Rescue Image
  6083. ------------------------------------------------------------------------
  6084. Set these variables in your distribution configuration file as follows::
  6085. DISTRO_FEATURES:append = " systemd"
  6086. VIRTUAL-RUNTIME_init_manager = "systemd"
  6087. Doing so causes your main image to use the
  6088. ``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal
  6089. image cannot use this package group. However, it can install SysVinit
  6090. and the appropriate packages will have support for both systemd and
  6091. SysVinit.
  6092. Using systemd-journald without a traditional syslog daemon
  6093. ----------------------------------------------------------
  6094. Counter-intuitively, ``systemd-journald`` is not a syslog runtime or provider,
  6095. and the proper way to use systemd-journald as your sole logging mechanism is to
  6096. effectively disable syslog entirely by setting these variables in your distribution
  6097. configuration file::
  6098. VIRTUAL-RUNTIME_syslog = ""
  6099. VIRTUAL-RUNTIME_base-utils-syslog = ""
  6100. Doing so will prevent ``rsyslog`` / ``busybox-syslog`` from being pulled in by
  6101. default, leaving only ``journald``.
  6102. Selecting a Device Manager
  6103. ==========================
  6104. The Yocto Project provides multiple ways to manage the device manager
  6105. (``/dev``):
  6106. - Persistent and Pre-Populated ``/dev``: For this case, the ``/dev``
  6107. directory is persistent and the required device nodes are created
  6108. during the build.
  6109. - Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev``
  6110. directory is provided by the kernel as an in-memory file system and
  6111. is automatically populated by the kernel at runtime. Additional
  6112. configuration of device nodes is done in user space by a device
  6113. manager like ``udev`` or ``busybox-mdev``.
  6114. Using Persistent and Pre-Populated ``/dev``
  6115. --------------------------------------------
  6116. To use the static method for device population, you need to set the
  6117. :term:`USE_DEVFS` variable to "0"
  6118. as follows::
  6119. USE_DEVFS = "0"
  6120. The content of the resulting ``/dev`` directory is defined in a Device
  6121. Table file. The
  6122. :term:`IMAGE_DEVICE_TABLES`
  6123. variable defines the Device Table to use and should be set in the
  6124. machine or distro configuration file. Alternatively, you can set this
  6125. variable in your ``local.conf`` configuration file.
  6126. If you do not define the :term:`IMAGE_DEVICE_TABLES` variable, the default
  6127. ``device_table-minimal.txt`` is used::
  6128. IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
  6129. The population is handled by the ``makedevs`` utility during image
  6130. creation:
  6131. Using ``devtmpfs`` and a Device Manager
  6132. ---------------------------------------
  6133. To use the dynamic method for device population, you need to use (or be
  6134. sure to set) the :term:`USE_DEVFS`
  6135. variable to "1", which is the default::
  6136. USE_DEVFS = "1"
  6137. With this
  6138. setting, the resulting ``/dev`` directory is populated by the kernel
  6139. using ``devtmpfs``. Make sure the corresponding kernel configuration
  6140. variable ``CONFIG_DEVTMPFS`` is set when building you build a Linux
  6141. kernel.
  6142. All devices created by ``devtmpfs`` will be owned by ``root`` and have
  6143. permissions ``0600``.
  6144. To have more control over the device nodes, you can use a device manager
  6145. like ``udev`` or ``busybox-mdev``. You choose the device manager by
  6146. defining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or
  6147. distro configuration file. Alternatively, you can set this variable in
  6148. your ``local.conf`` configuration file::
  6149. VIRTUAL-RUNTIME_dev_manager = "udev"
  6150. # Some alternative values
  6151. # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
  6152. # VIRTUAL-RUNTIME_dev_manager = "systemd"
  6153. Using an External SCM
  6154. =====================
  6155. If you're working on a recipe that pulls from an external Source Code
  6156. Manager (SCM), it is possible to have the OpenEmbedded build system
  6157. notice new recipe changes added to the SCM and then build the resulting
  6158. packages that depend on the new recipes by using the latest versions.
  6159. This only works for SCMs from which it is possible to get a sensible
  6160. revision number for changes. Currently, you can do this with Apache
  6161. Subversion (SVN), Git, and Bazaar (BZR) repositories.
  6162. To enable this behavior, the :term:`PV` of
  6163. the recipe needs to reference
  6164. :term:`SRCPV`. Here is an example::
  6165. PV = "1.2.3+git${SRCPV}"
  6166. Then, you can add the following to your
  6167. ``local.conf``::
  6168. SRCREV:pn-PN = "${AUTOREV}"
  6169. :term:`PN` is the name of the recipe for
  6170. which you want to enable automatic source revision updating.
  6171. If you do not want to update your local configuration file, you can add
  6172. the following directly to the recipe to finish enabling the feature::
  6173. SRCREV = "${AUTOREV}"
  6174. The Yocto Project provides a distribution named ``poky-bleeding``, whose
  6175. configuration file contains the line::
  6176. require conf/distro/include/poky-floating-revisions.inc
  6177. This line pulls in the
  6178. listed include file that contains numerous lines of exactly that form::
  6179. #SRCREV:pn-opkg-native ?= "${AUTOREV}"
  6180. #SRCREV:pn-opkg-sdk ?= "${AUTOREV}"
  6181. #SRCREV:pn-opkg ?= "${AUTOREV}"
  6182. #SRCREV:pn-opkg-utils-native ?= "${AUTOREV}"
  6183. #SRCREV:pn-opkg-utils ?= "${AUTOREV}"
  6184. SRCREV:pn-gconf-dbus ?= "${AUTOREV}"
  6185. SRCREV:pn-matchbox-common ?= "${AUTOREV}"
  6186. SRCREV:pn-matchbox-config-gtk ?= "${AUTOREV}"
  6187. SRCREV:pn-matchbox-desktop ?= "${AUTOREV}"
  6188. SRCREV:pn-matchbox-keyboard ?= "${AUTOREV}"
  6189. SRCREV:pn-matchbox-panel-2 ?= "${AUTOREV}"
  6190. SRCREV:pn-matchbox-themes-extra ?= "${AUTOREV}"
  6191. SRCREV:pn-matchbox-terminal ?= "${AUTOREV}"
  6192. SRCREV:pn-matchbox-wm ?= "${AUTOREV}"
  6193. SRCREV:pn-settings-daemon ?= "${AUTOREV}"
  6194. SRCREV:pn-screenshot ?= "${AUTOREV}"
  6195. . . .
  6196. These lines allow you to
  6197. experiment with building a distribution that tracks the latest
  6198. development source for numerous packages.
  6199. .. note::
  6200. The ``poky-bleeding`` distribution is not tested on a regular basis. Keep
  6201. this in mind if you use it.
  6202. Creating a Read-Only Root Filesystem
  6203. ====================================
  6204. Suppose, for security reasons, you need to disable your target device's
  6205. root filesystem's write permissions (i.e. you need a read-only root
  6206. filesystem). Or, perhaps you are running the device's operating system
  6207. from a read-only storage device. For either case, you can customize your
  6208. image for that behavior.
  6209. .. note::
  6210. Supporting a read-only root filesystem requires that the system and
  6211. applications do not try to write to the root filesystem. You must
  6212. configure all parts of the target system to write elsewhere, or to
  6213. gracefully fail in the event of attempting to write to the root
  6214. filesystem.
  6215. Creating the Root Filesystem
  6216. ----------------------------
  6217. To create the read-only root filesystem, simply add the
  6218. "read-only-rootfs" feature to your image, normally in one of two ways.
  6219. The first way is to add the "read-only-rootfs" image feature in the
  6220. image's recipe file via the :term:`IMAGE_FEATURES` variable::
  6221. IMAGE_FEATURES += "read-only-rootfs"
  6222. As an alternative, you can add the same feature
  6223. from within your build directory's ``local.conf`` file with the
  6224. associated :term:`EXTRA_IMAGE_FEATURES` variable, as in::
  6225. EXTRA_IMAGE_FEATURES = "read-only-rootfs"
  6226. For more information on how to use these variables, see the
  6227. ":ref:`dev-manual/common-tasks:Customizing Images Using Custom \`\`IMAGE_FEATURES\`\` and \`\`EXTRA_IMAGE_FEATURES\`\``"
  6228. section. For information on the variables, see
  6229. :term:`IMAGE_FEATURES` and
  6230. :term:`EXTRA_IMAGE_FEATURES`.
  6231. Post-Installation Scripts and Read-Only Root Filesystem
  6232. -------------------------------------------------------
  6233. It is very important that you make sure all post-Installation
  6234. (``pkg_postinst``) scripts for packages that are installed into the
  6235. image can be run at the time when the root filesystem is created during
  6236. the build on the host system. These scripts cannot attempt to run during
  6237. the first boot on the target device. With the "read-only-rootfs" feature
  6238. enabled, the build system makes sure that all post-installation scripts
  6239. succeed at file system creation time. If any of these scripts
  6240. still need to be run after the root filesystem is created, the build
  6241. immediately fails. These build-time checks ensure that the build fails
  6242. rather than the target device fails later during its initial boot
  6243. operation.
  6244. Most of the common post-installation scripts generated by the build
  6245. system for the out-of-the-box Yocto Project are engineered so that they
  6246. can run during root filesystem creation (e.g. post-installation scripts
  6247. for caching fonts). However, if you create and add custom scripts, you
  6248. need to be sure they can be run during this file system creation.
  6249. Here are some common problems that prevent post-installation scripts
  6250. from running during root filesystem creation:
  6251. - *Not using $D in front of absolute paths:* The build system defines
  6252. ``$``\ :term:`D` when the root
  6253. filesystem is created. Furthermore, ``$D`` is blank when the script
  6254. is run on the target device. This implies two purposes for ``$D``:
  6255. ensuring paths are valid in both the host and target environments,
  6256. and checking to determine which environment is being used as a method
  6257. for taking appropriate actions.
  6258. - *Attempting to run processes that are specific to or dependent on the
  6259. target architecture:* You can work around these attempts by using
  6260. native tools, which run on the host system, to accomplish the same
  6261. tasks, or by alternatively running the processes under QEMU, which
  6262. has the ``qemu_run_binary`` function. For more information, see the
  6263. :ref:`qemu <ref-classes-qemu>` class.
  6264. Areas With Write Access
  6265. -----------------------
  6266. With the "read-only-rootfs" feature enabled, any attempt by the target
  6267. to write to the root filesystem at runtime fails. Consequently, you must
  6268. make sure that you configure processes and applications that attempt
  6269. these types of writes do so to directories with write access (e.g.
  6270. ``/tmp`` or ``/var/run``).
  6271. Maintaining Build Output Quality
  6272. ================================
  6273. Many factors can influence the quality of a build. For example, if you
  6274. upgrade a recipe to use a new version of an upstream software package or
  6275. you experiment with some new configuration options, subtle changes can
  6276. occur that you might not detect until later. Consider the case where
  6277. your recipe is using a newer version of an upstream package. In this
  6278. case, a new version of a piece of software might introduce an optional
  6279. dependency on another library, which is auto-detected. If that library
  6280. has already been built when the software is building, the software will
  6281. link to the built library and that library will be pulled into your
  6282. image along with the new software even if you did not want the library.
  6283. The :ref:`buildhistory <ref-classes-buildhistory>`
  6284. class helps you maintain the quality of your build output. You
  6285. can use the class to highlight unexpected and possibly unwanted changes
  6286. in the build output. When you enable build history, it records
  6287. information about the contents of each package and image and then
  6288. commits that information to a local Git repository where you can examine
  6289. the information.
  6290. The remainder of this section describes the following:
  6291. - :ref:`How you can enable and disable build history <dev-manual/common-tasks:enabling and disabling build history>`
  6292. - :ref:`How to understand what the build history contains <dev-manual/common-tasks:understanding what the build history contains>`
  6293. - :ref:`How to limit the information used for build history <dev-manual/common-tasks:using build history to gather image information only>`
  6294. - :ref:`How to examine the build history from both a command-line and web interface <dev-manual/common-tasks:examining build history information>`
  6295. Enabling and Disabling Build History
  6296. ------------------------------------
  6297. Build history is disabled by default. To enable it, add the following
  6298. :term:`INHERIT` statement and set the
  6299. :term:`BUILDHISTORY_COMMIT`
  6300. variable to "1" at the end of your ``conf/local.conf`` file found in the
  6301. :term:`Build Directory`::
  6302. INHERIT += "buildhistory"
  6303. BUILDHISTORY_COMMIT = "1"
  6304. Enabling build history as
  6305. previously described causes the OpenEmbedded build system to collect
  6306. build output information and commit it as a single commit to a local
  6307. :ref:`overview-manual/development-environment:git` repository.
  6308. .. note::
  6309. Enabling build history increases your build times slightly,
  6310. particularly for images, and increases the amount of disk space used
  6311. during the build.
  6312. You can disable build history by removing the previous statements from
  6313. your ``conf/local.conf`` file.
  6314. Understanding What the Build History Contains
  6315. ---------------------------------------------
  6316. Build history information is kept in
  6317. ``${``\ :term:`TOPDIR`\ ``}/buildhistory``
  6318. in the Build Directory as defined by the
  6319. :term:`BUILDHISTORY_DIR`
  6320. variable. Here is an example abbreviated listing:
  6321. .. image:: figures/buildhistory.png
  6322. :align: center
  6323. At the top level, there is a ``metadata-revs`` file that lists the
  6324. revisions of the repositories for the enabled layers when the build was
  6325. produced. The rest of the data splits into separate ``packages``,
  6326. ``images`` and ``sdk`` directories, the contents of which are described
  6327. as follows.
  6328. Build History Package Information
  6329. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6330. The history for each package contains a text file that has name-value
  6331. pairs with information about the package. For example,
  6332. ``buildhistory/packages/i586-poky-linux/busybox/busybox/latest``
  6333. contains the following:
  6334. .. code-block:: none
  6335. PV = 1.22.1
  6336. PR = r32
  6337. RPROVIDES =
  6338. RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
  6339. RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
  6340. PKGSIZE = 540168
  6341. FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
  6342. /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
  6343. /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
  6344. /usr/share/pixmaps /usr/share/applications /usr/share/idl \
  6345. /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
  6346. FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
  6347. /etc/busybox.links.nosuid /etc/busybox.links.suid
  6348. Most of these
  6349. name-value pairs correspond to variables used to produce the package.
  6350. The exceptions are ``FILELIST``, which is the actual list of files in
  6351. the package, and ``PKGSIZE``, which is the total size of files in the
  6352. package in bytes.
  6353. There is also a file that corresponds to the recipe from which the package
  6354. came (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``):
  6355. .. code-block:: none
  6356. PV = 1.22.1
  6357. PR = r32
  6358. DEPENDS = initscripts kern-tools-native update-rc.d-native \
  6359. virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
  6360. virtual/libc virtual/update-alternatives
  6361. PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
  6362. busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
  6363. busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
  6364. Finally, for those recipes fetched from a version control system (e.g.,
  6365. Git), there is a file that lists source revisions that are specified in
  6366. the recipe and the actual revisions used during the build. Listed
  6367. and actual revisions might differ when
  6368. :term:`SRCREV` is set to
  6369. ${:term:`AUTOREV`}. Here is an
  6370. example assuming
  6371. ``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``)::
  6372. # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
  6373. SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
  6374. # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
  6375. SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f"
  6376. You can use the
  6377. ``buildhistory-collect-srcrevs`` command with the ``-a`` option to
  6378. collect the stored :term:`SRCREV` values from build history and report them
  6379. in a format suitable for use in global configuration (e.g.,
  6380. ``local.conf`` or a distro include file) to override floating
  6381. :term:`AUTOREV` values to a fixed set of revisions. Here is some example
  6382. output from this command::
  6383. $ buildhistory-collect-srcrevs -a
  6384. # all-poky-linux
  6385. SRCREV:pn-ca-certificates = "07de54fdcc5806bde549e1edf60738c6bccf50e8"
  6386. SRCREV:pn-update-rc.d = "8636cf478d426b568c1be11dbd9346f67e03adac"
  6387. # core2-64-poky-linux
  6388. SRCREV:pn-binutils = "87d4632d36323091e731eb07b8aa65f90293da66"
  6389. SRCREV:pn-btrfs-tools = "8ad326b2f28c044cb6ed9016d7c3285e23b673c8"
  6390. SRCREV_bzip2-tests:pn-bzip2 = "f9061c030a25de5b6829e1abf373057309c734c0"
  6391. SRCREV:pn-e2fsprogs = "02540dedd3ddc52c6ae8aaa8a95ce75c3f8be1c0"
  6392. SRCREV:pn-file = "504206e53a89fd6eed71aeaf878aa3512418eab1"
  6393. SRCREV_glibc:pn-glibc = "24962427071fa532c3c48c918e9d64d719cc8a6c"
  6394. SRCREV:pn-gnome-desktop-testing = "e346cd4ed2e2102c9b195b614f3c642d23f5f6e7"
  6395. SRCREV:pn-init-system-helpers = "dbd9197569c0935029acd5c9b02b84c68fd937ee"
  6396. SRCREV:pn-kmod = "b6ecfc916a17eab8f93be5b09f4e4f845aabd3d1"
  6397. SRCREV:pn-libnsl2 = "82245c0c58add79a8e34ab0917358217a70e5100"
  6398. SRCREV:pn-libseccomp = "57357d2741a3b3d3e8425889a6b79a130e0fa2f3"
  6399. SRCREV:pn-libxcrypt = "50cf2b6dd4fdf04309445f2eec8de7051d953abf"
  6400. SRCREV:pn-ncurses = "51d0fd9cc3edb975f04224f29f777f8f448e8ced"
  6401. SRCREV:pn-procps = "19a508ea121c0c4ac6d0224575a036de745eaaf8"
  6402. SRCREV:pn-psmisc = "5fab6b7ab385080f1db725d6803136ec1841a15f"
  6403. SRCREV:pn-ptest-runner = "bcb82804daa8f725b6add259dcef2067e61a75aa"
  6404. SRCREV:pn-shared-mime-info = "18e558fa1c8b90b86757ade09a4ba4d6a6cf8f70"
  6405. SRCREV:pn-zstd = "e47e674cd09583ff0503f0f6defd6d23d8b718d3"
  6406. # qemux86_64-poky-linux
  6407. SRCREV_machine:pn-linux-yocto = "20301aeb1a64164b72bc72af58802b315e025c9c"
  6408. SRCREV_meta:pn-linux-yocto = "2d38a472b21ae343707c8bd64ac68a9eaca066a0"
  6409. # x86_64-linux
  6410. SRCREV:pn-binutils-cross-x86_64 = "87d4632d36323091e731eb07b8aa65f90293da66"
  6411. SRCREV_glibc:pn-cross-localedef-native = "24962427071fa532c3c48c918e9d64d719cc8a6c"
  6412. SRCREV_localedef:pn-cross-localedef-native = "794da69788cbf9bf57b59a852f9f11307663fa87"
  6413. SRCREV:pn-debianutils-native = "de14223e5bffe15e374a441302c528ffc1cbed57"
  6414. SRCREV:pn-libmodulemd-native = "ee80309bc766d781a144e6879419b29f444d94eb"
  6415. SRCREV:pn-virglrenderer-native = "363915595e05fb252e70d6514be2f0c0b5ca312b"
  6416. SRCREV:pn-zstd-native = "e47e674cd09583ff0503f0f6defd6d23d8b718d3"
  6417. .. note::
  6418. Here are some notes on using the ``buildhistory-collect-srcrevs`` command:
  6419. - By default, only values where the :term:`SRCREV` was not hardcoded
  6420. (usually when :term:`AUTOREV` is used) are reported. Use the ``-a``
  6421. option to see all :term:`SRCREV` values.
  6422. - The output statements might not have any effect if overrides are
  6423. applied elsewhere in the build system configuration. Use the
  6424. ``-f`` option to add the ``forcevariable`` override to each output
  6425. line if you need to work around this restriction.
  6426. - The script does apply special handling when building for multiple
  6427. machines. However, the script does place a comment before each set
  6428. of values that specifies which triplet to which they belong as
  6429. previously shown (e.g., ``i586-poky-linux``).
  6430. Build History Image Information
  6431. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6432. The files produced for each image are as follows:
  6433. - ``image-files:`` A directory containing selected files from the root
  6434. filesystem. The files are defined by
  6435. :term:`BUILDHISTORY_IMAGE_FILES`.
  6436. - ``build-id.txt:`` Human-readable information about the build
  6437. configuration and metadata source revisions. This file contains the
  6438. full build header as printed by BitBake.
  6439. - ``*.dot:`` Dependency graphs for the image that are compatible with
  6440. ``graphviz``.
  6441. - ``files-in-image.txt:`` A list of files in the image with
  6442. permissions, owner, group, size, and symlink information.
  6443. - ``image-info.txt:`` A text file containing name-value pairs with
  6444. information about the image. See the following listing example for
  6445. more information.
  6446. - ``installed-package-names.txt:`` A list of installed packages by name
  6447. only.
  6448. - ``installed-package-sizes.txt:`` A list of installed packages ordered
  6449. by size.
  6450. - ``installed-packages.txt:`` A list of installed packages with full
  6451. package filenames.
  6452. .. note::
  6453. Installed package information is able to be gathered and produced
  6454. even if package management is disabled for the final image.
  6455. Here is an example of ``image-info.txt``:
  6456. .. code-block:: none
  6457. DISTRO = poky
  6458. DISTRO_VERSION = 3.4+snapshot-a0245d7be08f3d24ea1875e9f8872aa6bbff93be
  6459. USER_CLASSES = buildstats
  6460. IMAGE_CLASSES = qemuboot qemuboot license_image
  6461. IMAGE_FEATURES = debug-tweaks
  6462. IMAGE_LINGUAS =
  6463. IMAGE_INSTALL = packagegroup-core-boot speex speexdsp
  6464. BAD_RECOMMENDATIONS =
  6465. NO_RECOMMENDATIONS =
  6466. PACKAGE_EXCLUDE =
  6467. ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; cve_check_write_rootfs_manifest; ssh_allow_empty_password; ssh_allow_root_login; postinst_enable_logging; rootfs_update_timestamp; write_image_test_data; empty_var_volatile; sort_passwd; rootfs_reproducible;
  6468. IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
  6469. IMAGESIZE = 9265
  6470. Other than ``IMAGESIZE``,
  6471. which is the total size of the files in the image in Kbytes, the
  6472. name-value pairs are variables that may have influenced the content of
  6473. the image. This information is often useful when you are trying to
  6474. determine why a change in the package or file listings has occurred.
  6475. Using Build History to Gather Image Information Only
  6476. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6477. As you can see, build history produces image information, including
  6478. dependency graphs, so you can see why something was pulled into the
  6479. image. If you are just interested in this information and not interested
  6480. in collecting specific package or SDK information, you can enable
  6481. writing only image information without any history by adding the
  6482. following to your ``conf/local.conf`` file found in the
  6483. :term:`Build Directory`::
  6484. INHERIT += "buildhistory"
  6485. BUILDHISTORY_COMMIT = "0"
  6486. BUILDHISTORY_FEATURES = "image"
  6487. Here, you set the
  6488. :term:`BUILDHISTORY_FEATURES`
  6489. variable to use the image feature only.
  6490. Build History SDK Information
  6491. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6492. Build history collects similar information on the contents of SDKs (e.g.
  6493. ``bitbake -c populate_sdk imagename``) as compared to information it
  6494. collects for images. Furthermore, this information differs depending on
  6495. whether an extensible or standard SDK is being produced.
  6496. The following list shows the files produced for SDKs:
  6497. - ``files-in-sdk.txt:`` A list of files in the SDK with permissions,
  6498. owner, group, size, and symlink information. This list includes both
  6499. the host and target parts of the SDK.
  6500. - ``sdk-info.txt:`` A text file containing name-value pairs with
  6501. information about the SDK. See the following listing example for more
  6502. information.
  6503. - ``sstate-task-sizes.txt:`` A text file containing name-value pairs
  6504. with information about task group sizes (e.g. ``do_populate_sysroot``
  6505. tasks have a total size). The ``sstate-task-sizes.txt`` file exists
  6506. only when an extensible SDK is created.
  6507. - ``sstate-package-sizes.txt:`` A text file containing name-value pairs
  6508. with information for the shared-state packages and sizes in the SDK.
  6509. The ``sstate-package-sizes.txt`` file exists only when an extensible
  6510. SDK is created.
  6511. - ``sdk-files:`` A folder that contains copies of the files mentioned
  6512. in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output.
  6513. Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is
  6514. specific to the extensible SDK although you can set it differently if
  6515. you would like to pull in specific files from the standard SDK.
  6516. The default files are ``conf/local.conf``, ``conf/bblayers.conf``,
  6517. ``conf/auto.conf``, ``conf/locked-sigs.inc``, and
  6518. ``conf/devtool.conf``. Thus, for an extensible SDK, these files get
  6519. copied into the ``sdk-files`` directory.
  6520. - The following information appears under each of the ``host`` and
  6521. ``target`` directories for the portions of the SDK that run on the
  6522. host and on the target, respectively:
  6523. .. note::
  6524. The following files for the most part are empty when producing an
  6525. extensible SDK because this type of SDK is not constructed from
  6526. packages as is the standard SDK.
  6527. - ``depends.dot:`` Dependency graph for the SDK that is compatible
  6528. with ``graphviz``.
  6529. - ``installed-package-names.txt:`` A list of installed packages by
  6530. name only.
  6531. - ``installed-package-sizes.txt:`` A list of installed packages
  6532. ordered by size.
  6533. - ``installed-packages.txt:`` A list of installed packages with full
  6534. package filenames.
  6535. Here is an example of ``sdk-info.txt``:
  6536. .. code-block:: none
  6537. DISTRO = poky
  6538. DISTRO_VERSION = 1.3+snapshot-20130327
  6539. SDK_NAME = poky-glibc-i686-arm
  6540. SDK_VERSION = 1.3+snapshot
  6541. SDKMACHINE =
  6542. SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
  6543. BAD_RECOMMENDATIONS =
  6544. SDKSIZE = 352712
  6545. Other than ``SDKSIZE``, which is
  6546. the total size of the files in the SDK in Kbytes, the name-value pairs
  6547. are variables that might have influenced the content of the SDK. This
  6548. information is often useful when you are trying to determine why a
  6549. change in the package or file listings has occurred.
  6550. Examining Build History Information
  6551. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6552. You can examine build history output from the command line or from a web
  6553. interface.
  6554. To see any changes that have occurred (assuming you have
  6555. :term:`BUILDHISTORY_COMMIT` = "1"),
  6556. you can simply use any Git command that allows you to view the history
  6557. of a repository. Here is one method::
  6558. $ git log -p
  6559. You need to realize,
  6560. however, that this method does show changes that are not significant
  6561. (e.g. a package's size changing by a few bytes).
  6562. There is a command-line tool called ``buildhistory-diff``, though,
  6563. that queries the Git repository and prints just the differences that
  6564. might be significant in human-readable form. Here is an example::
  6565. $ poky/poky/scripts/buildhistory-diff . HEAD^
  6566. Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
  6567. /etc/anotherpkg.conf was added
  6568. /sbin/anotherpkg was added
  6569. * (installed-package-names.txt):
  6570. * anotherpkg was added
  6571. Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
  6572. anotherpkg was added
  6573. packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
  6574. * PR changed from "r0" to "r1"
  6575. * PV changed from "0.1.10" to "0.1.12"
  6576. packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
  6577. * PR changed from "r0" to "r1"
  6578. * PV changed from "0.1.10" to "0.1.12"
  6579. .. note::
  6580. The ``buildhistory-diff`` tool requires the ``GitPython``
  6581. package. Be sure to install it using Pip3 as follows::
  6582. $ pip3 install GitPython --user
  6583. Alternatively, you can install ``python3-git`` using the appropriate
  6584. distribution package manager (e.g. ``apt``, ``dnf``, or ``zipper``).
  6585. To see changes to the build history using a web interface, follow the
  6586. instruction in the ``README`` file
  6587. :yocto_git:`here </buildhistory-web/>`.
  6588. Here is a sample screenshot of the interface:
  6589. .. image:: figures/buildhistory-web.png
  6590. :align: center
  6591. Performing Automated Runtime Testing
  6592. ====================================
  6593. The OpenEmbedded build system makes available a series of automated
  6594. tests for images to verify runtime functionality. You can run these
  6595. tests on either QEMU or actual target hardware. Tests are written in
  6596. Python making use of the ``unittest`` module, and the majority of them
  6597. run commands on the target system over SSH. This section describes how
  6598. you set up the environment to use these tests, run available tests, and
  6599. write and add your own tests.
  6600. For information on the test and QA infrastructure available within the
  6601. Yocto Project, see the ":ref:`ref-manual/release-process:testing and quality assurance`"
  6602. section in the Yocto Project Reference Manual.
  6603. Enabling Tests
  6604. --------------
  6605. Depending on whether you are planning to run tests using QEMU or on the
  6606. hardware, you have to take different steps to enable the tests. See the
  6607. following subsections for information on how to enable both types of
  6608. tests.
  6609. Enabling Runtime Tests on QEMU
  6610. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6611. In order to run tests, you need to do the following:
  6612. - *Set up to avoid interaction with sudo for networking:* To
  6613. accomplish this, you must do one of the following:
  6614. - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all
  6615. commands or just for ``runqemu-ifup``. You must provide the full
  6616. path as that can change if you are using multiple clones of the
  6617. source repository.
  6618. .. note::
  6619. On some distributions, you also need to comment out "Defaults
  6620. requiretty" in ``/etc/sudoers``.
  6621. - Manually configure a tap interface for your system.
  6622. - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which
  6623. should generate a list of tap devices. This is the option
  6624. typically chosen for Autobuilder-type environments.
  6625. .. note::
  6626. - Be sure to use an absolute path when calling this script
  6627. with sudo.
  6628. - The package recipe ``qemu-helper-native`` is required to run
  6629. this script. Build the package using the following command::
  6630. $ bitbake qemu-helper-native
  6631. - *Set the DISPLAY variable:* You need to set this variable so that
  6632. you have an X server available (e.g. start ``vncserver`` for a
  6633. headless machine).
  6634. - *Be sure your host's firewall accepts incoming connections from
  6635. 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an
  6636. HTTP server on a random high number port, which is used to serve
  6637. files to the target. The DNF module serves
  6638. ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands.
  6639. That means your host's firewall must accept incoming connections from
  6640. 192.168.7.0/24, which is the default IP range used for tap devices by
  6641. ``runqemu``.
  6642. - *Be sure your host has the correct packages installed:* Depending
  6643. your host's distribution, you need to have the following packages
  6644. installed:
  6645. - Ubuntu and Debian: ``sysstat`` and ``iproute2``
  6646. - openSUSE: ``sysstat`` and ``iproute2``
  6647. - Fedora: ``sysstat`` and ``iproute``
  6648. - CentOS: ``sysstat`` and ``iproute``
  6649. Once you start running the tests, the following happens:
  6650. 1. A copy of the root filesystem is written to ``${WORKDIR}/testimage``.
  6651. 2. The image is booted under QEMU using the standard ``runqemu`` script.
  6652. 3. A default timeout of 500 seconds occurs to allow for the boot process
  6653. to reach the login prompt. You can change the timeout period by
  6654. setting
  6655. :term:`TEST_QEMUBOOT_TIMEOUT`
  6656. in the ``local.conf`` file.
  6657. 4. Once the boot process is reached and the login prompt appears, the
  6658. tests run. The full boot log is written to
  6659. ``${WORKDIR}/testimage/qemu_boot_log``.
  6660. 5. Each test module loads in the order found in :term:`TEST_SUITES`. You can
  6661. find the full output of the commands run over SSH in
  6662. ``${WORKDIR}/testimgage/ssh_target_log``.
  6663. 6. If no failures occur, the task running the tests ends successfully.
  6664. You can find the output from the ``unittest`` in the task log at
  6665. ``${WORKDIR}/temp/log.do_testimage``.
  6666. Enabling Runtime Tests on Hardware
  6667. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6668. The OpenEmbedded build system can run tests on real hardware, and for
  6669. certain devices it can also deploy the image to be tested onto the
  6670. device beforehand.
  6671. For automated deployment, a "controller image" is installed onto the
  6672. hardware once as part of setup. Then, each time tests are to be run, the
  6673. following occurs:
  6674. 1. The controller image is booted into and used to write the image to be
  6675. tested to a second partition.
  6676. 2. The device is then rebooted using an external script that you need to
  6677. provide.
  6678. 3. The device boots into the image to be tested.
  6679. When running tests (independent of whether the image has been deployed
  6680. automatically or not), the device is expected to be connected to a
  6681. network on a pre-determined IP address. You can either use static IP
  6682. addresses written into the image, or set the image to use DHCP and have
  6683. your DHCP server on the test network assign a known IP address based on
  6684. the MAC address of the device.
  6685. In order to run tests on hardware, you need to set :term:`TEST_TARGET` to an
  6686. appropriate value. For QEMU, you do not have to change anything, the
  6687. default value is "qemu". For running tests on hardware, the following
  6688. options are available:
  6689. - *"simpleremote":* Choose "simpleremote" if you are going to run tests
  6690. on a target system that is already running the image to be tested and
  6691. is available on the network. You can use "simpleremote" in
  6692. conjunction with either real hardware or an image running within a
  6693. separately started QEMU or any other virtual machine manager.
  6694. - *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is
  6695. an EFI-based machine with ``systemd-boot`` as bootloader and
  6696. ``core-image-testmaster`` (or something similar) is installed. Also,
  6697. your hardware under test must be in a DHCP-enabled network that gives
  6698. it the same IP address for each reboot.
  6699. If you choose "SystemdbootTarget", there are additional requirements
  6700. and considerations. See the
  6701. ":ref:`dev-manual/common-tasks:selecting systemdboottarget`" section, which
  6702. follows, for more information.
  6703. - *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying
  6704. images and running tests on the BeagleBone "Black" or original
  6705. "White" hardware. For information on how to use these tests, see the
  6706. comments at the top of the BeagleBoneTarget
  6707. ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file.
  6708. - *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying
  6709. images and running tests on the Ubiquiti Networks EdgeRouter Lite.
  6710. For information on how to use these tests, see the comments at the
  6711. top of the EdgeRouterTarget
  6712. ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file.
  6713. - *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running
  6714. tests on any generic PC that boots using GRUB. For information on how
  6715. to use these tests, see the comments at the top of the GrubTarget
  6716. ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file.
  6717. - *"your-target":* Create your own custom target if you want to run
  6718. tests when you are deploying images and running tests on a custom
  6719. machine within your BSP layer. To do this, you need to add a Python
  6720. unit that defines the target class under ``lib/oeqa/controllers/``
  6721. within your layer. You must also provide an empty ``__init__.py``.
  6722. For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``.
  6723. Selecting SystemdbootTarget
  6724. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6725. If you did not set :term:`TEST_TARGET` to "SystemdbootTarget", then you do
  6726. not need any information in this section. You can skip down to the
  6727. ":ref:`dev-manual/common-tasks:running tests`" section.
  6728. If you did set :term:`TEST_TARGET` to "SystemdbootTarget", you also need to
  6729. perform a one-time setup of your controller image by doing the following:
  6730. 1. *Set EFI_PROVIDER:* Be sure that :term:`EFI_PROVIDER` is as follows::
  6731. EFI_PROVIDER = "systemd-boot"
  6732. 2. *Build the controller image:* Build the ``core-image-testmaster`` image.
  6733. The ``core-image-testmaster`` recipe is provided as an example for a
  6734. "controller" image and you can customize the image recipe as you would
  6735. any other recipe.
  6736. Here are the image recipe requirements:
  6737. - Inherits ``core-image`` so that kernel modules are installed.
  6738. - Installs normal linux utilities not BusyBox ones (e.g. ``bash``,
  6739. ``coreutils``, ``tar``, ``gzip``, and ``kmod``).
  6740. - Uses a custom Initial RAM Disk (initramfs) image with a custom
  6741. installer. A normal image that you can install usually creates a
  6742. single root filesystem partition. This image uses another installer that
  6743. creates a specific partition layout. Not all Board Support
  6744. Packages (BSPs) can use an installer. For such cases, you need to
  6745. manually create the following partition layout on the target:
  6746. - First partition mounted under ``/boot``, labeled "boot".
  6747. - The main root filesystem partition where this image gets installed,
  6748. which is mounted under ``/``.
  6749. - Another partition labeled "testrootfs" where test images get
  6750. deployed.
  6751. 3. *Install image:* Install the image that you just built on the target
  6752. system.
  6753. The final thing you need to do when setting :term:`TEST_TARGET` to
  6754. "SystemdbootTarget" is to set up the test image:
  6755. 1. *Set up your local.conf file:* Make sure you have the following
  6756. statements in your ``local.conf`` file::
  6757. IMAGE_FSTYPES += "tar.gz"
  6758. INHERIT += "testimage"
  6759. TEST_TARGET = "SystemdbootTarget"
  6760. TEST_TARGET_IP = "192.168.2.3"
  6761. 2. *Build your test image:* Use BitBake to build the image::
  6762. $ bitbake core-image-sato
  6763. Power Control
  6764. ~~~~~~~~~~~~~
  6765. For most hardware targets other than "simpleremote", you can control
  6766. power:
  6767. - You can use :term:`TEST_POWERCONTROL_CMD` together with
  6768. :term:`TEST_POWERCONTROL_EXTRA_ARGS` as a command that runs on the host
  6769. and does power cycling. The test code passes one argument to that
  6770. command: off, on or cycle (off then on). Here is an example that
  6771. could appear in your ``local.conf`` file::
  6772. TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
  6773. In this example, the expect
  6774. script does the following:
  6775. .. code-block:: shell
  6776. ssh test@10.11.12.1 "pyctl nuc1 arg"
  6777. It then runs a Python script that controls power for a label called
  6778. ``nuc1``.
  6779. .. note::
  6780. You need to customize :term:`TEST_POWERCONTROL_CMD` and
  6781. :term:`TEST_POWERCONTROL_EXTRA_ARGS` for your own setup. The one requirement
  6782. is that it accepts "on", "off", and "cycle" as the last argument.
  6783. - When no command is defined, it connects to the device over SSH and
  6784. uses the classic reboot command to reboot the device. Classic reboot
  6785. is fine as long as the machine actually reboots (i.e. the SSH test
  6786. has not failed). It is useful for scenarios where you have a simple
  6787. setup, typically with a single board, and where some manual
  6788. interaction is okay from time to time.
  6789. If you have no hardware to automatically perform power control but still
  6790. wish to experiment with automated hardware testing, you can use the
  6791. ``dialog-power-control`` script that shows a dialog prompting you to perform
  6792. the required power action. This script requires either KDialog or Zenity
  6793. to be installed. To use this script, set the
  6794. :term:`TEST_POWERCONTROL_CMD`
  6795. variable as follows::
  6796. TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
  6797. Serial Console Connection
  6798. ~~~~~~~~~~~~~~~~~~~~~~~~~
  6799. For test target classes requiring a serial console to interact with the
  6800. bootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget),
  6801. you need to specify a command to use to connect to the serial console of
  6802. the target machine by using the
  6803. :term:`TEST_SERIALCONTROL_CMD`
  6804. variable and optionally the
  6805. :term:`TEST_SERIALCONTROL_EXTRA_ARGS`
  6806. variable.
  6807. These cases could be a serial terminal program if the machine is
  6808. connected to a local serial port, or a ``telnet`` or ``ssh`` command
  6809. connecting to a remote console server. Regardless of the case, the
  6810. command simply needs to connect to the serial console and forward that
  6811. connection to standard input and output as any normal terminal program
  6812. does. For example, to use the picocom terminal program on serial device
  6813. ``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows::
  6814. TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
  6815. For local
  6816. devices where the serial port device disappears when the device reboots,
  6817. an additional "serdevtry" wrapper script is provided. To use this
  6818. wrapper, simply prefix the terminal command with
  6819. ``${COREBASE}/scripts/contrib/serdevtry``::
  6820. TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0"
  6821. Running Tests
  6822. -------------
  6823. You can start the tests automatically or manually:
  6824. - *Automatically running tests:* To run the tests automatically after
  6825. the OpenEmbedded build system successfully creates an image, first
  6826. set the
  6827. :term:`TESTIMAGE_AUTO`
  6828. variable to "1" in your ``local.conf`` file in the
  6829. :term:`Build Directory`::
  6830. TESTIMAGE_AUTO = "1"
  6831. Next, build your image. If the image successfully builds, the
  6832. tests run::
  6833. bitbake core-image-sato
  6834. - *Manually running tests:* To manually run the tests, first globally
  6835. inherit the
  6836. :ref:`testimage <ref-classes-testimage*>` class
  6837. by editing your ``local.conf`` file::
  6838. INHERIT += "testimage"
  6839. Next, use BitBake to run the tests::
  6840. bitbake -c testimage image
  6841. All test files reside in ``meta/lib/oeqa/runtime`` in the
  6842. :term:`Source Directory`. A test name maps
  6843. directly to a Python module. Each test module may contain a number of
  6844. individual tests. Tests are usually grouped together by the area tested
  6845. (e.g tests for systemd reside in ``meta/lib/oeqa/runtime/systemd.py``).
  6846. You can add tests to any layer provided you place them in the proper
  6847. area and you extend :term:`BBPATH` in
  6848. the ``local.conf`` file as normal. Be sure that tests reside in
  6849. ``layer/lib/oeqa/runtime``.
  6850. .. note::
  6851. Be sure that module names do not collide with module names used in
  6852. the default set of test modules in ``meta/lib/oeqa/runtime``.
  6853. You can change the set of tests run by appending or overriding
  6854. :term:`TEST_SUITES` variable in
  6855. ``local.conf``. Each name in :term:`TEST_SUITES` represents a required test
  6856. for the image. Test modules named within :term:`TEST_SUITES` cannot be
  6857. skipped even if a test is not suitable for an image (e.g. running the
  6858. RPM tests on an image without ``rpm``). Appending "auto" to
  6859. :term:`TEST_SUITES` causes the build system to try to run all tests that are
  6860. suitable for the image (i.e. each test module may elect to skip itself).
  6861. The order you list tests in :term:`TEST_SUITES` is important and influences
  6862. test dependencies. Consequently, tests that depend on other tests should
  6863. be added after the test on which they depend. For example, since the
  6864. ``ssh`` test depends on the ``ping`` test, "ssh" needs to come after
  6865. "ping" in the list. The test class provides no re-ordering or dependency
  6866. handling.
  6867. .. note::
  6868. Each module can have multiple classes with multiple test methods.
  6869. And, Python ``unittest`` rules apply.
  6870. Here are some things to keep in mind when running tests:
  6871. - The default tests for the image are defined as::
  6872. DEFAULT_TEST_SUITES:pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg"
  6873. - Add your own test to the list of the by using the following::
  6874. TEST_SUITES:append = " mytest"
  6875. - Run a specific list of tests as follows::
  6876. TEST_SUITES = "test1 test2 test3"
  6877. Remember, order is important. Be sure to place a test that is
  6878. dependent on another test later in the order.
  6879. Exporting Tests
  6880. ---------------
  6881. You can export tests so that they can run independently of the build
  6882. system. Exporting tests is required if you want to be able to hand the
  6883. test execution off to a scheduler. You can only export tests that are
  6884. defined in :term:`TEST_SUITES`.
  6885. If your image is already built, make sure the following are set in your
  6886. ``local.conf`` file::
  6887. INHERIT += "testexport"
  6888. TEST_TARGET_IP = "IP-address-for-the-test-target"
  6889. TEST_SERVER_IP = "IP-address-for-the-test-server"
  6890. You can then export the tests with the
  6891. following BitBake command form::
  6892. $ bitbake image -c testexport
  6893. Exporting the tests places them in the
  6894. :term:`Build Directory` in
  6895. ``tmp/testexport/``\ image, which is controlled by the
  6896. :term:`TEST_EXPORT_DIR` variable.
  6897. You can now run the tests outside of the build environment::
  6898. $ cd tmp/testexport/image
  6899. $ ./runexported.py testdata.json
  6900. Here is a complete example that shows IP addresses and uses the
  6901. ``core-image-sato`` image::
  6902. INHERIT += "testexport"
  6903. TEST_TARGET_IP = "192.168.7.2"
  6904. TEST_SERVER_IP = "192.168.7.1"
  6905. Use BitBake to export the tests::
  6906. $ bitbake core-image-sato -c testexport
  6907. Run the tests outside of
  6908. the build environment using the following::
  6909. $ cd tmp/testexport/core-image-sato
  6910. $ ./runexported.py testdata.json
  6911. Writing New Tests
  6912. -----------------
  6913. As mentioned previously, all new test files need to be in the proper
  6914. place for the build system to find them. New tests for additional
  6915. functionality outside of the core should be added to the layer that adds
  6916. the functionality, in ``layer/lib/oeqa/runtime`` (as long as
  6917. :term:`BBPATH` is extended in the
  6918. layer's ``layer.conf`` file as normal). Just remember the following:
  6919. - Filenames need to map directly to test (module) names.
  6920. - Do not use module names that collide with existing core tests.
  6921. - Minimally, an empty ``__init__.py`` file must be present in the runtime
  6922. directory.
  6923. To create a new test, start by copying an existing module (e.g.
  6924. ``syslog.py`` or ``gcc.py`` are good ones to use). Test modules can use
  6925. code from ``meta/lib/oeqa/utils``, which are helper classes.
  6926. .. note::
  6927. Structure shell commands such that you rely on them and they return a
  6928. single code for success. Be aware that sometimes you will need to
  6929. parse the output. See the ``df.py`` and ``date.py`` modules for examples.
  6930. You will notice that all test classes inherit ``oeRuntimeTest``, which
  6931. is found in ``meta/lib/oetest.py``. This base class offers some helper
  6932. attributes, which are described in the following sections:
  6933. Class Methods
  6934. ~~~~~~~~~~~~~
  6935. Class methods are as follows:
  6936. - *hasPackage(pkg):* Returns "True" if ``pkg`` is in the installed
  6937. package list of the image, which is based on the manifest file that
  6938. is generated during the ``do_rootfs`` task.
  6939. - *hasFeature(feature):* Returns "True" if the feature is in
  6940. :term:`IMAGE_FEATURES` or
  6941. :term:`DISTRO_FEATURES`.
  6942. Class Attributes
  6943. ~~~~~~~~~~~~~~~~
  6944. Class attributes are as follows:
  6945. - *pscmd:* Equals "ps -ef" if ``procps`` is installed in the image.
  6946. Otherwise, ``pscmd`` equals "ps" (busybox).
  6947. - *tc:* The called test context, which gives access to the
  6948. following attributes:
  6949. - *d:* The BitBake datastore, which allows you to use stuff such
  6950. as ``oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")``.
  6951. - *testslist and testsrequired:* Used internally. The tests
  6952. do not need these.
  6953. - *filesdir:* The absolute path to
  6954. ``meta/lib/oeqa/runtime/files``, which contains helper files for
  6955. tests meant for copying on the target such as small files written
  6956. in C for compilation.
  6957. - *target:* The target controller object used to deploy and
  6958. start an image on a particular target (e.g. Qemu, SimpleRemote,
  6959. and SystemdbootTarget). Tests usually use the following:
  6960. - *ip:* The target's IP address.
  6961. - *server_ip:* The host's IP address, which is usually used
  6962. by the DNF test suite.
  6963. - *run(cmd, timeout=None):* The single, most used method.
  6964. This command is a wrapper for: ``ssh root@host "cmd"``. The
  6965. command returns a tuple: (status, output), which are what their
  6966. names imply - the return code of "cmd" and whatever output it
  6967. produces. The optional timeout argument represents the number
  6968. of seconds the test should wait for "cmd" to return. If the
  6969. argument is "None", the test uses the default instance's
  6970. timeout period, which is 300 seconds. If the argument is "0",
  6971. the test runs until the command returns.
  6972. - *copy_to(localpath, remotepath):*
  6973. ``scp localpath root@ip:remotepath``.
  6974. - *copy_from(remotepath, localpath):*
  6975. ``scp root@host:remotepath localpath``.
  6976. Instance Attributes
  6977. ~~~~~~~~~~~~~~~~~~~
  6978. There is a single instance attribute, which is ``target``. The ``target``
  6979. instance attribute is identical to the class attribute of the same name,
  6980. which is described in the previous section. This attribute exists as
  6981. both an instance and class attribute so tests can use
  6982. ``self.target.run(cmd)`` in instance methods instead of
  6983. ``oeRuntimeTest.tc.target.run(cmd)``.
  6984. Installing Packages in the DUT Without the Package Manager
  6985. ----------------------------------------------------------
  6986. When a test requires a package built by BitBake, it is possible to
  6987. install that package. Installing the package does not require a package
  6988. manager be installed in the device under test (DUT). It does, however,
  6989. require an SSH connection and the target must be using the
  6990. ``sshcontrol`` class.
  6991. .. note::
  6992. This method uses ``scp`` to copy files from the host to the target, which
  6993. causes permissions and special attributes to be lost.
  6994. A JSON file is used to define the packages needed by a test. This file
  6995. must be in the same path as the file used to define the tests.
  6996. Furthermore, the filename must map directly to the test module name with
  6997. a ``.json`` extension.
  6998. The JSON file must include an object with the test name as keys of an
  6999. object or an array. This object (or array of objects) uses the following
  7000. data:
  7001. - "pkg" - A mandatory string that is the name of the package to be
  7002. installed.
  7003. - "rm" - An optional boolean, which defaults to "false", that specifies
  7004. to remove the package after the test.
  7005. - "extract" - An optional boolean, which defaults to "false", that
  7006. specifies if the package must be extracted from the package format.
  7007. When set to "true", the package is not automatically installed into
  7008. the DUT.
  7009. Following is an example JSON file that handles test "foo" installing
  7010. package "bar" and test "foobar" installing packages "foo" and "bar".
  7011. Once the test is complete, the packages are removed from the DUT.
  7012. ::
  7013. {
  7014. "foo": {
  7015. "pkg": "bar"
  7016. },
  7017. "foobar": [
  7018. {
  7019. "pkg": "foo",
  7020. "rm": true
  7021. },
  7022. {
  7023. "pkg": "bar",
  7024. "rm": true
  7025. }
  7026. ]
  7027. }
  7028. Debugging Tools and Techniques
  7029. ==============================
  7030. The exact method for debugging build failures depends on the nature of
  7031. the problem and on the system's area from which the bug originates.
  7032. Standard debugging practices such as comparison against the last known
  7033. working version with examination of the changes and the re-application
  7034. of steps to identify the one causing the problem are valid for the Yocto
  7035. Project just as they are for any other system. Even though it is
  7036. impossible to detail every possible potential failure, this section
  7037. provides some general tips to aid in debugging given a variety of
  7038. situations.
  7039. .. note::
  7040. A useful feature for debugging is the error reporting tool.
  7041. Configuring the Yocto Project to use this tool causes the
  7042. OpenEmbedded build system to produce error reporting commands as part
  7043. of the console output. You can enter the commands after the build
  7044. completes to log error information into a common database, that can
  7045. help you figure out what might be going wrong. For information on how
  7046. to enable and use this feature, see the
  7047. ":ref:`dev-manual/common-tasks:using the error reporting tool`"
  7048. section.
  7049. The following list shows the debugging topics in the remainder of this
  7050. section:
  7051. - ":ref:`dev-manual/common-tasks:viewing logs from failed tasks`" describes
  7052. how to find and view logs from tasks that failed during the build
  7053. process.
  7054. - ":ref:`dev-manual/common-tasks:viewing variable values`" describes how to
  7055. use the BitBake ``-e`` option to examine variable values after a
  7056. recipe has been parsed.
  7057. - ":ref:`dev-manual/common-tasks:viewing package information with \`\`oe-pkgdata-util\`\``"
  7058. describes how to use the ``oe-pkgdata-util`` utility to query
  7059. :term:`PKGDATA_DIR` and
  7060. display package-related information for built packages.
  7061. - ":ref:`dev-manual/common-tasks:viewing dependencies between recipes and tasks`"
  7062. describes how to use the BitBake ``-g`` option to display recipe
  7063. dependency information used during the build.
  7064. - ":ref:`dev-manual/common-tasks:viewing task variable dependencies`" describes
  7065. how to use the ``bitbake-dumpsig`` command in conjunction with key
  7066. subdirectories in the
  7067. :term:`Build Directory` to determine
  7068. variable dependencies.
  7069. - ":ref:`dev-manual/common-tasks:running specific tasks`" describes
  7070. how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``)
  7071. to run specific tasks in the build chain. It can be useful to run
  7072. tasks "out-of-order" when trying isolate build issues.
  7073. - ":ref:`dev-manual/common-tasks:general BitBake problems`" describes how
  7074. to use BitBake's ``-D`` debug output option to reveal more about what
  7075. BitBake is doing during the build.
  7076. - ":ref:`dev-manual/common-tasks:building with no dependencies`"
  7077. describes how to use the BitBake ``-b`` option to build a recipe
  7078. while ignoring dependencies.
  7079. - ":ref:`dev-manual/common-tasks:recipe logging mechanisms`"
  7080. describes how to use the many recipe logging functions to produce
  7081. debugging output and report errors and warnings.
  7082. - ":ref:`dev-manual/common-tasks:debugging parallel make races`"
  7083. describes how to debug situations where the build consists of several
  7084. parts that are run simultaneously and when the output or result of
  7085. one part is not ready for use with a different part of the build that
  7086. depends on that output.
  7087. - ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) remotely`"
  7088. describes how to use GDB to allow you to examine running programs, which can
  7089. help you fix problems.
  7090. - ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) on the target`"
  7091. describes how to use GDB directly on target hardware for debugging.
  7092. - ":ref:`dev-manual/common-tasks:other debugging tips`" describes
  7093. miscellaneous debugging tips that can be useful.
  7094. Viewing Logs from Failed Tasks
  7095. ------------------------------
  7096. You can find the log for a task in the file
  7097. ``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`.
  7098. For example, the log for the
  7099. :ref:`ref-tasks-compile` task of the
  7100. QEMU minimal image for the x86 machine (``qemux86``) might be in
  7101. ``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``.
  7102. To see the commands :term:`BitBake` ran
  7103. to generate a log, look at the corresponding ``run.do_``\ `taskname` file
  7104. in the same directory.
  7105. ``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic
  7106. links to ``log.do_``\ `taskname`\ ``.``\ `pid` and
  7107. ``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had
  7108. when it ran. The symlinks always point to the files corresponding to the
  7109. most recent run.
  7110. Viewing Variable Values
  7111. -----------------------
  7112. Sometimes you need to know the value of a variable as a result of
  7113. BitBake's parsing step. This could be because some unexpected behavior
  7114. occurred in your project. Perhaps an attempt to :ref:`modify a variable
  7115. <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing
  7116. variables>` did not work out as expected.
  7117. BitBake's ``-e`` option is used to display variable values after
  7118. parsing. The following command displays the variable values after the
  7119. configuration files (i.e. ``local.conf``, ``bblayers.conf``,
  7120. ``bitbake.conf`` and so forth) have been parsed::
  7121. $ bitbake -e
  7122. The following command displays variable values after a specific recipe has
  7123. been parsed. The variables include those from the configuration as well::
  7124. $ bitbake -e recipename
  7125. .. note::
  7126. Each recipe has its own private set of variables (datastore).
  7127. Internally, after parsing the configuration, a copy of the resulting
  7128. datastore is made prior to parsing each recipe. This copying implies
  7129. that variables set in one recipe will not be visible to other
  7130. recipes.
  7131. Likewise, each task within a recipe gets a private datastore based on
  7132. the recipe datastore, which means that variables set within one task
  7133. will not be visible to other tasks.
  7134. In the output of ``bitbake -e``, each variable is preceded by a
  7135. description of how the variable got its value, including temporary
  7136. values that were later overridden. This description also includes
  7137. variable flags (varflags) set on the variable. The output can be very
  7138. helpful during debugging.
  7139. Variables that are exported to the environment are preceded by
  7140. ``export`` in the output of ``bitbake -e``. See the following example::
  7141. export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
  7142. In addition to variable values, the output of the ``bitbake -e`` and
  7143. ``bitbake -e`` recipe commands includes the following information:
  7144. - The output starts with a tree listing all configuration files and
  7145. classes included globally, recursively listing the files they include
  7146. or inherit in turn. Much of the behavior of the OpenEmbedded build
  7147. system (including the behavior of the :ref:`ref-manual/tasks:normal recipe build tasks`) is
  7148. implemented in the
  7149. :ref:`base <ref-classes-base>` class and the
  7150. classes it inherits, rather than being built into BitBake itself.
  7151. - After the variable values, all functions appear in the output. For
  7152. shell functions, variables referenced within the function body are
  7153. expanded. If a function has been modified using overrides or using
  7154. override-style operators like ``:append`` and ``:prepend``, then the
  7155. final assembled function body appears in the output.
  7156. Viewing Package Information with ``oe-pkgdata-util``
  7157. ----------------------------------------------------
  7158. You can use the ``oe-pkgdata-util`` command-line utility to query
  7159. :term:`PKGDATA_DIR` and display
  7160. various package-related information. When you use the utility, you must
  7161. use it to view information on packages that have already been built.
  7162. Following are a few of the available ``oe-pkgdata-util`` subcommands.
  7163. .. note::
  7164. You can use the standard \* and ? globbing wildcards as part of
  7165. package names and paths.
  7166. - ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages
  7167. that have been built, optionally limiting the match to packages that
  7168. match pattern.
  7169. - ``oe-pkgdata-util list-pkg-files package ...``: Lists the
  7170. files and directories contained in the given packages.
  7171. .. note::
  7172. A different way to view the contents of a package is to look at
  7173. the
  7174. ``${``\ :term:`WORKDIR`\ ``}/packages-split``
  7175. directory of the recipe that generates the package. This directory
  7176. is created by the
  7177. :ref:`ref-tasks-package` task
  7178. and has one subdirectory for each package the recipe generates,
  7179. which contains the files stored in that package.
  7180. If you want to inspect the ``${WORKDIR}/packages-split``
  7181. directory, make sure that
  7182. :ref:`rm_work <ref-classes-rm-work>` is not
  7183. enabled when you build the recipe.
  7184. - ``oe-pkgdata-util find-path path ...``: Lists the names of
  7185. the packages that contain the given paths. For example, the following
  7186. tells us that ``/usr/share/man/man1/make.1`` is contained in the
  7187. ``make-doc`` package::
  7188. $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
  7189. make-doc: /usr/share/man/man1/make.1
  7190. - ``oe-pkgdata-util lookup-recipe package ...``: Lists the name
  7191. of the recipes that produce the given packages.
  7192. For more information on the ``oe-pkgdata-util`` command, use the help
  7193. facility::
  7194. $ oe-pkgdata-util --help
  7195. $ oe-pkgdata-util subcommand --help
  7196. Viewing Dependencies Between Recipes and Tasks
  7197. ----------------------------------------------
  7198. Sometimes it can be hard to see why BitBake wants to build other recipes
  7199. before the one you have specified. Dependency information can help you
  7200. understand why a recipe is built.
  7201. To generate dependency information for a recipe, run the following
  7202. command::
  7203. $ bitbake -g recipename
  7204. This command writes the following files in the current directory:
  7205. - ``pn-buildlist``: A list of recipes/targets involved in building
  7206. `recipename`. "Involved" here means that at least one task from the
  7207. recipe needs to run when building `recipename` from scratch. Targets
  7208. that are in
  7209. :term:`ASSUME_PROVIDED`
  7210. are not listed.
  7211. - ``task-depends.dot``: A graph showing dependencies between tasks.
  7212. The graphs are in
  7213. `DOT <https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29>`__
  7214. format and can be converted to images (e.g. using the ``dot`` tool from
  7215. `Graphviz <https://www.graphviz.org/>`__).
  7216. .. note::
  7217. - DOT files use a plain text format. The graphs generated using the
  7218. ``bitbake -g`` command are often so large as to be difficult to
  7219. read without special pruning (e.g. with BitBake's ``-I`` option)
  7220. and processing. Despite the form and size of the graphs, the
  7221. corresponding ``.dot`` files can still be possible to read and
  7222. provide useful information.
  7223. As an example, the ``task-depends.dot`` file contains lines such
  7224. as the following::
  7225. "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
  7226. The above example line reveals that the
  7227. :ref:`ref-tasks-configure`
  7228. task in ``libxslt`` depends on the
  7229. :ref:`ref-tasks-populate_sysroot`
  7230. task in ``libxml2``, which is a normal
  7231. :term:`DEPENDS` dependency
  7232. between the two recipes.
  7233. - For an example of how ``.dot`` files can be processed, see the
  7234. ``scripts/contrib/graph-tool`` Python script, which finds and
  7235. displays paths between graph nodes.
  7236. You can use a different method to view dependency information by using
  7237. the following command::
  7238. $ bitbake -g -u taskexp recipename
  7239. This command
  7240. displays a GUI window from which you can view build-time and runtime
  7241. dependencies for the recipes involved in building recipename.
  7242. Viewing Task Variable Dependencies
  7243. ----------------------------------
  7244. As mentioned in the
  7245. ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake
  7246. User Manual, BitBake tries to automatically determine what variables a
  7247. task depends on so that it can rerun the task if any values of the
  7248. variables change. This determination is usually reliable. However, if
  7249. you do things like construct variable names at runtime, then you might
  7250. have to manually declare dependencies on those variables using
  7251. ``vardeps`` as described in the
  7252. ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake
  7253. User Manual.
  7254. If you are unsure whether a variable dependency is being picked up
  7255. automatically for a given task, you can list the variable dependencies
  7256. BitBake has determined by doing the following:
  7257. 1. Build the recipe containing the task::
  7258. $ bitbake recipename
  7259. 2. Inside the :term:`STAMPS_DIR`
  7260. directory, find the signature data (``sigdata``) file that
  7261. corresponds to the task. The ``sigdata`` files contain a pickled
  7262. Python database of all the metadata that went into creating the input
  7263. checksum for the task. As an example, for the
  7264. :ref:`ref-tasks-fetch` task of the
  7265. ``db`` recipe, the ``sigdata`` file might be found in the following
  7266. location::
  7267. ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
  7268. For tasks that are accelerated through the shared state
  7269. (:ref:`sstate <overview-manual/concepts:shared state cache>`) cache, an
  7270. additional ``siginfo`` file is written into
  7271. :term:`SSTATE_DIR` along with
  7272. the cached task output. The ``siginfo`` files contain exactly the
  7273. same information as ``sigdata`` files.
  7274. 3. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here
  7275. is an example::
  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:`BB_BASEHASH_IGNORE_VARS`
  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. ‐‐dump-signatures=SIGNATURE_HANDLER
  7299. -S SIGNATURE_HANDLER
  7300. .. note::
  7301. Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which
  7302. dump only the signature or compare the dumped signature with the cached one,
  7303. respectively.
  7304. Using BitBake with either of these options causes BitBake to dump out
  7305. ``sigdata`` files in the ``stamps`` directory for every task it would
  7306. have executed instead of building the specified target package.
  7307. Viewing Metadata Used to Create the Input Signature of a Shared State Task
  7308. --------------------------------------------------------------------------
  7309. Seeing what metadata went into creating the input signature of a shared
  7310. state (sstate) task can be a useful debugging aid. This information is
  7311. available in signature information (``siginfo``) files in
  7312. :term:`SSTATE_DIR`. For
  7313. information on how to view and interpret information in ``siginfo``
  7314. files, see the
  7315. ":ref:`dev-manual/common-tasks:viewing task variable dependencies`" section.
  7316. For conceptual information on shared state, see the
  7317. ":ref:`overview-manual/concepts:shared state`"
  7318. section in the Yocto Project Overview and Concepts Manual.
  7319. Invalidating Shared State to Force a Task to Run
  7320. ------------------------------------------------
  7321. The OpenEmbedded build system uses
  7322. :ref:`checksums <overview-manual/concepts:checksums (signatures)>` and
  7323. :ref:`overview-manual/concepts:shared state` cache to avoid unnecessarily
  7324. rebuilding tasks. Collectively, this scheme is known as "shared state
  7325. code".
  7326. As with all schemes, this one has some drawbacks. It is possible that
  7327. you could make implicit changes to your code that the checksum
  7328. calculations do not take into account. These implicit changes affect a
  7329. task's output but do not trigger the shared state code into rebuilding a
  7330. recipe. Consider an example during which a tool changes its output.
  7331. Assume that the output of ``rpmdeps`` changes. The result of the change
  7332. should be that all the ``package`` and ``package_write_rpm`` shared
  7333. state cache items become invalid. However, because the change to the
  7334. output is external to the code and therefore implicit, the associated
  7335. shared state cache items do not become invalidated. In this case, the
  7336. build process uses the cached items rather than running the task again.
  7337. Obviously, these types of implicit changes can cause problems.
  7338. To avoid these problems during the build, you need to understand the
  7339. effects of any changes you make. Realize that changes you make directly
  7340. to a function are automatically factored into the checksum calculation.
  7341. Thus, these explicit changes invalidate the associated area of shared
  7342. state cache. However, you need to be aware of any implicit changes that
  7343. are not obvious changes to the code and could affect the output of a
  7344. given task.
  7345. When you identify an implicit change, you can easily take steps to
  7346. invalidate the cache and force the tasks to run. The steps you can take
  7347. are as simple as changing a function's comments in the source code. For
  7348. example, to invalidate package shared state files, change the comment
  7349. statements of
  7350. :ref:`ref-tasks-package` or the
  7351. comments of one of the functions it calls. Even though the change is
  7352. purely cosmetic, it causes the checksum to be recalculated and forces
  7353. the build system to run the task again.
  7354. .. note::
  7355. For an example of a commit that makes a cosmetic change to invalidate
  7356. shared state, see this
  7357. :yocto_git:`commit </poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`.
  7358. Running Specific Tasks
  7359. ----------------------
  7360. Any given recipe consists of a set of tasks. The standard BitBake
  7361. behavior in most cases is: ``do_fetch``, ``do_unpack``, ``do_patch``,
  7362. ``do_configure``, ``do_compile``, ``do_install``, ``do_package``,
  7363. ``do_package_write_*``, and ``do_build``. The default task is
  7364. ``do_build`` and any tasks on which it depends build first. Some tasks,
  7365. such as ``do_devshell``, are not part of the default build chain. If you
  7366. wish to run a task that is not part of the default build chain, you can
  7367. use the ``-c`` option in BitBake. Here is an example::
  7368. $ bitbake matchbox-desktop -c devshell
  7369. The ``-c`` option respects task dependencies, which means that all other
  7370. tasks (including tasks from other recipes) that the specified task
  7371. depends on will be run before the task. Even when you manually specify a
  7372. task to run with ``-c``, BitBake will only run the task if it considers
  7373. it "out of date". See the
  7374. ":ref:`overview-manual/concepts:stamp files and the rerunning of tasks`"
  7375. section in the Yocto Project Overview and Concepts Manual for how
  7376. BitBake determines whether a task is "out of date".
  7377. If you want to force an up-to-date task to be rerun (e.g. because you
  7378. made manual modifications to the recipe's
  7379. :term:`WORKDIR` that you want to try
  7380. out), then you can use the ``-f`` option.
  7381. .. note::
  7382. The reason ``-f`` is never required when running the
  7383. :ref:`ref-tasks-devshell` task is because the
  7384. [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ]
  7385. variable flag is already set for the task.
  7386. The following example shows one way you can use the ``-f`` option::
  7387. $ bitbake matchbox-desktop
  7388. .
  7389. .
  7390. make some changes to the source code in the work directory
  7391. .
  7392. .
  7393. $ bitbake matchbox-desktop -c compile -f
  7394. $ bitbake matchbox-desktop
  7395. This sequence first builds and then recompiles ``matchbox-desktop``. The
  7396. last command reruns all tasks (basically the packaging tasks) after the
  7397. compile. BitBake recognizes that the ``do_compile`` task was rerun and
  7398. therefore understands that the other tasks also need to be run again.
  7399. Another, shorter way to rerun a task and all
  7400. :ref:`ref-manual/tasks:normal recipe build tasks`
  7401. that depend on it is to use the ``-C`` option.
  7402. .. note::
  7403. This option is upper-cased and is separate from the ``-c``
  7404. option, which is lower-cased.
  7405. Using this option invalidates the given task and then runs the
  7406. :ref:`ref-tasks-build` task, which is
  7407. the default task if no task is given, and the tasks on which it depends.
  7408. You could replace the final two commands in the previous example with
  7409. the following single command::
  7410. $ bitbake matchbox-desktop -C compile
  7411. Internally, the ``-f`` and ``-C`` options work by tainting (modifying)
  7412. the input checksum of the specified task. This tainting indirectly
  7413. causes the task and its dependent tasks to be rerun through the normal
  7414. task dependency mechanisms.
  7415. .. note::
  7416. BitBake explicitly keeps track of which tasks have been tainted in
  7417. this fashion, and will print warnings such as the following for
  7418. builds involving such tasks:
  7419. .. code-block:: none
  7420. WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
  7421. The purpose of the warning is to let you know that the work directory
  7422. and build output might not be in the clean state they would be in for
  7423. a "normal" build, depending on what actions you took. To get rid of
  7424. such warnings, you can remove the work directory and rebuild the
  7425. recipe, as follows::
  7426. $ bitbake matchbox-desktop -c clean
  7427. $ bitbake matchbox-desktop
  7428. You can view a list of tasks in a given package by running the
  7429. ``do_listtasks`` task as follows::
  7430. $ bitbake matchbox-desktop -c listtasks
  7431. The results appear as output to the console and are also in
  7432. the file ``${WORKDIR}/temp/log.do_listtasks``.
  7433. General BitBake Problems
  7434. ------------------------
  7435. You can see debug output from BitBake by using the ``-D`` option. The
  7436. debug output gives more information about what BitBake is doing and the
  7437. reason behind it. Each ``-D`` option you use increases the logging
  7438. level. The most common usage is ``-DDD``.
  7439. The output from ``bitbake -DDD -v targetname`` can reveal why BitBake
  7440. chose a certain version of a package or why BitBake picked a certain
  7441. provider. This command could also help you in a situation where you
  7442. think BitBake did something unexpected.
  7443. Building with No Dependencies
  7444. -----------------------------
  7445. To build a specific recipe (``.bb`` file), you can use the following
  7446. command form::
  7447. $ bitbake -b somepath/somerecipe.bb
  7448. This command form does
  7449. not check for dependencies. Consequently, you should use it only when
  7450. you know existing dependencies have been met.
  7451. .. note::
  7452. You can also specify fragments of the filename. In this case, BitBake
  7453. checks for a unique match.
  7454. Recipe Logging Mechanisms
  7455. -------------------------
  7456. The Yocto Project provides several logging functions for producing
  7457. debugging output and reporting errors and warnings. For Python
  7458. functions, the following logging functions are available. All of these functions
  7459. log to ``${T}/log.do_``\ `task`, and can also log to standard output
  7460. (stdout) with the right settings:
  7461. - ``bb.plain(msg)``: Writes msg as is to the log while also
  7462. logging to stdout.
  7463. - ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to
  7464. stdout if BitBake is called with "-v".
  7465. - ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the
  7466. log. Also logs to stdout if the log level is greater than or equal to
  7467. level. See the ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax`" option
  7468. in the BitBake User Manual for more information.
  7469. - ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also
  7470. logging to stdout.
  7471. - ``bb.error(msg)``: Writes "ERROR: msg" to the log while also
  7472. logging to standard out (stdout).
  7473. .. note::
  7474. Calling this function does not cause the task to fail.
  7475. - ``bb.fatal(msg)``: This logging function is similar to
  7476. ``bb.error(msg)`` but also causes the calling task to fail.
  7477. .. note::
  7478. ``bb.fatal()`` raises an exception, which means you do not need to put a
  7479. "return" statement after the function.
  7480. The same logging functions are also available in shell functions, under
  7481. the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``,
  7482. and ``bbfatal``. The
  7483. :ref:`logging <ref-classes-logging>` class
  7484. implements these functions. See that class in the ``meta/classes``
  7485. folder of the :term:`Source Directory` for information.
  7486. Logging With Python
  7487. ~~~~~~~~~~~~~~~~~~~
  7488. When creating recipes using Python and inserting code that handles build
  7489. logs, keep in mind the goal is to have informative logs while keeping
  7490. the console as "silent" as possible. Also, if you want status messages
  7491. in the log, use the "debug" loglevel.
  7492. Following is an example written in Python. The code handles logging for
  7493. a function that determines the number of tasks needed to be run. See the
  7494. ":ref:`ref-tasks-listtasks`"
  7495. section for additional information::
  7496. python do_listtasks() {
  7497. bb.debug(2, "Starting to figure out the task list")
  7498. if noteworthy_condition:
  7499. bb.note("There are 47 tasks to run")
  7500. bb.debug(2, "Got to point xyz")
  7501. if warning_trigger:
  7502. bb.warn("Detected warning_trigger, this might be a problem later.")
  7503. if recoverable_error:
  7504. bb.error("Hit recoverable_error, you really need to fix this!")
  7505. if fatal_error:
  7506. bb.fatal("fatal_error detected, unable to print the task list")
  7507. bb.plain("The tasks present are abc")
  7508. bb.debug(2, "Finished figuring out the tasklist")
  7509. }
  7510. Logging With Bash
  7511. ~~~~~~~~~~~~~~~~~
  7512. When creating recipes using Bash and inserting code that handles build
  7513. logs, you have the same goals - informative with minimal console output.
  7514. The syntax you use for recipes written in Bash is similar to that of
  7515. recipes written in Python described in the previous section.
  7516. Following is an example written in Bash. The code logs the progress of
  7517. the ``do_my_function`` function.
  7518. ::
  7519. do_my_function() {
  7520. bbdebug 2 "Running do_my_function"
  7521. if [ exceptional_condition ]; then
  7522. bbnote "Hit exceptional_condition"
  7523. fi
  7524. bbdebug 2 "Got to point xyz"
  7525. if [ warning_trigger ]; then
  7526. bbwarn "Detected warning_trigger, this might cause a problem later."
  7527. fi
  7528. if [ recoverable_error ]; then
  7529. bberror "Hit recoverable_error, correcting"
  7530. fi
  7531. if [ fatal_error ]; then
  7532. bbfatal "fatal_error detected"
  7533. fi
  7534. bbdebug 2 "Completed do_my_function"
  7535. }
  7536. Debugging Parallel Make Races
  7537. -----------------------------
  7538. A parallel ``make`` race occurs when the build consists of several parts
  7539. that are run simultaneously and a situation occurs when the output or
  7540. result of one part is not ready for use with a different part of the
  7541. build that depends on that output. Parallel make races are annoying and
  7542. can sometimes be difficult to reproduce and fix. However, there are some simple
  7543. tips and tricks that can help you debug and fix them. This section
  7544. presents a real-world example of an error encountered on the Yocto
  7545. Project autobuilder and the process used to fix it.
  7546. .. note::
  7547. If you cannot properly fix a ``make`` race condition, you can work around it
  7548. by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST`
  7549. variables.
  7550. The Failure
  7551. ~~~~~~~~~~~
  7552. For this example, assume that you are building an image that depends on
  7553. the "neard" package. And, during the build, BitBake runs into problems
  7554. and creates the following output.
  7555. .. note::
  7556. This example log file has longer lines artificially broken to make
  7557. the listing easier to read.
  7558. If you examine the output or the log file, you see the failure during
  7559. ``make``:
  7560. .. code-block:: none
  7561. | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
  7562. | DEBUG: Executing shell function do_compile
  7563. | NOTE: make -j 16
  7564. | make --no-print-directory all-am
  7565. | /bin/mkdir -p include/near
  7566. | /bin/mkdir -p include/near
  7567. | /bin/mkdir -p include/near
  7568. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7569. 0.14-r0/neard-0.14/include/types.h include/near/types.h
  7570. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7571. 0.14-r0/neard-0.14/include/log.h include/near/log.h
  7572. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7573. 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
  7574. | /bin/mkdir -p include/near
  7575. | /bin/mkdir -p include/near
  7576. | /bin/mkdir -p include/near
  7577. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7578. 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
  7579. | /bin/mkdir -p include/near
  7580. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7581. 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
  7582. | /bin/mkdir -p include/near
  7583. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7584. 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
  7585. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7586. 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
  7587. | /bin/mkdir -p include/near
  7588. | /bin/mkdir -p include/near
  7589. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7590. 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
  7591. | /bin/mkdir -p include/near
  7592. | /bin/mkdir -p include/near
  7593. | /bin/mkdir -p include/near
  7594. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7595. 0.14-r0/neard-0.14/include/device.h include/near/device.h
  7596. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7597. 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
  7598. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7599. 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
  7600. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7601. 0.14-r0/neard-0.14/include/version.h include/near/version.h
  7602. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7603. 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
  7604. | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
  7605. | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/nightly-x86/
  7606. build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
  7607. yocto-autobuilder/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
  7608. -I/home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
  7609. lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/nightly-x86/build/build/
  7610. tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/
  7611. nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
  7612. nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
  7613. -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
  7614. -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
  7615. -o tools/snep-send.o tools/snep-send.c
  7616. | In file included from tools/snep-send.c:16:0:
  7617. | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
  7618. | #include <near/dbus.h>
  7619. | ^
  7620. | compilation terminated.
  7621. | make[1]: *** [tools/snep-send.o] Error 1
  7622. | make[1]: *** Waiting for unfinished jobs....
  7623. | make: *** [all] Error 2
  7624. | ERROR: oe_runmake failed
  7625. Reproducing the Error
  7626. ~~~~~~~~~~~~~~~~~~~~~
  7627. Because race conditions are intermittent, they do not manifest
  7628. themselves every time you do the build. In fact, most times the build
  7629. will complete without problems even though the potential race condition
  7630. exists. Thus, once the error surfaces, you need a way to reproduce it.
  7631. In this example, compiling the "neard" package is causing the problem.
  7632. So the first thing to do is build "neard" locally. Before you start the
  7633. build, set the
  7634. :term:`PARALLEL_MAKE` variable
  7635. in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a
  7636. high value for :term:`PARALLEL_MAKE` increases the chances of the race
  7637. condition showing up::
  7638. $ bitbake neard
  7639. Once the local build for "neard" completes, start a ``devshell`` build::
  7640. $ bitbake neard -c devshell
  7641. For information on how to use a ``devshell``, see the
  7642. ":ref:`dev-manual/common-tasks:using a development shell`" section.
  7643. In the ``devshell``, do the following::
  7644. $ make clean
  7645. $ make tools/snep-send.o
  7646. The ``devshell`` commands cause the failure to clearly
  7647. be visible. In this case, there is a missing dependency for the ``neard``
  7648. Makefile target. Here is some abbreviated, sample output with the
  7649. missing dependency clearly visible at the end::
  7650. i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
  7651. .
  7652. .
  7653. .
  7654. tools/snep-send.c
  7655. In file included from tools/snep-send.c:16:0:
  7656. tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
  7657. #include <near/dbus.h>
  7658. ^
  7659. compilation terminated.
  7660. make: *** [tools/snep-send.o] Error 1
  7661. $
  7662. Creating a Patch for the Fix
  7663. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7664. Because there is a missing dependency for the Makefile target, you need
  7665. to patch the ``Makefile.am`` file, which is generated from
  7666. ``Makefile.in``. You can use Quilt to create the patch::
  7667. $ quilt new parallelmake.patch
  7668. Patch patches/parallelmake.patch is now on top
  7669. $ quilt add Makefile.am
  7670. File Makefile.am added to patch patches/parallelmake.patch
  7671. For more information on using Quilt, see the
  7672. ":ref:`dev-manual/common-tasks:using quilt in your workflow`" section.
  7673. At this point you need to make the edits to ``Makefile.am`` to add the
  7674. missing dependency. For our example, you have to add the following line
  7675. to the file::
  7676. tools/snep-send.$(OBJEXT): include/near/dbus.h
  7677. Once you have edited the file, use the ``refresh`` command to create the
  7678. patch::
  7679. $ quilt refresh
  7680. Refreshed patch patches/parallelmake.patch
  7681. Once the patch file is created, you need to add it back to the originating
  7682. recipe folder. Here is an example assuming a top-level
  7683. :term:`Source Directory` named ``poky``::
  7684. $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
  7685. The final thing you need to do to implement the fix in the build is to
  7686. update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the
  7687. :term:`SRC_URI` statement includes
  7688. the patch file. The recipe file is in the folder above the patch. Here
  7689. is what the edited :term:`SRC_URI` statement would look like::
  7690. SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
  7691. file://neard.in \
  7692. file://neard.service.in \
  7693. file://parallelmake.patch \
  7694. "
  7695. With the patch complete and moved to the correct folder and the
  7696. :term:`SRC_URI` statement updated, you can exit the ``devshell``::
  7697. $ exit
  7698. Testing the Build
  7699. ~~~~~~~~~~~~~~~~~
  7700. With everything in place, you can get back to trying the build again
  7701. locally::
  7702. $ bitbake neard
  7703. This build should succeed.
  7704. Now you can open up a ``devshell`` again and repeat the clean and make
  7705. operations as follows::
  7706. $ bitbake neard -c devshell
  7707. $ make clean
  7708. $ make tools/snep-send.o
  7709. The build should work without issue.
  7710. As with all solved problems, if they originated upstream, you need to
  7711. submit the fix for the recipe in OE-Core and upstream so that the
  7712. problem is taken care of at its source. See the
  7713. ":ref:`dev-manual/common-tasks:submitting a change to the yocto project`"
  7714. section for more information.
  7715. Debugging With the GNU Project Debugger (GDB) Remotely
  7716. ------------------------------------------------------
  7717. GDB allows you to examine running programs, which in turn helps you to
  7718. understand and fix problems. It also allows you to perform post-mortem
  7719. style analysis of program crashes. GDB is available as a package within
  7720. the Yocto Project and is installed in SDK images by default. See the
  7721. ":ref:`ref-manual/images:Images`" chapter in the Yocto
  7722. Project Reference Manual for a description of these images. You can find
  7723. information on GDB at https://sourceware.org/gdb/.
  7724. .. note::
  7725. For best results, install debug (``-dbg``) packages for the applications you
  7726. are going to debug. Doing so makes extra debug symbols available that give
  7727. you more meaningful output.
  7728. Sometimes, due to memory or disk space constraints, it is not possible
  7729. to use GDB directly on the remote target to debug applications. These
  7730. constraints arise because GDB needs to load the debugging information
  7731. and the binaries of the process being debugged. Additionally, GDB needs
  7732. to perform many computations to locate information such as function
  7733. names, variable names and values, stack traces and so forth - even
  7734. before starting the debugging process. These extra computations place
  7735. more load on the target system and can alter the characteristics of the
  7736. program being debugged.
  7737. To help get past the previously mentioned constraints, there are two
  7738. methods you can use: running a debuginfod server and using gdbserver.
  7739. Using the debuginfod server method
  7740. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7741. ``debuginfod`` from ``elfutils`` is a way to distribute ``debuginfo`` files.
  7742. Running a ``debuginfod`` server makes debug symbols readily available,
  7743. which means you don't need to download debugging information
  7744. and the binaries of the process being debugged. You can just fetch
  7745. debug symbols from the server.
  7746. To run a ``debuginfod`` server, you need to do the following:
  7747. - Ensure that ``debuginfod`` is present in :term:`DISTRO_FEATURES`
  7748. (it already is in ``OpenEmbedded-core`` defaults and ``poky`` reference distribution).
  7749. If not, set in your distro config file or in ``local.conf``::
  7750. DISTRO_FEATURES:append = " debuginfod"
  7751. This distro feature enables the server and client library in ``elfutils``,
  7752. and enables ``debuginfod`` support in clients (at the moment, ``gdb`` and ``binutils``).
  7753. - Run the following commands to launch the ``debuginfod`` server on the host::
  7754. $ oe-debuginfod
  7755. - To use ``debuginfod`` on the target, you need to know the ip:port where
  7756. ``debuginfod`` is listening on the host (port defaults to 8002), and export
  7757. that into the shell environment, for example in ``qemu``::
  7758. root@qemux86-64:~# export DEBUGINFOD_URLS="http://192.168.7.1:8002/"
  7759. - Then debug info fetching should simply work when running the target ``gdb``,
  7760. ``readelf`` or ``objdump``, for example::
  7761. root@qemux86-64:~# gdb /bin/cat
  7762. ...
  7763. Reading symbols from /bin/cat...
  7764. Downloading separate debug info for /bin/cat...
  7765. Reading symbols from /home/root/.cache/debuginfod_client/923dc4780cfbc545850c616bffa884b6b5eaf322/debuginfo...
  7766. - It's also possible to use ``debuginfod-find`` to just query the server::
  7767. root@qemux86-64:~# debuginfod-find debuginfo /bin/ls
  7768. /home/root/.cache/debuginfod_client/356edc585f7f82d46f94fcb87a86a3fe2d2e60bd/debuginfo
  7769. Using the gdbserver method
  7770. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7771. gdbserver, which runs on the remote target and does not load any
  7772. debugging information from the debugged process. Instead, a GDB instance
  7773. processes the debugging information that is run on a remote computer -
  7774. the host GDB. The host GDB then sends control commands to gdbserver to
  7775. make it stop or start the debugged program, as well as read or write
  7776. memory regions of that debugged program. All the debugging information
  7777. loaded and processed as well as all the heavy debugging is done by the
  7778. host GDB. Offloading these processes gives the gdbserver running on the
  7779. target a chance to remain small and fast.
  7780. Because the host GDB is responsible for loading the debugging
  7781. information and for doing the necessary processing to make actual
  7782. debugging happen, you have to make sure the host can access the
  7783. unstripped binaries complete with their debugging information and also
  7784. be sure the target is compiled with no optimizations. The host GDB must
  7785. also have local access to all the libraries used by the debugged
  7786. program. Because gdbserver does not need any local debugging
  7787. information, the binaries on the remote target can remain stripped.
  7788. However, the binaries must also be compiled without optimization so they
  7789. match the host's binaries.
  7790. To remain consistent with GDB documentation and terminology, the binary
  7791. being debugged on the remote target machine is referred to as the
  7792. "inferior" binary. For documentation on GDB see the `GDB
  7793. site <https://sourceware.org/gdb/documentation/>`__.
  7794. The following steps show you how to debug using the GNU project
  7795. debugger.
  7796. 1. *Configure your build system to construct the companion debug
  7797. filesystem:*
  7798. In your ``local.conf`` file, set the following::
  7799. IMAGE_GEN_DEBUGFS = "1"
  7800. IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
  7801. These options cause the
  7802. OpenEmbedded build system to generate a special companion filesystem
  7803. fragment, which contains the matching source and debug symbols to
  7804. your deployable filesystem. The build system does this by looking at
  7805. what is in the deployed filesystem, and pulling the corresponding
  7806. ``-dbg`` packages.
  7807. The companion debug filesystem is not a complete filesystem, but only
  7808. contains the debug fragments. This filesystem must be combined with
  7809. the full filesystem for debugging. Subsequent steps in this procedure
  7810. show how to combine the partial filesystem with the full filesystem.
  7811. 2. *Configure the system to include gdbserver in the target filesystem:*
  7812. Make the following addition in your ``local.conf`` file::
  7813. EXTRA_IMAGE_FEATURES:append = " tools-debug"
  7814. The change makes
  7815. sure the ``gdbserver`` package is included.
  7816. 3. *Build the environment:*
  7817. Use the following command to construct the image and the companion
  7818. Debug Filesystem::
  7819. $ bitbake image
  7820. Build the cross GDB component and
  7821. make it available for debugging. Build the SDK that matches the
  7822. image. Building the SDK is best for a production build that can be
  7823. used later for debugging, especially during long term maintenance::
  7824. $ bitbake -c populate_sdk image
  7825. Alternatively, you can build the minimal toolchain components that
  7826. match the target. Doing so creates a smaller than typical SDK and
  7827. only contains a minimal set of components with which to build simple
  7828. test applications, as well as run the debugger::
  7829. $ bitbake meta-toolchain
  7830. A final method is to build Gdb itself within the build system::
  7831. $ bitbake gdb-cross-<architecture>
  7832. Doing so produces a temporary copy of
  7833. ``cross-gdb`` you can use for debugging during development. While
  7834. this is the quickest approach, the two previous methods in this step
  7835. are better when considering long-term maintenance strategies.
  7836. .. note::
  7837. If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests
  7838. the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the
  7839. actual name you want to use.
  7840. 4. *Set up the* ``debugfs``\ *:*
  7841. Run the following commands to set up the ``debugfs``::
  7842. $ mkdir debugfs
  7843. $ cd debugfs
  7844. $ tar xvfj build-dir/tmp/deploy/images/machine/image.rootfs.tar.bz2
  7845. $ tar xvfj build-dir/tmp/deploy/images/machine/image-dbg.rootfs.tar.bz2
  7846. 5. *Set up GDB:*
  7847. Install the SDK (if you built one) and then source the correct
  7848. environment file. Sourcing the environment file puts the SDK in your
  7849. ``PATH`` environment variable and sets ``$GDB`` to the SDK's debugger.
  7850. If you are using the build system, Gdb is located in
  7851. `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb``
  7852. 6. *Boot the target:*
  7853. For information on how to run QEMU, see the `QEMU
  7854. Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__.
  7855. .. note::
  7856. Be sure to verify that your host can access the target via TCP.
  7857. 7. *Debug a program:*
  7858. Debugging a program involves running gdbserver on the target and then
  7859. running Gdb on the host. The example in this step debugs ``gzip``:
  7860. .. code-block:: shell
  7861. root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
  7862. For
  7863. additional gdbserver options, see the `GDB Server
  7864. Documentation <https://www.gnu.org/software/gdb/documentation/>`__.
  7865. After running gdbserver on the target, you need to run Gdb on the
  7866. host and configure it and connect to the target. Use these commands::
  7867. $ cd directory-holding-the-debugfs-directory
  7868. $ arch-gdb
  7869. (gdb) set sysroot debugfs
  7870. (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
  7871. (gdb) target remote IP-of-target:1234
  7872. At this
  7873. point, everything should automatically load (i.e. matching binaries,
  7874. symbols and headers).
  7875. .. note::
  7876. The Gdb ``set`` commands in the previous example can be placed into the
  7877. users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever
  7878. commands are in that file.
  7879. 8. *Deploying without a full image rebuild:*
  7880. In many cases, during development you want a quick method to deploy a
  7881. new binary to the target and debug it, without waiting for a full
  7882. image build.
  7883. One approach to solving this situation is to just build the component
  7884. you want to debug. Once you have built the component, copy the
  7885. executable directly to both the target and the host ``debugfs``.
  7886. If the binary is processed through the debug splitting in
  7887. OpenEmbedded, you should also copy the debug items (i.e. ``.debug``
  7888. contents and corresponding ``/usr/src/debug`` files) from the work
  7889. directory. Here is an example::
  7890. $ bitbake bash
  7891. $ bitbake -c devshell bash
  7892. $ cd ..
  7893. $ scp packages-split/bash/bin/bash target:/bin/bash
  7894. $ cp -a packages-split/bash-dbg/\* path/debugfs
  7895. Debugging with the GNU Project Debugger (GDB) on the Target
  7896. -----------------------------------------------------------
  7897. The previous section addressed using GDB remotely for debugging
  7898. purposes, which is the most usual case due to the inherent hardware
  7899. limitations on many embedded devices. However, debugging in the target
  7900. hardware itself is also possible with more powerful devices. This
  7901. section describes what you need to do in order to support using GDB to
  7902. debug on the target hardware.
  7903. To support this kind of debugging, you need do the following:
  7904. - Ensure that GDB is on the target. You can do this by making
  7905. the following addition to your ``local.conf`` file::
  7906. EXTRA_IMAGE_FEATURES:append = " tools-debug"
  7907. - Ensure that debug symbols are present. You can do so by adding the
  7908. corresponding ``-dbg`` package to :term:`IMAGE_INSTALL`::
  7909. IMAGE_INSTALL:append = " packagename-dbg"
  7910. Alternatively, you can add the following to ``local.conf`` to include
  7911. all the debug symbols::
  7912. EXTRA_IMAGE_FEATURES:append = " dbg-pkgs"
  7913. .. note::
  7914. To improve the debug information accuracy, you can reduce the level
  7915. of optimization used by the compiler. For example, when adding the
  7916. following line to your ``local.conf`` file, you will reduce optimization
  7917. from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION`
  7918. of "-O -fno-omit-frame-pointer"::
  7919. DEBUG_BUILD = "1"
  7920. Consider that this will reduce the application's performance and is
  7921. recommended only for debugging purposes.
  7922. Other Debugging Tips
  7923. --------------------
  7924. Here are some other tips that you might find useful:
  7925. - When adding new packages, it is worth watching for undesirable items
  7926. making their way into compiler command lines. For example, you do not
  7927. want references to local system files like ``/usr/lib/`` or
  7928. ``/usr/include/``.
  7929. - If you want to remove the ``psplash`` boot splashscreen, add
  7930. ``psplash=false`` to the kernel command line. Doing so prevents
  7931. ``psplash`` from loading and thus allows you to see the console. It
  7932. is also possible to switch out of the splashscreen by switching the
  7933. virtual console (e.g. Fn+Left or Fn+Right on a Zaurus).
  7934. - Removing :term:`TMPDIR` (usually
  7935. ``tmp/``, within the
  7936. :term:`Build Directory`) can often fix
  7937. temporary build issues. Removing :term:`TMPDIR` is usually a relatively
  7938. cheap operation, because task output will be cached in
  7939. :term:`SSTATE_DIR` (usually
  7940. ``sstate-cache/``, which is also in the Build Directory).
  7941. .. note::
  7942. Removing :term:`TMPDIR` might be a workaround rather than a fix.
  7943. Consequently, trying to determine the underlying cause of an issue before
  7944. removing the directory is a good idea.
  7945. - Understanding how a feature is used in practice within existing
  7946. recipes can be very helpful. It is recommended that you configure
  7947. some method that allows you to quickly search through files.
  7948. Using GNU Grep, you can use the following shell function to
  7949. recursively search through common recipe-related files, skipping
  7950. binary files, ``.git`` directories, and the Build Directory (assuming
  7951. its name starts with "build")::
  7952. g() {
  7953. grep -Ir \
  7954. --exclude-dir=.git \
  7955. --exclude-dir='build*' \
  7956. --include='*.bb*' \
  7957. --include='*.inc*' \
  7958. --include='*.conf*' \
  7959. --include='*.py*' \
  7960. "$@"
  7961. }
  7962. Following are some usage examples::
  7963. $ g FOO # Search recursively for "FOO"
  7964. $ g -i foo # Search recursively for "foo", ignoring case
  7965. $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
  7966. If figuring
  7967. out how some feature works requires a lot of searching, it might
  7968. indicate that the documentation should be extended or improved. In
  7969. such cases, consider filing a documentation bug using the Yocto
  7970. Project implementation of
  7971. :yocto_bugs:`Bugzilla <>`. For information on
  7972. how to submit a bug against the Yocto Project, see the Yocto Project
  7973. Bugzilla :yocto_wiki:`wiki page </Bugzilla_Configuration_and_Bug_Tracking>`
  7974. and the
  7975. ":ref:`dev-manual/common-tasks:submitting a defect against the yocto project`"
  7976. section.
  7977. .. note::
  7978. The manuals might not be the right place to document variables
  7979. that are purely internal and have a limited scope (e.g. internal
  7980. variables used to implement a single ``.bbclass`` file).
  7981. Making Changes to the Yocto Project
  7982. ===================================
  7983. Because the Yocto Project is an open-source, community-based project,
  7984. you can effect changes to the project. This section presents procedures
  7985. that show you how to submit a defect against the project and how to
  7986. submit a change.
  7987. Submitting a Defect Against the Yocto Project
  7988. ---------------------------------------------
  7989. Use the Yocto Project implementation of
  7990. `Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug)
  7991. against the Yocto Project. For additional information on this
  7992. implementation of Bugzilla see the ":ref:`Yocto Project
  7993. Bugzilla <resources-bugtracker>`" section in the
  7994. Yocto Project Reference Manual. For more detail on any of the following
  7995. steps, see the Yocto Project
  7996. :yocto_wiki:`Bugzilla wiki page </Bugzilla_Configuration_and_Bug_Tracking>`.
  7997. Use the following general steps to submit a bug:
  7998. 1. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`.
  7999. 2. Click "File a Bug" to enter a new bug.
  8000. 3. Choose the appropriate "Classification", "Product", and "Component"
  8001. for which the bug was found. Bugs for the Yocto Project fall into
  8002. one of several classifications, which in turn break down into
  8003. several products and components. For example, for a bug against the
  8004. ``meta-intel`` layer, you would choose "Build System, Metadata &
  8005. Runtime", "BSPs", and "bsps-meta-intel", respectively.
  8006. 4. Choose the "Version" of the Yocto Project for which you found the
  8007. bug (e.g. &DISTRO;).
  8008. 5. Determine and select the "Severity" of the bug. The severity
  8009. indicates how the bug impacted your work.
  8010. 6. Choose the "Hardware" that the bug impacts.
  8011. 7. Choose the "Architecture" that the bug impacts.
  8012. 8. Choose a "Documentation change" item for the bug. Fixing a bug might
  8013. or might not affect the Yocto Project documentation. If you are
  8014. unsure of the impact to the documentation, select "Don't Know".
  8015. 9. Provide a brief "Summary" of the bug. Try to limit your summary to
  8016. just a line or two and be sure to capture the essence of the bug.
  8017. 10. Provide a detailed "Description" of the bug. You should provide as
  8018. much detail as you can about the context, behavior, output, and so
  8019. forth that surrounds the bug. You can even attach supporting files
  8020. for output from logs by using the "Add an attachment" button.
  8021. 11. Click the "Submit Bug" button submit the bug. A new Bugzilla number
  8022. is assigned to the bug and the defect is logged in the bug tracking
  8023. system.
  8024. Once you file a bug, the bug is processed by the Yocto Project Bug
  8025. Triage Team and further details concerning the bug are assigned (e.g.
  8026. priority and owner). You are the "Submitter" of the bug and any further
  8027. categorization, progress, or comments on the bug result in Bugzilla
  8028. sending you an automated email concerning the particular change or
  8029. progress to the bug.
  8030. Submitting a Change to the Yocto Project
  8031. ----------------------------------------
  8032. Contributions to the Yocto Project and OpenEmbedded are very welcome.
  8033. Because the system is extremely configurable and flexible, we recognize
  8034. that developers will want to extend, configure or optimize it for their
  8035. specific uses.
  8036. The Yocto Project uses a mailing list and a patch-based workflow that is
  8037. similar to the Linux kernel but contains important differences. In
  8038. general, there is a mailing list through which you can submit patches. You
  8039. should send patches to the appropriate mailing list so that they can be
  8040. reviewed and merged by the appropriate maintainer. The specific mailing
  8041. list you need to use depends on the location of the code you are
  8042. changing. Each component (e.g. layer) should have a ``README`` file that
  8043. indicates where to send the changes and which process to follow.
  8044. You can send the patch to the mailing list using whichever approach you
  8045. feel comfortable with to generate the patch. Once sent, the patch is
  8046. usually reviewed by the community at large. If somebody has concerns
  8047. with the patch, they will usually voice their concern over the mailing
  8048. list. If a patch does not receive any negative reviews, the maintainer
  8049. of the affected layer typically takes the patch, tests it, and then
  8050. based on successful testing, merges the patch.
  8051. The "poky" repository, which is the Yocto Project's reference build
  8052. environment, is a hybrid repository that contains several individual
  8053. pieces (e.g. BitBake, Metadata, documentation, and so forth) built using
  8054. the combo-layer tool. The upstream location used for submitting changes
  8055. varies by component:
  8056. - *Core Metadata:* Send your patch to the
  8057. :oe_lists:`openembedded-core </g/openembedded-core>`
  8058. mailing list. For example, a change to anything under the ``meta`` or
  8059. ``scripts`` directories should be sent to this mailing list.
  8060. - *BitBake:* For changes to BitBake (i.e. anything under the
  8061. ``bitbake`` directory), send your patch to the
  8062. :oe_lists:`bitbake-devel </g/bitbake-devel>`
  8063. mailing list.
  8064. - *"meta-\*" trees:* These trees contain Metadata. Use the
  8065. :yocto_lists:`poky </g/poky>` mailing list.
  8066. - *Documentation*: For changes to the Yocto Project documentation, use the
  8067. :yocto_lists:`docs </g/docs>` mailing list.
  8068. For changes to other layers hosted in the Yocto Project source
  8069. repositories (i.e. ``yoctoproject.org``) and tools use the
  8070. :yocto_lists:`Yocto Project </g/yocto/>` general mailing list.
  8071. .. note::
  8072. Sometimes a layer's documentation specifies to use a particular
  8073. mailing list. If so, use that list.
  8074. For additional recipes that do not fit into the core Metadata, you
  8075. should determine which layer the recipe should go into and submit the
  8076. change in the manner recommended by the documentation (e.g. the
  8077. ``README`` file) supplied with the layer. If in doubt, please ask on the
  8078. Yocto general mailing list or on the openembedded-devel mailing list.
  8079. You can also push a change upstream and request a maintainer to pull the
  8080. change into the component's upstream repository. You do this by pushing
  8081. to a contribution repository that is upstream. See the
  8082. ":ref:`overview-manual/development-environment:git workflows and the yocto project`"
  8083. section in the Yocto Project Overview and Concepts Manual for additional
  8084. concepts on working in the Yocto Project development environment.
  8085. Maintainers commonly use ``-next`` branches to test submissions prior to
  8086. merging patches. Thus, you can get an idea of the status of a patch based on
  8087. whether the patch has been merged into one of these branches. The commonly
  8088. used testing branches for OpenEmbedded-Core are as follows:
  8089. - *openembedded-core "master-next" branch:* This branch is part of the
  8090. :oe_git:`openembedded-core </openembedded-core/>` repository and contains
  8091. proposed changes to the core metadata.
  8092. - *poky "master-next" branch:* This branch is part of the
  8093. :yocto_git:`poky </poky/>` repository and combines proposed
  8094. changes to BitBake, the core metadata and the poky distro.
  8095. Similarly, stable branches maintained by the project may have corresponding
  8096. ``-next`` branches which collect proposed changes. For example,
  8097. ``&DISTRO_NAME_NO_CAP;-next`` and ``&DISTRO_NAME_NO_CAP_MINUS_ONE;-next``
  8098. branches in both the "openembdedded-core" and "poky" repositories.
  8099. Other layers may have similar testing branches but there is no formal
  8100. requirement or standard for these so please check the documentation for the
  8101. layers you are contributing to.
  8102. The following sections provide procedures for submitting a change.
  8103. Preparing Changes for Submission
  8104. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8105. 1. *Make Your Changes Locally:* Make your changes in your local Git
  8106. repository. You should make small, controlled, isolated changes.
  8107. Keeping changes small and isolated aids review, makes
  8108. merging/rebasing easier and keeps the change history clean should
  8109. anyone need to refer to it in future.
  8110. 2. *Stage Your Changes:* Stage your changes by using the ``git add``
  8111. command on each file you changed.
  8112. 3. *Commit Your Changes:* Commit the change by using the ``git commit``
  8113. command. Make sure your commit information follows standards by
  8114. following these accepted conventions:
  8115. - Be sure to include a "Signed-off-by:" line in the same style as
  8116. required by the Linux kernel. This can be done by using the
  8117. ``git commit -s`` command. Adding this line signifies that you,
  8118. the submitter, have agreed to the Developer's Certificate of
  8119. Origin 1.1 as follows:
  8120. .. code-block:: none
  8121. Developer's Certificate of Origin 1.1
  8122. By making a contribution to this project, I certify that:
  8123. (a) The contribution was created in whole or in part by me and I
  8124. have the right to submit it under the open source license
  8125. indicated in the file; or
  8126. (b) The contribution is based upon previous work that, to the best
  8127. of my knowledge, is covered under an appropriate open source
  8128. license and I have the right under that license to submit that
  8129. work with modifications, whether created in whole or in part
  8130. by me, under the same open source license (unless I am
  8131. permitted to submit under a different license), as indicated
  8132. in the file; or
  8133. (c) The contribution was provided directly to me by some other
  8134. person who certified (a), (b) or (c) and I have not modified
  8135. it.
  8136. (d) I understand and agree that this project and the contribution
  8137. are public and that a record of the contribution (including all
  8138. personal information I submit with it, including my sign-off) is
  8139. maintained indefinitely and may be redistributed consistent with
  8140. this project or the open source license(s) involved.
  8141. - Provide a single-line summary of the change and, if more
  8142. explanation is needed, provide more detail in the body of the
  8143. commit. This summary is typically viewable in the "shortlist" of
  8144. changes. Thus, providing something short and descriptive that
  8145. gives the reader a summary of the change is useful when viewing a
  8146. list of many commits. You should prefix this short description
  8147. with the recipe name (if changing a recipe), or else with the
  8148. short form path to the file being changed.
  8149. - For the body of the commit message, provide detailed information
  8150. that describes what you changed, why you made the change, and the
  8151. approach you used. It might also be helpful if you mention how you
  8152. tested the change. Provide as much detail as you can in the body
  8153. of the commit message.
  8154. .. note::
  8155. You do not need to provide a more detailed explanation of a
  8156. change if the change is minor to the point of the single line
  8157. summary providing all the information.
  8158. - If the change addresses a specific bug or issue that is associated
  8159. with a bug-tracking ID, include a reference to that ID in your
  8160. detailed description. For example, the Yocto Project uses a
  8161. specific convention for bug references - any commit that addresses
  8162. a specific bug should use the following form for the detailed
  8163. description. Be sure to use the actual bug-tracking ID from
  8164. Bugzilla for bug-id::
  8165. Fixes [YOCTO #bug-id]
  8166. detailed description of change
  8167. Using Email to Submit a Patch
  8168. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8169. Depending on the components changed, you need to submit the email to a
  8170. specific mailing list. For some guidance on which mailing list to use,
  8171. see the
  8172. :ref:`list <dev-manual/common-tasks:submitting a change to the yocto project>`
  8173. at the beginning of this section. For a description of all the available
  8174. mailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the
  8175. Yocto Project Reference Manual.
  8176. Here is the general procedure on how to submit a patch through email
  8177. without using the scripts once the steps in
  8178. :ref:`dev-manual/common-tasks:preparing changes for submission` have been followed:
  8179. 1. *Format the Commit:* Format the commit into an email message. To
  8180. format commits, use the ``git format-patch`` command. When you
  8181. provide the command, you must include a revision list or a number of
  8182. patches as part of the command. For example, either of these two
  8183. commands takes your most recent single commit and formats it as an
  8184. email message in the current directory::
  8185. $ git format-patch -1
  8186. or ::
  8187. $ git format-patch HEAD~
  8188. After the command is run, the current directory contains a numbered
  8189. ``.patch`` file for the commit.
  8190. If you provide several commits as part of the command, the
  8191. ``git format-patch`` command produces a series of numbered files in
  8192. the current directory – one for each commit. If you have more than
  8193. one patch, you should also use the ``--cover`` option with the
  8194. command, which generates a cover letter as the first "patch" in the
  8195. series. You can then edit the cover letter to provide a description
  8196. for the series of patches. For information on the
  8197. ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed
  8198. using the ``man git-format-patch`` command.
  8199. .. note::
  8200. If you are or will be a frequent contributor to the Yocto Project
  8201. or to OpenEmbedded, you might consider requesting a contrib area
  8202. and the necessary associated rights.
  8203. 2. *Send the patches via email:* Send the patches to the recipients and
  8204. relevant mailing lists by using the ``git send-email`` command.
  8205. .. note::
  8206. In order to use ``git send-email``, you must have the proper Git packages
  8207. installed on your host.
  8208. For Ubuntu, Debian, and Fedora the package is ``git-email``.
  8209. The ``git send-email`` command sends email by using a local or remote
  8210. Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or
  8211. through a direct ``smtp`` configuration in your Git ``~/.gitconfig``
  8212. file. If you are submitting patches through email only, it is very
  8213. important that you submit them without any whitespace or HTML
  8214. formatting that either you or your mailer introduces. The maintainer
  8215. that receives your patches needs to be able to save and apply them
  8216. directly from your emails. A good way to verify that what you are
  8217. sending will be applicable by the maintainer is to do a dry run and
  8218. send them to yourself and then save and apply them as the maintainer
  8219. would.
  8220. The ``git send-email`` command is the preferred method for sending
  8221. your patches using email since there is no risk of compromising
  8222. whitespace in the body of the message, which can occur when you use
  8223. your own mail client. The command also has several options that let
  8224. you specify recipients and perform further editing of the email
  8225. message. For information on how to use the ``git send-email``
  8226. command, see ``GIT-SEND-EMAIL(1)`` displayed using the
  8227. ``man git-send-email`` command.
  8228. The Yocto Project uses a `Patchwork instance <https://patchwork.openembedded.org/>`__
  8229. to track the status of patches submitted to the various mailing lists and to
  8230. support automated patch testing. Each submitted patch is checked for common
  8231. mistakes and deviations from the expected patch format and submitters are
  8232. notified by patchtest if such mistakes are found. This process helps to
  8233. reduce the burden of patch review on maintainers.
  8234. .. note::
  8235. This system is imperfect and changes can sometimes get lost in the flow.
  8236. Asking about the status of a patch or change is reasonable if the change
  8237. has been idle for a while with no feedback.
  8238. Using Scripts to Push a Change Upstream and Request a Pull
  8239. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8240. For larger patch series it is preferable to send a pull request which not
  8241. only includes the patch but also a pointer to a branch that can be pulled
  8242. from. This involves making a local branch for your changes, pushing this
  8243. branch to an accessible repository and then using the ``create-pull-request``
  8244. and ``send-pull-request`` scripts from openembedded-core to create and send a
  8245. patch series with a link to the branch for review.
  8246. Follow this procedure to push a change to an upstream "contrib" Git
  8247. repository once the steps in :ref:`dev-manual/common-tasks:preparing changes for submission` have
  8248. been followed:
  8249. .. note::
  8250. You can find general Git information on how to push a change upstream
  8251. in the
  8252. `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__.
  8253. 1. *Push Your Commits to a "Contrib" Upstream:* If you have arranged for
  8254. permissions to push to an upstream contrib repository, push the
  8255. change to that repository::
  8256. $ git push upstream_remote_repo local_branch_name
  8257. For example, suppose you have permissions to push
  8258. into the upstream ``meta-intel-contrib`` repository and you are
  8259. working in a local branch named `your_name`\ ``/README``. The following
  8260. command pushes your local commits to the ``meta-intel-contrib``
  8261. upstream repository and puts the commit in a branch named
  8262. `your_name`\ ``/README``::
  8263. $ git push meta-intel-contrib your_name/README
  8264. 2. *Determine Who to Notify:* Determine the maintainer or the mailing
  8265. list that you need to notify for the change.
  8266. Before submitting any change, you need to be sure who the maintainer
  8267. is or what mailing list that you need to notify. Use either these
  8268. methods to find out:
  8269. - *Maintenance File:* Examine the ``maintainers.inc`` file, which is
  8270. located in the :term:`Source Directory` at
  8271. ``meta/conf/distro/include``, to see who is responsible for code.
  8272. - *Search by File:* Using :ref:`overview-manual/development-environment:git`, you can
  8273. enter the following command to bring up a short list of all
  8274. commits against a specific file::
  8275. git shortlog -- filename
  8276. Just provide the name of the file for which you are interested. The
  8277. information returned is not ordered by history but does include a
  8278. list of everyone who has committed grouped by name. From the list,
  8279. you can see who is responsible for the bulk of the changes against
  8280. the file.
  8281. - *Examine the List of Mailing Lists:* For a list of the Yocto
  8282. Project and related mailing lists, see the ":ref:`Mailing
  8283. lists <resources-mailinglist>`" section in
  8284. the Yocto Project Reference Manual.
  8285. 3. *Make a Pull Request:* Notify the maintainer or the mailing list that
  8286. you have pushed a change by making a pull request.
  8287. The Yocto Project provides two scripts that conveniently let you
  8288. generate and send pull requests to the Yocto Project. These scripts
  8289. are ``create-pull-request`` and ``send-pull-request``. You can find
  8290. these scripts in the ``scripts`` directory within the
  8291. :term:`Source Directory` (e.g.
  8292. ``poky/scripts``).
  8293. Using these scripts correctly formats the requests without
  8294. introducing any whitespace or HTML formatting. The maintainer that
  8295. receives your patches either directly or through the mailing list
  8296. needs to be able to save and apply them directly from your emails.
  8297. Using these scripts is the preferred method for sending patches.
  8298. First, create the pull request. For example, the following command
  8299. runs the script, specifies the upstream repository in the contrib
  8300. directory into which you pushed the change, and provides a subject
  8301. line in the created patch files::
  8302. $ poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
  8303. Running this script forms ``*.patch`` files in a folder named
  8304. ``pull-``\ `PID` in the current directory. One of the patch files is a
  8305. cover letter.
  8306. Before running the ``send-pull-request`` script, you must edit the
  8307. cover letter patch to insert information about your change. After
  8308. editing the cover letter, send the pull request. For example, the
  8309. following command runs the script and specifies the patch directory
  8310. and email address. In this example, the email address is a mailing
  8311. list::
  8312. $ poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@lists.yoctoproject.org
  8313. You need to follow the prompts as the script is interactive.
  8314. .. note::
  8315. For help on using these scripts, simply provide the ``-h``
  8316. argument as follows::
  8317. $ poky/scripts/create-pull-request -h
  8318. $ poky/scripts/send-pull-request -h
  8319. Responding to Patch Review
  8320. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  8321. You may get feedback on your submitted patches from other community members
  8322. or from the automated patchtest service. If issues are identified in your
  8323. patch then it is usually necessary to address these before the patch will be
  8324. accepted into the project. In this case you should amend the patch according
  8325. to the feedback and submit an updated version to the relevant mailing list,
  8326. copying in the reviewers who provided feedback to the previous version of the
  8327. patch.
  8328. The patch should be amended using ``git commit --amend`` or perhaps ``git
  8329. rebase`` for more expert git users. You should also modify the ``[PATCH]``
  8330. tag in the email subject line when sending the revised patch to mark the new
  8331. iteration as ``[PATCH v2]``, ``[PATCH v3]``, etc as appropriate. This can be
  8332. done by passing the ``-v`` argument to ``git format-patch`` with a version
  8333. number.
  8334. Lastly please ensure that you also test your revised changes. In particular
  8335. please don't just edit the patch file written out by ``git format-patch`` and
  8336. resend it.
  8337. Submitting Changes to Stable Release Branches
  8338. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8339. The process for proposing changes to a Yocto Project stable branch differs
  8340. from the steps described above. Changes to a stable branch must address
  8341. identified bugs or CVEs and should be made carefully in order to avoid the
  8342. risk of introducing new bugs or breaking backwards compatibility. Typically
  8343. bug fixes must already be accepted into the master branch before they can be
  8344. backported to a stable branch unless the bug in question does not affect the
  8345. master branch or the fix on the master branch is unsuitable for backporting.
  8346. The list of stable branches along with the status and maintainer for each
  8347. branch can be obtained from the
  8348. :yocto_wiki:`Releases wiki page </Releases>`.
  8349. .. note::
  8350. Changes will not typically be accepted for branches which are marked as
  8351. End-Of-Life (EOL).
  8352. With this in mind, the steps to submit a change for a stable branch are as
  8353. follows:
  8354. 1. *Identify the bug or CVE to be fixed:* This information should be
  8355. collected so that it can be included in your submission.
  8356. See :ref:`dev-manual/common-tasks:checking for vulnerabilities`
  8357. for details about CVE tracking.
  8358. 2. *Check if the fix is already present in the master branch:* This will
  8359. result in the most straightforward path into the stable branch for the
  8360. fix.
  8361. a. *If the fix is present in the master branch - Submit a backport request
  8362. by email:* You should send an email to the relevant stable branch
  8363. maintainer and the mailing list with details of the bug or CVE to be
  8364. fixed, the commit hash on the master branch that fixes the issue and
  8365. the stable branches which you would like this fix to be backported to.
  8366. b. *If the fix is not present in the master branch - Submit the fix to the
  8367. master branch first:* This will ensure that the fix passes through the
  8368. project's usual patch review and test processes before being accepted.
  8369. It will also ensure that bugs are not left unresolved in the master
  8370. branch itself. Once the fix is accepted in the master branch a backport
  8371. request can be submitted as above.
  8372. c. *If the fix is unsuitable for the master branch - Submit a patch
  8373. directly for the stable branch:* This method should be considered as a
  8374. last resort. It is typically necessary when the master branch is using
  8375. a newer version of the software which includes an upstream fix for the
  8376. issue or when the issue has been fixed on the master branch in a way
  8377. that introduces backwards incompatible changes. In this case follow the
  8378. steps in :ref:`dev-manual/common-tasks:preparing changes for submission` and
  8379. :ref:`dev-manual/common-tasks:using email to submit a patch` but modify the subject header of your patch
  8380. email to include the name of the stable branch which you are
  8381. targetting. This can be done using the ``--subject-prefix`` argument to
  8382. ``git format-patch``, for example to submit a patch to the dunfell
  8383. branch use
  8384. ``git format-patch --subject-prefix='&DISTRO_NAME_NO_CAP_MINUS_ONE;][PATCH' ...``.
  8385. Working With Licenses
  8386. =====================
  8387. As mentioned in the ":ref:`overview-manual/development-environment:licensing`"
  8388. section in the Yocto Project Overview and Concepts Manual, open source
  8389. projects are open to the public and they consequently have different
  8390. licensing structures in place. This section describes the mechanism by
  8391. which the :term:`OpenEmbedded Build System`
  8392. tracks changes to
  8393. licensing text and covers how to maintain open source license compliance
  8394. during your project's lifecycle. The section also describes how to
  8395. enable commercially licensed recipes, which by default are disabled.
  8396. Tracking License Changes
  8397. ------------------------
  8398. The license of an upstream project might change in the future. In order
  8399. to prevent these changes going unnoticed, the
  8400. :term:`LIC_FILES_CHKSUM`
  8401. variable tracks changes to the license text. The checksums are validated
  8402. at the end of the configure step, and if the checksums do not match, the
  8403. build will fail.
  8404. Specifying the ``LIC_FILES_CHKSUM`` Variable
  8405. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8406. The :term:`LIC_FILES_CHKSUM` variable contains checksums of the license text
  8407. in the source code for the recipe. Following is an example of how to
  8408. specify :term:`LIC_FILES_CHKSUM`::
  8409. LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
  8410. file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
  8411. file://licfile2.txt;endline=50;md5=zzzz \
  8412. ..."
  8413. .. note::
  8414. - When using "beginline" and "endline", realize that line numbering
  8415. begins with one and not zero. Also, the included lines are
  8416. inclusive (i.e. lines five through and including 29 in the
  8417. previous example for ``licfile1.txt``).
  8418. - When a license check fails, the selected license text is included
  8419. as part of the QA message. Using this output, you can determine
  8420. the exact start and finish for the needed license text.
  8421. The build system uses the :term:`S`
  8422. variable as the default directory when searching files listed in
  8423. :term:`LIC_FILES_CHKSUM`. The previous example employs the default
  8424. directory.
  8425. Consider this next example::
  8426. LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
  8427. md5=bb14ed3c4cda583abc85401304b5cd4e"
  8428. LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
  8429. The first line locates a file in ``${S}/src/ls.c`` and isolates lines
  8430. five through 16 as license text. The second line refers to a file in
  8431. :term:`WORKDIR`.
  8432. Note that :term:`LIC_FILES_CHKSUM` variable is mandatory for all recipes,
  8433. unless the :term:`LICENSE` variable is set to "CLOSED".
  8434. Explanation of Syntax
  8435. ~~~~~~~~~~~~~~~~~~~~~
  8436. As mentioned in the previous section, the :term:`LIC_FILES_CHKSUM` variable
  8437. lists all the important files that contain the license text for the
  8438. source code. It is possible to specify a checksum for an entire file, or
  8439. a specific section of a file (specified by beginning and ending line
  8440. numbers with the "beginline" and "endline" parameters, respectively).
  8441. The latter is useful for source files with a license notice header,
  8442. README documents, and so forth. If you do not use the "beginline"
  8443. parameter, then it is assumed that the text begins on the first line of
  8444. the file. Similarly, if you do not use the "endline" parameter, it is
  8445. assumed that the license text ends with the last line of the file.
  8446. The "md5" parameter stores the md5 checksum of the license text. If the
  8447. license text changes in any way as compared to this parameter then a
  8448. mismatch occurs. This mismatch triggers a build failure and notifies the
  8449. developer. Notification allows the developer to review and address the
  8450. license text changes. Also note that if a mismatch occurs during the
  8451. build, the correct md5 checksum is placed in the build log and can be
  8452. easily copied to the recipe.
  8453. There is no limit to how many files you can specify using the
  8454. :term:`LIC_FILES_CHKSUM` variable. Generally, however, every project
  8455. requires a few specifications for license tracking. Many projects have a
  8456. "COPYING" file that stores the license information for all the source
  8457. code files. This practice allows you to just track the "COPYING" file as
  8458. long as it is kept up to date.
  8459. .. note::
  8460. - If you specify an empty or invalid "md5" parameter,
  8461. :term:`BitBake` returns an md5
  8462. mis-match error and displays the correct "md5" parameter value
  8463. during the build. The correct parameter is also captured in the
  8464. build log.
  8465. - If the whole file contains only license text, you do not need to
  8466. use the "beginline" and "endline" parameters.
  8467. Enabling Commercially Licensed Recipes
  8468. --------------------------------------
  8469. By default, the OpenEmbedded build system disables components that have
  8470. commercial or other special licensing requirements. Such requirements
  8471. are defined on a recipe-by-recipe basis through the
  8472. :term:`LICENSE_FLAGS` variable
  8473. definition in the affected recipe. For instance, the
  8474. ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe
  8475. contains the following statement::
  8476. LICENSE_FLAGS = "commercial"
  8477. Here is a
  8478. slightly more complicated example that contains both an explicit recipe
  8479. name and version (after variable expansion)::
  8480. LICENSE_FLAGS = "license_${PN}_${PV}"
  8481. In order for a component restricted by a
  8482. :term:`LICENSE_FLAGS` definition to be enabled and included in an image, it
  8483. needs to have a matching entry in the global
  8484. :term:`LICENSE_FLAGS_ACCEPTED`
  8485. variable, which is a variable typically defined in your ``local.conf``
  8486. file. For example, to enable the
  8487. ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you
  8488. could add either the string "commercial_gst-plugins-ugly" or the more
  8489. general string "commercial" to :term:`LICENSE_FLAGS_ACCEPTED`. See the
  8490. ":ref:`dev-manual/common-tasks:license flag matching`" section for a full
  8491. explanation of how :term:`LICENSE_FLAGS` matching works. Here is the
  8492. example::
  8493. LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly"
  8494. Likewise, to additionally enable the package built from the recipe
  8495. containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that
  8496. the actual recipe name was ``emgd_1.10.bb``, the following string would
  8497. enable that package as well as the original ``gst-plugins-ugly``
  8498. package::
  8499. LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly license_emgd_1.10"
  8500. As a convenience, you do not need to specify the
  8501. complete license string for every package. You can use
  8502. an abbreviated form, which consists of just the first portion or
  8503. portions of the license string before the initial underscore character
  8504. or characters. A partial string will match any license that contains the
  8505. given string as the first portion of its license. For example, the
  8506. following value will also match both of the packages
  8507. previously mentioned as well as any other packages that have licenses
  8508. starting with "commercial" or "license".
  8509. ::
  8510. LICENSE_FLAGS_ACCEPTED = "commercial license"
  8511. License Flag Matching
  8512. ~~~~~~~~~~~~~~~~~~~~~
  8513. License flag matching allows you to control what recipes the
  8514. OpenEmbedded build system includes in the build. Fundamentally, the
  8515. build system attempts to match :term:`LICENSE_FLAGS` strings found in
  8516. recipes against strings found in :term:`LICENSE_FLAGS_ACCEPTED`.
  8517. A match causes the build system to include a recipe in the
  8518. build, while failure to find a match causes the build system to exclude
  8519. a recipe.
  8520. In general, license flag matching is simple. However, understanding some
  8521. concepts will help you correctly and effectively use matching.
  8522. Before a flag defined by a particular recipe is tested against the
  8523. entries of :term:`LICENSE_FLAGS_ACCEPTED`, the expanded
  8524. string ``_${PN}`` is appended to the flag. This expansion makes each
  8525. :term:`LICENSE_FLAGS` value recipe-specific. After expansion, the
  8526. string is then matched against the entries. Thus, specifying
  8527. ``LICENSE_FLAGS = "commercial"`` in recipe "foo", for example, results
  8528. in the string ``"commercial_foo"``. And, to create a match, that string
  8529. must appear among the entries of :term:`LICENSE_FLAGS_ACCEPTED`.
  8530. Judicious use of the :term:`LICENSE_FLAGS` strings and the contents of the
  8531. :term:`LICENSE_FLAGS_ACCEPTED` variable allows you a lot of flexibility for
  8532. including or excluding recipes based on licensing. For example, you can
  8533. broaden the matching capabilities by using license flags string subsets
  8534. in :term:`LICENSE_FLAGS_ACCEPTED`.
  8535. .. note::
  8536. When using a string subset, be sure to use the part of the expanded
  8537. string that precedes the appended underscore character (e.g.
  8538. ``usethispart_1.3``, ``usethispart_1.4``, and so forth).
  8539. For example, simply specifying the string "commercial" in the
  8540. :term:`LICENSE_FLAGS_ACCEPTED` variable matches any expanded
  8541. :term:`LICENSE_FLAGS` definition that starts with the string
  8542. "commercial" such as "commercial_foo" and "commercial_bar", which
  8543. are the strings the build system automatically generates for
  8544. hypothetical recipes named "foo" and "bar" assuming those recipes simply
  8545. specify the following::
  8546. LICENSE_FLAGS = "commercial"
  8547. Thus, you can choose to exhaustively enumerate each license flag in the
  8548. list and allow only specific recipes into the image, or you can use a
  8549. string subset that causes a broader range of matches to allow a range of
  8550. recipes into the image.
  8551. This scheme works even if the :term:`LICENSE_FLAGS` string already has
  8552. ``_${PN}`` appended. For example, the build system turns the license
  8553. flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match
  8554. both the general "commercial" and the specific "commercial_1.2_foo"
  8555. strings found in the :term:`LICENSE_FLAGS_ACCEPTED` variable, as expected.
  8556. Here are some other scenarios:
  8557. - You can specify a versioned string in the recipe such as
  8558. "commercial_foo_1.2" in a "foo" recipe. The build system expands this
  8559. string to "commercial_foo_1.2_foo". Combine this license flag with a
  8560. :term:`LICENSE_FLAGS_ACCEPTED` variable that has the string
  8561. "commercial" and you match the flag along with any other flag that
  8562. starts with the string "commercial".
  8563. - Under the same circumstances, you can add "commercial_foo" in the
  8564. :term:`LICENSE_FLAGS_ACCEPTED` variable and the build system not only
  8565. matches "commercial_foo_1.2" but also matches any license flag with
  8566. the string "commercial_foo", regardless of the version.
  8567. - You can be very specific and use both the package and version parts
  8568. in the :term:`LICENSE_FLAGS_ACCEPTED` list (e.g.
  8569. "commercial_foo_1.2") to specifically match a versioned recipe.
  8570. Other Variables Related to Commercial Licenses
  8571. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8572. There are other helpful variables related to commercial license handling,
  8573. defined in the
  8574. ``poky/meta/conf/distro/include/default-distrovars.inc`` file::
  8575. COMMERCIAL_AUDIO_PLUGINS ?= ""
  8576. COMMERCIAL_VIDEO_PLUGINS ?= ""
  8577. If you
  8578. want to enable these components, you can do so by making sure you have
  8579. statements similar to the following in your ``local.conf`` configuration
  8580. file::
  8581. COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
  8582. gst-plugins-ugly-mpegaudioparse"
  8583. COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
  8584. gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
  8585. LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
  8586. Of course, you could also create a matching list for those
  8587. components using the more general "commercial" in the
  8588. :term:`LICENSE_FLAGS_ACCEPTED` variable, but that would also enable all
  8589. the other packages with :term:`LICENSE_FLAGS`
  8590. containing "commercial", which you may or may not want::
  8591. LICENSE_FLAGS_ACCEPTED = "commercial"
  8592. Specifying audio and video plugins as part of the
  8593. ``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements
  8594. (along with the enabling :term:`LICENSE_FLAGS_ACCEPTED`) includes the
  8595. plugins or components into built images, thus adding support for media
  8596. formats or components.
  8597. Maintaining Open Source License Compliance During Your Product's Lifecycle
  8598. --------------------------------------------------------------------------
  8599. One of the concerns for a development organization using open source
  8600. software is how to maintain compliance with various open source
  8601. licensing during the lifecycle of the product. While this section does
  8602. not provide legal advice or comprehensively cover all scenarios, it does
  8603. present methods that you can use to assist you in meeting the compliance
  8604. requirements during a software release.
  8605. With hundreds of different open source licenses that the Yocto Project
  8606. tracks, it is difficult to know the requirements of each and every
  8607. license. However, the requirements of the major FLOSS licenses can begin
  8608. to be covered by assuming that there are three main areas of concern:
  8609. - Source code must be provided.
  8610. - License text for the software must be provided.
  8611. - Compilation scripts and modifications to the source code must be
  8612. provided.
  8613. - spdx files can be provided.
  8614. There are other requirements beyond the scope of these three and the
  8615. methods described in this section (e.g. the mechanism through which
  8616. source code is distributed).
  8617. As different organizations have different methods of complying with open
  8618. source licensing, this section is not meant to imply that there is only
  8619. one single way to meet your compliance obligations, but rather to
  8620. describe one method of achieving compliance. The remainder of this
  8621. section describes methods supported to meet the previously mentioned
  8622. three requirements. Once you take steps to meet these requirements, and
  8623. prior to releasing images, sources, and the build system, you should
  8624. audit all artifacts to ensure completeness.
  8625. .. note::
  8626. The Yocto Project generates a license manifest during image creation
  8627. that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp`
  8628. to assist with any audits.
  8629. Providing the Source Code
  8630. ~~~~~~~~~~~~~~~~~~~~~~~~~
  8631. Compliance activities should begin before you generate the final image.
  8632. The first thing you should look at is the requirement that tops the list
  8633. for most compliance groups - providing the source. The Yocto Project has
  8634. a few ways of meeting this requirement.
  8635. One of the easiest ways to meet this requirement is to provide the
  8636. entire :term:`DL_DIR` used by the
  8637. build. This method, however, has a few issues. The most obvious is the
  8638. size of the directory since it includes all sources used in the build
  8639. and not just the source used in the released image. It will include
  8640. toolchain source, and other artifacts, which you would not generally
  8641. release. However, the more serious issue for most companies is
  8642. accidental release of proprietary software. The Yocto Project provides
  8643. an :ref:`archiver <ref-classes-archiver>` class to
  8644. help avoid some of these concerns.
  8645. Before you employ :term:`DL_DIR` or the :ref:`archiver <ref-classes-archiver>` class, you need to
  8646. decide how you choose to provide source. The source ``archiver`` class
  8647. can generate tarballs and SRPMs and can create them with various levels
  8648. of compliance in mind.
  8649. One way of doing this (but certainly not the only way) is to release
  8650. just the source as a tarball. You can do this by adding the following to
  8651. the ``local.conf`` file found in the
  8652. :term:`Build Directory`::
  8653. INHERIT += "archiver"
  8654. ARCHIVER_MODE[src] = "original"
  8655. During the creation of your
  8656. image, the source from all recipes that deploy packages to the image is
  8657. placed within subdirectories of ``DEPLOY_DIR/sources`` based on the
  8658. :term:`LICENSE` for each recipe.
  8659. Releasing the entire directory enables you to comply with requirements
  8660. concerning providing the unmodified source. It is important to note that
  8661. the size of the directory can get large.
  8662. A way to help mitigate the size issue is to only release tarballs for
  8663. licenses that require the release of source. Let us assume you are only
  8664. concerned with GPL code as identified by running the following script:
  8665. .. code-block:: shell
  8666. # Script to archive a subset of packages matching specific license(s)
  8667. # Source and license files are copied into sub folders of package folder
  8668. # Must be run from build folder
  8669. #!/bin/bash
  8670. src_release_dir="source-release"
  8671. mkdir -p $src_release_dir
  8672. for a in tmp/deploy/sources/*; do
  8673. for d in $a/*; do
  8674. # Get package name from path
  8675. p=`basename $d`
  8676. p=${p%-*}
  8677. p=${p%-*}
  8678. # Only archive GPL packages (update *GPL* regex for your license check)
  8679. numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
  8680. if [ $numfiles -ge 1 ]; then
  8681. echo Archiving $p
  8682. mkdir -p $src_release_dir/$p/source
  8683. cp $d/* $src_release_dir/$p/source 2> /dev/null
  8684. mkdir -p $src_release_dir/$p/license
  8685. cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
  8686. fi
  8687. done
  8688. done
  8689. At this point, you
  8690. could create a tarball from the ``gpl_source_release`` directory and
  8691. provide that to the end user. This method would be a step toward
  8692. achieving compliance with section 3a of GPLv2 and with section 6 of
  8693. GPLv3.
  8694. Providing License Text
  8695. ~~~~~~~~~~~~~~~~~~~~~~
  8696. One requirement that is often overlooked is inclusion of license text.
  8697. This requirement also needs to be dealt with prior to generating the
  8698. final image. Some licenses require the license text to accompany the
  8699. binary. You can achieve this by adding the following to your
  8700. ``local.conf`` file::
  8701. COPY_LIC_MANIFEST = "1"
  8702. COPY_LIC_DIRS = "1"
  8703. LICENSE_CREATE_PACKAGE = "1"
  8704. Adding these statements to the
  8705. configuration file ensures that the licenses collected during package
  8706. generation are included on your image.
  8707. .. note::
  8708. Setting all three variables to "1" results in the image having two
  8709. copies of the same license file. One copy resides in
  8710. ``/usr/share/common-licenses`` and the other resides in
  8711. ``/usr/share/license``.
  8712. The reason for this behavior is because
  8713. :term:`COPY_LIC_DIRS` and
  8714. :term:`COPY_LIC_MANIFEST`
  8715. add a copy of the license when the image is built but do not offer a
  8716. path for adding licenses for newly installed packages to an image.
  8717. :term:`LICENSE_CREATE_PACKAGE`
  8718. adds a separate package and an upgrade path for adding licenses to an
  8719. image.
  8720. As the source ``archiver`` class has already archived the original
  8721. unmodified source that contains the license files, you would have
  8722. already met the requirements for inclusion of the license information
  8723. with source as defined by the GPL and other open source licenses.
  8724. Providing Compilation Scripts and Source Code Modifications
  8725. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8726. At this point, we have addressed all we need to prior to generating the
  8727. image. The next two requirements are addressed during the final
  8728. packaging of the release.
  8729. By releasing the version of the OpenEmbedded build system and the layers
  8730. used during the build, you will be providing both compilation scripts
  8731. and the source code modifications in one step.
  8732. If the deployment team has a :ref:`overview-manual/concepts:bsp layer`
  8733. and a distro layer, and those
  8734. those layers are used to patch, compile, package, or modify (in any way)
  8735. any open source software included in your released images, you might be
  8736. required to release those layers under section 3 of GPLv2 or section 1
  8737. of GPLv3. One way of doing that is with a clean checkout of the version
  8738. of the Yocto Project and layers used during your build. Here is an
  8739. example:
  8740. .. code-block:: shell
  8741. # We built using the dunfell branch of the poky repo
  8742. $ git clone -b dunfell git://git.yoctoproject.org/poky
  8743. $ cd poky
  8744. # We built using the release_branch for our layers
  8745. $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
  8746. $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
  8747. # clean up the .git repos
  8748. $ find . -name ".git" -type d -exec rm -rf {} \;
  8749. One
  8750. thing a development organization might want to consider for end-user
  8751. convenience is to modify ``meta-poky/conf/bblayers.conf.sample`` to
  8752. ensure that when the end user utilizes the released build system to
  8753. build an image, the development organization's layers are included in
  8754. the ``bblayers.conf`` file automatically::
  8755. # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
  8756. # changes incompatibly
  8757. POKY_BBLAYERS_CONF_VERSION = "2"
  8758. BBPATH = "${TOPDIR}"
  8759. BBFILES ?= ""
  8760. BBLAYERS ?= " \
  8761. ##OEROOT##/meta \
  8762. ##OEROOT##/meta-poky \
  8763. ##OEROOT##/meta-yocto-bsp \
  8764. ##OEROOT##/meta-mylayer \
  8765. "
  8766. Creating and
  8767. providing an archive of the :term:`Metadata`
  8768. layers (recipes, configuration files, and so forth) enables you to meet
  8769. your requirements to include the scripts to control compilation as well
  8770. as any modifications to the original source.
  8771. Providing spdx files
  8772. ~~~~~~~~~~~~~~~~~~~~~~~~~
  8773. The spdx module has been integrated to a layer named meta-spdxscanner.
  8774. meta-spdxscanner provides several kinds of scanner. If you want to enable
  8775. this function, you have to follow the following steps:
  8776. 1. Add meta-spdxscanner layer into ``bblayers.conf``.
  8777. 2. Refer to the README in meta-spdxscanner to setup the environment (e.g,
  8778. setup a fossology server) needed for the scanner.
  8779. 3. Meta-spdxscanner provides several methods within the bbclass to create spdx files.
  8780. Please choose one that you want to use and enable the spdx task. You have to
  8781. add some config options in ``local.conf`` file in your :term:`Build
  8782. Directory`. Here is an example showing how to generate spdx files
  8783. during BitBake using the fossology-python.bbclass::
  8784. # Select fossology-python.bbclass.
  8785. INHERIT += "fossology-python"
  8786. # For fossology-python.bbclass, TOKEN is necessary, so, after setup a
  8787. # Fossology server, you have to create a token.
  8788. TOKEN = "eyJ0eXAiO..."
  8789. # The fossology server is necessary for fossology-python.bbclass.
  8790. FOSSOLOGY_SERVER = "http://xx.xx.xx.xx:8081/repo"
  8791. # If you want to upload the source code to a special folder:
  8792. FOLDER_NAME = "xxxx" //Optional
  8793. # If you don't want to put spdx files in tmp/deploy/spdx, you can enable:
  8794. SPDX_DEPLOY_DIR = "${DEPLOY_DIR}" //Optional
  8795. For more usage information refer to :yocto_git:`the meta-spdxscanner repository
  8796. </meta-spdxscanner/>`.
  8797. Compliance Limitations with Executables Built from Static Libraries
  8798. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8799. When package A is added to an image via the :term:`RDEPENDS` or :term:`RRECOMMENDS`
  8800. mechanisms as well as explicitly included in the image recipe with
  8801. :term:`IMAGE_INSTALL`, and depends on a static linked library recipe B
  8802. (``DEPENDS += "B"``), package B will neither appear in the generated license
  8803. manifest nor in the generated source tarballs. This occurs as the
  8804. :ref:`license <ref-classes-license>` and :ref:`archiver <ref-classes-archiver>`
  8805. classes assume that only packages included via :term:`RDEPENDS` or :term:`RRECOMMENDS`
  8806. end up in the image.
  8807. As a result, potential obligations regarding license compliance for package B
  8808. may not be met.
  8809. The Yocto Project doesn't enable static libraries by default, in part because
  8810. of this issue. Before a solution to this limitation is found, you need to
  8811. keep in mind that if your root filesystem is built from static libraries,
  8812. you will need to manually ensure that your deliveries are compliant
  8813. with the licenses of these libraries.
  8814. Copying Non Standard Licenses
  8815. -----------------------------
  8816. Some packages, such as the linux-firmware package, have many licenses
  8817. that are not in any way common. You can avoid adding a lot of these
  8818. types of common license files, which are only applicable to a specific
  8819. package, by using the
  8820. :term:`NO_GENERIC_LICENSE`
  8821. variable. Using this variable also avoids QA errors when you use a
  8822. non-common, non-CLOSED license in a recipe.
  8823. Here is an example that uses the ``LICENSE.Abilis.txt`` file as
  8824. the license from the fetched source::
  8825. NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
  8826. Checking for Vulnerabilities
  8827. ============================
  8828. Vulnerabilities in images
  8829. -------------------------
  8830. The Yocto Project has an infrastructure to track and address unfixed
  8831. known security vulnerabilities, as tracked by the public
  8832. `Common Vulnerabilities and Exposures (CVE) <https://en.wikipedia.org/wiki/Common_Vulnerabilities_and_Exposures>`__
  8833. database.
  8834. To know which packages are vulnerable to known security vulnerabilities,
  8835. add the following setting to your configuration::
  8836. INHERIT += "cve-check"
  8837. This way, at build time, BitBake will warn you about known CVEs
  8838. as in the example below::
  8839. WARNING: flex-2.6.4-r0 do_cve_check: Found unpatched CVE (CVE-2019-6293), for more information check /poky/build/tmp/work/core2-64-poky-linux/flex/2.6.4-r0/temp/cve.log
  8840. WARNING: libarchive-3.5.1-r0 do_cve_check: Found unpatched CVE (CVE-2021-36976), for more information check /poky/build/tmp/work/core2-64-poky-linux/libarchive/3.5.1-r0/temp/cve.log
  8841. It is also possible to check the CVE status of individual packages as follows::
  8842. bitbake -c cve_check flex libarchive
  8843. Note that OpenEmbedded-Core keeps a list of known unfixed CVE issues which can
  8844. be ignored. You can pass this list to the check as follows::
  8845. bitbake -c cve_check libarchive -R conf/distro/include/cve-extra-exclusions.inc
  8846. Enabling vulnerabily tracking in recipes
  8847. ----------------------------------------
  8848. The :term:`CVE_PRODUCT` variable defines the name used to match the recipe name
  8849. against the name in the upstream `NIST CVE database <https://nvd.nist.gov/>`__.
  8850. Editing recipes to fix vulnerabilities
  8851. --------------------------------------
  8852. To fix a given known vulnerability, you need to add a patch file to your recipe. Here's
  8853. an example from the :oe_layerindex:`ffmpeg recipe</layerindex/recipe/47350>`::
  8854. SRC_URI = "https://www.ffmpeg.org/releases/${BP}.tar.xz \
  8855. file://0001-libavutil-include-assembly-with-full-path-from-sourc.patch \
  8856. file://fix-CVE-2020-20446.patch \
  8857. file://fix-CVE-2020-20453.patch \
  8858. file://fix-CVE-2020-22015.patch \
  8859. file://fix-CVE-2020-22021.patch \
  8860. file://fix-CVE-2020-22033-CVE-2020-22019.patch \
  8861. file://fix-CVE-2021-33815.patch \
  8862. The :ref:`cve-check <ref-classes-cve-check>` class defines two ways of
  8863. supplying a patch for a given CVE. The first
  8864. way is to use a patch filename that matches the below pattern::
  8865. cve_file_name_match = re.compile(".*([Cc][Vv][Ee]\-\d{4}\-\d+)")
  8866. As shown in the example above, multiple CVE IDs can appear in a patch filename,
  8867. but the :ref:`cve-check <ref-classes-cve-check>` class will only consider
  8868. the last CVE ID in the filename as patched.
  8869. The second way to recognize a patched CVE ID is when a line matching the
  8870. below pattern is found in any patch file provided by the recipe::
  8871. cve_match = re.compile("CVE:( CVE\-\d{4}\-\d+)+")
  8872. This allows a single patch file to address multiple CVE IDs at the same time.
  8873. Of course, another way to fix vulnerabilities is to upgrade to a version
  8874. of the package which is not impacted, typically a more recent one.
  8875. The NIST database knows which versions are vulnerable and which ones
  8876. are not.
  8877. Last but not least, you can choose to ignore vulnerabilities through
  8878. the :term:`CVE_CHECK_SKIP_RECIPE` and :term:`CVE_CHECK_IGNORE`
  8879. variables.
  8880. Implementation details
  8881. ----------------------
  8882. Here's what the :ref:`cve-check <ref-classes-cve-check>` class does to
  8883. find unpatched CVE IDs.
  8884. First the code goes through each patch file provided by a recipe. If a valid CVE ID
  8885. is found in the name of the file, the corresponding CVE is considered as patched.
  8886. Don't forget that if multiple CVE IDs are found in the filename, only the last
  8887. one is considered. Then, the code looks for ``CVE: CVE-ID`` lines in the patch
  8888. file. The found CVE IDs are also considered as patched.
  8889. Then, the code looks up all the CVE IDs in the NIST database for all the
  8890. products defined in :term:`CVE_PRODUCT`. Then, for each found CVE:
  8891. - If the package name (:term:`PN`) is part of
  8892. :term:`CVE_CHECK_SKIP_RECIPE`, it is considered as patched.
  8893. - If the CVE ID is part of :term:`CVE_CHECK_IGNORE`, it is
  8894. considered as patched too.
  8895. - If the CVE ID is part of the patched CVE for the recipe, it is
  8896. already considered as patched.
  8897. - Otherwise, the code checks whether the recipe version (:term:`PV`)
  8898. is within the range of versions impacted by the CVE. If so, the CVE
  8899. is considered as unpatched.
  8900. The CVE database is stored in :term:`DL_DIR` and can be inspected using
  8901. ``sqlite3`` command as follows::
  8902. sqlite3 downloads/CVE_CHECK/nvdcve_1.1.db .dump | grep CVE-2021-37462
  8903. Using the Error Reporting Tool
  8904. ==============================
  8905. The error reporting tool allows you to submit errors encountered during
  8906. builds to a central database. Outside of the build environment, you can
  8907. use a web interface to browse errors, view statistics, and query for
  8908. errors. The tool works using a client-server system where the client
  8909. portion is integrated with the installed Yocto Project
  8910. :term:`Source Directory` (e.g. ``poky``).
  8911. The server receives the information collected and saves it in a
  8912. database.
  8913. There is a live instance of the error reporting server at
  8914. https://errors.yoctoproject.org.
  8915. When you want to get help with build failures, you can submit all of the
  8916. information on the failure easily and then point to the URL in your bug
  8917. report or send an email to the mailing list.
  8918. .. note::
  8919. If you send error reports to this server, the reports become publicly
  8920. visible.
  8921. Enabling and Using the Tool
  8922. ---------------------------
  8923. By default, the error reporting tool is disabled. You can enable it by
  8924. inheriting the
  8925. :ref:`report-error <ref-classes-report-error>`
  8926. class by adding the following statement to the end of your
  8927. ``local.conf`` file in your
  8928. :term:`Build Directory`.
  8929. ::
  8930. INHERIT += "report-error"
  8931. By default, the error reporting feature stores information in
  8932. ``${``\ :term:`LOG_DIR`\ ``}/error-report``.
  8933. However, you can specify a directory to use by adding the following to
  8934. your ``local.conf`` file::
  8935. ERR_REPORT_DIR = "path"
  8936. Enabling error
  8937. reporting causes the build process to collect the errors and store them
  8938. in a file as previously described. When the build system encounters an
  8939. error, it includes a command as part of the console output. You can run
  8940. the command to send the error file to the server. For example, the
  8941. following command sends the errors to an upstream server::
  8942. $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
  8943. In the previous example, the errors are sent to a public database
  8944. available at https://errors.yoctoproject.org, which is used by the
  8945. entire community. If you specify a particular server, you can send the
  8946. errors to a different database. Use the following command for more
  8947. information on available options::
  8948. $ send-error-report --help
  8949. When sending the error file, you are prompted to review the data being
  8950. sent as well as to provide a name and optional email address. Once you
  8951. satisfy these prompts, the command returns a link from the server that
  8952. corresponds to your entry in the database. For example, here is a
  8953. typical link: https://errors.yoctoproject.org/Errors/Details/9522/
  8954. Following the link takes you to a web interface where you can browse,
  8955. query the errors, and view statistics.
  8956. Disabling the Tool
  8957. ------------------
  8958. To disable the error reporting feature, simply remove or comment out the
  8959. following statement from the end of your ``local.conf`` file in your
  8960. :term:`Build Directory`.
  8961. ::
  8962. INHERIT += "report-error"
  8963. Setting Up Your Own Error Reporting Server
  8964. ------------------------------------------
  8965. If you want to set up your own error reporting server, you can obtain
  8966. the code from the Git repository at :yocto_git:`/error-report-web/`.
  8967. Instructions on how to set it up are in the README document.
  8968. Using Wayland and Weston
  8969. ========================
  8970. `Wayland <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)>`__
  8971. is a computer display server protocol that provides a method for
  8972. compositing window managers to communicate directly with applications
  8973. and video hardware and expects them to communicate with input hardware
  8974. using other libraries. Using Wayland with supporting targets can result
  8975. in better control over graphics frame rendering than an application
  8976. might otherwise achieve.
  8977. The Yocto Project provides the Wayland protocol libraries and the
  8978. reference
  8979. `Weston <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston>`__
  8980. compositor as part of its release. You can find the integrated packages
  8981. in the ``meta`` layer of the :term:`Source Directory`.
  8982. Specifically, you
  8983. can find the recipes that build both Wayland and Weston at
  8984. ``meta/recipes-graphics/wayland``.
  8985. You can build both the Wayland and Weston packages for use only with
  8986. targets that accept the `Mesa 3D and Direct Rendering
  8987. Infrastructure <https://en.wikipedia.org/wiki/Mesa_(computer_graphics)>`__,
  8988. which is also known as Mesa DRI. This implies that you cannot build and
  8989. use the packages if your target uses, for example, the Intel Embedded
  8990. Media and Graphics Driver (Intel EMGD) that overrides Mesa DRI.
  8991. .. note::
  8992. Due to lack of EGL support, Weston 1.0.3 will not run directly on the
  8993. emulated QEMU hardware. However, this version of Weston will run
  8994. under X emulation without issues.
  8995. This section describes what you need to do to implement Wayland and use
  8996. the Weston compositor when building an image for a supporting target.
  8997. Enabling Wayland in an Image
  8998. ----------------------------
  8999. To enable Wayland, you need to enable it to be built and enable it to be
  9000. included (installed) in the image.
  9001. Building Wayland
  9002. ~~~~~~~~~~~~~~~~
  9003. To cause Mesa to build the ``wayland-egl`` platform and Weston to build
  9004. Wayland with Kernel Mode Setting
  9005. (`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__)
  9006. support, include the "wayland" flag in the
  9007. :term:`DISTRO_FEATURES`
  9008. statement in your ``local.conf`` file::
  9009. DISTRO_FEATURES:append = " wayland"
  9010. .. note::
  9011. If X11 has been enabled elsewhere, Weston will build Wayland with X11
  9012. support
  9013. Installing Wayland and Weston
  9014. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9015. To install the Wayland feature into an image, you must include the
  9016. following
  9017. :term:`CORE_IMAGE_EXTRA_INSTALL`
  9018. statement in your ``local.conf`` file::
  9019. CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
  9020. Running Weston
  9021. --------------
  9022. To run Weston inside X11, enabling it as described earlier and building
  9023. a Sato image is sufficient. If you are running your image under Sato, a
  9024. Weston Launcher appears in the "Utility" category.
  9025. Alternatively, you can run Weston through the command-line interpretor
  9026. (CLI), which is better suited for development work. To run Weston under
  9027. the CLI, you need to do the following after your image is built:
  9028. 1. Run these commands to export ``XDG_RUNTIME_DIR``::
  9029. mkdir -p /tmp/$USER-weston
  9030. chmod 0700 /tmp/$USER-weston
  9031. export XDG_RUNTIME_DIR=/tmp/$USER-weston
  9032. 2. Launch Weston in the shell::
  9033. weston