common-tasks.rst 455 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. ************
  3. Common Tasks
  4. ************
  5. This chapter describes fundamental procedures such as creating layers,
  6. adding new software packages, extending or customizing images, porting
  7. work to new hardware (adding a new machine), and so forth. You will find
  8. that the procedures documented here occur often in the development cycle
  9. using the Yocto Project.
  10. Understanding and Creating Layers
  11. =================================
  12. The OpenEmbedded build system supports organizing
  13. :term:`Metadata` into multiple layers.
  14. Layers allow you to isolate different types of customizations from each
  15. other. For introductory information on the Yocto Project Layer Model,
  16. see the
  17. ":ref:`overview-manual/yp-intro:the yocto project layer model`"
  18. section in the Yocto Project Overview and Concepts Manual.
  19. Creating Your Own Layer
  20. -----------------------
  21. It is very easy to create your own layers to use with the OpenEmbedded
  22. build system. The Yocto Project ships with tools that speed up creating
  23. layers. This section describes the steps you perform by hand to create
  24. layers so that you can better understand them. For information about the
  25. layer-creation tools, see the
  26. ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
  27. section in the Yocto Project Board Support Package (BSP) Developer's
  28. Guide and the ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
  29. section further down in this manual.
  30. Follow these general steps to create your layer without using tools:
  31. 1. *Check Existing Layers:* Before creating a new layer, you should be
  32. sure someone has not already created a layer containing the Metadata
  33. you need. You can see the :oe_layerindex:`OpenEmbedded Metadata Index <>`
  34. for a list of layers from the OpenEmbedded community that can be used in
  35. the Yocto Project. You could find a layer that is identical or close
  36. to what you need.
  37. 2. *Create a Directory:* Create the directory for your layer. When you
  38. create the layer, be sure to create the directory in an area not
  39. associated with the Yocto Project :term:`Source Directory`
  40. (e.g. the cloned ``poky`` repository).
  41. While not strictly required, prepend the name of the directory with
  42. the string "meta-". For example::
  43. meta-mylayer
  44. meta-GUI_xyz
  45. meta-mymachine
  46. With rare exceptions, a layer's name follows this form::
  47. meta-root_name
  48. Following this layer naming convention can save
  49. you trouble later when tools, components, or variables "assume" your
  50. layer name begins with "meta-". A notable example is in configuration
  51. files as shown in the following step where layer names without the
  52. "meta-" string are appended to several variables used in the
  53. configuration.
  54. 3. *Create a Layer Configuration File:* Inside your new layer folder,
  55. you need to create a ``conf/layer.conf`` file. It is easiest to take
  56. an existing layer configuration file and copy that to your layer's
  57. ``conf`` directory and then modify the file as needed.
  58. The ``meta-yocto-bsp/conf/layer.conf`` file in the Yocto Project
  59. :yocto_git:`Source Repositories </poky/tree/meta-yocto-bsp/conf>`
  60. demonstrates the required syntax. For your layer, you need to replace
  61. "yoctobsp" with a unique identifier for your layer (e.g. "machinexyz"
  62. for a layer named "meta-machinexyz")::
  63. # We have a conf and classes directory, add to BBPATH
  64. BBPATH .= ":${LAYERDIR}"
  65. # We have recipes-* directories, add to BBFILES
  66. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  67. ${LAYERDIR}/recipes-*/*/*.bbappend"
  68. BBFILE_COLLECTIONS += "yoctobsp"
  69. BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
  70. BBFILE_PRIORITY_yoctobsp = "5"
  71. LAYERVERSION_yoctobsp = "4"
  72. LAYERSERIES_COMPAT_yoctobsp = "dunfell"
  73. Following is an explanation of the layer configuration file:
  74. - :term:`BBPATH`: Adds the layer's
  75. root directory to BitBake's search path. Through the use of the
  76. :term:`BBPATH` variable, BitBake locates class files (``.bbclass``),
  77. configuration files, and files that are included with ``include``
  78. and ``require`` statements. For these cases, BitBake uses the
  79. first file that matches the name found in :term:`BBPATH`. This is
  80. similar to the way the ``PATH`` variable is used for binaries. It
  81. is recommended, therefore, that you use unique class and
  82. configuration filenames in your custom layer.
  83. - :term:`BBFILES`: Defines the
  84. location for all recipes in the layer.
  85. - :term:`BBFILE_COLLECTIONS`:
  86. Establishes the current layer through a unique identifier that is
  87. used throughout the OpenEmbedded build system to refer to the
  88. layer. In this example, the identifier "yoctobsp" is the
  89. representation for the container layer named "meta-yocto-bsp".
  90. - :term:`BBFILE_PATTERN`:
  91. Expands immediately during parsing to provide the directory of the
  92. layer.
  93. - :term:`BBFILE_PRIORITY`:
  94. Establishes a priority to use for recipes in the layer when the
  95. OpenEmbedded build finds recipes of the same name in different
  96. layers.
  97. - :term:`LAYERVERSION`:
  98. Establishes a version number for the layer. You can use this
  99. version number to specify this exact version of the layer as a
  100. dependency when using the
  101. :term:`LAYERDEPENDS`
  102. variable.
  103. - :term:`LAYERDEPENDS`:
  104. Lists all layers on which this layer depends (if any).
  105. - :term:`LAYERSERIES_COMPAT`:
  106. Lists the :yocto_wiki:`Yocto Project </Releases>`
  107. releases for which the current version is compatible. This
  108. variable is a good way to indicate if your particular layer is
  109. current.
  110. 4. *Add Content:* Depending on the type of layer, add the content. If
  111. the layer adds support for a machine, add the machine configuration
  112. in a ``conf/machine/`` file within the layer. If the layer adds
  113. distro policy, add the distro configuration in a ``conf/distro/``
  114. file within the layer. If the layer introduces new recipes, put the
  115. recipes you need in ``recipes-*`` subdirectories within the layer.
  116. .. note::
  117. For an explanation of layer hierarchy that is compliant with the
  118. Yocto Project, see the ":ref:`bsp-guide/bsp:example filesystem layout`"
  119. section in the Yocto Project Board Support Package (BSP) Developer's Guide.
  120. 5. *Optionally Test for Compatibility:* If you want permission to use
  121. the Yocto Project Compatibility logo with your layer or application
  122. that uses your layer, perform the steps to apply for compatibility.
  123. See the
  124. ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`"
  125. section for more information.
  126. Following Best Practices When Creating Layers
  127. ---------------------------------------------
  128. To create layers that are easier to maintain and that will not impact
  129. builds for other machines, you should consider the information in the
  130. following list:
  131. - *Avoid "Overlaying" Entire Recipes from Other Layers in Your
  132. Configuration:* In other words, do not copy an entire recipe into
  133. your layer and then modify it. Rather, use an append file
  134. (``.bbappend``) to override only those parts of the original recipe
  135. you need to modify.
  136. - *Avoid Duplicating Include Files:* Use append files (``.bbappend``)
  137. for each recipe that uses an include file. Or, if you are introducing
  138. a new recipe that requires the included file, use the path relative
  139. to the original layer directory to refer to the file. For example,
  140. use ``require recipes-core/``\ `package`\ ``/``\ `file`\ ``.inc`` instead
  141. of ``require`` `file`\ ``.inc``. If you're finding you have to overlay
  142. the include file, it could indicate a deficiency in the include file
  143. in the layer to which it originally belongs. If this is the case, you
  144. should try to address that deficiency instead of overlaying the
  145. include file. For example, you could address this by getting the
  146. maintainer of the include file to add a variable or variables to make
  147. it easy to override the parts needing to be overridden.
  148. - *Structure Your Layers:* Proper use of overrides within append files
  149. and placement of machine-specific files within your layer can ensure
  150. that a build is not using the wrong Metadata and negatively impacting
  151. a build for a different machine. Following are some examples:
  152. - *Modify Variables to Support a Different Machine:* Suppose you
  153. have a layer named ``meta-one`` that adds support for building
  154. machine "one". To do so, you use an append file named
  155. ``base-files.bbappend`` and create a dependency on "foo" by
  156. altering the :term:`DEPENDS`
  157. variable::
  158. DEPENDS = "foo"
  159. The dependency is created during any
  160. build that includes the layer ``meta-one``. However, you might not
  161. want this dependency for all machines. For example, suppose you
  162. are building for machine "two" but your ``bblayers.conf`` file has
  163. the ``meta-one`` layer included. During the build, the
  164. ``base-files`` for machine "two" will also have the dependency on
  165. ``foo``.
  166. To make sure your changes apply only when building machine "one",
  167. use a machine override with the :term:`DEPENDS` statement::
  168. DEPENDS_one = "foo"
  169. You should follow the same strategy when using ``_append``
  170. and ``_prepend`` operations::
  171. DEPENDS_append_one = " foo"
  172. DEPENDS_prepend_one = "foo "
  173. As an actual example, here's a
  174. snippet from the generic kernel include file ``linux-yocto.inc``,
  175. wherein the kernel compile and link options are adjusted in the
  176. case of a subset of the supported architectures::
  177. DEPENDS_append_aarch64 = " libgcc"
  178. KERNEL_CC_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
  179. KERNEL_LD_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
  180. DEPENDS_append_nios2 = " libgcc"
  181. KERNEL_CC_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
  182. KERNEL_LD_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
  183. DEPENDS_append_arc = " libgcc"
  184. KERNEL_CC_append_arc = " ${TOOLCHAIN_OPTIONS}"
  185. KERNEL_LD_append_arc = " ${TOOLCHAIN_OPTIONS}"
  186. KERNEL_FEATURES_append_qemuall=" features/debug/printk.scc"
  187. .. note::
  188. Avoiding "+=" and "=+" and using machine-specific ``_append``
  189. and ``_prepend`` operations is recommended as well.
  190. - *Place Machine-Specific Files in Machine-Specific Locations:* When
  191. you have a base recipe, such as ``base-files.bb``, that contains a
  192. :term:`SRC_URI` statement to a
  193. file, you can use an append file to cause the build to use your
  194. own version of the file. For example, an append file in your layer
  195. at ``meta-one/recipes-core/base-files/base-files.bbappend`` could
  196. extend :term:`FILESPATH` using :term:`FILESEXTRAPATHS` as follows::
  197. FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
  198. The build for machine "one" will pick up your machine-specific file as
  199. long as you have the file in
  200. ``meta-one/recipes-core/base-files/base-files/``. However, if you
  201. are building for a different machine and the ``bblayers.conf``
  202. file includes the ``meta-one`` layer and the location of your
  203. machine-specific file is the first location where that file is
  204. found according to :term:`FILESPATH`, builds for all machines will
  205. also use that machine-specific file.
  206. You can make sure that a machine-specific file is used for a
  207. particular machine by putting the file in a subdirectory specific
  208. to the machine. For example, rather than placing the file in
  209. ``meta-one/recipes-core/base-files/base-files/`` as shown above,
  210. put it in ``meta-one/recipes-core/base-files/base-files/one/``.
  211. Not only does this make sure the file is used only when building
  212. for machine "one", but the build process locates the file more
  213. quickly.
  214. In summary, you need to place all files referenced from
  215. :term:`SRC_URI` in a machine-specific subdirectory within the layer in
  216. order to restrict those files to machine-specific builds.
  217. - *Perform Steps to Apply for Yocto Project Compatibility:* If you want
  218. permission to use the Yocto Project Compatibility logo with your
  219. layer or application that uses your layer, perform the steps to apply
  220. for compatibility. See the
  221. ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`"
  222. section for more information.
  223. - *Follow the Layer Naming Convention:* Store custom layers in a Git
  224. repository that use the ``meta-layer_name`` format.
  225. - *Group Your Layers Locally:* Clone your repository alongside other
  226. cloned ``meta`` directories from the :term:`Source Directory`.
  227. Making Sure Your Layer is Compatible With Yocto Project
  228. -------------------------------------------------------
  229. When you create a layer used with the Yocto Project, it is advantageous
  230. to make sure that the layer interacts well with existing Yocto Project
  231. layers (i.e. the layer is compatible with the Yocto Project). Ensuring
  232. compatibility makes the layer easy to be consumed by others in the Yocto
  233. Project community and could allow you permission to use the Yocto
  234. Project Compatible Logo.
  235. .. note::
  236. Only Yocto Project member organizations are permitted to use the
  237. Yocto Project Compatible Logo. The logo is not available for general
  238. use. For information on how to become a Yocto Project member
  239. organization, see the :yocto_home:`Yocto Project Website <>`.
  240. The Yocto Project Compatibility Program consists of a layer application
  241. process that requests permission to use the Yocto Project Compatibility
  242. Logo for your layer and application. The process consists of two parts:
  243. 1. Successfully passing a script (``yocto-check-layer``) that when run
  244. against your layer, tests it against constraints based on experiences
  245. of how layers have worked in the real world and where pitfalls have
  246. been found. Getting a "PASS" result from the script is required for
  247. successful compatibility registration.
  248. 2. Completion of an application acceptance form, which you can find at
  249. :yocto_home:`/webform/yocto-project-compatible-registration`.
  250. To be granted permission to use the logo, you need to satisfy the
  251. following:
  252. - Be able to check the box indicating that you got a "PASS" when
  253. running the script against your layer.
  254. - Answer "Yes" to the questions on the form or have an acceptable
  255. explanation for any questions answered "No".
  256. - Be a Yocto Project Member Organization.
  257. The remainder of this section presents information on the registration
  258. form and on the ``yocto-check-layer`` script.
  259. Yocto Project Compatible Program Application
  260. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  261. Use the form to apply for your layer's approval. Upon successful
  262. application, you can use the Yocto Project Compatibility Logo with your
  263. layer and the application that uses your layer.
  264. To access the form, use this link:
  265. :yocto_home:`/webform/yocto-project-compatible-registration`.
  266. Follow the instructions on the form to complete your application.
  267. The application consists of the following sections:
  268. - *Contact Information:* Provide your contact information as the fields
  269. require. Along with your information, provide the released versions
  270. of the Yocto Project for which your layer is compatible.
  271. - *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the
  272. items in the checklist. There is space at the bottom of the form for
  273. any explanations for items for which you answered "No".
  274. - *Recommendations:* Provide answers for the questions regarding Linux
  275. kernel use and build success.
  276. ``yocto-check-layer`` Script
  277. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  278. The ``yocto-check-layer`` script provides you a way to assess how
  279. compatible your layer is with the Yocto Project. You should run this
  280. script prior to using the form to apply for compatibility as described
  281. in the previous section. You need to achieve a "PASS" result in order to
  282. have your application form successfully processed.
  283. The script divides tests into three areas: COMMON, BSP, and DISTRO. For
  284. example, given a distribution layer (DISTRO), the layer must pass both
  285. the COMMON and DISTRO related tests. Furthermore, if your layer is a BSP
  286. layer, the layer must pass the COMMON and BSP set of tests.
  287. To execute the script, enter the following commands from your build
  288. directory::
  289. $ source oe-init-build-env
  290. $ yocto-check-layer your_layer_directory
  291. Be sure to provide the actual directory for your
  292. layer as part of the command.
  293. Entering the command causes the script to determine the type of layer
  294. and then to execute a set of specific tests against the layer. The
  295. following list overviews the test:
  296. - ``common.test_readme``: Tests if a ``README`` file exists in the
  297. layer and the file is not empty.
  298. - ``common.test_parse``: Tests to make sure that BitBake can parse the
  299. files without error (i.e. ``bitbake -p``).
  300. - ``common.test_show_environment``: Tests that the global or per-recipe
  301. environment is in order without errors (i.e. ``bitbake -e``).
  302. - ``common.test_world``: Verifies that ``bitbake world`` works.
  303. - ``common.test_signatures``: Tests to be sure that BSP and DISTRO
  304. layers do not come with recipes that change signatures.
  305. - ``common.test_layerseries_compat``: Verifies layer compatibility is
  306. set properly.
  307. - ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine
  308. configurations.
  309. - ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not
  310. set the machine when the layer is added.
  311. - ``bsp.test_machine_world``: Verifies that ``bitbake world`` works
  312. regardless of which machine is selected.
  313. - ``bsp.test_machine_signatures``: Verifies that building for a
  314. particular machine affects only the signature of tasks specific to
  315. that machine.
  316. - ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has
  317. distro configurations.
  318. - ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer
  319. does not set the distribution when the layer is added.
  320. Enabling Your Layer
  321. -------------------
  322. Before the OpenEmbedded build system can use your new layer, you need to
  323. enable it. To enable your layer, simply add your layer's path to the
  324. :term:`BBLAYERS` variable in your ``conf/bblayers.conf`` file, which is
  325. found in the :term:`Build Directory`.
  326. The following example shows how to enable a layer named
  327. ``meta-mylayer``::
  328. # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
  329. # changes incompatibly
  330. POKY_BBLAYERS_CONF_VERSION = "2"
  331. BBPATH = "${TOPDIR}"
  332. BBFILES ?= ""
  333. BBLAYERS ?= " \
  334. /home/user/poky/meta \
  335. /home/user/poky/meta-poky \
  336. /home/user/poky/meta-yocto-bsp \
  337. /home/user/poky/meta-mylayer \
  338. "
  339. BitBake parses each ``conf/layer.conf`` file from the top down as
  340. specified in the :term:`BBLAYERS` variable within the ``conf/bblayers.conf``
  341. file. During the processing of each ``conf/layer.conf`` file, BitBake
  342. adds the recipes, classes and configurations contained within the
  343. particular layer to the source directory.
  344. Using .bbappend Files in Your Layer
  345. -----------------------------------
  346. A recipe that appends Metadata to another recipe is called a BitBake
  347. append file. A BitBake append file uses the ``.bbappend`` file type
  348. suffix, while the corresponding recipe to which Metadata is being
  349. appended uses the ``.bb`` file type suffix.
  350. You can use a ``.bbappend`` file in your layer to make additions or
  351. changes to the content of another layer's recipe without having to copy
  352. the other layer's recipe into your layer. Your ``.bbappend`` file
  353. resides in your layer, while the main ``.bb`` recipe file to which you
  354. are appending Metadata resides in a different layer.
  355. Being able to append information to an existing recipe not only avoids
  356. duplication, but also automatically applies recipe changes from a
  357. different layer into your layer. If you were copying recipes, you would
  358. have to manually merge changes as they occur.
  359. When you create an append file, you must use the same root name as the
  360. corresponding recipe file. For example, the append file
  361. ``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This
  362. means the original recipe and append file names are version
  363. number-specific. If the corresponding recipe is renamed to update to a
  364. newer version, you must also rename and possibly update the
  365. corresponding ``.bbappend`` as well. During the build process, BitBake
  366. displays an error on starting if it detects a ``.bbappend`` file that
  367. does not have a corresponding recipe with a matching name. See the
  368. :term:`BB_DANGLINGAPPENDS_WARNONLY`
  369. variable for information on how to handle this error.
  370. As an example, consider the main formfactor recipe and a corresponding
  371. formfactor append file both from the :term:`Source Directory`.
  372. Here is the main
  373. formfactor recipe, which is named ``formfactor_0.0.bb`` and located in
  374. the "meta" layer at ``meta/recipes-bsp/formfactor``::
  375. SUMMARY = "Device formfactor information"
  376. DESCRIPTION = "A formfactor configuration file provides information about the \
  377. target hardware for which the image is being built and information that the \
  378. build system cannot obtain from other sources such as the kernel."
  379. SECTION = "base"
  380. LICENSE = "MIT"
  381. LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
  382. PR = "r45"
  383. SRC_URI = "file://config file://machconfig"
  384. S = "${WORKDIR}"
  385. PACKAGE_ARCH = "${MACHINE_ARCH}"
  386. INHIBIT_DEFAULT_DEPS = "1"
  387. do_install() {
  388. # Install file only if it has contents
  389. install -d ${D}${sysconfdir}/formfactor/
  390. install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
  391. if [ -s "${S}/machconfig" ]; then
  392. install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
  393. fi
  394. }
  395. In the main recipe, note the :term:`SRC_URI`
  396. variable, which tells the OpenEmbedded build system where to find files
  397. during the build.
  398. Following is the append file, which is named ``formfactor_0.0.bbappend``
  399. and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The
  400. file is in the layer at ``recipes-bsp/formfactor``::
  401. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
  402. By default, the build system uses the
  403. :term:`FILESPATH` variable to
  404. locate files. This append file extends the locations by setting the
  405. :term:`FILESEXTRAPATHS`
  406. variable. Setting this variable in the ``.bbappend`` file is the most
  407. reliable and recommended method for adding directories to the search
  408. path used by the build system to find files.
  409. The statement in this example extends the directories to include
  410. ``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``,
  411. which resolves to a directory named ``formfactor`` in the same directory
  412. in which the append file resides (i.e.
  413. ``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must
  414. have the supporting directory structure set up that will contain any
  415. files or patches you will be including from the layer.
  416. Using the immediate expansion assignment operator ``:=`` is important
  417. because of the reference to :term:`THISDIR`. The trailing colon character is
  418. important as it ensures that items in the list remain colon-separated.
  419. .. note::
  420. BitBake automatically defines the :term:`THISDIR` variable. You should
  421. never set this variable yourself. Using "_prepend" as part of the
  422. :term:`FILESEXTRAPATHS` ensures your path will be searched prior to other
  423. paths in the final list.
  424. Also, not all append files add extra files. Many append files simply
  425. allow to add build options (e.g. ``systemd``). For these cases, your
  426. append file would not even use the :term:`FILESEXTRAPATHS` statement.
  427. Prioritizing Your Layer
  428. -----------------------
  429. Each layer is assigned a priority value. Priority values control which
  430. layer takes precedence if there are recipe files with the same name in
  431. multiple layers. For these cases, the recipe file from the layer with a
  432. higher priority number takes precedence. Priority values also affect the
  433. order in which multiple ``.bbappend`` files for the same recipe are
  434. applied. You can either specify the priority manually, or allow the
  435. build system to calculate it based on the layer's dependencies.
  436. To specify the layer's priority manually, use the
  437. :term:`BBFILE_PRIORITY`
  438. variable and append the layer's root name::
  439. BBFILE_PRIORITY_mylayer = "1"
  440. .. note::
  441. It is possible for a recipe with a lower version number
  442. :term:`PV` in a layer that has a higher
  443. priority to take precedence.
  444. Also, the layer priority does not currently affect the precedence
  445. order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake
  446. might address this.
  447. Managing Layers
  448. ---------------
  449. You can use the BitBake layer management tool ``bitbake-layers`` to
  450. provide a view into the structure of recipes across a multi-layer
  451. project. Being able to generate output that reports on configured layers
  452. with their paths and priorities and on ``.bbappend`` files and their
  453. applicable recipes can help to reveal potential problems.
  454. For help on the BitBake layer management tool, use the following
  455. command::
  456. $ bitbake-layers --help
  457. NOTE: Starting bitbake server...
  458. usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] <subcommand> ...
  459. BitBake layers utility
  460. optional arguments:
  461. -d, --debug Enable debug output
  462. -q, --quiet Print only errors
  463. -F, --force Force add without recipe parse verification
  464. --color COLOR Colorize output (where COLOR is auto, always, never)
  465. -h, --help show this help message and exit
  466. subcommands:
  467. <subcommand>
  468. layerindex-fetch Fetches a layer from a layer index along with its
  469. dependent layers, and adds them to conf/bblayers.conf.
  470. layerindex-show-depends
  471. Find layer dependencies from layer index.
  472. add-layer Add one or more layers to bblayers.conf.
  473. remove-layer Remove one or more layers from bblayers.conf.
  474. flatten flatten layer configuration into a separate output
  475. directory.
  476. show-layers show current configured layers.
  477. show-overlayed list overlayed recipes (where the same recipe exists
  478. in another layer)
  479. show-recipes list available recipes, showing the layer they are
  480. provided by
  481. show-appends list bbappend files and recipe files they apply to
  482. show-cross-depends Show dependencies between recipes that cross layer
  483. boundaries.
  484. create-layer Create a basic layer
  485. Use bitbake-layers <subcommand> --help to get help on a specific command
  486. The following list describes the available commands:
  487. - ``help:`` Displays general help or help on a specified command.
  488. - ``show-layers:`` Shows the current configured layers.
  489. - ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed
  490. when a recipe with the same name exists in another layer that has a
  491. higher layer priority.
  492. - ``show-recipes:`` Lists available recipes and the layers that
  493. provide them.
  494. - ``show-appends:`` Lists ``.bbappend`` files and the recipe files to
  495. which they apply.
  496. - ``show-cross-depends:`` Lists dependency relationships between
  497. recipes that cross layer boundaries.
  498. - ``add-layer:`` Adds a layer to ``bblayers.conf``.
  499. - ``remove-layer:`` Removes a layer from ``bblayers.conf``
  500. - ``flatten:`` Flattens the layer configuration into a separate
  501. output directory. Flattening your layer configuration builds a
  502. "flattened" directory that contains the contents of all layers, with
  503. any overlayed recipes removed and any ``.bbappend`` files appended to
  504. the corresponding recipes. You might have to perform some manual
  505. cleanup of the flattened layer as follows:
  506. - Non-recipe files (such as patches) are overwritten. The flatten
  507. command shows a warning for these files.
  508. - Anything beyond the normal layer setup has been added to the
  509. ``layer.conf`` file. Only the lowest priority layer's
  510. ``layer.conf`` is used.
  511. - Overridden and appended items from ``.bbappend`` files need to be
  512. cleaned up. The contents of each ``.bbappend`` end up in the
  513. flattened recipe. However, if there are appended or changed
  514. variable values, you need to tidy these up yourself. Consider the
  515. following example. Here, the ``bitbake-layers`` command adds the
  516. line ``#### bbappended ...`` so that you know where the following
  517. lines originate::
  518. ...
  519. DESCRIPTION = "A useful utility"
  520. ...
  521. EXTRA_OECONF = "--enable-something"
  522. ...
  523. #### bbappended from meta-anotherlayer ####
  524. DESCRIPTION = "Customized utility"
  525. EXTRA_OECONF += "--enable-somethingelse"
  526. Ideally, you would tidy up these utilities as follows::
  527. ...
  528. DESCRIPTION = "Customized utility"
  529. ...
  530. EXTRA_OECONF = "--enable-something --enable-somethingelse"
  531. ...
  532. - ``layerindex-fetch``: Fetches a layer from a layer index, along
  533. with its dependent layers, and adds the layers to the
  534. ``conf/bblayers.conf`` file.
  535. - ``layerindex-show-depends``: Finds layer dependencies from the
  536. layer index.
  537. - ``create-layer``: Creates a basic layer.
  538. Creating a General Layer Using the ``bitbake-layers`` Script
  539. ------------------------------------------------------------
  540. The ``bitbake-layers`` script with the ``create-layer`` subcommand
  541. simplifies creating a new general layer.
  542. .. note::
  543. - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`"
  544. section in the Yocto
  545. Project Board Specific (BSP) Developer's Guide.
  546. - In order to use a layer with the OpenEmbedded build system, you
  547. need to add the layer to your ``bblayers.conf`` configuration
  548. file. See the ":ref:`dev-manual/common-tasks:adding a layer using the \`\`bitbake-layers\`\` script`"
  549. section for more information.
  550. The default mode of the script's operation with this subcommand is to
  551. create a layer with the following:
  552. - A layer priority of 6.
  553. - A ``conf`` subdirectory that contains a ``layer.conf`` file.
  554. - A ``recipes-example`` subdirectory that contains a further
  555. subdirectory named ``example``, which contains an ``example.bb``
  556. recipe file.
  557. - A ``COPYING.MIT``, which is the license statement for the layer. The
  558. script assumes you want to use the MIT license, which is typical for
  559. most layers, for the contents of the layer itself.
  560. - A ``README`` file, which is a file describing the contents of your
  561. new layer.
  562. In its simplest form, you can use the following command form to create a
  563. layer. The command creates a layer whose name corresponds to
  564. "your_layer_name" in the current directory::
  565. $ bitbake-layers create-layer your_layer_name
  566. As an example, the following command creates a layer named ``meta-scottrif``
  567. in your home directory::
  568. $ cd /usr/home
  569. $ bitbake-layers create-layer meta-scottrif
  570. NOTE: Starting bitbake server...
  571. Add your new layer with 'bitbake-layers add-layer meta-scottrif'
  572. If you want to set the priority of the layer to other than the default
  573. value of "6", you can either use the ``--priority`` option or you
  574. can edit the
  575. :term:`BBFILE_PRIORITY` value
  576. in the ``conf/layer.conf`` after the script creates it. Furthermore, if
  577. you want to give the example recipe file some name other than the
  578. default, you can use the ``--example-recipe-name`` option.
  579. The easiest way to see how the ``bitbake-layers create-layer`` command
  580. works is to experiment with the script. You can also read the usage
  581. information by entering the following::
  582. $ bitbake-layers create-layer --help
  583. NOTE: Starting bitbake server...
  584. usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
  585. [--example-recipe-name EXAMPLERECIPE]
  586. layerdir
  587. Create a basic layer
  588. positional arguments:
  589. layerdir Layer directory to create
  590. optional arguments:
  591. -h, --help show this help message and exit
  592. --priority PRIORITY, -p PRIORITY
  593. Layer directory to create
  594. --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
  595. Filename of the example recipe
  596. Adding a Layer Using the ``bitbake-layers`` Script
  597. --------------------------------------------------
  598. Once you create your general layer, you must add it to your
  599. ``bblayers.conf`` file. Adding the layer to this configuration file
  600. makes the OpenEmbedded build system aware of your layer so that it can
  601. search it for metadata.
  602. Add your layer by using the ``bitbake-layers add-layer`` command::
  603. $ bitbake-layers add-layer your_layer_name
  604. Here is an example that adds a
  605. layer named ``meta-scottrif`` to the configuration file. Following the
  606. command that adds the layer is another ``bitbake-layers`` command that
  607. shows the layers that are in your ``bblayers.conf`` file::
  608. $ bitbake-layers add-layer meta-scottrif
  609. NOTE: Starting bitbake server...
  610. Parsing recipes: 100% |##########################################################| Time: 0:00:49
  611. Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
  612. $ bitbake-layers show-layers
  613. NOTE: Starting bitbake server...
  614. layer path priority
  615. ==========================================================================
  616. meta /home/scottrif/poky/meta 5
  617. meta-poky /home/scottrif/poky/meta-poky 5
  618. meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
  619. workspace /home/scottrif/poky/build/workspace 99
  620. meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
  621. Adding the layer to this file
  622. enables the build system to locate the layer during the build.
  623. .. note::
  624. During a build, the OpenEmbedded build system looks in the layers
  625. from the top of the list down to the bottom in that order.
  626. Customizing Images
  627. ==================
  628. You can customize images to satisfy particular requirements. This
  629. section describes several methods and provides guidelines for each.
  630. Customizing Images Using ``local.conf``
  631. ---------------------------------------
  632. Probably the easiest way to customize an image is to add a package by
  633. way of the ``local.conf`` configuration file. Because it is limited to
  634. local use, this method generally only allows you to add packages and is
  635. not as flexible as creating your own customized image. When you add
  636. packages using local variables this way, you need to realize that these
  637. variable changes are in effect for every build and consequently affect
  638. all images, which might not be what you require.
  639. To add a package to your image using the local configuration file, use
  640. the :term:`IMAGE_INSTALL` variable with the ``_append`` operator::
  641. IMAGE_INSTALL_append = " strace"
  642. Use of the syntax is important -
  643. specifically, the space between the quote and the package name, which is
  644. ``strace`` in this example. This space is required since the ``_append``
  645. operator does not add the space.
  646. Furthermore, you must use ``_append`` instead of the ``+=`` operator if
  647. you want to avoid ordering issues. The reason for this is because doing
  648. so unconditionally appends to the variable and avoids ordering problems
  649. due to the variable being set in image recipes and ``.bbclass`` files
  650. with operators like ``?=``. Using ``_append`` ensures the operation
  651. takes effect.
  652. As shown in its simplest use, ``IMAGE_INSTALL_append`` affects all
  653. images. It is possible to extend the syntax so that the variable applies
  654. to a specific image only. Here is an example::
  655. IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
  656. This example adds ``strace`` to the ``core-image-minimal`` image only.
  657. You can add packages using a similar approach through the
  658. :term:`CORE_IMAGE_EXTRA_INSTALL` variable. If you use this variable, only
  659. ``core-image-*`` images are affected.
  660. Customizing Images Using Custom ``IMAGE_FEATURES`` and ``EXTRA_IMAGE_FEATURES``
  661. -------------------------------------------------------------------------------
  662. Another method for customizing your image is to enable or disable
  663. high-level image features by using the
  664. :term:`IMAGE_FEATURES` and
  665. :term:`EXTRA_IMAGE_FEATURES`
  666. variables. Although the functions for both variables are nearly
  667. equivalent, best practices dictate using :term:`IMAGE_FEATURES` from within
  668. a recipe and using :term:`EXTRA_IMAGE_FEATURES` from within your
  669. ``local.conf`` file, which is found in the
  670. :term:`Build Directory`.
  671. To understand how these features work, the best reference is
  672. ``meta/classes/core-image.bbclass``. This class lists out the available
  673. :term:`IMAGE_FEATURES` of which most map to package groups while some, such
  674. as ``debug-tweaks`` and ``read-only-rootfs``, resolve as general
  675. configuration settings.
  676. In summary, the file looks at the contents of the :term:`IMAGE_FEATURES`
  677. variable and then maps or configures the feature accordingly. Based on
  678. this information, the build system automatically adds the appropriate
  679. packages or configurations to the
  680. :term:`IMAGE_INSTALL` variable.
  681. Effectively, you are enabling extra features by extending the class or
  682. creating a custom class for use with specialized image ``.bb`` files.
  683. Use the :term:`EXTRA_IMAGE_FEATURES` variable from within your local
  684. configuration file. Using a separate area from which to enable features
  685. with this variable helps you avoid overwriting the features in the image
  686. recipe that are enabled with :term:`IMAGE_FEATURES`. The value of
  687. :term:`EXTRA_IMAGE_FEATURES` is added to :term:`IMAGE_FEATURES` within
  688. ``meta/conf/bitbake.conf``.
  689. To illustrate how you can use these variables to modify your image,
  690. consider an example that selects the SSH server. The Yocto Project ships
  691. with two SSH servers you can use with your images: Dropbear and OpenSSH.
  692. Dropbear is a minimal SSH server appropriate for resource-constrained
  693. environments, while OpenSSH is a well-known standard SSH server
  694. implementation. By default, the ``core-image-sato`` image is configured
  695. to use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb``
  696. images both include OpenSSH. The ``core-image-minimal`` image does not
  697. contain an SSH server.
  698. You can customize your image and change these defaults. Edit the
  699. :term:`IMAGE_FEATURES` variable in your recipe or use the
  700. :term:`EXTRA_IMAGE_FEATURES` in your ``local.conf`` file so that it
  701. configures the image you are working with to include
  702. ``ssh-server-dropbear`` or ``ssh-server-openssh``.
  703. .. note::
  704. See the ":ref:`ref-manual/features:image features`" section in the Yocto
  705. Project Reference Manual for a complete list of image features that ship
  706. with the Yocto Project.
  707. Customizing Images Using Custom .bb Files
  708. -----------------------------------------
  709. You can also customize an image by creating a custom recipe that defines
  710. additional software as part of the image. The following example shows
  711. the form for the two lines you need::
  712. IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
  713. inherit core-image
  714. Defining the software using a custom recipe gives you total control over
  715. the contents of the image. It is important to use the correct names of
  716. packages in the :term:`IMAGE_INSTALL` variable. You must use the
  717. OpenEmbedded notation and not the Debian notation for the names (e.g.
  718. ``glibc-dev`` instead of ``libc6-dev``).
  719. The other method for creating a custom image is to base it on an
  720. existing image. For example, if you want to create an image based on
  721. ``core-image-sato`` but add the additional package ``strace`` to the
  722. image, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new
  723. ``.bb`` and add the following line to the end of the copy::
  724. IMAGE_INSTALL += "strace"
  725. Customizing Images Using Custom Package Groups
  726. ----------------------------------------------
  727. For complex custom images, the best approach for customizing an image is
  728. to create a custom package group recipe that is used to build the image
  729. or images. A good example of a package group recipe is
  730. ``meta/recipes-core/packagegroups/packagegroup-base.bb``.
  731. If you examine that recipe, you see that the :term:`PACKAGES` variable lists
  732. the package group packages to produce. The ``inherit packagegroup``
  733. statement sets appropriate default values and automatically adds
  734. ``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each
  735. package specified in the :term:`PACKAGES` statement.
  736. .. note::
  737. The ``inherit packagegroup`` line should be located near the top of the
  738. recipe, certainly before the :term:`PACKAGES` statement.
  739. For each package you specify in :term:`PACKAGES`, you can use :term:`RDEPENDS`
  740. and :term:`RRECOMMENDS` entries to provide a list of packages the parent
  741. task package should contain. You can see examples of these further down
  742. in the ``packagegroup-base.bb`` recipe.
  743. Here is a short, fabricated example showing the same basic pieces for a
  744. hypothetical packagegroup defined in ``packagegroup-custom.bb``, where
  745. the variable :term:`PN` is the standard way to abbreviate the reference to
  746. the full packagegroup name ``packagegroup-custom``::
  747. DESCRIPTION = "My Custom Package Groups"
  748. inherit packagegroup
  749. PACKAGES = "\
  750. ${PN}-apps \
  751. ${PN}-tools \
  752. "
  753. RDEPENDS_${PN}-apps = "\
  754. dropbear \
  755. portmap \
  756. psplash"
  757. RDEPENDS_${PN}-tools = "\
  758. oprofile \
  759. oprofileui-server \
  760. lttng-tools"
  761. RRECOMMENDS_${PN}-tools = "\
  762. kernel-module-oprofile"
  763. In the previous example, two package group packages are created with
  764. their dependencies and their recommended package dependencies listed:
  765. ``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To
  766. build an image using these package group packages, you need to add
  767. ``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to
  768. :term:`IMAGE_INSTALL`. For other forms of image dependencies see the other
  769. areas of this section.
  770. Customizing an Image Hostname
  771. -----------------------------
  772. By default, the configured hostname (i.e. ``/etc/hostname``) in an image
  773. is the same as the machine name. For example, if
  774. :term:`MACHINE` equals "qemux86", the
  775. configured hostname written to ``/etc/hostname`` is "qemux86".
  776. You can customize this name by altering the value of the "hostname"
  777. variable in the ``base-files`` recipe using either an append file or a
  778. configuration file. Use the following in an append file::
  779. hostname = "myhostname"
  780. Use the following in a configuration file::
  781. hostname_pn-base-files = "myhostname"
  782. Changing the default value of the variable "hostname" can be useful in
  783. certain situations. For example, suppose you need to do extensive
  784. testing on an image and you would like to easily identify the image
  785. under test from existing images with typical default hostnames. In this
  786. situation, you could change the default hostname to "testme", which
  787. results in all the images using the name "testme". Once testing is
  788. complete and you do not need to rebuild the image for test any longer,
  789. you can easily reset the default hostname.
  790. Another point of interest is that if you unset the variable, the image
  791. will have no default hostname in the filesystem. Here is an example that
  792. unsets the variable in a configuration file::
  793. hostname_pn-base-files = ""
  794. Having no default hostname in the filesystem is suitable for
  795. environments that use dynamic hostnames such as virtual machines.
  796. Writing a New Recipe
  797. ====================
  798. Recipes (``.bb`` files) are fundamental components in the Yocto Project
  799. environment. Each software component built by the OpenEmbedded build
  800. system requires a recipe to define the component. This section describes
  801. how to create, write, and test a new recipe.
  802. .. note::
  803. For information on variables that are useful for recipes and for
  804. information about recipe naming issues, see the
  805. ":ref:`ref-manual/varlocality:recipes`" section of the Yocto Project
  806. Reference Manual.
  807. Overview
  808. --------
  809. The following figure shows the basic process for creating a new recipe.
  810. The remainder of the section provides details for the steps.
  811. .. image:: figures/recipe-workflow.png
  812. :align: center
  813. Locate or Automatically Create a Base Recipe
  814. --------------------------------------------
  815. You can always write a recipe from scratch. However, there are three choices
  816. that can help you quickly get started with a new recipe:
  817. - ``devtool add``: A command that assists in creating a recipe and an
  818. environment conducive to development.
  819. - ``recipetool create``: A command provided by the Yocto Project that
  820. automates creation of a base recipe based on the source files.
  821. - *Existing Recipes:* Location and modification of an existing recipe
  822. that is similar in function to the recipe you need.
  823. .. note::
  824. For information on recipe syntax, see the
  825. ":ref:`dev-manual/common-tasks:recipe syntax`" section.
  826. Creating the Base Recipe Using ``devtool add``
  827. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  828. The ``devtool add`` command uses the same logic for auto-creating the
  829. recipe as ``recipetool create``, which is listed below. Additionally,
  830. however, ``devtool add`` sets up an environment that makes it easy for
  831. you to patch the source and to make changes to the recipe as is often
  832. necessary when adding a recipe to build a new piece of software to be
  833. included in a build.
  834. You can find a complete description of the ``devtool add`` command in
  835. the ":ref:`sdk-manual/extensible:a closer look at \`\`devtool add\`\``" section
  836. in the Yocto Project Application Development and the Extensible Software
  837. Development Kit (eSDK) manual.
  838. Creating the Base Recipe Using ``recipetool create``
  839. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  840. ``recipetool create`` automates creation of a base recipe given a set of
  841. source code files. As long as you can extract or point to the source
  842. files, the tool will construct a recipe and automatically configure all
  843. pre-build information into the recipe. For example, suppose you have an
  844. application that builds using Autotools. Creating the base recipe using
  845. ``recipetool`` results in a recipe that has the pre-build dependencies,
  846. license requirements, and checksums configured.
  847. To run the tool, you just need to be in your
  848. :term:`Build Directory` and have sourced the
  849. build environment setup script (i.e.
  850. :ref:`structure-core-script`).
  851. To get help on the tool, use the following command::
  852. $ recipetool -h
  853. NOTE: Starting bitbake server...
  854. usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ...
  855. OpenEmbedded recipe tool
  856. options:
  857. -d, --debug Enable debug output
  858. -q, --quiet Print only errors
  859. --color COLOR Colorize output (where COLOR is auto, always, never)
  860. -h, --help show this help message and exit
  861. subcommands:
  862. create Create a new recipe
  863. newappend Create a bbappend for the specified target in the specified
  864. layer
  865. setvar Set a variable within a recipe
  866. appendfile Create/update a bbappend to replace a target file
  867. appendsrcfiles Create/update a bbappend to add or replace source files
  868. appendsrcfile Create/update a bbappend to add or replace a source file
  869. Use recipetool <subcommand> --help to get help on a specific command
  870. Running ``recipetool create -o OUTFILE`` creates the base recipe and
  871. locates it properly in the layer that contains your source files.
  872. Following are some syntax examples:
  873. - Use this syntax to generate a recipe based on source. Once generated,
  874. the recipe resides in the existing source code layer::
  875. recipetool create -o OUTFILE source
  876. - Use this syntax to generate a recipe using code that
  877. you extract from source. The extracted code is placed in its own layer
  878. defined by :term:`EXTERNALSRC`.
  879. ::
  880. recipetool create -o OUTFILE -x EXTERNALSRC source
  881. - Use this syntax to generate a recipe based on source. The options
  882. direct ``recipetool`` to generate debugging information. Once generated,
  883. the recipe resides in the existing source code layer::
  884. recipetool create -d -o OUTFILE source
  885. Locating and Using a Similar Recipe
  886. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  887. Before writing a recipe from scratch, it is often useful to discover
  888. whether someone else has already written one that meets (or comes close
  889. to meeting) your needs. The Yocto Project and OpenEmbedded communities
  890. maintain many recipes that might be candidates for what you are doing.
  891. You can find a good central index of these recipes in the
  892. :oe_layerindex:`OpenEmbedded Layer Index <>`.
  893. Working from an existing recipe or a skeleton recipe is the best way to
  894. get started. Here are some points on both methods:
  895. - *Locate and modify a recipe that is close to what you want to do:*
  896. This method works when you are familiar with the current recipe
  897. space. The method does not work so well for those new to the Yocto
  898. Project or writing recipes.
  899. Some risks associated with this method are using a recipe that has
  900. areas totally unrelated to what you are trying to accomplish with
  901. your recipe, not recognizing areas of the recipe that you might have
  902. to add from scratch, and so forth. All these risks stem from
  903. unfamiliarity with the existing recipe space.
  904. - *Use and modify the following skeleton recipe:* If for some reason
  905. you do not want to use ``recipetool`` and you cannot find an existing
  906. recipe that is close to meeting your needs, you can use the following
  907. structure to provide the fundamental areas of a new recipe.
  908. ::
  909. DESCRIPTION = ""
  910. HOMEPAGE = ""
  911. LICENSE = ""
  912. SECTION = ""
  913. DEPENDS = ""
  914. LIC_FILES_CHKSUM = ""
  915. SRC_URI = ""
  916. Storing and Naming the Recipe
  917. -----------------------------
  918. Once you have your base recipe, you should put it in your own layer and
  919. name it appropriately. Locating it correctly ensures that the
  920. OpenEmbedded build system can find it when you use BitBake to process
  921. the recipe.
  922. - *Storing Your Recipe:* The OpenEmbedded build system locates your
  923. recipe through the layer's ``conf/layer.conf`` file and the
  924. :term:`BBFILES` variable. This
  925. variable sets up a path from which the build system can locate
  926. recipes. Here is the typical use::
  927. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  928. ${LAYERDIR}/recipes-*/*/*.bbappend"
  929. Consequently, you need to be sure you locate your new recipe inside
  930. your layer such that it can be found.
  931. You can find more information on how layers are structured in the
  932. ":ref:`dev-manual/common-tasks:understanding and creating layers`" section.
  933. - *Naming Your Recipe:* When you name your recipe, you need to follow
  934. this naming convention::
  935. basename_version.bb
  936. Use lower-cased characters and do not include the reserved suffixes
  937. ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use
  938. them as part of your recipe name unless the string applies). Here are some
  939. examples:
  940. .. code-block:: none
  941. cups_1.7.0.bb
  942. gawk_4.0.2.bb
  943. irssi_0.8.16-rc1.bb
  944. Running a Build on the Recipe
  945. -----------------------------
  946. Creating a new recipe is usually an iterative process that requires
  947. using BitBake to process the recipe multiple times in order to
  948. progressively discover and add information to the recipe file.
  949. Assuming you have sourced the build environment setup script (i.e.
  950. :ref:`structure-core-script`) and you are in
  951. the :term:`Build Directory`, use
  952. BitBake to process your recipe. All you need to provide is the
  953. ``basename`` of the recipe as described in the previous section::
  954. $ bitbake basename
  955. During the build, the OpenEmbedded build system creates a temporary work
  956. directory for each recipe
  957. (``${``\ :term:`WORKDIR`\ ``}``)
  958. where it keeps extracted source files, log files, intermediate
  959. compilation and packaging files, and so forth.
  960. The path to the per-recipe temporary work directory depends on the
  961. context in which it is being built. The quickest way to find this path
  962. is to have BitBake return it by running the following::
  963. $ bitbake -e basename | grep ^WORKDIR=
  964. As an example, assume a Source Directory
  965. top-level folder named ``poky``, a default Build Directory at
  966. ``poky/build``, and a ``qemux86-poky-linux`` machine target system.
  967. Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this
  968. case, the work directory the build system uses to build the package
  969. would be as follows::
  970. poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
  971. Inside this directory you can find sub-directories such as ``image``,
  972. ``packages-split``, and ``temp``. After the build, you can examine these
  973. to determine how well the build went.
  974. .. note::
  975. You can find log files for each task in the recipe's ``temp``
  976. directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``).
  977. Log files are named ``log.taskname`` (e.g. ``log.do_configure``,
  978. ``log.do_fetch``, and ``log.do_compile``).
  979. You can find more information about the build process in
  980. ":doc:`/overview-manual/development-environment`"
  981. chapter of the Yocto Project Overview and Concepts Manual.
  982. Fetching Code
  983. -------------
  984. The first thing your recipe must do is specify how to fetch the source
  985. files. Fetching is controlled mainly through the
  986. :term:`SRC_URI` variable. Your recipe
  987. must have a :term:`SRC_URI` variable that points to where the source is
  988. located. For a graphical representation of source locations, see the
  989. ":ref:`overview-manual/concepts:sources`" section in
  990. the Yocto Project Overview and Concepts Manual.
  991. The :ref:`ref-tasks-fetch` task uses
  992. the prefix of each entry in the :term:`SRC_URI` variable value to determine
  993. which :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>` to use to get your
  994. source files. It is the :term:`SRC_URI` variable that triggers the fetcher.
  995. The :ref:`ref-tasks-patch` task uses
  996. the variable after source is fetched to apply patches. The OpenEmbedded
  997. build system uses
  998. :term:`FILESOVERRIDES` for
  999. scanning directory locations for local files in :term:`SRC_URI`.
  1000. The :term:`SRC_URI` variable in your recipe must define each unique location
  1001. for your source files. It is good practice to not hard-code version
  1002. numbers in a URL used in :term:`SRC_URI`. Rather than hard-code these
  1003. values, use ``${``\ :term:`PV`\ ``}``,
  1004. which causes the fetch process to use the version specified in the
  1005. recipe filename. Specifying the version in this manner means that
  1006. upgrading the recipe to a future version is as simple as renaming the
  1007. recipe to match the new version.
  1008. Here is a simple example from the
  1009. ``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source
  1010. comes from a single tarball. Notice the use of the
  1011. :term:`PV` variable::
  1012. SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \
  1013. Files mentioned in :term:`SRC_URI` whose names end in a typical archive
  1014. extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so
  1015. forth), are automatically extracted during the
  1016. :ref:`ref-tasks-unpack` task. For
  1017. another example that specifies these types of files, see the
  1018. ":ref:`dev-manual/common-tasks:autotooled package`" section.
  1019. Another way of specifying source is from an SCM. For Git repositories,
  1020. you must specify :term:`SRCREV` and
  1021. you should specify :term:`PV` to include
  1022. the revision with :term:`SRCPV`. Here
  1023. is an example from the recipe
  1024. ``meta/recipes-kernel/blktrace/blktrace_git.bb``::
  1025. SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
  1026. PR = "r6"
  1027. PV = "1.0.5+git${SRCPV}"
  1028. SRC_URI = "git://git.kernel.dk/blktrace.git \
  1029. file://ldflags.patch"
  1030. If your :term:`SRC_URI` statement includes URLs pointing to individual files
  1031. fetched from a remote server other than a version control system,
  1032. BitBake attempts to verify the files against checksums defined in your
  1033. recipe to ensure they have not been tampered with or otherwise modified
  1034. since the recipe was written. Two checksums are used:
  1035. ``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``.
  1036. If your :term:`SRC_URI` variable points to more than a single URL (excluding
  1037. SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for
  1038. each URL. For these cases, you provide a name for each URL as part of
  1039. the :term:`SRC_URI` and then reference that name in the subsequent checksum
  1040. statements. Here is an example combining lines from the files
  1041. ``git.inc`` and ``git_2.24.1.bb``::
  1042. SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
  1043. ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages"
  1044. SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b"
  1045. SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02"
  1046. SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d"
  1047. SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230"
  1048. Proper values for ``md5`` and ``sha256`` checksums might be available
  1049. with other signatures on the download page for the upstream source (e.g.
  1050. ``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the
  1051. OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``,
  1052. you should verify all the signatures you find by hand.
  1053. If no :term:`SRC_URI` checksums are specified when you attempt to build the
  1054. recipe, or you provide an incorrect checksum, the build will produce an
  1055. error for each missing or incorrect checksum. As part of the error
  1056. message, the build system provides the checksum string corresponding to
  1057. the fetched file. Once you have the correct checksums, you can copy and
  1058. paste them into your recipe and then run the build again to continue.
  1059. .. note::
  1060. As mentioned, if the upstream source provides signatures for
  1061. verifying the downloaded source code, you should verify those
  1062. manually before setting the checksum values in the recipe and
  1063. continuing with the build.
  1064. This final example is a bit more complicated and is from the
  1065. ``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The
  1066. example's :term:`SRC_URI` statement identifies multiple files as the source
  1067. files for the recipe: a tarball, a patch file, a desktop file, and an
  1068. icon.
  1069. ::
  1070. SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
  1071. file://xwc.patch \
  1072. file://rxvt.desktop \
  1073. file://rxvt.png"
  1074. When you specify local files using the ``file://`` URI protocol, the
  1075. build system fetches files from the local machine. The path is relative
  1076. to the :term:`FILESPATH` variable
  1077. and searches specific directories in a certain order:
  1078. ``${``\ :term:`BP`\ ``}``,
  1079. ``${``\ :term:`BPN`\ ``}``, and
  1080. ``files``. The directories are assumed to be subdirectories of the
  1081. directory in which the recipe or append file resides. For another
  1082. example that specifies these types of files, see the
  1083. ":ref:`dev-manual/common-tasks:single .c file package (hello world!)`" section.
  1084. The previous example also specifies a patch file. Patch files are files
  1085. whose names usually end in ``.patch`` or ``.diff`` but can end with
  1086. compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example.
  1087. The build system automatically applies patches as described in the
  1088. ":ref:`dev-manual/common-tasks:patching code`" section.
  1089. Unpacking Code
  1090. --------------
  1091. During the build, the
  1092. :ref:`ref-tasks-unpack` task unpacks
  1093. the source with ``${``\ :term:`S`\ ``}``
  1094. pointing to where it is unpacked.
  1095. If you are fetching your source files from an upstream source archived
  1096. tarball and the tarball's internal structure matches the common
  1097. convention of a top-level subdirectory named
  1098. ``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``,
  1099. then you do not need to set :term:`S`. However, if :term:`SRC_URI` specifies to
  1100. fetch source from an archive that does not use this convention, or from
  1101. an SCM like Git or Subversion, your recipe needs to define :term:`S`.
  1102. If processing your recipe using BitBake successfully unpacks the source
  1103. files, you need to be sure that the directory pointed to by ``${S}``
  1104. matches the structure of the source.
  1105. Patching Code
  1106. -------------
  1107. Sometimes it is necessary to patch code after it has been fetched. Any
  1108. files mentioned in :term:`SRC_URI` whose names end in ``.patch`` or
  1109. ``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are
  1110. treated as patches. The
  1111. :ref:`ref-tasks-patch` task
  1112. automatically applies these patches.
  1113. The build system should be able to apply patches with the "-p1" option
  1114. (i.e. one directory level in the path will be stripped off). If your
  1115. patch needs to have more directory levels stripped off, specify the
  1116. number of levels using the "striplevel" option in the :term:`SRC_URI` entry
  1117. for the patch. Alternatively, if your patch needs to be applied in a
  1118. specific subdirectory that is not specified in the patch file, use the
  1119. "patchdir" option in the entry.
  1120. As with all local files referenced in
  1121. :term:`SRC_URI` using ``file://``,
  1122. you should place patch files in a directory next to the recipe either
  1123. named the same as the base name of the recipe
  1124. (:term:`BP` and
  1125. :term:`BPN`) or "files".
  1126. Licensing
  1127. ---------
  1128. Your recipe needs to have both the
  1129. :term:`LICENSE` and
  1130. :term:`LIC_FILES_CHKSUM`
  1131. variables:
  1132. - :term:`LICENSE`: This variable specifies the license for the software.
  1133. If you do not know the license under which the software you are
  1134. building is distributed, you should go to the source code and look
  1135. for that information. Typical files containing this information
  1136. include ``COPYING``, :term:`LICENSE`, and ``README`` files. You could
  1137. also find the information near the top of a source file. For example,
  1138. given a piece of software licensed under the GNU General Public
  1139. License version 2, you would set :term:`LICENSE` as follows::
  1140. LICENSE = "GPLv2"
  1141. The licenses you specify within :term:`LICENSE` can have any name as long
  1142. as you do not use spaces, since spaces are used as separators between
  1143. license names. For standard licenses, use the names of the files in
  1144. ``meta/files/common-licenses/`` or the :term:`SPDXLICENSEMAP` flag names
  1145. defined in ``meta/conf/licenses.conf``.
  1146. - :term:`LIC_FILES_CHKSUM`: The OpenEmbedded build system uses this
  1147. variable to make sure the license text has not changed. If it has,
  1148. the build produces an error and it affords you the chance to figure
  1149. it out and correct the problem.
  1150. You need to specify all applicable licensing files for the software.
  1151. At the end of the configuration step, the build process will compare
  1152. the checksums of the files to be sure the text has not changed. Any
  1153. differences result in an error with the message containing the
  1154. current checksum. For more explanation and examples of how to set the
  1155. :term:`LIC_FILES_CHKSUM` variable, see the
  1156. ":ref:`dev-manual/common-tasks:tracking license changes`" section.
  1157. To determine the correct checksum string, you can list the
  1158. appropriate files in the :term:`LIC_FILES_CHKSUM` variable with incorrect
  1159. md5 strings, attempt to build the software, and then note the
  1160. resulting error messages that will report the correct md5 strings.
  1161. See the ":ref:`dev-manual/common-tasks:fetching code`" section for
  1162. additional information.
  1163. Here is an example that assumes the software has a ``COPYING`` file::
  1164. LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
  1165. When you try to build the
  1166. software, the build system will produce an error and give you the
  1167. correct string that you can substitute into the recipe file for a
  1168. subsequent build.
  1169. Dependencies
  1170. ------------
  1171. Most software packages have a short list of other packages that they
  1172. require, which are called dependencies. These dependencies fall into two
  1173. main categories: build-time dependencies, which are required when the
  1174. software is built; and runtime dependencies, which are required to be
  1175. installed on the target in order for the software to run.
  1176. Within a recipe, you specify build-time dependencies using the
  1177. :term:`DEPENDS` variable. Although there are nuances,
  1178. items specified in :term:`DEPENDS` should be names of other
  1179. recipes. It is important that you specify all build-time dependencies
  1180. explicitly.
  1181. Another consideration is that configure scripts might automatically
  1182. check for optional dependencies and enable corresponding functionality
  1183. if those dependencies are found. If you wish to make a recipe that is
  1184. more generally useful (e.g. publish the recipe in a layer for others to
  1185. use), instead of hard-disabling the functionality, you can use the
  1186. :term:`PACKAGECONFIG` variable to allow functionality and the
  1187. corresponding dependencies to be enabled and disabled easily by other
  1188. users of the recipe.
  1189. Similar to build-time dependencies, you specify runtime dependencies
  1190. through a variable -
  1191. :term:`RDEPENDS`, which is
  1192. package-specific. All variables that are package-specific need to have
  1193. the name of the package added to the end as an override. Since the main
  1194. package for a recipe has the same name as the recipe, and the recipe's
  1195. name can be found through the
  1196. ``${``\ :term:`PN`\ ``}`` variable, then
  1197. you specify the dependencies for the main package by setting
  1198. ``RDEPENDS_${PN}``. If the package were named ``${PN}-tools``, then you
  1199. would set ``RDEPENDS_${PN}-tools``, and so forth.
  1200. Some runtime dependencies will be set automatically at packaging time.
  1201. These dependencies include any shared library dependencies (i.e. if a
  1202. package "example" contains "libexample" and another package "mypackage"
  1203. contains a binary that links to "libexample" then the OpenEmbedded build
  1204. system will automatically add a runtime dependency to "mypackage" on
  1205. "example"). See the
  1206. ":ref:`overview-manual/concepts:automatically added runtime dependencies`"
  1207. section in the Yocto Project Overview and Concepts Manual for further
  1208. details.
  1209. Configuring the Recipe
  1210. ----------------------
  1211. Most software provides some means of setting build-time configuration
  1212. options before compilation. Typically, setting these options is
  1213. accomplished by running a configure script with options, or by modifying
  1214. a build configuration file.
  1215. .. note::
  1216. As of Yocto Project Release 1.7, some of the core recipes that
  1217. package binary configuration scripts now disable the scripts due to
  1218. the scripts previously requiring error-prone path substitution. The
  1219. OpenEmbedded build system uses ``pkg-config`` now, which is much more
  1220. robust. You can find a list of the ``*-config`` scripts that are disabled
  1221. in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section
  1222. in the Yocto Project Reference Manual.
  1223. A major part of build-time configuration is about checking for
  1224. build-time dependencies and possibly enabling optional functionality as
  1225. a result. You need to specify any build-time dependencies for the
  1226. software you are building in your recipe's
  1227. :term:`DEPENDS` value, in terms of
  1228. other recipes that satisfy those dependencies. You can often find
  1229. build-time or runtime dependencies described in the software's
  1230. documentation.
  1231. The following list provides configuration items of note based on how
  1232. your software is built:
  1233. - *Autotools:* If your source files have a ``configure.ac`` file, then
  1234. your software is built using Autotools. If this is the case, you just
  1235. need to modify the configuration.
  1236. When using Autotools, your recipe needs to inherit the
  1237. :ref:`autotools <ref-classes-autotools>` class
  1238. and your recipe does not have to contain a
  1239. :ref:`ref-tasks-configure` task.
  1240. However, you might still want to make some adjustments. For example,
  1241. you can set
  1242. :term:`EXTRA_OECONF` or
  1243. :term:`PACKAGECONFIG_CONFARGS`
  1244. to pass any needed configure options that are specific to the recipe.
  1245. - *CMake:* If your source files have a ``CMakeLists.txt`` file, then
  1246. your software is built using CMake. If this is the case, you just
  1247. need to modify the configuration.
  1248. When you use CMake, your recipe needs to inherit the
  1249. :ref:`cmake <ref-classes-cmake>` class and your
  1250. recipe does not have to contain a
  1251. :ref:`ref-tasks-configure` task.
  1252. You can make some adjustments by setting
  1253. :term:`EXTRA_OECMAKE` to
  1254. pass any needed configure options that are specific to the recipe.
  1255. .. note::
  1256. If you need to install one or more custom CMake toolchain files
  1257. that are supplied by the application you are building, install the
  1258. files to ``${D}${datadir}/cmake/Modules`` during ``do_install``.
  1259. - *Other:* If your source files do not have a ``configure.ac`` or
  1260. ``CMakeLists.txt`` file, then your software is built using some
  1261. method other than Autotools or CMake. If this is the case, you
  1262. normally need to provide a
  1263. :ref:`ref-tasks-configure` task
  1264. in your recipe unless, of course, there is nothing to configure.
  1265. Even if your software is not being built by Autotools or CMake, you
  1266. still might not need to deal with any configuration issues. You need
  1267. to determine if configuration is even a required step. You might need
  1268. to modify a Makefile or some configuration file used for the build to
  1269. specify necessary build options. Or, perhaps you might need to run a
  1270. provided, custom configure script with the appropriate options.
  1271. For the case involving a custom configure script, you would run
  1272. ``./configure --help`` and look for the options you need to set.
  1273. Once configuration succeeds, it is always good practice to look at the
  1274. ``log.do_configure`` file to ensure that the appropriate options have
  1275. been enabled and no additional build-time dependencies need to be added
  1276. to :term:`DEPENDS`. For example, if the configure script reports that it
  1277. found something not mentioned in :term:`DEPENDS`, or that it did not find
  1278. something that it needed for some desired optional functionality, then
  1279. you would need to add those to :term:`DEPENDS`. Looking at the log might
  1280. also reveal items being checked for, enabled, or both that you do not
  1281. want, or items not being found that are in :term:`DEPENDS`, in which case
  1282. you would need to look at passing extra options to the configure script
  1283. as needed. For reference information on configure options specific to
  1284. the software you are building, you can consult the output of the
  1285. ``./configure --help`` command within ``${S}`` or consult the software's
  1286. upstream documentation.
  1287. Using Headers to Interface with Devices
  1288. ---------------------------------------
  1289. If your recipe builds an application that needs to communicate with some
  1290. device or needs an API into a custom kernel, you will need to provide
  1291. appropriate header files. Under no circumstances should you ever modify
  1292. the existing
  1293. ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file.
  1294. These headers are used to build ``libc`` and must not be compromised
  1295. with custom or machine-specific header information. If you customize
  1296. ``libc`` through modified headers all other applications that use
  1297. ``libc`` thus become affected.
  1298. .. note::
  1299. Never copy and customize the ``libc`` header file (i.e.
  1300. ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``).
  1301. The correct way to interface to a device or custom kernel is to use a
  1302. separate package that provides the additional headers for the driver or
  1303. other unique interfaces. When doing so, your application also becomes
  1304. responsible for creating a dependency on that specific provider.
  1305. Consider the following:
  1306. - Never modify ``linux-libc-headers.inc``. Consider that file to be
  1307. part of the ``libc`` system, and not something you use to access the
  1308. kernel directly. You should access ``libc`` through specific ``libc``
  1309. calls.
  1310. - Applications that must talk directly to devices should either provide
  1311. necessary headers themselves, or establish a dependency on a special
  1312. headers package that is specific to that driver.
  1313. For example, suppose you want to modify an existing header that adds I/O
  1314. control or network support. If the modifications are used by a small
  1315. number programs, providing a unique version of a header is easy and has
  1316. little impact. When doing so, bear in mind the guidelines in the
  1317. previous list.
  1318. .. note::
  1319. If for some reason your changes need to modify the behavior of the ``libc``,
  1320. and subsequently all other applications on the system, use a ``.bbappend``
  1321. to modify the ``linux-kernel-headers.inc`` file. However, take care to not
  1322. make the changes machine specific.
  1323. Consider a case where your kernel is older and you need an older
  1324. ``libc`` ABI. The headers installed by your recipe should still be a
  1325. standard mainline kernel, not your own custom one.
  1326. When you use custom kernel headers you need to get them from
  1327. :term:`STAGING_KERNEL_DIR`,
  1328. which is the directory with kernel headers that are required to build
  1329. out-of-tree modules. Your recipe will also need the following::
  1330. do_configure[depends] += "virtual/kernel:do_shared_workdir"
  1331. Compilation
  1332. -----------
  1333. During a build, the ``do_compile`` task happens after source is fetched,
  1334. unpacked, and configured. If the recipe passes through ``do_compile``
  1335. successfully, nothing needs to be done.
  1336. However, if the compile step fails, you need to diagnose the failure.
  1337. Here are some common issues that cause failures.
  1338. .. note::
  1339. For cases where improper paths are detected for configuration files
  1340. or for when libraries/headers cannot be found, be sure you are using
  1341. the more robust ``pkg-config``. See the note in section
  1342. ":ref:`dev-manual/common-tasks:Configuring the Recipe`" for additional information.
  1343. - *Parallel build failures:* These failures manifest themselves as
  1344. intermittent errors, or errors reporting that a file or directory
  1345. that should be created by some other part of the build process could
  1346. not be found. This type of failure can occur even if, upon
  1347. inspection, the file or directory does exist after the build has
  1348. failed, because that part of the build process happened in the wrong
  1349. order.
  1350. To fix the problem, you need to either satisfy the missing dependency
  1351. in the Makefile or whatever script produced the Makefile, or (as a
  1352. workaround) set :term:`PARALLEL_MAKE` to an empty string::
  1353. PARALLEL_MAKE = ""
  1354. For information on parallel Makefile issues, see the
  1355. ":ref:`dev-manual/common-tasks:debugging parallel make races`" section.
  1356. - *Improper host path usage:* This failure applies to recipes building
  1357. for the target or ``nativesdk`` only. The failure occurs when the
  1358. compilation process uses improper headers, libraries, or other files
  1359. from the host system when cross-compiling for the target.
  1360. To fix the problem, examine the ``log.do_compile`` file to identify
  1361. the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and
  1362. so forth) and then either add configure options, apply a patch, or do
  1363. both.
  1364. - *Failure to find required libraries/headers:* If a build-time
  1365. dependency is missing because it has not been declared in
  1366. :term:`DEPENDS`, or because the
  1367. dependency exists but the path used by the build process to find the
  1368. file is incorrect and the configure step did not detect it, the
  1369. compilation process could fail. For either of these failures, the
  1370. compilation process notes that files could not be found. In these
  1371. cases, you need to go back and add additional options to the
  1372. configure script as well as possibly add additional build-time
  1373. dependencies to :term:`DEPENDS`.
  1374. Occasionally, it is necessary to apply a patch to the source to
  1375. ensure the correct paths are used. If you need to specify paths to
  1376. find files staged into the sysroot from other recipes, use the
  1377. variables that the OpenEmbedded build system provides (e.g.
  1378. :term:`STAGING_BINDIR`, :term:`STAGING_INCDIR`, :term:`STAGING_DATADIR`, and so
  1379. forth).
  1380. Installing
  1381. ----------
  1382. During ``do_install``, the task copies the built files along with their
  1383. hierarchy to locations that would mirror their locations on the target
  1384. device. The installation process copies files from the
  1385. ``${``\ :term:`S`\ ``}``,
  1386. ``${``\ :term:`B`\ ``}``, and
  1387. ``${``\ :term:`WORKDIR`\ ``}``
  1388. directories to the ``${``\ :term:`D`\ ``}``
  1389. directory to create the structure as it should appear on the target
  1390. system.
  1391. How your software is built affects what you must do to be sure your
  1392. software is installed correctly. The following list describes what you
  1393. must do for installation depending on the type of build system used by
  1394. the software being built:
  1395. - *Autotools and CMake:* If the software your recipe is building uses
  1396. Autotools or CMake, the OpenEmbedded build system understands how to
  1397. install the software. Consequently, you do not have to have a
  1398. ``do_install`` task as part of your recipe. You just need to make
  1399. sure the install portion of the build completes with no issues.
  1400. However, if you wish to install additional files not already being
  1401. installed by ``make install``, you should do this using a
  1402. ``do_install_append`` function using the install command as described
  1403. in the "Manual" bulleted item later in this list.
  1404. - *Other (using* ``make install``\ *)*: You need to define a ``do_install``
  1405. function in your recipe. The function should call
  1406. ``oe_runmake install`` and will likely need to pass in the
  1407. destination directory as well. How you pass that path is dependent on
  1408. how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``,
  1409. ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth).
  1410. For an example recipe using ``make install``, see the
  1411. ":ref:`dev-manual/common-tasks:makefile-based package`" section.
  1412. - *Manual:* You need to define a ``do_install`` function in your
  1413. recipe. The function must first use ``install -d`` to create the
  1414. directories under
  1415. ``${``\ :term:`D`\ ``}``. Once the
  1416. directories exist, your function can use ``install`` to manually
  1417. install the built software into the directories.
  1418. You can find more information on ``install`` at
  1419. https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html.
  1420. For the scenarios that do not use Autotools or CMake, you need to track
  1421. the installation and diagnose and fix any issues until everything
  1422. installs correctly. You need to look in the default location of
  1423. ``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been
  1424. installed correctly.
  1425. .. note::
  1426. - During the installation process, you might need to modify some of
  1427. the installed files to suit the target layout. For example, you
  1428. might need to replace hard-coded paths in an initscript with
  1429. values of variables provided by the build system, such as
  1430. replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such
  1431. modifications during ``do_install``, be sure to modify the
  1432. destination file after copying rather than before copying.
  1433. Modifying after copying ensures that the build system can
  1434. re-execute ``do_install`` if needed.
  1435. - ``oe_runmake install``, which can be run directly or can be run
  1436. indirectly by the
  1437. :ref:`autotools <ref-classes-autotools>` and
  1438. :ref:`cmake <ref-classes-cmake>` classes,
  1439. runs ``make install`` in parallel. Sometimes, a Makefile can have
  1440. missing dependencies between targets that can result in race
  1441. conditions. If you experience intermittent failures during
  1442. ``do_install``, you might be able to work around them by disabling
  1443. parallel Makefile installs by adding the following to the recipe::
  1444. PARALLEL_MAKEINST = ""
  1445. See :term:`PARALLEL_MAKEINST` for additional information.
  1446. - If you need to install one or more custom CMake toolchain files
  1447. that are supplied by the application you are building, install the
  1448. files to ``${D}${datadir}/cmake/Modules`` during
  1449. :ref:`ref-tasks-install`.
  1450. Enabling System Services
  1451. ------------------------
  1452. If you want to install a service, which is a process that usually starts
  1453. on boot and runs in the background, then you must include some
  1454. additional definitions in your recipe.
  1455. If you are adding services and the service initialization script or the
  1456. service file itself is not installed, you must provide for that
  1457. installation in your recipe using a ``do_install_append`` function. If
  1458. your recipe already has a ``do_install`` function, update the function
  1459. near its end rather than adding an additional ``do_install_append``
  1460. function.
  1461. When you create the installation for your services, you need to
  1462. accomplish what is normally done by ``make install``. In other words,
  1463. make sure your installation arranges the output similar to how it is
  1464. arranged on the target system.
  1465. The OpenEmbedded build system provides support for starting services two
  1466. different ways:
  1467. - *SysVinit:* SysVinit is a system and service manager that manages the
  1468. init system used to control the very basic functions of your system.
  1469. The init program is the first program started by the Linux kernel
  1470. when the system boots. Init then controls the startup, running and
  1471. shutdown of all other programs.
  1472. To enable a service using SysVinit, your recipe needs to inherit the
  1473. :ref:`update-rc.d <ref-classes-update-rc.d>`
  1474. class. The class helps facilitate safely installing the package on
  1475. the target.
  1476. You will need to set the
  1477. :term:`INITSCRIPT_PACKAGES`,
  1478. :term:`INITSCRIPT_NAME`,
  1479. and
  1480. :term:`INITSCRIPT_PARAMS`
  1481. variables within your recipe.
  1482. - *systemd:* System Management Daemon (systemd) was designed to replace
  1483. SysVinit and to provide enhanced management of services. For more
  1484. information on systemd, see the systemd homepage at
  1485. https://freedesktop.org/wiki/Software/systemd/.
  1486. To enable a service using systemd, your recipe needs to inherit the
  1487. :ref:`systemd <ref-classes-systemd>` class. See
  1488. the ``systemd.bbclass`` file located in your :term:`Source Directory`
  1489. section for
  1490. more information.
  1491. Packaging
  1492. ---------
  1493. Successful packaging is a combination of automated processes performed
  1494. by the OpenEmbedded build system and some specific steps you need to
  1495. take. The following list describes the process:
  1496. - *Splitting Files*: The ``do_package`` task splits the files produced
  1497. by the recipe into logical components. Even software that produces a
  1498. single binary might still have debug symbols, documentation, and
  1499. other logical components that should be split out. The ``do_package``
  1500. task ensures that files are split up and packaged correctly.
  1501. - *Running QA Checks*: The
  1502. :ref:`insane <ref-classes-insane>` class adds a
  1503. step to the package generation process so that output quality
  1504. assurance checks are generated by the OpenEmbedded build system. This
  1505. step performs a range of checks to be sure the build's output is free
  1506. of common problems that show up during runtime. For information on
  1507. these checks, see the
  1508. :ref:`insane <ref-classes-insane>` class and
  1509. the ":ref:`ref-manual/qa-checks:qa error and warning messages`"
  1510. chapter in the Yocto Project Reference Manual.
  1511. - *Hand-Checking Your Packages*: After you build your software, you
  1512. need to be sure your packages are correct. Examine the
  1513. ``${``\ :term:`WORKDIR`\ ``}/packages-split``
  1514. directory and make sure files are where you expect them to be. If you
  1515. discover problems, you can set
  1516. :term:`PACKAGES`,
  1517. :term:`FILES`,
  1518. ``do_install(_append)``, and so forth as needed.
  1519. - *Splitting an Application into Multiple Packages*: If you need to
  1520. split an application into several packages, see the
  1521. ":ref:`dev-manual/common-tasks:splitting an application into multiple packages`"
  1522. section for an example.
  1523. - *Installing a Post-Installation Script*: For an example showing how
  1524. to install a post-installation script, see the
  1525. ":ref:`dev-manual/common-tasks:post-installation scripts`" section.
  1526. - *Marking Package Architecture*: Depending on what your recipe is
  1527. building and how it is configured, it might be important to mark the
  1528. packages produced as being specific to a particular machine, or to
  1529. mark them as not being specific to a particular machine or
  1530. architecture at all.
  1531. By default, packages apply to any machine with the same architecture
  1532. as the target machine. When a recipe produces packages that are
  1533. machine-specific (e.g. the
  1534. :term:`MACHINE` value is passed
  1535. into the configure script or a patch is applied only for a particular
  1536. machine), you should mark them as such by adding the following to the
  1537. recipe::
  1538. PACKAGE_ARCH = "${MACHINE_ARCH}"
  1539. On the other hand, if the recipe produces packages that do not
  1540. contain anything specific to the target machine or architecture at
  1541. all (e.g. recipes that simply package script files or configuration
  1542. files), you should use the
  1543. :ref:`allarch <ref-classes-allarch>` class to
  1544. do this for you by adding this to your recipe::
  1545. inherit allarch
  1546. Ensuring that the package architecture is correct is not critical
  1547. while you are doing the first few builds of your recipe. However, it
  1548. is important in order to ensure that your recipe rebuilds (or does
  1549. not rebuild) appropriately in response to changes in configuration,
  1550. and to ensure that you get the appropriate packages installed on the
  1551. target machine, particularly if you run separate builds for more than
  1552. one target machine.
  1553. Sharing Files Between Recipes
  1554. -----------------------------
  1555. Recipes often need to use files provided by other recipes on the build
  1556. host. For example, an application linking to a common library needs
  1557. access to the library itself and its associated headers. The way this
  1558. access is accomplished is by populating a sysroot with files. Each
  1559. recipe has two sysroots in its work directory, one for target files
  1560. (``recipe-sysroot``) and one for files that are native to the build host
  1561. (``recipe-sysroot-native``).
  1562. .. note::
  1563. You could find the term "staging" used within the Yocto project
  1564. regarding files populating sysroots (e.g. the :term:`STAGING_DIR`
  1565. variable).
  1566. Recipes should never populate the sysroot directly (i.e. write files
  1567. into sysroot). Instead, files should be installed into standard
  1568. locations during the
  1569. :ref:`ref-tasks-install` task within
  1570. the ``${``\ :term:`D`\ ``}`` directory. The
  1571. reason for this limitation is that almost all files that populate the
  1572. sysroot are cataloged in manifests in order to ensure the files can be
  1573. removed later when a recipe is either modified or removed. Thus, the
  1574. sysroot is able to remain free from stale files.
  1575. A subset of the files installed by the :ref:`ref-tasks-install` task are
  1576. used by the :ref:`ref-tasks-populate_sysroot` task as defined by the the
  1577. :term:`SYSROOT_DIRS` variable to automatically populate the sysroot. It
  1578. is possible to modify the list of directories that populate the sysroot.
  1579. The following example shows how you could add the ``/opt`` directory to
  1580. the list of directories within a recipe::
  1581. SYSROOT_DIRS += "/opt"
  1582. .. note::
  1583. The `/sysroot-only` is to be used by recipes that generate artifacts
  1584. that are not included in the target filesystem, allowing them to share
  1585. these artifacts without needing to use the :term:`DEPLOY_DIR`.
  1586. For a more complete description of the :ref:`ref-tasks-populate_sysroot`
  1587. task and its associated functions, see the
  1588. :ref:`staging <ref-classes-staging>` class.
  1589. Using Virtual Providers
  1590. -----------------------
  1591. Prior to a build, if you know that several different recipes provide the
  1592. same functionality, you can use a virtual provider (i.e. ``virtual/*``)
  1593. as a placeholder for the actual provider. The actual provider is
  1594. determined at build-time.
  1595. A common scenario where a virtual provider is used would be for the
  1596. kernel recipe. Suppose you have three kernel recipes whose
  1597. :term:`PN` values map to ``kernel-big``,
  1598. ``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes
  1599. in some way uses a :term:`PROVIDES`
  1600. statement that essentially identifies itself as being able to provide
  1601. ``virtual/kernel``. Here is one way through the
  1602. :ref:`kernel <ref-classes-kernel>` class::
  1603. PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }"
  1604. Any recipe that inherits the ``kernel`` class is
  1605. going to utilize a :term:`PROVIDES` statement that identifies that recipe as
  1606. being able to provide the ``virtual/kernel`` item.
  1607. Now comes the time to actually build an image and you need a kernel
  1608. recipe, but which one? You can configure your build to call out the
  1609. kernel recipe you want by using the :term:`PREFERRED_PROVIDER` variable. As
  1610. an example, consider the :yocto_git:`x86-base.inc
  1611. </poky/tree/meta/conf/machine/include/x86-base.inc>` include file, which is a
  1612. machine (i.e. :term:`MACHINE`) configuration file. This include file is the
  1613. reason all x86-based machines use the ``linux-yocto`` kernel. Here are the
  1614. relevant lines from the include file::
  1615. PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
  1616. PREFERRED_VERSION_linux-yocto ??= "4.15%"
  1617. When you use a virtual provider, you do not have to "hard code" a recipe
  1618. name as a build dependency. You can use the
  1619. :term:`DEPENDS` variable to state the
  1620. build is dependent on ``virtual/kernel`` for example::
  1621. DEPENDS = "virtual/kernel"
  1622. During the build, the OpenEmbedded build system picks
  1623. the correct recipe needed for the ``virtual/kernel`` dependency based on
  1624. the :term:`PREFERRED_PROVIDER` variable. If you want to use the small kernel
  1625. mentioned at the beginning of this section, configure your build as
  1626. follows::
  1627. PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
  1628. .. note::
  1629. Any recipe that :term:`PROVIDES` a ``virtual/*`` item that is ultimately not
  1630. selected through :term:`PREFERRED_PROVIDER` does not get built. Preventing these
  1631. recipes from building is usually the desired behavior since this mechanism's
  1632. purpose is to select between mutually exclusive alternative providers.
  1633. The following lists specific examples of virtual providers:
  1634. - ``virtual/kernel``: Provides the name of the kernel recipe to use
  1635. when building a kernel image.
  1636. - ``virtual/bootloader``: Provides the name of the bootloader to use
  1637. when building an image.
  1638. - ``virtual/libgbm``: Provides ``gbm.pc``.
  1639. - ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``.
  1640. - ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL).
  1641. - ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM).
  1642. - ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2).
  1643. .. note::
  1644. Virtual providers only apply to build time dependencies specified with
  1645. :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime
  1646. dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`.
  1647. Properly Versioning Pre-Release Recipes
  1648. ---------------------------------------
  1649. Sometimes the name of a recipe can lead to versioning problems when the
  1650. recipe is upgraded to a final release. For example, consider the
  1651. ``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in
  1652. the ":ref:`dev-manual/common-tasks:storing and naming the recipe`" section.
  1653. This recipe is at a release candidate stage (i.e. "rc1"). When the recipe is
  1654. released, the recipe filename becomes ``irssi_0.8.16.bb``. The version
  1655. change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the
  1656. build system and package managers, so the resulting packages will not
  1657. correctly trigger an upgrade.
  1658. In order to ensure the versions compare properly, the recommended
  1659. convention is to set :term:`PV` within the
  1660. recipe to "previous_version+current_version". You can use an additional
  1661. variable so that you can use the current version elsewhere. Here is an
  1662. example::
  1663. REALPV = "0.8.16-rc1"
  1664. PV = "0.8.15+${REALPV}"
  1665. Post-Installation Scripts
  1666. -------------------------
  1667. Post-installation scripts run immediately after installing a package on
  1668. the target or during image creation when a package is included in an
  1669. image. To add a post-installation script to a package, add a
  1670. ``pkg_postinst_``\ `PACKAGENAME`\ ``()`` function to the recipe file
  1671. (``.bb``) and replace `PACKAGENAME` with the name of the package you want
  1672. to attach to the ``postinst`` script. To apply the post-installation
  1673. script to the main package for the recipe, which is usually what is
  1674. required, specify
  1675. ``${``\ :term:`PN`\ ``}`` in place of
  1676. PACKAGENAME.
  1677. A post-installation function has the following structure::
  1678. pkg_postinst_PACKAGENAME() {
  1679. # Commands to carry out
  1680. }
  1681. The script defined in the post-installation function is called when the
  1682. root filesystem is created. If the script succeeds, the package is
  1683. marked as installed.
  1684. .. note::
  1685. Any RPM post-installation script that runs on the target should
  1686. return a 0 exit code. RPM does not allow non-zero exit codes for
  1687. these scripts, and the RPM package manager will cause the package to
  1688. fail installation on the target.
  1689. Sometimes it is necessary for the execution of a post-installation
  1690. script to be delayed until the first boot. For example, the script might
  1691. need to be executed on the device itself. To delay script execution
  1692. until boot time, you must explicitly mark post installs to defer to the
  1693. target. You can use ``pkg_postinst_ontarget()`` or call
  1694. ``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any
  1695. failure of a ``pkg_postinst()`` script (including exit 1) triggers an
  1696. error during the
  1697. :ref:`ref-tasks-rootfs` task.
  1698. If you have recipes that use ``pkg_postinst`` function and they require
  1699. the use of non-standard native tools that have dependencies during
  1700. rootfs construction, you need to use the
  1701. :term:`PACKAGE_WRITE_DEPS`
  1702. variable in your recipe to list these tools. If you do not use this
  1703. variable, the tools might be missing and execution of the
  1704. post-installation script is deferred until first boot. Deferring the
  1705. script to first boot is undesirable and for read-only rootfs impossible.
  1706. .. note::
  1707. There is equivalent support for pre-install, pre-uninstall, and post-uninstall
  1708. scripts by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``,
  1709. respectively. These scrips work in exactly the same way as does
  1710. ``pkg_postinst`` with the exception that they run at different times. Also,
  1711. because of when they run, they are not applicable to being run at image
  1712. creation time like ``pkg_postinst``.
  1713. Testing
  1714. -------
  1715. The final step for completing your recipe is to be sure that the
  1716. software you built runs correctly. To accomplish runtime testing, add
  1717. the build's output packages to your image and test them on the target.
  1718. For information on how to customize your image by adding specific
  1719. packages, see ":ref:`dev-manual/common-tasks:customizing images`" section.
  1720. Examples
  1721. --------
  1722. To help summarize how to write a recipe, this section provides some
  1723. examples given various scenarios:
  1724. - Recipes that use local files
  1725. - Using an Autotooled package
  1726. - Using a Makefile-based package
  1727. - Splitting an application into multiple packages
  1728. - Adding binaries to an image
  1729. Single .c File Package (Hello World!)
  1730. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1731. Building an application from a single file that is stored locally (e.g.
  1732. under ``files``) requires a recipe that has the file listed in the
  1733. :term:`SRC_URI` variable. Additionally, you need to manually write the
  1734. ``do_compile`` and ``do_install`` tasks. The :term:`S` variable defines the
  1735. directory containing the source code, which is set to
  1736. :term:`WORKDIR` in this case - the
  1737. directory BitBake uses for the build.
  1738. ::
  1739. SUMMARY = "Simple helloworld application"
  1740. SECTION = "examples"
  1741. LICENSE = "MIT"
  1742. LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
  1743. SRC_URI = "file://helloworld.c"
  1744. S = "${WORKDIR}"
  1745. do_compile() {
  1746. ${CC} ${LDFLAGS} helloworld.c -o helloworld
  1747. }
  1748. do_install() {
  1749. install -d ${D}${bindir}
  1750. install -m 0755 helloworld ${D}${bindir}
  1751. }
  1752. By default, the ``helloworld``, ``helloworld-dbg``, and
  1753. ``helloworld-dev`` packages are built. For information on how to
  1754. customize the packaging process, see the
  1755. ":ref:`dev-manual/common-tasks:splitting an application into multiple packages`"
  1756. section.
  1757. Autotooled Package
  1758. ~~~~~~~~~~~~~~~~~~
  1759. Applications that use Autotools such as ``autoconf`` and ``automake``
  1760. require a recipe that has a source archive listed in :term:`SRC_URI` and
  1761. also inherit the
  1762. :ref:`autotools <ref-classes-autotools>` class,
  1763. which contains the definitions of all the steps needed to build an
  1764. Autotool-based application. The result of the build is automatically
  1765. packaged. And, if the application uses NLS for localization, packages
  1766. with local information are generated (one package per language).
  1767. Following is one example: (``hello_2.3.bb``)
  1768. ::
  1769. SUMMARY = "GNU Helloworld application"
  1770. SECTION = "examples"
  1771. LICENSE = "GPLv2+"
  1772. LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
  1773. SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
  1774. inherit autotools gettext
  1775. The variable :term:`LIC_FILES_CHKSUM` is used to track source license
  1776. changes as described in the
  1777. ":ref:`dev-manual/common-tasks:tracking license changes`" section in
  1778. the Yocto Project Overview and Concepts Manual. You can quickly create
  1779. Autotool-based recipes in a manner similar to the previous example.
  1780. Makefile-Based Package
  1781. ~~~~~~~~~~~~~~~~~~~~~~
  1782. Applications that use GNU ``make`` also require a recipe that has the
  1783. source archive listed in :term:`SRC_URI`. You do not need to add a
  1784. ``do_compile`` step since by default BitBake starts the ``make`` command
  1785. to compile the application. If you need additional ``make`` options, you
  1786. should store them in the
  1787. :term:`EXTRA_OEMAKE` or
  1788. :term:`PACKAGECONFIG_CONFARGS`
  1789. variables. BitBake passes these options into the GNU ``make``
  1790. invocation. Note that a ``do_install`` task is still required.
  1791. Otherwise, BitBake runs an empty ``do_install`` task by default.
  1792. Some applications might require extra parameters to be passed to the
  1793. compiler. For example, the application might need an additional header
  1794. path. You can accomplish this by adding to the :term:`CFLAGS` variable. The
  1795. following example shows this::
  1796. CFLAGS_prepend = "-I ${S}/include "
  1797. In the following example, ``mtd-utils`` is a makefile-based package::
  1798. SUMMARY = "Tools for managing memory technology devices"
  1799. SECTION = "base"
  1800. DEPENDS = "zlib lzo e2fsprogs util-linux"
  1801. HOMEPAGE = "http://www.linux-mtd.infradead.org/"
  1802. LICENSE = "GPLv2+"
  1803. LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
  1804. file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
  1805. # Use the latest version at 26 Oct, 2013
  1806. SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
  1807. SRC_URI = "git://git.infradead.org/mtd-utils.git \
  1808. file://add-exclusion-to-mkfs-jffs2-git-2.patch \
  1809. "
  1810. PV = "1.5.1+git${SRCPV}"
  1811. S = "${WORKDIR}/git"
  1812. EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
  1813. do_install () {
  1814. oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
  1815. }
  1816. PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
  1817. FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
  1818. FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
  1819. FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image"
  1820. PARALLEL_MAKE = ""
  1821. BBCLASSEXTEND = "native"
  1822. Splitting an Application into Multiple Packages
  1823. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1824. You can use the variables :term:`PACKAGES` and :term:`FILES` to split an
  1825. application into multiple packages.
  1826. Following is an example that uses the ``libxpm`` recipe. By default,
  1827. this recipe generates a single package that contains the library along
  1828. with a few binaries. You can modify the recipe to split the binaries
  1829. into separate packages::
  1830. require xorg-lib-common.inc
  1831. SUMMARY = "Xpm: X Pixmap extension library"
  1832. LICENSE = "BSD"
  1833. LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
  1834. DEPENDS += "libxext libsm libxt"
  1835. PE = "1"
  1836. XORG_PN = "libXpm"
  1837. PACKAGES =+ "sxpm cxpm"
  1838. FILES_cxpm = "${bindir}/cxpm"
  1839. FILES_sxpm = "${bindir}/sxpm"
  1840. In the previous example, we want to ship the ``sxpm`` and ``cxpm``
  1841. binaries in separate packages. Since ``bindir`` would be packaged into
  1842. the main :term:`PN` package by default, we prepend the :term:`PACKAGES` variable
  1843. so additional package names are added to the start of list. This results
  1844. in the extra ``FILES_*`` variables then containing information that
  1845. define which files and directories go into which packages. Files
  1846. included by earlier packages are skipped by latter packages. Thus, the
  1847. main :term:`PN` package does not include the above listed files.
  1848. Packaging Externally Produced Binaries
  1849. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1850. Sometimes, you need to add pre-compiled binaries to an image. For
  1851. example, suppose that there are binaries for proprietary code,
  1852. created by a particular division of a company. Your part of the company
  1853. needs to use those binaries as part of an image that you are building
  1854. using the OpenEmbedded build system. Since you only have the binaries
  1855. and not the source code, you cannot use a typical recipe that expects to
  1856. fetch the source specified in
  1857. :term:`SRC_URI` and then compile it.
  1858. One method is to package the binaries and then install them as part of
  1859. the image. Generally, it is not a good idea to package binaries since,
  1860. among other things, it can hinder the ability to reproduce builds and
  1861. could lead to compatibility problems with ABI in the future. However,
  1862. sometimes you have no choice.
  1863. The easiest solution is to create a recipe that uses the
  1864. :ref:`bin_package <ref-classes-bin-package>` class
  1865. and to be sure that you are using default locations for build artifacts.
  1866. In most cases, the ``bin_package`` class handles "skipping" the
  1867. configure and compile steps as well as sets things up to grab packages
  1868. from the appropriate area. In particular, this class sets ``noexec`` on
  1869. both the :ref:`ref-tasks-configure`
  1870. and :ref:`ref-tasks-compile` tasks,
  1871. sets ``FILES_${PN}`` to "/" so that it picks up all files, and sets up a
  1872. :ref:`ref-tasks-install` task, which
  1873. effectively copies all files from ``${S}`` to ``${D}``. The
  1874. ``bin_package`` class works well when the files extracted into ``${S}``
  1875. are already laid out in the way they should be laid out on the target.
  1876. For more information on these variables, see the
  1877. :term:`FILES`,
  1878. :term:`PN`,
  1879. :term:`S`, and
  1880. :term:`D` variables in the Yocto Project
  1881. Reference Manual's variable glossary.
  1882. .. note::
  1883. - Using :term:`DEPENDS` is a good
  1884. idea even for components distributed in binary form, and is often
  1885. necessary for shared libraries. For a shared library, listing the
  1886. library dependencies in :term:`DEPENDS` makes sure that the libraries
  1887. are available in the staging sysroot when other recipes link
  1888. against the library, which might be necessary for successful
  1889. linking.
  1890. - Using :term:`DEPENDS` also allows runtime dependencies between
  1891. packages to be added automatically. See the
  1892. ":ref:`overview-manual/concepts:automatically added runtime dependencies`"
  1893. section in the Yocto Project Overview and Concepts Manual for more
  1894. information.
  1895. If you cannot use the ``bin_package`` class, you need to be sure you are
  1896. doing the following:
  1897. - Create a recipe where the
  1898. :ref:`ref-tasks-configure` and
  1899. :ref:`ref-tasks-compile` tasks do
  1900. nothing: It is usually sufficient to just not define these tasks in
  1901. the recipe, because the default implementations do nothing unless a
  1902. Makefile is found in
  1903. ``${``\ :term:`S`\ ``}``.
  1904. If ``${S}`` might contain a Makefile, or if you inherit some class
  1905. that replaces ``do_configure`` and ``do_compile`` with custom
  1906. versions, then you can use the
  1907. ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]``
  1908. flag to turn the tasks into no-ops, as follows::
  1909. do_configure[noexec] = "1"
  1910. do_compile[noexec] = "1"
  1911. Unlike
  1912. :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`,
  1913. using the flag preserves the dependency chain from the
  1914. :ref:`ref-tasks-fetch`,
  1915. :ref:`ref-tasks-unpack`, and
  1916. :ref:`ref-tasks-patch` tasks to the
  1917. :ref:`ref-tasks-install` task.
  1918. - Make sure your ``do_install`` task installs the binaries
  1919. appropriately.
  1920. - Ensure that you set up :term:`FILES`
  1921. (usually
  1922. ``FILES_${``\ :term:`PN`\ ``}``) to
  1923. point to the files you have installed, which of course depends on
  1924. where you have installed them and whether those files are in
  1925. different locations than the defaults.
  1926. .. note::
  1927. If image prelinking is enabled (e.g. "image-prelink" is in :term:`USER_CLASSES`
  1928. which it is by default), prelink will change the binaries in the generated images
  1929. and this often catches people out. Remove that class to ensure binaries are
  1930. preserved exactly if that is necessary.
  1931. Following Recipe Style Guidelines
  1932. ---------------------------------
  1933. When writing recipes, it is good to conform to existing style
  1934. guidelines. The :oe_wiki:`OpenEmbedded Styleguide </Styleguide>` wiki page
  1935. provides rough guidelines for preferred recipe style.
  1936. It is common for existing recipes to deviate a bit from this style.
  1937. However, aiming for at least a consistent style is a good idea. Some
  1938. practices, such as omitting spaces around ``=`` operators in assignments
  1939. or ordering recipe components in an erratic way, are widely seen as poor
  1940. style.
  1941. Recipe Syntax
  1942. -------------
  1943. Understanding recipe file syntax is important for writing recipes. The
  1944. following list overviews the basic items that make up a BitBake recipe
  1945. file. For more complete BitBake syntax descriptions, see the
  1946. ":doc:`bitbake-user-manual/bitbake-user-manual-metadata`"
  1947. chapter of the BitBake User Manual.
  1948. - *Variable Assignments and Manipulations:* Variable assignments allow
  1949. a value to be assigned to a variable. The assignment can be static
  1950. text or might include the contents of other variables. In addition to
  1951. the assignment, appending and prepending operations are also
  1952. supported.
  1953. The following example shows some of the ways you can use variables in
  1954. recipes::
  1955. S = "${WORKDIR}/postfix-${PV}"
  1956. CFLAGS += "-DNO_ASM"
  1957. SRC_URI_append = " file://fixup.patch"
  1958. - *Functions:* Functions provide a series of actions to be performed.
  1959. You usually use functions to override the default implementation of a
  1960. task function or to complement a default function (i.e. append or
  1961. prepend to an existing function). Standard functions use ``sh`` shell
  1962. syntax, although access to OpenEmbedded variables and internal
  1963. methods are also available.
  1964. Here is an example function from the ``sed`` recipe::
  1965. do_install () {
  1966. autotools_do_install
  1967. install -d ${D}${base_bindir}
  1968. mv ${D}${bindir}/sed ${D}${base_bindir}/sed
  1969. rmdir ${D}${bindir}/
  1970. }
  1971. It is
  1972. also possible to implement new functions that are called between
  1973. existing tasks as long as the new functions are not replacing or
  1974. complementing the default functions. You can implement functions in
  1975. Python instead of shell. Both of these options are not seen in the
  1976. majority of recipes.
  1977. - *Keywords:* BitBake recipes use only a few keywords. You use keywords
  1978. to include common functions (``inherit``), load parts of a recipe
  1979. from other files (``include`` and ``require``) and export variables
  1980. to the environment (``export``).
  1981. The following example shows the use of some of these keywords::
  1982. export POSTCONF = "${STAGING_BINDIR}/postconf"
  1983. inherit autoconf
  1984. require otherfile.inc
  1985. - *Comments (#):* Any lines that begin with the hash character (``#``)
  1986. are treated as comment lines and are ignored::
  1987. # This is a comment
  1988. This next list summarizes the most important and most commonly used
  1989. parts of the recipe syntax. For more information on these parts of the
  1990. syntax, you can reference the
  1991. :doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata` chapter
  1992. in the BitBake User Manual.
  1993. - *Line Continuation (\\):* Use the backward slash (``\``) character to
  1994. split a statement over multiple lines. Place the slash character at
  1995. the end of the line that is to be continued on the next line::
  1996. VAR = "A really long \
  1997. line"
  1998. .. note::
  1999. You cannot have any characters including spaces or tabs after the
  2000. slash character.
  2001. - *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to
  2002. access the contents of a variable::
  2003. SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
  2004. .. note::
  2005. It is important to understand that the value of a variable
  2006. expressed in this form does not get substituted automatically. The
  2007. expansion of these expressions happens on-demand later (e.g.
  2008. usually when a function that makes reference to the variable
  2009. executes). This behavior ensures that the values are most
  2010. appropriate for the context in which they are finally used. On the
  2011. rare occasion that you do need the variable expression to be
  2012. expanded immediately, you can use the
  2013. :=
  2014. operator instead of
  2015. =
  2016. when you make the assignment, but this is not generally needed.
  2017. - *Quote All Assignments ("value"):* Use double quotes around values in
  2018. all variable assignments (e.g. ``"value"``). Following is an example::
  2019. VAR1 = "${OTHERVAR}"
  2020. VAR2 = "The version is ${PV}"
  2021. - *Conditional Assignment (?=):* Conditional assignment is used to
  2022. assign a value to a variable, but only when the variable is currently
  2023. unset. Use the question mark followed by the equal sign (``?=``) to
  2024. make a "soft" assignment used for conditional assignment. Typically,
  2025. "soft" assignments are used in the ``local.conf`` file for variables
  2026. that are allowed to come through from the external environment.
  2027. Here is an example where ``VAR1`` is set to "New value" if it is
  2028. currently empty. However, if ``VAR1`` has already been set, it
  2029. remains unchanged::
  2030. VAR1 ?= "New value"
  2031. In this next example, ``VAR1`` is left with the value "Original value"::
  2032. VAR1 = "Original value"
  2033. VAR1 ?= "New value"
  2034. - *Appending (+=):* Use the plus character followed by the equals sign
  2035. (``+=``) to append values to existing variables.
  2036. .. note::
  2037. This operator adds a space between the existing content of the
  2038. variable and the new content.
  2039. Here is an example::
  2040. SRC_URI += "file://fix-makefile.patch"
  2041. - *Prepending (=+):* Use the equals sign followed by the plus character
  2042. (``=+``) to prepend values to existing variables.
  2043. .. note::
  2044. This operator adds a space between the new content and the
  2045. existing content of the variable.
  2046. Here is an example::
  2047. VAR =+ "Starts"
  2048. - *Appending (_append):* Use the ``_append`` operator to append values
  2049. to existing variables. This operator does not add any additional
  2050. space. Also, the operator is applied after all the ``+=``, and ``=+``
  2051. operators have been applied and after all ``=`` assignments have
  2052. occurred.
  2053. The following example shows the space being explicitly added to the
  2054. start to ensure the appended value is not merged with the existing
  2055. value::
  2056. SRC_URI_append = " file://fix-makefile.patch"
  2057. You can also use
  2058. the ``_append`` operator with overrides, which results in the actions
  2059. only being performed for the specified target or machine::
  2060. SRC_URI_append_sh4 = " file://fix-makefile.patch"
  2061. - *Prepending (_prepend):* Use the ``_prepend`` operator to prepend
  2062. values to existing variables. This operator does not add any
  2063. additional space. Also, the operator is applied after all the ``+=``,
  2064. and ``=+`` operators have been applied and after all ``=``
  2065. assignments have occurred.
  2066. The following example shows the space being explicitly added to the
  2067. end to ensure the prepended value is not merged with the existing
  2068. value::
  2069. CFLAGS_prepend = "-I${S}/myincludes "
  2070. You can also use the
  2071. ``_prepend`` operator with overrides, which results in the actions
  2072. only being performed for the specified target or machine::
  2073. CFLAGS_prepend_sh4 = "-I${S}/myincludes "
  2074. - *Overrides:* You can use overrides to set a value conditionally,
  2075. typically based on how the recipe is being built. For example, to set
  2076. the :term:`KBRANCH` variable's
  2077. value to "standard/base" for any target
  2078. :term:`MACHINE`, except for
  2079. qemuarm where it should be set to "standard/arm-versatile-926ejs",
  2080. you would do the following::
  2081. KBRANCH = "standard/base"
  2082. KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
  2083. Overrides are also used to separate
  2084. alternate values of a variable in other situations. For example, when
  2085. setting variables such as
  2086. :term:`FILES` and
  2087. :term:`RDEPENDS` that are
  2088. specific to individual packages produced by a recipe, you should
  2089. always use an override that specifies the name of the package.
  2090. - *Indentation:* Use spaces for indentation rather than tabs. For
  2091. shell functions, both currently work. However, it is a policy
  2092. decision of the Yocto Project to use tabs in shell functions. Realize
  2093. that some layers have a policy to use spaces for all indentation.
  2094. - *Using Python for Complex Operations:* For more advanced processing,
  2095. it is possible to use Python code during variable assignments (e.g.
  2096. search and replacement on a variable).
  2097. You indicate Python code using the ``${@python_code}`` syntax for the
  2098. variable assignment::
  2099. SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
  2100. - *Shell Function Syntax:* Write shell functions as if you were writing
  2101. a shell script when you describe a list of actions to take. You
  2102. should ensure that your script works with a generic ``sh`` and that
  2103. it does not require any ``bash`` or other shell-specific
  2104. functionality. The same considerations apply to various system
  2105. utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you
  2106. might wish to use. If in doubt, you should check with multiple
  2107. implementations - including those from BusyBox.
  2108. Adding a New Machine
  2109. ====================
  2110. Adding a new machine to the Yocto Project is a straightforward process.
  2111. This section describes how to add machines that are similar to those
  2112. that the Yocto Project already supports.
  2113. .. note::
  2114. Although well within the capabilities of the Yocto Project, adding a
  2115. totally new architecture might require changes to ``gcc``/``glibc``
  2116. and to the site information, which is beyond the scope of this
  2117. manual.
  2118. For a complete example that shows how to add a new machine, see the
  2119. ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
  2120. section in the Yocto Project Board Support Package (BSP) Developer's
  2121. Guide.
  2122. Adding the Machine Configuration File
  2123. -------------------------------------
  2124. To add a new machine, you need to add a new machine configuration file
  2125. to the layer's ``conf/machine`` directory. This configuration file
  2126. provides details about the device you are adding.
  2127. The OpenEmbedded build system uses the root name of the machine
  2128. configuration file to reference the new machine. For example, given a
  2129. machine configuration file named ``crownbay.conf``, the build system
  2130. recognizes the machine as "crownbay".
  2131. The most important variables you must set in your machine configuration
  2132. file or include from a lower-level configuration file are as follows:
  2133. - :term:`TARGET_ARCH` (e.g. "arm")
  2134. - ``PREFERRED_PROVIDER_virtual/kernel``
  2135. - :term:`MACHINE_FEATURES` (e.g. "apm screen wifi")
  2136. You might also need these variables:
  2137. - :term:`SERIAL_CONSOLES` (e.g. "115200;ttyS0 115200;ttyS1")
  2138. - :term:`KERNEL_IMAGETYPE` (e.g. "zImage")
  2139. - :term:`IMAGE_FSTYPES` (e.g. "tar.gz jffs2")
  2140. You can find full details on these variables in the reference section.
  2141. You can leverage existing machine ``.conf`` files from
  2142. ``meta-yocto-bsp/conf/machine/``.
  2143. Adding a Kernel for the Machine
  2144. -------------------------------
  2145. The OpenEmbedded build system needs to be able to build a kernel for the
  2146. machine. You need to either create a new kernel recipe for this machine,
  2147. or extend an existing kernel recipe. You can find several kernel recipe
  2148. examples in the Source Directory at ``meta/recipes-kernel/linux`` that
  2149. you can use as references.
  2150. If you are creating a new kernel recipe, normal recipe-writing rules
  2151. apply for setting up a :term:`SRC_URI`. Thus, you need to specify any
  2152. necessary patches and set :term:`S` to point at the source code. You need to
  2153. create a ``do_configure`` task that configures the unpacked kernel with
  2154. a ``defconfig`` file. You can do this by using a ``make defconfig``
  2155. command or, more commonly, by copying in a suitable ``defconfig`` file
  2156. and then running ``make oldconfig``. By making use of ``inherit kernel``
  2157. and potentially some of the ``linux-*.inc`` files, most other
  2158. functionality is centralized and the defaults of the class normally work
  2159. well.
  2160. If you are extending an existing kernel recipe, it is usually a matter
  2161. of adding a suitable ``defconfig`` file. The file needs to be added into
  2162. a location similar to ``defconfig`` files used for other machines in a
  2163. given kernel recipe. A possible way to do this is by listing the file in
  2164. the :term:`SRC_URI` and adding the machine to the expression in
  2165. :term:`COMPATIBLE_MACHINE`::
  2166. COMPATIBLE_MACHINE = '(qemux86|qemumips)'
  2167. For more information on ``defconfig`` files, see the
  2168. ":ref:`kernel-dev/common:changing the configuration`"
  2169. section in the Yocto Project Linux Kernel Development Manual.
  2170. Adding a Formfactor Configuration File
  2171. --------------------------------------
  2172. A formfactor configuration file provides information about the target
  2173. hardware for which the image is being built and information that the
  2174. build system cannot obtain from other sources such as the kernel. Some
  2175. examples of information contained in a formfactor configuration file
  2176. include framebuffer orientation, whether or not the system has a
  2177. keyboard, the positioning of the keyboard in relation to the screen, and
  2178. the screen resolution.
  2179. The build system uses reasonable defaults in most cases. However, if
  2180. customization is necessary, you need to create a ``machconfig`` file in
  2181. the ``meta/recipes-bsp/formfactor/files`` directory. This directory
  2182. contains directories for specific machines such as ``qemuarm`` and
  2183. ``qemux86``. For information about the settings available and the
  2184. defaults, see the ``meta/recipes-bsp/formfactor/files/config`` file
  2185. found in the same area.
  2186. Following is an example for "qemuarm" machine::
  2187. HAVE_TOUCHSCREEN=1
  2188. HAVE_KEYBOARD=1
  2189. DISPLAY_CAN_ROTATE=0
  2190. DISPLAY_ORIENTATION=0
  2191. #DISPLAY_WIDTH_PIXELS=640
  2192. #DISPLAY_HEIGHT_PIXELS=480
  2193. #DISPLAY_BPP=16
  2194. DISPLAY_DPI=150
  2195. DISPLAY_SUBPIXEL_ORDER=vrgb
  2196. Upgrading Recipes
  2197. =================
  2198. Over time, upstream developers publish new versions for software built
  2199. by layer recipes. It is recommended to keep recipes up-to-date with
  2200. upstream version releases.
  2201. While there are several methods to upgrade a recipe, you might
  2202. consider checking on the upgrade status of a recipe first. You can do so
  2203. using the ``devtool check-upgrade-status`` command. See the
  2204. ":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`"
  2205. section in the Yocto Project Reference Manual for more information.
  2206. The remainder of this section describes three ways you can upgrade a
  2207. recipe. You can use the Automated Upgrade Helper (AUH) to set up
  2208. automatic version upgrades. Alternatively, you can use
  2209. ``devtool upgrade`` to set up semi-automatic version upgrades. Finally,
  2210. you can manually upgrade a recipe by editing the recipe itself.
  2211. Using the Auto Upgrade Helper (AUH)
  2212. -----------------------------------
  2213. The AUH utility works in conjunction with the OpenEmbedded build system
  2214. in order to automatically generate upgrades for recipes based on new
  2215. versions being published upstream. Use AUH when you want to create a
  2216. service that performs the upgrades automatically and optionally sends
  2217. you an email with the results.
  2218. AUH allows you to update several recipes with a single use. You can also
  2219. optionally perform build and integration tests using images with the
  2220. results saved to your hard drive and emails of results optionally sent
  2221. to recipe maintainers. Finally, AUH creates Git commits with appropriate
  2222. commit messages in the layer's tree for the changes made to recipes.
  2223. .. note::
  2224. In some conditions, you should not use AUH to upgrade recipes
  2225. and should instead use either ``devtool upgrade`` or upgrade your
  2226. recipes manually:
  2227. - When AUH cannot complete the upgrade sequence. This situation
  2228. usually results because custom patches carried by the recipe
  2229. cannot be automatically rebased to the new version. In this case,
  2230. ``devtool upgrade`` allows you to manually resolve conflicts.
  2231. - When for any reason you want fuller control over the upgrade
  2232. process. For example, when you want special arrangements for
  2233. testing.
  2234. The following steps describe how to set up the AUH utility:
  2235. 1. *Be Sure the Development Host is Set Up:* You need to be sure that
  2236. your development host is set up to use the Yocto Project. For
  2237. information on how to set up your host, see the
  2238. ":ref:`dev-manual/start:Preparing the Build Host`" section.
  2239. 2. *Make Sure Git is Configured:* The AUH utility requires Git to be
  2240. configured because AUH uses Git to save upgrades. Thus, you must have
  2241. Git user and email configured. The following command shows your
  2242. configurations::
  2243. $ git config --list
  2244. If you do not have the user and
  2245. email configured, you can use the following commands to do so::
  2246. $ git config --global user.name some_name
  2247. $ git config --global user.email username@domain.com
  2248. 3. *Clone the AUH Repository:* To use AUH, you must clone the repository
  2249. onto your development host. The following command uses Git to create
  2250. a local copy of the repository on your system::
  2251. $ git clone git://git.yoctoproject.org/auto-upgrade-helper
  2252. Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done.
  2253. remote: Compressing objects: 100% (300/300), done.
  2254. remote: Total 768 (delta 499), reused 703 (delta 434)
  2255. Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
  2256. Resolving deltas: 100% (499/499), done.
  2257. Checking connectivity... done.
  2258. AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or
  2259. :term:`Poky` repositories.
  2260. 4. *Create a Dedicated Build Directory:* Run the
  2261. :ref:`structure-core-script`
  2262. script to create a fresh build directory that you use exclusively for
  2263. running the AUH utility::
  2264. $ cd poky
  2265. $ source oe-init-build-env your_AUH_build_directory
  2266. Re-using an existing build directory and its configurations is not
  2267. recommended as existing settings could cause AUH to fail or behave
  2268. undesirably.
  2269. 5. *Make Configurations in Your Local Configuration File:* Several
  2270. settings are needed in the ``local.conf`` file in the build
  2271. directory you just created for AUH. Make these following
  2272. configurations:
  2273. - If you want to enable :ref:`Build
  2274. History <dev-manual/common-tasks:maintaining build output quality>`,
  2275. which is optional, you need the following lines in the
  2276. ``conf/local.conf`` file::
  2277. INHERIT =+ "buildhistory"
  2278. BUILDHISTORY_COMMIT = "1"
  2279. With this configuration and a successful
  2280. upgrade, a build history "diff" file appears in the
  2281. ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in
  2282. your build directory.
  2283. - If you want to enable testing through the
  2284. :ref:`testimage <ref-classes-testimage*>`
  2285. class, which is optional, you need to have the following set in
  2286. your ``conf/local.conf`` file::
  2287. INHERIT += "testimage"
  2288. .. note::
  2289. If your distro does not enable by default ptest, which Poky
  2290. does, you need the following in your ``local.conf`` file::
  2291. DISTRO_FEATURES_append = " ptest"
  2292. 6. *Optionally Start a vncserver:* If you are running in a server
  2293. without an X11 session, you need to start a vncserver::
  2294. $ vncserver :1
  2295. $ export DISPLAY=:1
  2296. 7. *Create and Edit an AUH Configuration File:* You need to have the
  2297. ``upgrade-helper/upgrade-helper.conf`` configuration file in your
  2298. build directory. You can find a sample configuration file in the
  2299. :yocto_git:`AUH source repository </auto-upgrade-helper/tree/>`.
  2300. Read through the sample file and make configurations as needed. For
  2301. example, if you enabled build history in your ``local.conf`` as
  2302. described earlier, you must enable it in ``upgrade-helper.conf``.
  2303. Also, if you are using the default ``maintainers.inc`` file supplied
  2304. with Poky and located in ``meta-yocto`` and you do not set a
  2305. "maintainers_whitelist" or "global_maintainer_override" in the
  2306. ``upgrade-helper.conf`` configuration, and you specify "-e all" on
  2307. the AUH command-line, the utility automatically sends out emails to
  2308. all the default maintainers. Please avoid this.
  2309. This next set of examples describes how to use the AUH:
  2310. - *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the
  2311. following form::
  2312. $ upgrade-helper.py recipe_name
  2313. For example, this command upgrades the ``xmodmap`` recipe::
  2314. $ upgrade-helper.py xmodmap
  2315. - *Upgrading a Specific Recipe to a Particular Version:* To upgrade a
  2316. specific recipe to a particular version, use the following form::
  2317. $ upgrade-helper.py recipe_name -t version
  2318. For example, this command upgrades the ``xmodmap`` recipe to version 1.2.3::
  2319. $ upgrade-helper.py xmodmap -t 1.2.3
  2320. - *Upgrading all Recipes to the Latest Versions and Suppressing Email
  2321. Notifications:* To upgrade all recipes to their most recent versions
  2322. and suppress the email notifications, use the following command::
  2323. $ upgrade-helper.py all
  2324. - *Upgrading all Recipes to the Latest Versions and Send Email
  2325. Notifications:* To upgrade all recipes to their most recent versions
  2326. and send email messages to maintainers for each attempted recipe as
  2327. well as a status email, use the following command::
  2328. $ upgrade-helper.py -e all
  2329. Once you have run the AUH utility, you can find the results in the AUH
  2330. build directory::
  2331. ${BUILDDIR}/upgrade-helper/timestamp
  2332. The AUH utility
  2333. also creates recipe update commits from successful upgrade attempts in
  2334. the layer tree.
  2335. You can easily set up to run the AUH utility on a regular basis by using
  2336. a cron job. See the
  2337. :yocto_git:`weeklyjob.sh </auto-upgrade-helper/tree/weeklyjob.sh>`
  2338. file distributed with the utility for an example.
  2339. Using ``devtool upgrade``
  2340. -------------------------
  2341. As mentioned earlier, an alternative method for upgrading recipes to
  2342. newer versions is to use
  2343. :doc:`devtool upgrade </ref-manual/devtool-reference>`.
  2344. You can read about ``devtool upgrade`` in general in the
  2345. ":ref:`sdk-manual/extensible:use \`\`devtool upgrade\`\` to create a version of the recipe that supports a newer version of the software`"
  2346. section in the Yocto Project Application Development and the Extensible
  2347. Software Development Kit (eSDK) Manual.
  2348. To see all the command-line options available with ``devtool upgrade``,
  2349. use the following help command::
  2350. $ devtool upgrade -h
  2351. If you want to find out what version a recipe is currently at upstream
  2352. without any attempt to upgrade your local version of the recipe, you can
  2353. use the following command::
  2354. $ devtool latest-version recipe_name
  2355. As mentioned in the previous section describing AUH, ``devtool upgrade``
  2356. works in a less-automated manner than AUH. Specifically,
  2357. ``devtool upgrade`` only works on a single recipe that you name on the
  2358. command line, cannot perform build and integration testing using images,
  2359. and does not automatically generate commits for changes in the source
  2360. tree. Despite all these "limitations", ``devtool upgrade`` updates the
  2361. recipe file to the new upstream version and attempts to rebase custom
  2362. patches contained by the recipe as needed.
  2363. .. note::
  2364. AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat
  2365. of a "wrapper" application for ``devtool upgrade``.
  2366. A typical scenario involves having used Git to clone an upstream
  2367. repository that you use during build operations. Because you have built the
  2368. recipe in the past, the layer is likely added to your
  2369. configuration already. If for some reason, the layer is not added, you
  2370. could add it easily using the
  2371. ":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`"
  2372. script. For example, suppose you use the ``nano.bb`` recipe from the
  2373. ``meta-oe`` layer in the ``meta-openembedded`` repository. For this
  2374. example, assume that the layer has been cloned into following area::
  2375. /home/scottrif/meta-openembedded
  2376. The following command from your
  2377. :term:`Build Directory` adds the layer to
  2378. your build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``)::
  2379. $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
  2380. NOTE: Starting bitbake server...
  2381. Parsing recipes: 100% |##########################################| Time: 0:00:55
  2382. Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
  2383. Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
  2384. Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
  2385. Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
  2386. Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
  2387. For this example, assume that the ``nano.bb`` recipe that
  2388. is upstream has a 2.9.3 version number. However, the version in the
  2389. local repository is 2.7.4. The following command from your build
  2390. directory automatically upgrades the recipe for you:
  2391. .. note::
  2392. Using the ``-V`` option is not necessary. Omitting the version number causes
  2393. ``devtool upgrade`` to upgrade the recipe to the most recent version.
  2394. ::
  2395. $ devtool upgrade nano -V 2.9.3
  2396. NOTE: Starting bitbake server...
  2397. NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
  2398. Parsing recipes: 100% |##########################################| Time: 0:00:46
  2399. Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
  2400. NOTE: Extracting current version source...
  2401. NOTE: Resolving any missing task queue dependencies
  2402. .
  2403. .
  2404. .
  2405. NOTE: Executing SetScene Tasks
  2406. NOTE: Executing RunQueue Tasks
  2407. NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
  2408. Adding changed files: 100% |#####################################| Time: 0:00:00
  2409. NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
  2410. NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
  2411. Continuing with this example, you can use ``devtool build`` to build the
  2412. newly upgraded recipe::
  2413. $ devtool build nano
  2414. NOTE: Starting bitbake server...
  2415. Loading cache: 100% |################################################################################################| Time: 0:00:01
  2416. Loaded 2040 entries from dependency cache.
  2417. Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
  2418. Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
  2419. NOTE: Resolving any missing task queue dependencies
  2420. .
  2421. .
  2422. .
  2423. NOTE: Executing SetScene Tasks
  2424. NOTE: Executing RunQueue Tasks
  2425. NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
  2426. NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
  2427. Within the ``devtool upgrade`` workflow, you can
  2428. deploy and test your rebuilt software. For this example,
  2429. however, running ``devtool finish`` cleans up the workspace once the
  2430. source in your workspace is clean. This usually means using Git to stage
  2431. and submit commits for the changes generated by the upgrade process.
  2432. Once the tree is clean, you can clean things up in this example with the
  2433. following command from the ``${BUILDDIR}/workspace/sources/nano``
  2434. directory::
  2435. $ devtool finish nano meta-oe
  2436. NOTE: Starting bitbake server...
  2437. Loading cache: 100% |################################################################################################| Time: 0:00:00
  2438. Loaded 2040 entries from dependency cache.
  2439. Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
  2440. Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
  2441. NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
  2442. NOTE: Updating recipe nano_2.9.3.bb
  2443. NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
  2444. NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
  2445. NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
  2446. Using the ``devtool finish`` command cleans up the workspace and creates a patch
  2447. file based on your commits. The tool puts all patch files back into the
  2448. source directory in a sub-directory named ``nano`` in this case.
  2449. Manually Upgrading a Recipe
  2450. ---------------------------
  2451. If for some reason you choose not to upgrade recipes using
  2452. :ref:`dev-manual/common-tasks:Using the Auto Upgrade Helper (AUH)` or
  2453. by :ref:`dev-manual/common-tasks:Using \`\`devtool upgrade\`\``,
  2454. you can manually edit the recipe files to upgrade the versions.
  2455. .. note::
  2456. Manually updating multiple recipes scales poorly and involves many
  2457. steps. The recommendation to upgrade recipe versions is through AUH
  2458. or ``devtool upgrade``, both of which automate some steps and provide
  2459. guidance for others needed for the manual process.
  2460. To manually upgrade recipe versions, follow these general steps:
  2461. 1. *Change the Version:* Rename the recipe such that the version (i.e.
  2462. the :term:`PV` part of the recipe name)
  2463. changes appropriately. If the version is not part of the recipe name,
  2464. change the value as it is set for :term:`PV` within the recipe itself.
  2465. 2. *Update* :term:`SRCREV` *if Needed*: If the source code your recipe builds
  2466. is fetched from Git or some other version control system, update
  2467. :term:`SRCREV` to point to the
  2468. commit hash that matches the new version.
  2469. 3. *Build the Software:* Try to build the recipe using BitBake. Typical
  2470. build failures include the following:
  2471. - License statements were updated for the new version. For this
  2472. case, you need to review any changes to the license and update the
  2473. values of :term:`LICENSE` and
  2474. :term:`LIC_FILES_CHKSUM`
  2475. as needed.
  2476. .. note::
  2477. License changes are often inconsequential. For example, the
  2478. license text's copyright year might have changed.
  2479. - Custom patches carried by the older version of the recipe might
  2480. fail to apply to the new version. For these cases, you need to
  2481. review the failures. Patches might not be necessary for the new
  2482. version of the software if the upgraded version has fixed those
  2483. issues. If a patch is necessary and failing, you need to rebase it
  2484. into the new version.
  2485. 4. *Optionally Attempt to Build for Several Architectures:* Once you
  2486. successfully build the new software for a given architecture, you
  2487. could test the build for other architectures by changing the
  2488. :term:`MACHINE` variable and
  2489. rebuilding the software. This optional step is especially important
  2490. if the recipe is to be released publicly.
  2491. 5. *Check the Upstream Change Log or Release Notes:* Checking both these
  2492. reveals if there are new features that could break
  2493. backwards-compatibility. If so, you need to take steps to mitigate or
  2494. eliminate that situation.
  2495. 6. *Optionally Create a Bootable Image and Test:* If you want, you can
  2496. test the new software by booting it onto actual hardware.
  2497. 7. *Create a Commit with the Change in the Layer Repository:* After all
  2498. builds work and any testing is successful, you can create commits for
  2499. any changes in the layer holding your upgraded recipe.
  2500. Finding Temporary Source Code
  2501. =============================
  2502. You might find it helpful during development to modify the temporary
  2503. source code used by recipes to build packages. For example, suppose you
  2504. are developing a patch and you need to experiment a bit to figure out
  2505. your solution. After you have initially built the package, you can
  2506. iteratively tweak the source code, which is located in the
  2507. :term:`Build Directory`, and then you can
  2508. force a re-compile and quickly test your altered code. Once you settle
  2509. on a solution, you can then preserve your changes in the form of
  2510. patches.
  2511. During a build, the unpacked temporary source code used by recipes to
  2512. build packages is available in the Build Directory as defined by the
  2513. :term:`S` variable. Below is the default
  2514. value for the :term:`S` variable as defined in the
  2515. ``meta/conf/bitbake.conf`` configuration file in the
  2516. :term:`Source Directory`::
  2517. S = "${WORKDIR}/${BP}"
  2518. You should be aware that many recipes override the
  2519. :term:`S` variable. For example, recipes that fetch their source from Git
  2520. usually set :term:`S` to ``${WORKDIR}/git``.
  2521. .. note::
  2522. The :term:`BP` represents the base recipe name, which consists of the name
  2523. and version::
  2524. BP = "${BPN}-${PV}"
  2525. The path to the work directory for the recipe
  2526. (:term:`WORKDIR`) is defined as
  2527. follows::
  2528. ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
  2529. The actual directory depends on several things:
  2530. - :term:`TMPDIR`: The top-level build
  2531. output directory.
  2532. - :term:`MULTIMACH_TARGET_SYS`:
  2533. The target system identifier.
  2534. - :term:`PN`: The recipe name.
  2535. - :term:`EXTENDPE`: The epoch - (if
  2536. :term:`PE` is not specified, which is
  2537. usually the case for most recipes, then :term:`EXTENDPE` is blank).
  2538. - :term:`PV`: The recipe version.
  2539. - :term:`PR`: The recipe revision.
  2540. As an example, assume a Source Directory top-level folder named
  2541. ``poky``, a default Build Directory at ``poky/build``, and a
  2542. ``qemux86-poky-linux`` machine target system. Furthermore, suppose your
  2543. recipe is named ``foo_1.3.0.bb``. In this case, the work directory the
  2544. build system uses to build the package would be as follows::
  2545. poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
  2546. Using Quilt in Your Workflow
  2547. ============================
  2548. `Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool
  2549. that allows you to capture source code changes without having a clean
  2550. source tree. This section outlines the typical workflow you can use to
  2551. modify source code, test changes, and then preserve the changes in the
  2552. form of a patch all using Quilt.
  2553. .. note::
  2554. With regard to preserving changes to source files, if you clean a
  2555. recipe or have ``rm_work`` enabled, the
  2556. :ref:`devtool workflow <sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow>`
  2557. as described in the Yocto Project Application Development and the
  2558. Extensible Software Development Kit (eSDK) manual is a safer
  2559. development flow than the flow that uses Quilt.
  2560. Follow these general steps:
  2561. 1. *Find the Source Code:* Temporary source code used by the
  2562. OpenEmbedded build system is kept in the
  2563. :term:`Build Directory`. See the
  2564. ":ref:`dev-manual/common-tasks:finding temporary source code`" section to
  2565. learn how to locate the directory that has the temporary source code for a
  2566. particular package.
  2567. 2. *Change Your Working Directory:* You need to be in the directory that
  2568. has the temporary source code. That directory is defined by the
  2569. :term:`S` variable.
  2570. 3. *Create a New Patch:* Before modifying source code, you need to
  2571. create a new patch. To create a new patch file, use ``quilt new`` as
  2572. below::
  2573. $ quilt new my_changes.patch
  2574. 4. *Notify Quilt and Add Files:* After creating the patch, you need to
  2575. notify Quilt about the files you plan to edit. You notify Quilt by
  2576. adding the files to the patch you just created::
  2577. $ quilt add file1.c file2.c file3.c
  2578. 5. *Edit the Files:* Make your changes in the source code to the files
  2579. you added to the patch.
  2580. 6. *Test Your Changes:* Once you have modified the source code, the
  2581. easiest way to test your changes is by calling the ``do_compile``
  2582. task as shown in the following example::
  2583. $ bitbake -c compile -f package
  2584. The ``-f`` or ``--force`` option forces the specified task to
  2585. execute. If you find problems with your code, you can just keep
  2586. editing and re-testing iteratively until things work as expected.
  2587. .. note::
  2588. All the modifications you make to the temporary source code disappear
  2589. once you run the ``do_clean`` or ``do_cleanall`` tasks using BitBake
  2590. (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``).
  2591. Modifications will also disappear if you use the ``rm_work`` feature as
  2592. described in the
  2593. ":ref:`dev-manual/common-tasks:conserving disk space during builds`"
  2594. section.
  2595. 7. *Generate the Patch:* Once your changes work as expected, you need to
  2596. use Quilt to generate the final patch that contains all your
  2597. modifications.
  2598. ::
  2599. $ quilt refresh
  2600. At this point, the
  2601. ``my_changes.patch`` file has all your edits made to the ``file1.c``,
  2602. ``file2.c``, and ``file3.c`` files.
  2603. You can find the resulting patch file in the ``patches/``
  2604. subdirectory of the source (:term:`S`) directory.
  2605. 8. *Copy the Patch File:* For simplicity, copy the patch file into a
  2606. directory named ``files``, which you can create in the same directory
  2607. that holds the recipe (``.bb``) file or the append (``.bbappend``)
  2608. file. Placing the patch here guarantees that the OpenEmbedded build
  2609. system will find the patch. Next, add the patch into the :term:`SRC_URI`
  2610. of the recipe. Here is an example::
  2611. SRC_URI += "file://my_changes.patch"
  2612. Using a Development Shell
  2613. =========================
  2614. When debugging certain commands or even when just editing packages,
  2615. ``devshell`` can be a useful tool. When you invoke ``devshell``, all
  2616. tasks up to and including
  2617. :ref:`ref-tasks-patch` are run for the
  2618. specified target. Then, a new terminal is opened and you are placed in
  2619. ``${``\ :term:`S`\ ``}``, the source
  2620. directory. In the new terminal, all the OpenEmbedded build-related
  2621. environment variables are still defined so you can use commands such as
  2622. ``configure`` and ``make``. The commands execute just as if the
  2623. OpenEmbedded build system were executing them. Consequently, working
  2624. this way can be helpful when debugging a build or preparing software to
  2625. be used with the OpenEmbedded build system.
  2626. Following is an example that uses ``devshell`` on a target named
  2627. ``matchbox-desktop``::
  2628. $ bitbake matchbox-desktop -c devshell
  2629. This command spawns a terminal with a shell prompt within the
  2630. OpenEmbedded build environment. The
  2631. :term:`OE_TERMINAL` variable
  2632. controls what type of shell is opened.
  2633. For spawned terminals, the following occurs:
  2634. - The ``PATH`` variable includes the cross-toolchain.
  2635. - The ``pkgconfig`` variables find the correct ``.pc`` files.
  2636. - The ``configure`` command finds the Yocto Project site files as well
  2637. as any other necessary files.
  2638. Within this environment, you can run configure or compile commands as if
  2639. they were being run by the OpenEmbedded build system itself. As noted
  2640. earlier, the working directory also automatically changes to the Source
  2641. Directory (:term:`S`).
  2642. To manually run a specific task using ``devshell``, run the
  2643. corresponding ``run.*`` script in the
  2644. ``${``\ :term:`WORKDIR`\ ``}/temp``
  2645. directory (e.g., ``run.do_configure.``\ `pid`). If a task's script does
  2646. not exist, which would be the case if the task was skipped by way of the
  2647. sstate cache, you can create the task by first running it outside of the
  2648. ``devshell``::
  2649. $ bitbake -c task
  2650. .. note::
  2651. - Execution of a task's ``run.*`` script and BitBake's execution of
  2652. a task are identical. In other words, running the script re-runs
  2653. the task just as it would be run using the ``bitbake -c`` command.
  2654. - Any ``run.*`` file that does not have a ``.pid`` extension is a
  2655. symbolic link (symlink) to the most recent version of that file.
  2656. Remember, that the ``devshell`` is a mechanism that allows you to get
  2657. into the BitBake task execution environment. And as such, all commands
  2658. must be called just as BitBake would call them. That means you need to
  2659. provide the appropriate options for cross-compilation and so forth as
  2660. applicable.
  2661. When you are finished using ``devshell``, exit the shell or close the
  2662. terminal window.
  2663. .. note::
  2664. - It is worth remembering that when using ``devshell`` you need to
  2665. use the full compiler name such as ``arm-poky-linux-gnueabi-gcc``
  2666. instead of just using ``gcc``. The same applies to other
  2667. applications such as ``binutils``, ``libtool`` and so forth.
  2668. BitBake sets up environment variables such as :term:`CC` to assist
  2669. applications, such as ``make`` to find the correct tools.
  2670. - It is also worth noting that ``devshell`` still works over X11
  2671. forwarding and similar situations.
  2672. Using a Development Python Shell
  2673. ================================
  2674. Similar to working within a development shell as described in the
  2675. previous section, you can also spawn and work within an interactive
  2676. Python development shell. When debugging certain commands or even when
  2677. just editing packages, ``devpyshell`` can be a useful tool. When you
  2678. invoke ``devpyshell``, all tasks up to and including
  2679. :ref:`ref-tasks-patch` are run for the
  2680. specified target. Then a new terminal is opened. Additionally, key
  2681. Python objects and code are available in the same way they are to
  2682. BitBake tasks, in particular, the data store 'd'. So, commands such as
  2683. the following are useful when exploring the data store and running
  2684. functions::
  2685. pydevshell> d.getVar("STAGING_DIR")
  2686. '/media/build1/poky/build/tmp/sysroots'
  2687. pydevshell> d.getVar("STAGING_DIR")
  2688. '${TMPDIR}/sysroots'
  2689. pydevshell> d.setVar("FOO", "bar")
  2690. pydevshell> d.getVar("FOO")
  2691. 'bar'
  2692. pydevshell> d.delVar("FOO")
  2693. pydevshell> d.getVar("FOO")
  2694. pydevshell> bb.build.exec_func("do_unpack", d)
  2695. pydevshell>
  2696. The commands execute just as if the OpenEmbedded build
  2697. system were executing them. Consequently, working this way can be
  2698. helpful when debugging a build or preparing software to be used with the
  2699. OpenEmbedded build system.
  2700. Following is an example that uses ``devpyshell`` on a target named
  2701. ``matchbox-desktop``::
  2702. $ bitbake matchbox-desktop -c devpyshell
  2703. This command spawns a terminal and places you in an interactive Python
  2704. interpreter within the OpenEmbedded build environment. The
  2705. :term:`OE_TERMINAL` variable
  2706. controls what type of shell is opened.
  2707. When you are finished using ``devpyshell``, you can exit the shell
  2708. either by using Ctrl+d or closing the terminal window.
  2709. Building
  2710. ========
  2711. This section describes various build procedures. For example, the steps
  2712. needed for a simple build, a target that uses multiple configurations,
  2713. building an image for more than one machine, and so forth.
  2714. Building a Simple Image
  2715. -----------------------
  2716. In the development environment, you need to build an image whenever you
  2717. change hardware support, add or change system libraries, or add or
  2718. change services that have dependencies. There are several methods that allow
  2719. you to build an image within the Yocto Project. This section presents
  2720. the basic steps you need to build a simple image using BitBake from a
  2721. build host running Linux.
  2722. .. note::
  2723. - For information on how to build an image using
  2724. :term:`Toaster`, see the
  2725. :doc:`/toaster-manual/index`.
  2726. - For information on how to use ``devtool`` to build images, see the
  2727. ":ref:`sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow`"
  2728. section in the Yocto Project Application Development and the
  2729. Extensible Software Development Kit (eSDK) manual.
  2730. - For a quick example on how to build an image using the
  2731. OpenEmbedded build system, see the
  2732. :doc:`/brief-yoctoprojectqs/index` document.
  2733. The build process creates an entire Linux distribution from source and
  2734. places it in your :term:`Build Directory` under
  2735. ``tmp/deploy/images``. For detailed information on the build process
  2736. using BitBake, see the ":ref:`overview-manual/concepts:images`" section in the
  2737. Yocto Project Overview and Concepts Manual.
  2738. The following figure and list overviews the build process:
  2739. .. image:: figures/bitbake-build-flow.png
  2740. :align: center
  2741. 1. *Set up Your Host Development System to Support Development Using the
  2742. Yocto Project*: See the ":doc:`start`" section for options on how to get a
  2743. build host ready to use the Yocto Project.
  2744. 2. *Initialize the Build Environment:* Initialize the build environment
  2745. by sourcing the build environment script (i.e.
  2746. :ref:`structure-core-script`)::
  2747. $ source oe-init-build-env [build_dir]
  2748. When you use the initialization script, the OpenEmbedded build system
  2749. uses ``build`` as the default :term:`Build Directory` in your current work
  2750. directory. You can use a `build_dir` argument with the script to
  2751. specify a different build directory.
  2752. .. note::
  2753. A common practice is to use a different Build Directory for
  2754. different targets. For example, ``~/build/x86`` for a ``qemux86``
  2755. target, and ``~/build/arm`` for a ``qemuarm`` target.
  2756. 3. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the
  2757. ``conf/local.conf`` configuration file, which is found in the Build
  2758. Directory, is set up how you want it. This file defines many aspects
  2759. of the build environment including the target machine architecture
  2760. through the :term:`MACHINE` variable, the packaging format used during
  2761. the build
  2762. (:term:`PACKAGE_CLASSES`),
  2763. and a centralized tarball download directory through the
  2764. :term:`DL_DIR` variable.
  2765. 4. *Build the Image:* Build the image using the ``bitbake`` command::
  2766. $ bitbake target
  2767. .. note::
  2768. For information on BitBake, see the :doc:`bitbake:index`.
  2769. The target is the name of the recipe you want to build. Common
  2770. targets are the images in ``meta/recipes-core/images``,
  2771. ``meta/recipes-sato/images``, and so forth all found in the
  2772. :term:`Source Directory`. Or, the target
  2773. can be the name of a recipe for a specific piece of software such as
  2774. BusyBox. For more details about the images the OpenEmbedded build
  2775. system supports, see the
  2776. ":ref:`ref-manual/images:Images`" chapter in the Yocto
  2777. Project Reference Manual.
  2778. As an example, the following command builds the
  2779. ``core-image-minimal`` image::
  2780. $ bitbake core-image-minimal
  2781. Once an
  2782. image has been built, it often needs to be installed. The images and
  2783. kernels built by the OpenEmbedded build system are placed in the
  2784. Build Directory in ``tmp/deploy/images``. For information on how to
  2785. run pre-built images such as ``qemux86`` and ``qemuarm``, see the
  2786. :doc:`/sdk-manual/index` manual. For
  2787. information about how to install these images, see the documentation
  2788. for your particular board or machine.
  2789. Building Images for Multiple Targets Using Multiple Configurations
  2790. ------------------------------------------------------------------
  2791. You can use a single ``bitbake`` command to build multiple images or
  2792. packages for different targets where each image or package requires a
  2793. different configuration (multiple configuration builds). The builds, in
  2794. this scenario, are sometimes referred to as "multiconfigs", and this
  2795. section uses that term throughout.
  2796. This section describes how to set up for multiple configuration builds
  2797. and how to account for cross-build dependencies between the
  2798. multiconfigs.
  2799. Setting Up and Running a Multiple Configuration Build
  2800. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2801. To accomplish a multiple configuration build, you must define each
  2802. target's configuration separately using a parallel configuration file in
  2803. the :term:`Build Directory`, and you
  2804. must follow a required file hierarchy. Additionally, you must enable the
  2805. multiple configuration builds in your ``local.conf`` file.
  2806. Follow these steps to set up and execute multiple configuration builds:
  2807. - *Create Separate Configuration Files*: You need to create a single
  2808. configuration file for each build target (each multiconfig).
  2809. Minimally, each configuration file must define the machine and the
  2810. temporary directory BitBake uses for the build. Suggested practice
  2811. dictates that you do not overlap the temporary directories used
  2812. during the builds. However, it is possible that you can share the
  2813. temporary directory
  2814. (:term:`TMPDIR`). For example,
  2815. consider a scenario with two different multiconfigs for the same
  2816. :term:`MACHINE`: "qemux86" built
  2817. for two distributions such as "poky" and "poky-lsb". In this case,
  2818. you might want to use the same :term:`TMPDIR`.
  2819. Here is an example showing the minimal statements needed in a
  2820. configuration file for a "qemux86" target whose temporary build
  2821. directory is ``tmpmultix86``::
  2822. MACHINE = "qemux86"
  2823. TMPDIR = "${TOPDIR}/tmpmultix86"
  2824. The location for these multiconfig configuration files is specific.
  2825. They must reside in the current build directory in a sub-directory of
  2826. ``conf`` named ``multiconfig``. Following is an example that defines
  2827. two configuration files for the "x86" and "arm" multiconfigs:
  2828. .. image:: figures/multiconfig_files.png
  2829. :align: center
  2830. The reason for this required file hierarchy is because the :term:`BBPATH`
  2831. variable is not constructed until the layers are parsed.
  2832. Consequently, using the configuration file as a pre-configuration
  2833. file is not possible unless it is located in the current working
  2834. directory.
  2835. - *Add the BitBake Multi-configuration Variable to the Local
  2836. Configuration File*: Use the
  2837. :term:`BBMULTICONFIG`
  2838. variable in your ``conf/local.conf`` configuration file to specify
  2839. each multiconfig. Continuing with the example from the previous
  2840. figure, the :term:`BBMULTICONFIG` variable needs to enable two
  2841. multiconfigs: "x86" and "arm" by specifying each configuration file::
  2842. BBMULTICONFIG = "x86 arm"
  2843. .. note::
  2844. A "default" configuration already exists by definition. This
  2845. configuration is named: "" (i.e. empty string) and is defined by
  2846. the variables coming from your ``local.conf``
  2847. file. Consequently, the previous example actually adds two
  2848. additional configurations to your build: "arm" and "x86" along
  2849. with "".
  2850. - *Launch BitBake*: Use the following BitBake command form to launch
  2851. the multiple configuration build::
  2852. $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ]
  2853. For the example in this section, the following command applies::
  2854. $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base
  2855. The previous BitBake command builds a ``core-image-minimal`` image
  2856. that is configured through the ``x86.conf`` configuration file, a
  2857. ``core-image-sato`` image that is configured through the ``arm.conf``
  2858. configuration file and a ``core-image-base`` that is configured
  2859. through your ``local.conf`` configuration file.
  2860. .. note::
  2861. Support for multiple configuration builds in the Yocto Project &DISTRO;
  2862. (&DISTRO_NAME;) Release does not include Shared State (sstate)
  2863. optimizations. Consequently, if a build uses the same object twice
  2864. in, for example, two different :term:`TMPDIR`
  2865. directories, the build either loads from an existing sstate cache for
  2866. that build at the start or builds the object fresh.
  2867. Enabling Multiple Configuration Build Dependencies
  2868. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2869. Sometimes dependencies can exist between targets (multiconfigs) in a
  2870. multiple configuration build. For example, suppose that in order to
  2871. build a ``core-image-sato`` image for an "x86" multiconfig, the root
  2872. filesystem of an "arm" multiconfig must exist. This dependency is
  2873. essentially that the
  2874. :ref:`ref-tasks-image` task in the
  2875. ``core-image-sato`` recipe depends on the completion of the
  2876. :ref:`ref-tasks-rootfs` task of the
  2877. ``core-image-minimal`` recipe.
  2878. To enable dependencies in a multiple configuration build, you must
  2879. declare the dependencies in the recipe using the following statement
  2880. form::
  2881. task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend"
  2882. To better show how to use this statement, consider the example scenario
  2883. from the first paragraph of this section. The following statement needs
  2884. to be added to the recipe that builds the ``core-image-sato`` image::
  2885. do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs"
  2886. In this example, the `from_multiconfig` is "x86". The `to_multiconfig` is "arm". The
  2887. task on which the ``do_image`` task in the recipe depends is the
  2888. ``do_rootfs`` task from the ``core-image-minimal`` recipe associated
  2889. with the "arm" multiconfig.
  2890. Once you set up this dependency, you can build the "x86" multiconfig
  2891. using a BitBake command as follows::
  2892. $ bitbake mc:x86:core-image-sato
  2893. This command executes all the tasks needed to create the
  2894. ``core-image-sato`` image for the "x86" multiconfig. Because of the
  2895. dependency, BitBake also executes through the ``do_rootfs`` task for the
  2896. "arm" multiconfig build.
  2897. Having a recipe depend on the root filesystem of another build might not
  2898. seem that useful. Consider this change to the statement in the
  2899. ``core-image-sato`` recipe::
  2900. do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image"
  2901. In this case, BitBake must
  2902. create the ``core-image-minimal`` image for the "arm" build since the
  2903. "x86" build depends on it.
  2904. Because "x86" and "arm" are enabled for multiple configuration builds
  2905. and have separate configuration files, BitBake places the artifacts for
  2906. each build in the respective temporary build directories (i.e.
  2907. :term:`TMPDIR`).
  2908. Building an Initial RAM Filesystem (initramfs) Image
  2909. ----------------------------------------------------
  2910. An initial RAM filesystem (initramfs) image provides a temporary root
  2911. filesystem used for early system initialization (e.g. loading of modules
  2912. needed to locate and mount the "real" root filesystem).
  2913. .. note::
  2914. The initramfs image is the successor of initial RAM disk (initrd). It
  2915. is a "copy in and out" (cpio) archive of the initial filesystem that
  2916. gets loaded into memory during the Linux startup process. Because
  2917. Linux uses the contents of the archive during initialization, the
  2918. initramfs image needs to contain all of the device drivers and tools
  2919. needed to mount the final root filesystem.
  2920. Follow these steps to create an initramfs image:
  2921. 1. *Create the initramfs Image Recipe:* You can reference the
  2922. ``core-image-minimal-initramfs.bb`` recipe found in the
  2923. ``meta/recipes-core`` directory of the :term:`Source Directory`
  2924. as an example
  2925. from which to work.
  2926. 2. *Decide if You Need to Bundle the initramfs Image Into the Kernel
  2927. Image:* If you want the initramfs image that is built to be bundled
  2928. in with the kernel image, set the
  2929. :term:`INITRAMFS_IMAGE_BUNDLE`
  2930. variable to "1" in your ``local.conf`` configuration file and set the
  2931. :term:`INITRAMFS_IMAGE`
  2932. variable in the recipe that builds the kernel image.
  2933. .. note::
  2934. It is recommended that you do bundle the initramfs image with the
  2935. kernel image to avoid circular dependencies between the kernel
  2936. recipe and the initramfs recipe should the initramfs image include
  2937. kernel modules.
  2938. Setting the :term:`INITRAMFS_IMAGE_BUNDLE` flag causes the initramfs
  2939. image to be unpacked into the ``${B}/usr/`` directory. The unpacked
  2940. initramfs image is then passed to the kernel's ``Makefile`` using the
  2941. :term:`CONFIG_INITRAMFS_SOURCE`
  2942. variable, allowing the initramfs image to be built into the kernel
  2943. normally.
  2944. .. note::
  2945. If you choose to not bundle the initramfs image with the kernel
  2946. image, you are essentially using an
  2947. `Initial RAM Disk (initrd) <https://en.wikipedia.org/wiki/Initrd>`__.
  2948. Creating an initrd is handled primarily through the :term:`INITRD_IMAGE`,
  2949. ``INITRD_LIVE``, and ``INITRD_IMAGE_LIVE`` variables. For more
  2950. information, see the :ref:`ref-classes-image-live` file.
  2951. 3. *Optionally Add Items to the initramfs Image Through the initramfs
  2952. Image Recipe:* If you add items to the initramfs image by way of its
  2953. recipe, you should use
  2954. :term:`PACKAGE_INSTALL`
  2955. rather than
  2956. :term:`IMAGE_INSTALL`.
  2957. :term:`PACKAGE_INSTALL` gives more direct control of what is added to the
  2958. image as compared to the defaults you might not necessarily want that
  2959. are set by the :ref:`image <ref-classes-image>`
  2960. or :ref:`core-image <ref-classes-core-image>`
  2961. classes.
  2962. 4. *Build the Kernel Image and the initramfs Image:* Build your kernel
  2963. image using BitBake. Because the initramfs image recipe is a
  2964. dependency of the kernel image, the initramfs image is built as well
  2965. and bundled with the kernel image if you used the
  2966. :term:`INITRAMFS_IMAGE_BUNDLE`
  2967. variable described earlier.
  2968. Building a Tiny System
  2969. ----------------------
  2970. Very small distributions have some significant advantages such as
  2971. requiring less on-die or in-package memory (cheaper), better performance
  2972. through efficient cache usage, lower power requirements due to less
  2973. memory, faster boot times, and reduced development overhead. Some
  2974. real-world examples where a very small distribution gives you distinct
  2975. advantages are digital cameras, medical devices, and small headless
  2976. systems.
  2977. This section presents information that shows you how you can trim your
  2978. distribution to even smaller sizes than the ``poky-tiny`` distribution,
  2979. which is around 5 Mbytes, that can be built out-of-the-box using the
  2980. Yocto Project.
  2981. Tiny System Overview
  2982. ~~~~~~~~~~~~~~~~~~~~
  2983. The following list presents the overall steps you need to consider and
  2984. perform to create distributions with smaller root filesystems, achieve
  2985. faster boot times, maintain your critical functionality, and avoid
  2986. initial RAM disks:
  2987. - :ref:`Determine your goals and guiding principles
  2988. <dev-manual/common-tasks:goals and guiding principles>`
  2989. - :ref:`dev-manual/common-tasks:understand what contributes to your image size`
  2990. - :ref:`Reduce the size of the root filesystem
  2991. <dev-manual/common-tasks:trim the root filesystem>`
  2992. - :ref:`Reduce the size of the kernel <dev-manual/common-tasks:trim the kernel>`
  2993. - :ref:`dev-manual/common-tasks:remove package management requirements`
  2994. - :ref:`dev-manual/common-tasks:look for other ways to minimize size`
  2995. - :ref:`dev-manual/common-tasks:iterate on the process`
  2996. Goals and Guiding Principles
  2997. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2998. Before you can reach your destination, you need to know where you are
  2999. going. Here is an example list that you can use as a guide when creating
  3000. very small distributions:
  3001. - Determine how much space you need (e.g. a kernel that is 1 Mbyte or
  3002. less and a root filesystem that is 3 Mbytes or less).
  3003. - Find the areas that are currently taking 90% of the space and
  3004. concentrate on reducing those areas.
  3005. - Do not create any difficult "hacks" to achieve your goals.
  3006. - Leverage the device-specific options.
  3007. - Work in a separate layer so that you keep changes isolated. For
  3008. information on how to create layers, see the
  3009. ":ref:`dev-manual/common-tasks:understanding and creating layers`" section.
  3010. Understand What Contributes to Your Image Size
  3011. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3012. It is easiest to have something to start with when creating your own
  3013. distribution. You can use the Yocto Project out-of-the-box to create the
  3014. ``poky-tiny`` distribution. Ultimately, you will want to make changes in
  3015. your own distribution that are likely modeled after ``poky-tiny``.
  3016. .. note::
  3017. To use ``poky-tiny`` in your build, set the :term:`DISTRO` variable in your
  3018. ``local.conf`` file to "poky-tiny" as described in the
  3019. ":ref:`dev-manual/common-tasks:creating your own distribution`"
  3020. section.
  3021. Understanding some memory concepts will help you reduce the system size.
  3022. Memory consists of static, dynamic, and temporary memory. Static memory
  3023. is the TEXT (code), DATA (initialized data in the code), and BSS
  3024. (uninitialized data) sections. Dynamic memory represents memory that is
  3025. allocated at runtime: stacks, hash tables, and so forth. Temporary
  3026. memory is recovered after the boot process. This memory consists of
  3027. memory used for decompressing the kernel and for the ``__init__``
  3028. functions.
  3029. To help you see where you currently are with kernel and root filesystem
  3030. sizes, you can use two tools found in the :term:`Source Directory`
  3031. in the
  3032. ``scripts/tiny/`` directory:
  3033. - ``ksize.py``: Reports component sizes for the kernel build objects.
  3034. - ``dirsize.py``: Reports component sizes for the root filesystem.
  3035. This next tool and command help you organize configuration fragments and
  3036. view file dependencies in a human-readable form:
  3037. - ``merge_config.sh``: Helps you manage configuration files and
  3038. fragments within the kernel. With this tool, you can merge individual
  3039. configuration fragments together. The tool allows you to make
  3040. overrides and warns you of any missing configuration options. The
  3041. tool is ideal for allowing you to iterate on configurations, create
  3042. minimal configurations, and create configuration files for different
  3043. machines without having to duplicate your process.
  3044. The ``merge_config.sh`` script is part of the Linux Yocto kernel Git
  3045. repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``,
  3046. ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig``
  3047. directory.
  3048. For more information on configuration fragments, see the
  3049. ":ref:`kernel-dev/common:creating configuration fragments`"
  3050. section in the Yocto Project Linux Kernel Development Manual.
  3051. - ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command
  3052. with these options brings up a Dependency Explorer from which you can
  3053. view file dependencies. Understanding these dependencies allows you
  3054. to make informed decisions when cutting out various pieces of the
  3055. kernel and root filesystem.
  3056. Trim the Root Filesystem
  3057. ~~~~~~~~~~~~~~~~~~~~~~~~
  3058. The root filesystem is made up of packages for booting, libraries, and
  3059. applications. To change things, you can configure how the packaging
  3060. happens, which changes the way you build them. You can also modify the
  3061. filesystem itself or select a different filesystem.
  3062. First, find out what is hogging your root filesystem by running the
  3063. ``dirsize.py`` script from your root directory::
  3064. $ cd root-directory-of-image
  3065. $ dirsize.py 100000 > dirsize-100k.log
  3066. $ cat dirsize-100k.log
  3067. You can apply a filter to the script to ignore files
  3068. under a certain size. The previous example filters out any files below
  3069. 100 Kbytes. The sizes reported by the tool are uncompressed, and thus
  3070. will be smaller by a relatively constant factor in a compressed root
  3071. filesystem. When you examine your log file, you can focus on areas of
  3072. the root filesystem that take up large amounts of memory.
  3073. You need to be sure that what you eliminate does not cripple the
  3074. functionality you need. One way to see how packages relate to each other
  3075. is by using the Dependency Explorer UI with the BitBake command::
  3076. $ cd image-directory
  3077. $ bitbake -u taskexp -g image
  3078. Use the interface to
  3079. select potential packages you wish to eliminate and see their dependency
  3080. relationships.
  3081. When deciding how to reduce the size, get rid of packages that result in
  3082. minimal impact on the feature set. For example, you might not need a VGA
  3083. display. Or, you might be able to get by with ``devtmpfs`` and ``mdev``
  3084. instead of ``udev``.
  3085. Use your ``local.conf`` file to make changes. For example, to eliminate
  3086. ``udev`` and ``glib``, set the following in the local configuration
  3087. file::
  3088. VIRTUAL-RUNTIME_dev_manager = ""
  3089. Finally, you should consider exactly the type of root filesystem you
  3090. need to meet your needs while also reducing its size. For example,
  3091. consider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an
  3092. ``initramfs`` using ``initramfs``. Be aware that ``ext3`` requires a 1
  3093. Mbyte journal. If you are okay with running read-only, you do not need
  3094. this journal.
  3095. .. note::
  3096. After each round of elimination, you need to rebuild your system and
  3097. then use the tools to see the effects of your reductions.
  3098. Trim the Kernel
  3099. ~~~~~~~~~~~~~~~
  3100. The kernel is built by including policies for hardware-independent
  3101. aspects. What subsystems do you enable? For what architecture are you
  3102. building? Which drivers do you build by default?
  3103. .. note::
  3104. You can modify the kernel source if you want to help with boot time.
  3105. Run the ``ksize.py`` script from the top-level Linux build directory to
  3106. get an idea of what is making up the kernel::
  3107. $ cd top-level-linux-build-directory
  3108. $ ksize.py > ksize.log
  3109. $ cat ksize.log
  3110. When you examine the log, you will see how much space is taken up with
  3111. the built-in ``.o`` files for drivers, networking, core kernel files,
  3112. filesystem, sound, and so forth. The sizes reported by the tool are
  3113. uncompressed, and thus will be smaller by a relatively constant factor
  3114. in a compressed kernel image. Look to reduce the areas that are large
  3115. and taking up around the "90% rule."
  3116. To examine, or drill down, into any particular area, use the ``-d``
  3117. option with the script::
  3118. $ ksize.py -d > ksize.log
  3119. Using this option
  3120. breaks out the individual file information for each area of the kernel
  3121. (e.g. drivers, networking, and so forth).
  3122. Use your log file to see what you can eliminate from the kernel based on
  3123. features you can let go. For example, if you are not going to need
  3124. sound, you do not need any drivers that support sound.
  3125. After figuring out what to eliminate, you need to reconfigure the kernel
  3126. to reflect those changes during the next build. You could run
  3127. ``menuconfig`` and make all your changes at once. However, that makes it
  3128. difficult to see the effects of your individual eliminations and also
  3129. makes it difficult to replicate the changes for perhaps another target
  3130. device. A better method is to start with no configurations using
  3131. ``allnoconfig``, create configuration fragments for individual changes,
  3132. and then manage the fragments into a single configuration file using
  3133. ``merge_config.sh``. The tool makes it easy for you to iterate using the
  3134. configuration change and build cycle.
  3135. Each time you make configuration changes, you need to rebuild the kernel
  3136. and check to see what impact your changes had on the overall size.
  3137. Remove Package Management Requirements
  3138. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3139. Packaging requirements add size to the image. One way to reduce the size
  3140. of the image is to remove all the packaging requirements from the image.
  3141. This reduction includes both removing the package manager and its unique
  3142. dependencies as well as removing the package management data itself.
  3143. To eliminate all the packaging requirements for an image, be sure that
  3144. "package-management" is not part of your
  3145. :term:`IMAGE_FEATURES`
  3146. statement for the image. When you remove this feature, you are removing
  3147. the package manager as well as its dependencies from the root
  3148. filesystem.
  3149. Look for Other Ways to Minimize Size
  3150. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3151. Depending on your particular circumstances, other areas that you can
  3152. trim likely exist. The key to finding these areas is through tools and
  3153. methods described here combined with experimentation and iteration. Here
  3154. are a couple of areas to experiment with:
  3155. - ``glibc``: In general, follow this process:
  3156. 1. Remove ``glibc`` features from
  3157. :term:`DISTRO_FEATURES`
  3158. that you think you do not need.
  3159. 2. Build your distribution.
  3160. 3. If the build fails due to missing symbols in a package, determine
  3161. if you can reconfigure the package to not need those features. For
  3162. example, change the configuration to not support wide character
  3163. support as is done for ``ncurses``. Or, if support for those
  3164. characters is needed, determine what ``glibc`` features provide
  3165. the support and restore the configuration.
  3166. 4. Rebuild and repeat the process.
  3167. - ``busybox``: For BusyBox, use a process similar as described for
  3168. ``glibc``. A difference is you will need to boot the resulting system
  3169. to see if you are able to do everything you expect from the running
  3170. system. You need to be sure to integrate configuration fragments into
  3171. Busybox because BusyBox handles its own core features and then allows
  3172. you to add configuration fragments on top.
  3173. Iterate on the Process
  3174. ~~~~~~~~~~~~~~~~~~~~~~
  3175. If you have not reached your goals on system size, you need to iterate
  3176. on the process. The process is the same. Use the tools and see just what
  3177. is taking up 90% of the root filesystem and the kernel. Decide what you
  3178. can eliminate without limiting your device beyond what you need.
  3179. Depending on your system, a good place to look might be Busybox, which
  3180. provides a stripped down version of Unix tools in a single, executable
  3181. file. You might be able to drop virtual terminal services or perhaps
  3182. ipv6.
  3183. Building Images for More than One Machine
  3184. -----------------------------------------
  3185. A common scenario developers face is creating images for several
  3186. different machines that use the same software environment. In this
  3187. situation, it is tempting to set the tunings and optimization flags for
  3188. each build specifically for the targeted hardware (i.e. "maxing out" the
  3189. tunings). Doing so can considerably add to build times and package feed
  3190. maintenance collectively for the machines. For example, selecting tunes
  3191. that are extremely specific to a CPU core used in a system might enable
  3192. some micro optimizations in GCC for that particular system but would
  3193. otherwise not gain you much of a performance difference across the other
  3194. systems as compared to using a more general tuning across all the builds
  3195. (e.g. setting :term:`DEFAULTTUNE`
  3196. specifically for each machine's build). Rather than "max out" each
  3197. build's tunings, you can take steps that cause the OpenEmbedded build
  3198. system to reuse software across the various machines where it makes
  3199. sense.
  3200. If build speed and package feed maintenance are considerations, you
  3201. should consider the points in this section that can help you optimize
  3202. your tunings to best consider build times and package feed maintenance.
  3203. - *Share the Build Directory:* If at all possible, share the
  3204. :term:`TMPDIR` across builds. The
  3205. Yocto Project supports switching between different
  3206. :term:`MACHINE` values in the same
  3207. :term:`TMPDIR`. This practice is well supported and regularly used by
  3208. developers when building for multiple machines. When you use the same
  3209. :term:`TMPDIR` for multiple machine builds, the OpenEmbedded build system
  3210. can reuse the existing native and often cross-recipes for multiple
  3211. machines. Thus, build time decreases.
  3212. .. note::
  3213. If :term:`DISTRO` settings change or fundamental configuration settings
  3214. such as the filesystem layout, you need to work with a clean :term:`TMPDIR`.
  3215. Sharing :term:`TMPDIR` under these circumstances might work but since it is
  3216. not guaranteed, you should use a clean :term:`TMPDIR`.
  3217. - *Enable the Appropriate Package Architecture:* By default, the
  3218. OpenEmbedded build system enables three levels of package
  3219. architectures: "all", "tune" or "package", and "machine". Any given
  3220. recipe usually selects one of these package architectures (types) for
  3221. its output. Depending for what a given recipe creates packages,
  3222. making sure you enable the appropriate package architecture can
  3223. directly impact the build time.
  3224. A recipe that just generates scripts can enable "all" architecture
  3225. because there are no binaries to build. To specifically enable "all"
  3226. architecture, be sure your recipe inherits the
  3227. :ref:`allarch <ref-classes-allarch>` class.
  3228. This class is useful for "all" architectures because it configures
  3229. many variables so packages can be used across multiple architectures.
  3230. If your recipe needs to generate packages that are machine-specific
  3231. or when one of the build or runtime dependencies is already
  3232. machine-architecture dependent, which makes your recipe also
  3233. machine-architecture dependent, make sure your recipe enables the
  3234. "machine" package architecture through the
  3235. :term:`MACHINE_ARCH`
  3236. variable::
  3237. PACKAGE_ARCH = "${MACHINE_ARCH}"
  3238. When you do not
  3239. specifically enable a package architecture through the
  3240. :term:`PACKAGE_ARCH`, The
  3241. OpenEmbedded build system defaults to the
  3242. :term:`TUNE_PKGARCH` setting::
  3243. PACKAGE_ARCH = "${TUNE_PKGARCH}"
  3244. - *Choose a Generic Tuning File if Possible:* Some tunes are more
  3245. generic and can run on multiple targets (e.g. an ``armv5`` set of
  3246. packages could run on ``armv6`` and ``armv7`` processors in most
  3247. cases). Similarly, ``i486`` binaries could work on ``i586`` and
  3248. higher processors. You should realize, however, that advances on
  3249. newer processor versions would not be used.
  3250. If you select the same tune for several different machines, the
  3251. OpenEmbedded build system reuses software previously built, thus
  3252. speeding up the overall build time. Realize that even though a new
  3253. sysroot for each machine is generated, the software is not recompiled
  3254. and only one package feed exists.
  3255. - *Manage Granular Level Packaging:* Sometimes there are cases where
  3256. injecting another level of package architecture beyond the three
  3257. higher levels noted earlier can be useful. For example, consider how
  3258. NXP (formerly Freescale) allows for the easy reuse of binary packages
  3259. in their layer
  3260. :yocto_git:`meta-freescale </meta-freescale/>`.
  3261. In this example, the
  3262. :yocto_git:`fsl-dynamic-packagearch </meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass>`
  3263. class shares GPU packages for i.MX53 boards because all boards share
  3264. the AMD GPU. The i.MX6-based boards can do the same because all
  3265. boards share the Vivante GPU. This class inspects the BitBake
  3266. datastore to identify if the package provides or depends on one of
  3267. the sub-architecture values. If so, the class sets the
  3268. :term:`PACKAGE_ARCH` value
  3269. based on the ``MACHINE_SUBARCH`` value. If the package does not
  3270. provide or depend on one of the sub-architecture values but it
  3271. matches a value in the machine-specific filter, it sets
  3272. :term:`MACHINE_ARCH`. This
  3273. behavior reduces the number of packages built and saves build time by
  3274. reusing binaries.
  3275. - *Use Tools to Debug Issues:* Sometimes you can run into situations
  3276. where software is being rebuilt when you think it should not be. For
  3277. example, the OpenEmbedded build system might not be using shared
  3278. state between machines when you think it should be. These types of
  3279. situations are usually due to references to machine-specific
  3280. variables such as :term:`MACHINE`,
  3281. :term:`SERIAL_CONSOLES`,
  3282. :term:`XSERVER`,
  3283. :term:`MACHINE_FEATURES`,
  3284. and so forth in code that is supposed to only be tune-specific or
  3285. when the recipe depends
  3286. (:term:`DEPENDS`,
  3287. :term:`RDEPENDS`,
  3288. :term:`RRECOMMENDS`,
  3289. :term:`RSUGGESTS`, and so forth)
  3290. on some other recipe that already has
  3291. :term:`PACKAGE_ARCH` defined
  3292. as "${MACHINE_ARCH}".
  3293. .. note::
  3294. Patches to fix any issues identified are most welcome as these
  3295. issues occasionally do occur.
  3296. For such cases, you can use some tools to help you sort out the
  3297. situation:
  3298. - ``state-diff-machines.sh``*:* You can find this tool in the
  3299. ``scripts`` directory of the Source Repositories. See the comments
  3300. in the script for information on how to use the tool.
  3301. - *BitBake's "-S printdiff" Option:* Using this option causes
  3302. BitBake to try to establish the closest signature match it can
  3303. (e.g. in the shared state cache) and then run ``bitbake-diffsigs``
  3304. over the matches to determine the stamps and delta where these two
  3305. stamp trees diverge.
  3306. Building Software from an External Source
  3307. -----------------------------------------
  3308. By default, the OpenEmbedded build system uses the
  3309. :term:`Build Directory` when building source
  3310. code. The build process involves fetching the source files, unpacking
  3311. them, and then patching them if necessary before the build takes place.
  3312. There are situations where you might want to build software from source
  3313. files that are external to and thus outside of the OpenEmbedded build
  3314. system. For example, suppose you have a project that includes a new BSP
  3315. with a heavily customized kernel. And, you want to minimize exposing the
  3316. build system to the development team so that they can focus on their
  3317. project and maintain everyone's workflow as much as possible. In this
  3318. case, you want a kernel source directory on the development machine
  3319. where the development occurs. You want the recipe's
  3320. :term:`SRC_URI` variable to point to
  3321. the external directory and use it as is, not copy it.
  3322. To build from software that comes from an external source, all you need
  3323. to do is inherit the
  3324. :ref:`externalsrc <ref-classes-externalsrc>` class
  3325. and then set the
  3326. :term:`EXTERNALSRC` variable to
  3327. point to your external source code. Here are the statements to put in
  3328. your ``local.conf`` file::
  3329. INHERIT += "externalsrc"
  3330. EXTERNALSRC_pn-myrecipe = "path-to-your-source-tree"
  3331. This next example shows how to accomplish the same thing by setting
  3332. :term:`EXTERNALSRC` in the recipe itself or in the recipe's append file::
  3333. EXTERNALSRC = "path"
  3334. EXTERNALSRC_BUILD = "path"
  3335. .. note::
  3336. In order for these settings to take effect, you must globally or
  3337. locally inherit the :ref:`externalsrc <ref-classes-externalsrc>`
  3338. class.
  3339. By default, ``externalsrc.bbclass`` builds the source code in a
  3340. directory separate from the external source directory as specified by
  3341. :term:`EXTERNALSRC`. If you need
  3342. to have the source built in the same directory in which it resides, or
  3343. some other nominated directory, you can set
  3344. :term:`EXTERNALSRC_BUILD`
  3345. to point to that directory::
  3346. EXTERNALSRC_BUILD_pn-myrecipe = "path-to-your-source-tree"
  3347. Replicating a Build Offline
  3348. ---------------------------
  3349. It can be useful to take a "snapshot" of upstream sources used in a
  3350. build and then use that "snapshot" later to replicate the build offline.
  3351. To do so, you need to first prepare and populate your downloads
  3352. directory your "snapshot" of files. Once your downloads directory is
  3353. ready, you can use it at any time and from any machine to replicate your
  3354. build.
  3355. Follow these steps to populate your Downloads directory:
  3356. 1. *Create a Clean Downloads Directory:* Start with an empty downloads
  3357. directory (:term:`DL_DIR`). You
  3358. start with an empty downloads directory by either removing the files
  3359. in the existing directory or by setting :term:`DL_DIR` to point to either
  3360. an empty location or one that does not yet exist.
  3361. 2. *Generate Tarballs of the Source Git Repositories:* Edit your
  3362. ``local.conf`` configuration file as follows::
  3363. DL_DIR = "/home/your-download-dir/"
  3364. BB_GENERATE_MIRROR_TARBALLS = "1"
  3365. During
  3366. the fetch process in the next step, BitBake gathers the source files
  3367. and creates tarballs in the directory pointed to by :term:`DL_DIR`. See
  3368. the
  3369. :term:`BB_GENERATE_MIRROR_TARBALLS`
  3370. variable for more information.
  3371. 3. *Populate Your Downloads Directory Without Building:* Use BitBake to
  3372. fetch your sources but inhibit the build::
  3373. $ bitbake target --runonly=fetch
  3374. The downloads directory (i.e. ``${DL_DIR}``) now has
  3375. a "snapshot" of the source files in the form of tarballs, which can
  3376. be used for the build.
  3377. 4. *Optionally Remove Any Git or other SCM Subdirectories From the
  3378. Downloads Directory:* If you want, you can clean up your downloads
  3379. directory by removing any Git or other Source Control Management
  3380. (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs
  3381. already contain these subdirectories.
  3382. Once your downloads directory has everything it needs regarding source
  3383. files, you can create your "own-mirror" and build your target.
  3384. Understand that you can use the files to build the target offline from
  3385. any machine and at any time.
  3386. Follow these steps to build your target using the files in the downloads
  3387. directory:
  3388. 1. *Using Local Files Only:* Inside your ``local.conf`` file, add the
  3389. :term:`SOURCE_MIRROR_URL`
  3390. variable, inherit the
  3391. :ref:`own-mirrors <ref-classes-own-mirrors>`
  3392. class, and use the
  3393. :term:`bitbake:BB_NO_NETWORK`
  3394. variable to your ``local.conf``.
  3395. ::
  3396. SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/"
  3397. INHERIT += "own-mirrors"
  3398. BB_NO_NETWORK = "1"
  3399. The :term:`SOURCE_MIRROR_URL` and ``own-mirror``
  3400. class set up the system to use the downloads directory as your "own
  3401. mirror". Using the :term:`BB_NO_NETWORK` variable makes sure that
  3402. BitBake's fetching process in step 3 stays local, which means files
  3403. from your "own-mirror" are used.
  3404. 2. *Start With a Clean Build:* You can start with a clean build by
  3405. removing the
  3406. ``${``\ :term:`TMPDIR`\ ``}``
  3407. directory or using a new :term:`Build Directory`.
  3408. 3. *Build Your Target:* Use BitBake to build your target::
  3409. $ bitbake target
  3410. The build completes using the known local "snapshot" of source
  3411. files from your mirror. The resulting tarballs for your "snapshot" of
  3412. source files are in the downloads directory.
  3413. .. note::
  3414. The offline build does not work if recipes attempt to find the
  3415. latest version of software by setting
  3416. :term:`SRCREV` to
  3417. ``${``\ :term:`AUTOREV`\ ``}``::
  3418. SRCREV = "${AUTOREV}"
  3419. When a recipe sets :term:`SRCREV` to
  3420. ``${AUTOREV}``, the build system accesses the network in an
  3421. attempt to determine the latest version of software from the SCM.
  3422. Typically, recipes that use :term:`AUTOREV` are custom or modified
  3423. recipes. Recipes that reside in public repositories usually do not
  3424. use :term:`AUTOREV`.
  3425. If you do have recipes that use :term:`AUTOREV`, you can take steps to
  3426. still use the recipes in an offline build. Do the following:
  3427. 1. Use a configuration generated by enabling :ref:`build
  3428. history <dev-manual/common-tasks:maintaining build output quality>`.
  3429. 2. Use the ``buildhistory-collect-srcrevs`` command to collect the
  3430. stored :term:`SRCREV` values from the build's history. For more
  3431. information on collecting these values, see the
  3432. ":ref:`dev-manual/common-tasks:build history package information`"
  3433. section.
  3434. 3. Once you have the correct source revisions, you can modify
  3435. those recipes to set :term:`SRCREV` to specific versions of the
  3436. software.
  3437. Speeding Up a Build
  3438. ===================
  3439. Build time can be an issue. By default, the build system uses simple
  3440. controls to try and maximize build efficiency. In general, the default
  3441. settings for all the following variables result in the most efficient
  3442. build times when dealing with single socket systems (i.e. a single CPU).
  3443. If you have multiple CPUs, you might try increasing the default values
  3444. to gain more speed. See the descriptions in the glossary for each
  3445. variable for more information:
  3446. - :term:`BB_NUMBER_THREADS`:
  3447. The maximum number of threads BitBake simultaneously executes.
  3448. - :term:`bitbake:BB_NUMBER_PARSE_THREADS`:
  3449. The number of threads BitBake uses during parsing.
  3450. - :term:`PARALLEL_MAKE`: Extra
  3451. options passed to the ``make`` command during the
  3452. :ref:`ref-tasks-compile` task in
  3453. order to specify parallel compilation on the local build host.
  3454. - :term:`PARALLEL_MAKEINST`:
  3455. Extra options passed to the ``make`` command during the
  3456. :ref:`ref-tasks-install` task in
  3457. order to specify parallel installation on the local build host.
  3458. As mentioned, these variables all scale to the number of processor cores
  3459. available on the build system. For single socket systems, this
  3460. auto-scaling ensures that the build system fundamentally takes advantage
  3461. of potential parallel operations during the build based on the build
  3462. machine's capabilities.
  3463. Following are additional factors that can affect build speed:
  3464. - File system type: The file system type that the build is being
  3465. performed on can also influence performance. Using ``ext4`` is
  3466. recommended as compared to ``ext2`` and ``ext3`` due to ``ext4``
  3467. improved features such as extents.
  3468. - Disabling the updating of access time using ``noatime``: The
  3469. ``noatime`` mount option prevents the build system from updating file
  3470. and directory access times.
  3471. - Setting a longer commit: Using the "commit=" mount option increases
  3472. the interval in seconds between disk cache writes. Changing this
  3473. interval from the five second default to something longer increases
  3474. the risk of data loss but decreases the need to write to the disk,
  3475. thus increasing the build performance.
  3476. - Choosing the packaging backend: Of the available packaging backends,
  3477. IPK is the fastest. Additionally, selecting a singular packaging
  3478. backend also helps.
  3479. - Using ``tmpfs`` for :term:`TMPDIR`
  3480. as a temporary file system: While this can help speed up the build,
  3481. the benefits are limited due to the compiler using ``-pipe``. The
  3482. build system goes to some lengths to avoid ``sync()`` calls into the
  3483. file system on the principle that if there was a significant failure,
  3484. the :term:`Build Directory`
  3485. contents could easily be rebuilt.
  3486. - Inheriting the
  3487. :ref:`rm_work <ref-classes-rm-work>` class:
  3488. Inheriting this class has shown to speed up builds due to
  3489. significantly lower amounts of data stored in the data cache as well
  3490. as on disk. Inheriting this class also makes cleanup of
  3491. :term:`TMPDIR` faster, at the
  3492. expense of being easily able to dive into the source code. File
  3493. system maintainers have recommended that the fastest way to clean up
  3494. large numbers of files is to reformat partitions rather than delete
  3495. files due to the linear nature of partitions. This, of course,
  3496. assumes you structure the disk partitions and file systems in a way
  3497. that this is practical.
  3498. Aside from the previous list, you should keep some trade offs in mind
  3499. that can help you speed up the build:
  3500. - Remove items from
  3501. :term:`DISTRO_FEATURES`
  3502. that you might not need.
  3503. - Exclude debug symbols and other debug information: If you do not need
  3504. these symbols and other debug information, disabling the ``*-dbg``
  3505. package generation can speed up the build. You can disable this
  3506. generation by setting the
  3507. :term:`INHIBIT_PACKAGE_DEBUG_SPLIT`
  3508. variable to "1".
  3509. - Disable static library generation for recipes derived from
  3510. ``autoconf`` or ``libtool``: Following is an example showing how to
  3511. disable static libraries and still provide an override to handle
  3512. exceptions::
  3513. STATICLIBCONF = "--disable-static"
  3514. STATICLIBCONF_sqlite3-native = ""
  3515. EXTRA_OECONF += "${STATICLIBCONF}"
  3516. .. note::
  3517. - Some recipes need static libraries in order to work correctly
  3518. (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides,
  3519. as in the previous example, account for these kinds of
  3520. exceptions.
  3521. - Some packages have packaging code that assumes the presence of
  3522. the static libraries. If so, you might need to exclude them as
  3523. well.
  3524. Working With Libraries
  3525. ======================
  3526. Libraries are an integral part of your system. This section describes
  3527. some common practices you might find helpful when working with libraries
  3528. to build your system:
  3529. - :ref:`How to include static library files
  3530. <dev-manual/common-tasks:including static library files>`
  3531. - :ref:`How to use the Multilib feature to combine multiple versions of
  3532. library files into a single image
  3533. <dev-manual/common-tasks:combining multiple versions of library files into one image>`
  3534. - :ref:`How to install multiple versions of the same library in parallel on
  3535. the same system
  3536. <dev-manual/common-tasks:installing multiple versions of the same library>`
  3537. Including Static Library Files
  3538. ------------------------------
  3539. If you are building a library and the library offers static linking, you
  3540. can control which static library files (``*.a`` files) get included in
  3541. the built library.
  3542. The :term:`PACKAGES` and
  3543. :term:`FILES_* <FILES>` variables in the
  3544. ``meta/conf/bitbake.conf`` configuration file define how files installed
  3545. by the ``do_install`` task are packaged. By default, the :term:`PACKAGES`
  3546. variable includes ``${PN}-staticdev``, which represents all static
  3547. library files.
  3548. .. note::
  3549. Some previously released versions of the Yocto Project defined the
  3550. static library files through ``${PN}-dev``.
  3551. Following is part of the BitBake configuration file, where you can see
  3552. how the static library files are defined::
  3553. PACKAGE_BEFORE_PN ?= ""
  3554. PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
  3555. PACKAGES_DYNAMIC = "^${PN}-locale-.*"
  3556. FILES = ""
  3557. FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
  3558. ${sysconfdir} ${sharedstatedir} ${localstatedir} \
  3559. ${base_bindir}/* ${base_sbindir}/* \
  3560. ${base_libdir}/*${SOLIBS} \
  3561. ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
  3562. ${datadir}/${BPN} ${libdir}/${BPN}/* \
  3563. ${datadir}/pixmaps ${datadir}/applications \
  3564. ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
  3565. ${libdir}/bonobo/servers"
  3566. FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
  3567. FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
  3568. ${datadir}/gnome/help"
  3569. SECTION_${PN}-doc = "doc"
  3570. FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
  3571. FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
  3572. ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
  3573. ${datadir}/aclocal ${base_libdir}/*.o \
  3574. ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
  3575. SECTION_${PN}-dev = "devel"
  3576. ALLOW_EMPTY_${PN}-dev = "1"
  3577. RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
  3578. FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
  3579. SECTION_${PN}-staticdev = "devel"
  3580. RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
  3581. Combining Multiple Versions of Library Files into One Image
  3582. -----------------------------------------------------------
  3583. The build system offers the ability to build libraries with different
  3584. target optimizations or architecture formats and combine these together
  3585. into one system image. You can link different binaries in the image
  3586. against the different libraries as needed for specific use cases. This
  3587. feature is called "Multilib".
  3588. An example would be where you have most of a system compiled in 32-bit
  3589. mode using 32-bit libraries, but you have something large, like a
  3590. database engine, that needs to be a 64-bit application and uses 64-bit
  3591. libraries. Multilib allows you to get the best of both 32-bit and 64-bit
  3592. libraries.
  3593. While the Multilib feature is most commonly used for 32 and 64-bit
  3594. differences, the approach the build system uses facilitates different
  3595. target optimizations. You could compile some binaries to use one set of
  3596. libraries and other binaries to use a different set of libraries. The
  3597. libraries could differ in architecture, compiler options, or other
  3598. optimizations.
  3599. There are several examples in the ``meta-skeleton`` layer found in the
  3600. :term:`Source Directory`:
  3601. - ``conf/multilib-example.conf`` configuration file
  3602. - ``conf/multilib-example2.conf`` configuration file
  3603. - ``recipes-multilib/images/core-image-multilib-example.bb`` recipe
  3604. Preparing to Use Multilib
  3605. ~~~~~~~~~~~~~~~~~~~~~~~~~
  3606. User-specific requirements drive the Multilib feature. Consequently,
  3607. there is no one "out-of-the-box" configuration that would
  3608. meet your needs.
  3609. In order to enable Multilib, you first need to ensure your recipe is
  3610. extended to support multiple libraries. Many standard recipes are
  3611. already extended and support multiple libraries. You can check in the
  3612. ``meta/conf/multilib.conf`` configuration file in the
  3613. :term:`Source Directory` to see how this is
  3614. done using the
  3615. :term:`BBCLASSEXTEND` variable.
  3616. Eventually, all recipes will be covered and this list will not be
  3617. needed.
  3618. For the most part, the Multilib class extension works automatically to
  3619. extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where
  3620. :term:`MLPREFIX` is the particular multilib (e.g. "lib32-" or "lib64-").
  3621. Standard variables such as
  3622. :term:`DEPENDS`,
  3623. :term:`RDEPENDS`,
  3624. :term:`RPROVIDES`,
  3625. :term:`RRECOMMENDS`,
  3626. :term:`PACKAGES`, and
  3627. :term:`PACKAGES_DYNAMIC` are
  3628. automatically extended by the system. If you are extending any manual
  3629. code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure
  3630. those names are extended correctly. This automatic extension code
  3631. resides in ``multilib.bbclass``.
  3632. Using Multilib
  3633. ~~~~~~~~~~~~~~
  3634. After you have set up the recipes, you need to define the actual
  3635. combination of multiple libraries you want to build. You accomplish this
  3636. through your ``local.conf`` configuration file in the
  3637. :term:`Build Directory`. An example
  3638. configuration would be as follows::
  3639. MACHINE = "qemux86-64"
  3640. require conf/multilib.conf
  3641. MULTILIBS = "multilib:lib32"
  3642. DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
  3643. IMAGE_INSTALL_append = "lib32-glib-2.0"
  3644. This example enables an additional library named
  3645. ``lib32`` alongside the normal target packages. When combining these
  3646. "lib32" alternatives, the example uses "x86" for tuning. For information
  3647. on this particular tuning, see
  3648. ``meta/conf/machine/include/ia32/arch-ia32.inc``.
  3649. The example then includes ``lib32-glib-2.0`` in all the images, which
  3650. illustrates one method of including a multiple library dependency. You
  3651. can use a normal image build to include this dependency, for example::
  3652. $ bitbake core-image-sato
  3653. You can also build Multilib packages
  3654. specifically with a command like this::
  3655. $ bitbake lib32-glib-2.0
  3656. Additional Implementation Details
  3657. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3658. There are generic implementation details as well as details that are specific to
  3659. package management systems. Following are implementation details
  3660. that exist regardless of the package management system:
  3661. - The typical convention used for the class extension code as used by
  3662. Multilib assumes that all package names specified in
  3663. :term:`PACKAGES` that contain
  3664. ``${PN}`` have ``${PN}`` at the start of the name. When that
  3665. convention is not followed and ``${PN}`` appears at the middle or the
  3666. end of a name, problems occur.
  3667. - The :term:`TARGET_VENDOR`
  3668. value under Multilib will be extended to "-vendormlmultilib" (e.g.
  3669. "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this
  3670. slightly unwieldy contraction is that any "-" characters in the
  3671. vendor string presently break Autoconf's ``config.sub``, and other
  3672. separators are problematic for different reasons.
  3673. Here are the implementation details for the RPM Package Management System:
  3674. - A unique architecture is defined for the Multilib packages, along
  3675. with creating a unique deploy folder under ``tmp/deploy/rpm`` in the
  3676. :term:`Build Directory`. For
  3677. example, consider ``lib32`` in a ``qemux86-64`` image. The possible
  3678. architectures in the system are "all", "qemux86_64",
  3679. "lib32_qemux86_64", and "lib32_x86".
  3680. - The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM
  3681. packaging. The naming for a normal RPM package and a Multilib RPM
  3682. package in a ``qemux86-64`` system resolves to something similar to
  3683. ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``,
  3684. respectively.
  3685. - When installing a Multilib image, the RPM backend first installs the
  3686. base image and then installs the Multilib libraries.
  3687. - The build system relies on RPM to resolve the identical files in the
  3688. two (or more) Multilib packages.
  3689. Here are the implementation details for the IPK Package Management System:
  3690. - The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK
  3691. packaging. The naming for a normal RPM package and a Multilib IPK
  3692. package in a ``qemux86-64`` system resolves to something like
  3693. ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw_x86.ipk``,
  3694. respectively.
  3695. - The IPK deploy folder is not modified with ``${MLPREFIX}`` because
  3696. packages with and without the Multilib feature can exist in the same
  3697. folder due to the ``${PN}`` differences.
  3698. - IPK defines a sanity check for Multilib installation using certain
  3699. rules for file comparison, overridden, etc.
  3700. Installing Multiple Versions of the Same Library
  3701. ------------------------------------------------
  3702. There are be situations where you need to install and use multiple versions
  3703. of the same library on the same system at the same time. This
  3704. almost always happens when a library API changes and you have
  3705. multiple pieces of software that depend on the separate versions of the
  3706. library. To accommodate these situations, you can install multiple
  3707. versions of the same library in parallel on the same system.
  3708. The process is straightforward as long as the libraries use proper
  3709. versioning. With properly versioned libraries, all you need to do to
  3710. individually specify the libraries is create separate, appropriately
  3711. named recipes where the :term:`PN` part of
  3712. the name includes a portion that differentiates each library version
  3713. (e.g. the major part of the version number). Thus, instead of having a
  3714. single recipe that loads one version of a library (e.g. ``clutter``),
  3715. you provide multiple recipes that result in different versions of the
  3716. libraries you want. As an example, the following two recipes would allow
  3717. the two separate versions of the ``clutter`` library to co-exist on the
  3718. same system:
  3719. .. code-block:: none
  3720. clutter-1.6_1.6.20.bb
  3721. clutter-1.8_1.8.4.bb
  3722. Additionally, if
  3723. you have other recipes that depend on a given library, you need to use
  3724. the :term:`DEPENDS` variable to
  3725. create the dependency. Continuing with the same example, if you want to
  3726. have a recipe depend on the 1.8 version of the ``clutter`` library, use
  3727. the following in your recipe::
  3728. DEPENDS = "clutter-1.8"
  3729. Using x32 psABI
  3730. ===============
  3731. x32 processor-specific Application Binary Interface (`x32
  3732. psABI <https://software.intel.com/en-us/node/628948>`__) is a native
  3733. 32-bit processor-specific ABI for Intel 64 (x86-64) architectures. An
  3734. ABI defines the calling conventions between functions in a processing
  3735. environment. The interface determines what registers are used and what
  3736. the sizes are for various C data types.
  3737. Some processing environments prefer using 32-bit applications even when
  3738. running on Intel 64-bit platforms. Consider the i386 psABI, which is a
  3739. very old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not
  3740. provide efficient use and access of the Intel 64-bit processor
  3741. resources, leaving the system underutilized. Now consider the x86_64
  3742. psABI. This ABI is newer and uses 64-bits for data sizes and program
  3743. pointers. The extra bits increase the footprint size of the programs,
  3744. libraries, and also increases the memory and file system size
  3745. requirements. Executing under the x32 psABI enables user programs to
  3746. utilize CPU and system resources more efficiently while keeping the
  3747. memory footprint of the applications low. Extra bits are used for
  3748. registers but not for addressing mechanisms.
  3749. The Yocto Project supports the final specifications of x32 psABI as
  3750. follows:
  3751. - You can create packages and images in x32 psABI format on x86_64
  3752. architecture targets.
  3753. - You can successfully build recipes with the x32 toolchain.
  3754. - You can create and boot ``core-image-minimal`` and
  3755. ``core-image-sato`` images.
  3756. - There is RPM Package Manager (RPM) support for x32 binaries.
  3757. - There is support for large images.
  3758. To use the x32 psABI, you need to edit your ``conf/local.conf``
  3759. configuration file as follows::
  3760. MACHINE = "qemux86-64"
  3761. DEFAULTTUNE = "x86-64-x32"
  3762. baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \
  3763. or 'INVALID')) or 'lib'}"
  3764. Once you have set
  3765. up your configuration file, use BitBake to build an image that supports
  3766. the x32 psABI. Here is an example::
  3767. $ bitbake core-image-sato
  3768. Enabling GObject Introspection Support
  3769. ======================================
  3770. `GObject
  3771. introspection <https://wiki.gnome.org/Projects/GObjectIntrospection>`__
  3772. is the standard mechanism for accessing GObject-based software from
  3773. runtime environments. GObject is a feature of the GLib library that
  3774. provides an object framework for the GNOME desktop and related software.
  3775. GObject Introspection adds information to GObject that allows objects
  3776. created within it to be represented across different programming
  3777. languages. If you want to construct GStreamer pipelines using Python, or
  3778. control UPnP infrastructure using Javascript and GUPnP, GObject
  3779. introspection is the only way to do it.
  3780. This section describes the Yocto Project support for generating and
  3781. packaging GObject introspection data. GObject introspection data is a
  3782. description of the API provided by libraries built on top of GLib
  3783. framework, and, in particular, that framework's GObject mechanism.
  3784. GObject Introspection Repository (GIR) files go to ``-dev`` packages,
  3785. ``typelib`` files go to main packages as they are packaged together with
  3786. libraries that are introspected.
  3787. The data is generated when building such a library, by linking the
  3788. library with a small executable binary that asks the library to describe
  3789. itself, and then executing the binary and processing its output.
  3790. Generating this data in a cross-compilation environment is difficult
  3791. because the library is produced for the target architecture, but its
  3792. code needs to be executed on the build host. This problem is solved with
  3793. the OpenEmbedded build system by running the code through QEMU, which
  3794. allows precisely that. Unfortunately, QEMU does not always work
  3795. perfectly as mentioned in the ":ref:`dev-manual/common-tasks:known issues`"
  3796. section.
  3797. Enabling the Generation of Introspection Data
  3798. ---------------------------------------------
  3799. Enabling the generation of introspection data (GIR files) in your
  3800. library package involves the following:
  3801. 1. Inherit the
  3802. :ref:`gobject-introspection <ref-classes-gobject-introspection>`
  3803. class.
  3804. 2. Make sure introspection is not disabled anywhere in the recipe or
  3805. from anything the recipe includes. Also, make sure that
  3806. "gobject-introspection-data" is not in
  3807. :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
  3808. and that "qemu-usermode" is not in
  3809. :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
  3810. In either of these conditions, nothing will happen.
  3811. 3. Try to build the recipe. If you encounter build errors that look like
  3812. something is unable to find ``.so`` libraries, check where these
  3813. libraries are located in the source tree and add the following to the
  3814. recipe::
  3815. GIR_EXTRA_LIBS_PATH = "${B}/something/.libs"
  3816. .. note::
  3817. See recipes in the ``oe-core`` repository that use that
  3818. ``GIR_EXTRA_LIBS_PATH`` variable as an example.
  3819. 4. Look for any other errors, which probably mean that introspection
  3820. support in a package is not entirely standard, and thus breaks down
  3821. in a cross-compilation environment. For such cases, custom-made fixes
  3822. are needed. A good place to ask and receive help in these cases is
  3823. the :ref:`Yocto Project mailing
  3824. lists <resources-mailinglist>`.
  3825. .. note::
  3826. Using a library that no longer builds against the latest Yocto
  3827. Project release and prints introspection related errors is a good
  3828. candidate for the previous procedure.
  3829. Disabling the Generation of Introspection Data
  3830. ----------------------------------------------
  3831. You might find that you do not want to generate introspection data. Or,
  3832. perhaps QEMU does not work on your build host and target architecture
  3833. combination. If so, you can use either of the following methods to
  3834. disable GIR file generations:
  3835. - Add the following to your distro configuration::
  3836. DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
  3837. Adding this statement disables generating introspection data using
  3838. QEMU but will still enable building introspection tools and libraries
  3839. (i.e. building them does not require the use of QEMU).
  3840. - Add the following to your machine configuration::
  3841. MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
  3842. Adding this statement disables the use of QEMU when building packages for your
  3843. machine. Currently, this feature is used only by introspection
  3844. recipes and has the same effect as the previously described option.
  3845. .. note::
  3846. Future releases of the Yocto Project might have other features
  3847. affected by this option.
  3848. If you disable introspection data, you can still obtain it through other
  3849. means such as copying the data from a suitable sysroot, or by generating
  3850. it on the target hardware. The OpenEmbedded build system does not
  3851. currently provide specific support for these techniques.
  3852. Testing that Introspection Works in an Image
  3853. --------------------------------------------
  3854. Use the following procedure to test if generating introspection data is
  3855. working in an image:
  3856. 1. Make sure that "gobject-introspection-data" is not in
  3857. :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
  3858. and that "qemu-usermode" is not in
  3859. :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
  3860. 2. Build ``core-image-sato``.
  3861. 3. Launch a Terminal and then start Python in the terminal.
  3862. 4. Enter the following in the terminal::
  3863. >>> from gi.repository import GLib
  3864. >>> GLib.get_host_name()
  3865. 5. For something a little more advanced, enter the following see:
  3866. https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html
  3867. Known Issues
  3868. ------------
  3869. Here are know issues in GObject Introspection Support:
  3870. - ``qemu-ppc64`` immediately crashes. Consequently, you cannot build
  3871. introspection data on that architecture.
  3872. - x32 is not supported by QEMU. Consequently, introspection data is
  3873. disabled.
  3874. - musl causes transient GLib binaries to crash on assertion failures.
  3875. Consequently, generating introspection data is disabled.
  3876. - Because QEMU is not able to run the binaries correctly, introspection
  3877. is disabled for some specific packages under specific architectures
  3878. (e.g. ``gcr``, ``libsecret``, and ``webkit``).
  3879. - QEMU usermode might not work properly when running 64-bit binaries
  3880. under 32-bit host machines. In particular, "qemumips64" is known to
  3881. not work under i686.
  3882. Optionally Using an External Toolchain
  3883. ======================================
  3884. You might want to use an external toolchain as part of your development.
  3885. If this is the case, the fundamental steps you need to accomplish are as
  3886. follows:
  3887. - Understand where the installed toolchain resides. For cases where you
  3888. need to build the external toolchain, you would need to take separate
  3889. steps to build and install the toolchain.
  3890. - Make sure you add the layer that contains the toolchain to your
  3891. ``bblayers.conf`` file through the
  3892. :term:`BBLAYERS` variable.
  3893. - Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file
  3894. to the location in which you installed the toolchain.
  3895. A good example of an external toolchain used with the Yocto Project is
  3896. Mentor Graphics Sourcery G++ Toolchain. You can see information on how
  3897. to use that particular layer in the ``README`` file at
  3898. https://github.com/MentorEmbedded/meta-sourcery/. You can find
  3899. further information by reading about the
  3900. :term:`TCMODE` variable in the Yocto
  3901. Project Reference Manual's variable glossary.
  3902. Creating Partitioned Images Using Wic
  3903. =====================================
  3904. Creating an image for a particular hardware target using the
  3905. OpenEmbedded build system does not necessarily mean you can boot that
  3906. image as is on your device. Physical devices accept and boot images in
  3907. various ways depending on the specifics of the device. Usually,
  3908. information about the hardware can tell you what image format the device
  3909. requires. Should your device require multiple partitions on an SD card,
  3910. flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to
  3911. create the properly partitioned image.
  3912. The ``wic`` command generates partitioned images from existing
  3913. OpenEmbedded build artifacts. Image generation is driven by partitioning
  3914. commands contained in an Openembedded kickstart file (``.wks``)
  3915. specified either directly on the command line or as one of a selection
  3916. of canned kickstart files as shown with the ``wic list images`` command
  3917. in the
  3918. ":ref:`dev-manual/common-tasks:generate an image using an existing kickstart file`"
  3919. section. When you apply the command to a given set of build artifacts, the
  3920. result is an image or set of images that can be directly written onto media and
  3921. used on a particular system.
  3922. .. note::
  3923. For a kickstart file reference, see the
  3924. ":ref:`ref-manual/kickstart:openembedded kickstart (\`\`.wks\`\`) reference`"
  3925. Chapter in the Yocto Project Reference Manual.
  3926. The ``wic`` command and the infrastructure it is based on is by
  3927. definition incomplete. The purpose of the command is to allow the
  3928. generation of customized images, and as such, was designed to be
  3929. completely extensible through a plugin interface. See the
  3930. ":ref:`dev-manual/common-tasks:using the wic plugin interface`" section
  3931. for information on these plugins.
  3932. This section provides some background information on Wic, describes what
  3933. you need to have in place to run the tool, provides instruction on how
  3934. to use the Wic utility, provides information on using the Wic plugins
  3935. interface, and provides several examples that show how to use Wic.
  3936. Background
  3937. ----------
  3938. This section provides some background on the Wic utility. While none of
  3939. this information is required to use Wic, you might find it interesting.
  3940. - The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The
  3941. "oe" diphthong in "oeic" was promoted to the letter "w", because
  3942. "oeic" is both difficult to remember and to pronounce.
  3943. - Wic is loosely based on the Meego Image Creator (``mic``) framework.
  3944. The Wic implementation has been heavily modified to make direct use
  3945. of OpenEmbedded build artifacts instead of package installation and
  3946. configuration, which are already incorporated within the OpenEmbedded
  3947. artifacts.
  3948. - Wic is a completely independent standalone utility that initially
  3949. provides easier-to-use and more flexible replacements for an existing
  3950. functionality in OE-Core's
  3951. :ref:`image-live <ref-classes-image-live>`
  3952. class. The difference between Wic and those examples is that with Wic
  3953. the functionality of those scripts is implemented by a
  3954. general-purpose partitioning language, which is based on Redhat
  3955. kickstart syntax.
  3956. Requirements
  3957. ------------
  3958. In order to use the Wic utility with the OpenEmbedded Build system, your
  3959. system needs to meet the following requirements:
  3960. - The Linux distribution on your development host must support the
  3961. Yocto Project. See the ":ref:`detailed-supported-distros`"
  3962. section in the Yocto Project Reference Manual for the list of
  3963. distributions that support the Yocto Project.
  3964. - The standard system utilities, such as ``cp``, must be installed on
  3965. your development host system.
  3966. - You must have sourced the build environment setup script (i.e.
  3967. :ref:`structure-core-script`) found in the
  3968. :term:`Build Directory`.
  3969. - You need to have the build artifacts already available, which
  3970. typically means that you must have already created an image using the
  3971. Openembedded build system (e.g. ``core-image-minimal``). While it
  3972. might seem redundant to generate an image in order to create an image
  3973. using Wic, the current version of Wic requires the artifacts in the
  3974. form generated by the OpenEmbedded build system.
  3975. - You must build several native tools, which are built to run on the
  3976. build system::
  3977. $ bitbake parted-native dosfstools-native mtools-native
  3978. - Include "wic" as part of the
  3979. :term:`IMAGE_FSTYPES`
  3980. variable.
  3981. - Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>`
  3982. as part of the :term:`WKS_FILE` variable
  3983. Getting Help
  3984. ------------
  3985. You can get general help for the ``wic`` command by entering the ``wic``
  3986. command by itself or by entering the command with a help argument as
  3987. follows::
  3988. $ wic -h
  3989. $ wic --help
  3990. $ wic help
  3991. Currently, Wic supports seven commands: ``cp``, ``create``, ``help``,
  3992. ``list``, ``ls``, ``rm``, and ``write``. You can get help for all these
  3993. commands except "help" by using the following form::
  3994. $ wic help command
  3995. For example, the following command returns help for the ``write``
  3996. command::
  3997. $ wic help write
  3998. Wic supports help for three topics: ``overview``, ``plugins``, and
  3999. ``kickstart``. You can get help for any topic using the following form::
  4000. $ wic help topic
  4001. For example, the following returns overview help for Wic::
  4002. $ wic help overview
  4003. There is one additional level of help for Wic. You can get help on
  4004. individual images through the ``list`` command. You can use the ``list``
  4005. command to return the available Wic images as follows::
  4006. $ wic list images
  4007. genericx86 Create an EFI disk image for genericx86*
  4008. beaglebone-yocto Create SD card image for Beaglebone
  4009. edgerouter Create SD card image for Edgerouter
  4010. qemux86-directdisk Create a QEMU machine 'pcbios' direct disk image
  4011. directdisk-gpt Create a 'pcbios' direct disk image
  4012. mkefidisk Create an EFI disk image
  4013. directdisk Create a 'pcbios' direct disk image
  4014. systemd-bootdisk Create an EFI disk image with systemd-boot
  4015. mkhybridiso Create a hybrid ISO image
  4016. sdimage-bootpart Create SD card image with a boot partition
  4017. directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
  4018. directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
  4019. Once you know the list of available
  4020. Wic images, you can use ``help`` with the command to get help on a
  4021. particular image. For example, the following command returns help on the
  4022. "beaglebone-yocto" image::
  4023. $ wic list beaglebone-yocto help
  4024. Creates a partitioned SD card image for Beaglebone.
  4025. Boot files are located in the first vfat partition.
  4026. Operational Modes
  4027. -----------------
  4028. You can use Wic in two different modes, depending on how much control
  4029. you need for specifying the Openembedded build artifacts that are used
  4030. for creating the image: Raw and Cooked:
  4031. - *Raw Mode:* You explicitly specify build artifacts through Wic
  4032. command-line arguments.
  4033. - *Cooked Mode:* The current
  4034. :term:`MACHINE` setting and image
  4035. name are used to automatically locate and provide the build
  4036. artifacts. You just supply a kickstart file and the name of the image
  4037. from which to use artifacts.
  4038. Regardless of the mode you use, you need to have the build artifacts
  4039. ready and available.
  4040. Raw Mode
  4041. ~~~~~~~~
  4042. Running Wic in raw mode allows you to specify all the partitions through
  4043. the ``wic`` command line. The primary use for raw mode is if you have
  4044. built your kernel outside of the Yocto Project
  4045. :term:`Build Directory`. In other words, you
  4046. can point to arbitrary kernel, root filesystem locations, and so forth.
  4047. Contrast this behavior with cooked mode where Wic looks in the Build
  4048. Directory (e.g. ``tmp/deploy/images/``\ machine).
  4049. The general form of the ``wic`` command in raw mode is::
  4050. $ wic create wks_file options ...
  4051. Where:
  4052. wks_file:
  4053. An OpenEmbedded kickstart file. You can provide
  4054. your own custom file or use a file from a set of
  4055. existing files as described by further options.
  4056. optional arguments:
  4057. -h, --help show this help message and exit
  4058. -o OUTDIR, --outdir OUTDIR
  4059. name of directory to create image in
  4060. -e IMAGE_NAME, --image-name IMAGE_NAME
  4061. name of the image to use the artifacts from e.g. core-
  4062. image-sato
  4063. -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR
  4064. path to the /rootfs dir to use as the .wks rootfs
  4065. source
  4066. -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR
  4067. path to the dir containing the boot artifacts (e.g.
  4068. /EFI or /syslinux dirs) to use as the .wks bootimg
  4069. source
  4070. -k KERNEL_DIR, --kernel-dir KERNEL_DIR
  4071. path to the dir containing the kernel to use in the
  4072. .wks bootimg
  4073. -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT
  4074. path to the native sysroot containing the tools to use
  4075. to build the image
  4076. -s, --skip-build-check
  4077. skip the build check
  4078. -f, --build-rootfs build rootfs
  4079. -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
  4080. compress image with specified compressor
  4081. -m, --bmap generate .bmap
  4082. --no-fstab-update Do not change fstab file.
  4083. -v VARS_DIR, --vars VARS_DIR
  4084. directory with <image>.env files that store bitbake
  4085. variables
  4086. -D, --debug output debug information
  4087. .. note::
  4088. You do not need root privileges to run Wic. In fact, you should not
  4089. run as root when using the utility.
  4090. Cooked Mode
  4091. ~~~~~~~~~~~
  4092. Running Wic in cooked mode leverages off artifacts in the Build
  4093. Directory. In other words, you do not have to specify kernel or root
  4094. filesystem locations as part of the command. All you need to provide is
  4095. a kickstart file and the name of the image from which to use artifacts
  4096. by using the "-e" option. Wic looks in the Build Directory (e.g.
  4097. ``tmp/deploy/images/``\ machine) for artifacts.
  4098. The general form of the ``wic`` command using Cooked Mode is as follows::
  4099. $ wic create wks_file -e IMAGE_NAME
  4100. Where:
  4101. wks_file:
  4102. An OpenEmbedded kickstart file. You can provide
  4103. your own custom file or use a file from a set of
  4104. existing files provided with the Yocto Project
  4105. release.
  4106. required argument:
  4107. -e IMAGE_NAME, --image-name IMAGE_NAME
  4108. name of the image to use the artifacts from e.g. core-
  4109. image-sato
  4110. Using an Existing Kickstart File
  4111. --------------------------------
  4112. If you do not want to create your own kickstart file, you can use an
  4113. existing file provided by the Wic installation. As shipped, kickstart
  4114. files can be found in the :ref:`overview-manual/development-environment:yocto project source repositories` in the
  4115. following two locations::
  4116. poky/meta-yocto-bsp/wic
  4117. poky/scripts/lib/wic/canned-wks
  4118. Use the following command to list the available kickstart files::
  4119. $ wic list images
  4120. genericx86 Create an EFI disk image for genericx86*
  4121. beaglebone-yocto Create SD card image for Beaglebone
  4122. edgerouter Create SD card image for Edgerouter
  4123. qemux86-directdisk Create a QEMU machine 'pcbios' direct disk image
  4124. directdisk-gpt Create a 'pcbios' direct disk image
  4125. mkefidisk Create an EFI disk image
  4126. directdisk Create a 'pcbios' direct disk image
  4127. systemd-bootdisk Create an EFI disk image with systemd-boot
  4128. mkhybridiso Create a hybrid ISO image
  4129. sdimage-bootpart Create SD card image with a boot partition
  4130. directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
  4131. directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
  4132. When you use an existing file, you
  4133. do not have to use the ``.wks`` extension. Here is an example in Raw
  4134. Mode that uses the ``directdisk`` file::
  4135. $ wic create directdisk -r rootfs_dir -b bootimg_dir \
  4136. -k kernel_dir -n native_sysroot
  4137. Here are the actual partition language commands used in the
  4138. ``genericx86.wks`` file to generate an image::
  4139. # short-description: Create an EFI disk image for genericx86*
  4140. # long-description: Creates a partitioned EFI disk image for genericx86* machines
  4141. part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
  4142. part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
  4143. part swap --ondisk sda --size 44 --label swap1 --fstype=swap
  4144. bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
  4145. Using the Wic Plugin Interface
  4146. ------------------------------
  4147. You can extend and specialize Wic functionality by using Wic plugins.
  4148. This section explains the Wic plugin interface.
  4149. .. note::
  4150. Wic plugins consist of "source" and "imager" plugins. Imager plugins
  4151. are beyond the scope of this section.
  4152. Source plugins provide a mechanism to customize partition content during
  4153. the Wic image generation process. You can use source plugins to map
  4154. values that you specify using ``--source`` commands in kickstart files
  4155. (i.e. ``*.wks``) to a plugin implementation used to populate a given
  4156. partition.
  4157. .. note::
  4158. If you use plugins that have build-time dependencies (e.g. native
  4159. tools, bootloaders, and so forth) when building a Wic image, you need
  4160. to specify those dependencies using the :term:`WKS_FILE_DEPENDS`
  4161. variable.
  4162. Source plugins are subclasses defined in plugin files. As shipped, the
  4163. Yocto Project provides several plugin files. You can see the source
  4164. plugin files that ship with the Yocto Project
  4165. :yocto_git:`here </poky/tree/scripts/lib/wic/plugins/source>`.
  4166. Each of these plugin files contains source plugins that are designed to
  4167. populate a specific Wic image partition.
  4168. Source plugins are subclasses of the ``SourcePlugin`` class, which is
  4169. defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example,
  4170. the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py``
  4171. file is a subclass of the ``SourcePlugin`` class, which is found in the
  4172. ``pluginbase.py`` file.
  4173. You can also implement source plugins in a layer outside of the Source
  4174. Repositories (external layer). To do so, be sure that your plugin files
  4175. are located in a directory whose path is
  4176. ``scripts/lib/wic/plugins/source/`` within your external layer. When the
  4177. plugin files are located there, the source plugins they contain are made
  4178. available to Wic.
  4179. When the Wic implementation needs to invoke a partition-specific
  4180. implementation, it looks for the plugin with the same name as the
  4181. ``--source`` parameter used in the kickstart file given to that
  4182. partition. For example, if the partition is set up using the following
  4183. command in a kickstart file::
  4184. part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
  4185. The methods defined as class
  4186. members of the matching source plugin (i.e. ``bootimg-pcbios``) in the
  4187. ``bootimg-pcbios.py`` plugin file are used.
  4188. To be more concrete, here is the corresponding plugin definition from
  4189. the ``bootimg-pcbios.py`` file for the previous command along with an
  4190. example method called by the Wic implementation when it needs to prepare
  4191. a partition using an implementation-specific function::
  4192. .
  4193. .
  4194. .
  4195. class BootimgPcbiosPlugin(SourcePlugin):
  4196. """
  4197. Create MBR boot partition and install syslinux on it.
  4198. """
  4199. name = 'bootimg-pcbios'
  4200. .
  4201. .
  4202. .
  4203. @classmethod
  4204. def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
  4205. oe_builddir, bootimg_dir, kernel_dir,
  4206. rootfs_dir, native_sysroot):
  4207. """
  4208. Called to do the actual content population for a partition i.e. it
  4209. 'prepares' the partition to be incorporated into the image.
  4210. In this case, prepare content for legacy bios boot partition.
  4211. """
  4212. .
  4213. .
  4214. .
  4215. If a
  4216. subclass (plugin) itself does not implement a particular function, Wic
  4217. locates and uses the default version in the superclass. It is for this
  4218. reason that all source plugins are derived from the ``SourcePlugin``
  4219. class.
  4220. The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines
  4221. a set of methods that source plugins can implement or override. Any
  4222. plugins (subclass of ``SourcePlugin``) that do not implement a
  4223. particular method inherit the implementation of the method from the
  4224. ``SourcePlugin`` class. For more information, see the ``SourcePlugin``
  4225. class in the ``pluginbase.py`` file for details:
  4226. The following list describes the methods implemented in the
  4227. ``SourcePlugin`` class:
  4228. - ``do_prepare_partition()``: Called to populate a partition with
  4229. actual content. In other words, the method prepares the final
  4230. partition image that is incorporated into the disk image.
  4231. - ``do_configure_partition()``: Called before
  4232. ``do_prepare_partition()`` to create custom configuration files for a
  4233. partition (e.g. syslinux or grub configuration files).
  4234. - ``do_install_disk()``: Called after all partitions have been
  4235. prepared and assembled into a disk image. This method provides a hook
  4236. to allow finalization of a disk image (e.g. writing an MBR).
  4237. - ``do_stage_partition()``: Special content-staging hook called
  4238. before ``do_prepare_partition()``. This method is normally empty.
  4239. Typically, a partition just uses the passed-in parameters (e.g. the
  4240. unmodified value of ``bootimg_dir``). However, in some cases, things
  4241. might need to be more tailored. As an example, certain files might
  4242. additionally need to be taken from ``bootimg_dir + /boot``. This hook
  4243. allows those files to be staged in a customized fashion.
  4244. .. note::
  4245. ``get_bitbake_var()`` allows you to access non-standard variables that
  4246. you might want to use for this behavior.
  4247. You can extend the source plugin mechanism. To add more hooks, create
  4248. more source plugin methods within ``SourcePlugin`` and the corresponding
  4249. derived subclasses. The code that calls the plugin methods uses the
  4250. ``plugin.get_source_plugin_methods()`` function to find the method or
  4251. methods needed by the call. Retrieval of those methods is accomplished
  4252. by filling up a dict with keys that contain the method names of
  4253. interest. On success, these will be filled in with the actual methods.
  4254. See the Wic implementation for examples and details.
  4255. Wic Examples
  4256. ------------
  4257. This section provides several examples that show how to use the Wic
  4258. utility. All the examples assume the list of requirements in the
  4259. ":ref:`dev-manual/common-tasks:requirements`" section have been met. The
  4260. examples assume the previously generated image is
  4261. ``core-image-minimal``.
  4262. Generate an Image using an Existing Kickstart File
  4263. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4264. This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart
  4265. file::
  4266. $ wic create mkefidisk -e core-image-minimal
  4267. INFO: Building wic-tools...
  4268. .
  4269. .
  4270. .
  4271. INFO: The new image(s) can be found here:
  4272. ./mkefidisk-201804191017-sda.direct
  4273. The following build artifacts were used to create the image(s):
  4274. ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
  4275. BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
  4276. KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
  4277. NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4278. INFO: The image(s) were created using OE kickstart file:
  4279. /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
  4280. The previous example shows the easiest way to create an image by running
  4281. in cooked mode and supplying a kickstart file and the "-e" option to
  4282. point to the existing build artifacts. Your ``local.conf`` file needs to
  4283. have the :term:`MACHINE` variable set
  4284. to the machine you are using, which is "qemux86" in this example.
  4285. Once the image builds, the output provides image location, artifact use,
  4286. and kickstart file information.
  4287. .. note::
  4288. You should always verify the details provided in the output to make
  4289. sure that the image was indeed created exactly as expected.
  4290. Continuing with the example, you can now write the image from the Build
  4291. Directory onto a USB stick, or whatever media for which you built your
  4292. image, and boot from the media. You can write the image by using
  4293. ``bmaptool`` or ``dd``::
  4294. $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX
  4295. or ::
  4296. $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX
  4297. .. note::
  4298. For more information on how to use the ``bmaptool``
  4299. to flash a device with an image, see the
  4300. ":ref:`dev-manual/common-tasks:flashing images using \`\`bmaptool\`\``"
  4301. section.
  4302. Using a Modified Kickstart File
  4303. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4304. Because partitioned image creation is driven by the kickstart file, it
  4305. is easy to affect image creation by changing the parameters in the file.
  4306. This next example demonstrates that through modification of the
  4307. ``directdisk-gpt`` kickstart file.
  4308. As mentioned earlier, you can use the command ``wic list images`` to
  4309. show the list of existing kickstart files. The directory in which the
  4310. ``directdisk-gpt.wks`` file resides is
  4311. ``scripts/lib/image/canned-wks/``, which is located in the
  4312. :term:`Source Directory` (e.g. ``poky``).
  4313. Because available files reside in this directory, you can create and add
  4314. your own custom files to the directory. Subsequent use of the
  4315. ``wic list images`` command would then include your kickstart files.
  4316. In this example, the existing ``directdisk-gpt`` file already does most
  4317. of what is needed. However, for the hardware in this example, the image
  4318. will need to boot from ``sdb`` instead of ``sda``, which is what the
  4319. ``directdisk-gpt`` kickstart file uses.
  4320. The example begins by making a copy of the ``directdisk-gpt.wks`` file
  4321. in the ``scripts/lib/image/canned-wks`` directory and then by changing
  4322. the lines that specify the target disk from which to boot.
  4323. ::
  4324. $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
  4325. /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
  4326. Next, the example modifies the ``directdisksdb-gpt.wks`` file and
  4327. changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The
  4328. example changes the following two lines and leaves the remaining lines
  4329. untouched::
  4330. part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
  4331. part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
  4332. Once the lines are changed, the
  4333. example generates the ``directdisksdb-gpt`` image. The command points
  4334. the process at the ``core-image-minimal`` artifacts for the Next Unit of
  4335. Computing (nuc) :term:`MACHINE` the
  4336. ``local.conf``.
  4337. ::
  4338. $ wic create directdisksdb-gpt -e core-image-minimal
  4339. INFO: Building wic-tools...
  4340. .
  4341. .
  4342. .
  4343. Initialising tasks: 100% |#######################################| Time: 0:00:01
  4344. NOTE: Executing SetScene Tasks
  4345. NOTE: Executing RunQueue Tasks
  4346. NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
  4347. INFO: Creating image(s)...
  4348. INFO: The new image(s) can be found here:
  4349. ./directdisksdb-gpt-201710090938-sdb.direct
  4350. The following build artifacts were used to create the image(s):
  4351. ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
  4352. BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
  4353. KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
  4354. NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4355. INFO: The image(s) were created using OE kickstart file:
  4356. /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
  4357. Continuing with the example, you can now directly ``dd`` the image to a
  4358. USB stick, or whatever media for which you built your image, and boot
  4359. the resulting media::
  4360. $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
  4361. 140966+0 records in
  4362. 140966+0 records out
  4363. 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
  4364. $ sudo eject /dev/sdb
  4365. Using a Modified Kickstart File and Running in Raw Mode
  4366. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4367. This next example manually specifies each build artifact (runs in Raw
  4368. Mode) and uses a modified kickstart file. The example also uses the
  4369. ``-o`` option to cause Wic to create the output somewhere other than the
  4370. default output directory, which is the current directory::
  4371. $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
  4372. --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
  4373. --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
  4374. --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
  4375. --native-sysroot /home/stephano/build/master/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4376. INFO: Creating image(s)...
  4377. INFO: The new image(s) can be found here:
  4378. /home/stephano/testwic/test-201710091445-sdb.direct
  4379. The following build artifacts were used to create the image(s):
  4380. ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
  4381. BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
  4382. KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
  4383. NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
  4384. INFO: The image(s) were created using OE kickstart file:
  4385. /home/stephano/my_yocto/test.wks
  4386. For this example,
  4387. :term:`MACHINE` did not have to be
  4388. specified in the ``local.conf`` file since the artifact is manually
  4389. specified.
  4390. Using Wic to Manipulate an Image
  4391. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4392. Wic image manipulation allows you to shorten turnaround time during
  4393. image development. For example, you can use Wic to delete the kernel
  4394. partition of a Wic image and then insert a newly built kernel. This
  4395. saves you time from having to rebuild the entire image each time you
  4396. modify the kernel.
  4397. .. note::
  4398. In order to use Wic to manipulate a Wic image as in this example,
  4399. your development machine must have the ``mtools`` package installed.
  4400. The following example examines the contents of the Wic image, deletes
  4401. the existing kernel, and then inserts a new kernel:
  4402. 1. *List the Partitions:* Use the ``wic ls`` command to list all the
  4403. partitions in the Wic image::
  4404. $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
  4405. Num Start End Size Fstype
  4406. 1 1048576 25041919 23993344 fat16
  4407. 2 25165824 72157183 46991360 ext4
  4408. The previous output shows two partitions in the
  4409. ``core-image-minimal-qemux86.wic`` image.
  4410. 2. *Examine a Particular Partition:* Use the ``wic ls`` command again
  4411. but in a different form to examine a particular partition.
  4412. .. note::
  4413. You can get command usage on any Wic command using the following
  4414. form::
  4415. $ wic help command
  4416. For example, the following command shows you the various ways to
  4417. use the
  4418. wic ls
  4419. command::
  4420. $ wic help ls
  4421. The following command shows what is in partition one::
  4422. $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
  4423. Volume in drive : is boot
  4424. Volume Serial Number is E894-1809
  4425. Directory for ::/
  4426. libcom32 c32 186500 2017-10-09 16:06
  4427. libutil c32 24148 2017-10-09 16:06
  4428. syslinux cfg 220 2017-10-09 16:06
  4429. vesamenu c32 27104 2017-10-09 16:06
  4430. vmlinuz 6904608 2017-10-09 16:06
  4431. 5 files 7 142 580 bytes
  4432. 16 582 656 bytes free
  4433. The previous output shows five files, with the
  4434. ``vmlinuz`` being the kernel.
  4435. .. note::
  4436. If you see the following error, you need to update or create a
  4437. ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1"
  4438. in the file. Then, run the Wic command again::
  4439. ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
  4440. output: Total number of sectors (47824) not a multiple of sectors per track (32)!
  4441. Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
  4442. 3. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the
  4443. ``vmlinuz`` file (kernel)::
  4444. $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
  4445. 4. *Add In the New Kernel:* Use the ``wic cp`` command to add the
  4446. updated kernel to the Wic image. Depending on how you built your
  4447. kernel, it could be in different places. If you used ``devtool`` and
  4448. an SDK to build your kernel, it resides in the ``tmp/work`` directory
  4449. of the extensible SDK. If you used ``make`` to build the kernel, the
  4450. kernel will be in the ``workspace/sources`` area.
  4451. The following example assumes ``devtool`` was used to build the
  4452. kernel::
  4453. $ 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 \
  4454. poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
  4455. Once the new kernel is added back into the image, you can use the
  4456. ``dd`` command or :ref:`bmaptool
  4457. <dev-manual/common-tasks:flashing images using \`\`bmaptool\`\`>`
  4458. to flash your wic image onto an SD card or USB stick and test your
  4459. target.
  4460. .. note::
  4461. Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``.
  4462. Flashing Images Using ``bmaptool``
  4463. ==================================
  4464. A fast and easy way to flash an image to a bootable device is to use
  4465. Bmaptool, which is integrated into the OpenEmbedded build system.
  4466. Bmaptool is a generic tool that creates a file's block map (bmap) and
  4467. then uses that map to copy the file. As compared to traditional tools
  4468. such as dd or cp, Bmaptool can copy (or flash) large files like raw
  4469. system image files much faster.
  4470. .. note::
  4471. - If you are using Ubuntu or Debian distributions, you can install
  4472. the ``bmap-tools`` package using the following command and then
  4473. use the tool without specifying ``PATH`` even from the root
  4474. account::
  4475. $ sudo apt-get install bmap-tools
  4476. - If you are unable to install the ``bmap-tools`` package, you will
  4477. need to build Bmaptool before using it. Use the following command::
  4478. $ bitbake bmap-tools-native
  4479. Following, is an example that shows how to flash a Wic image. Realize
  4480. that while this example uses a Wic image, you can use Bmaptool to flash
  4481. any type of image. Use these steps to flash an image using Bmaptool:
  4482. 1. *Update your local.conf File:* You need to have the following set
  4483. in your ``local.conf`` file before building your image::
  4484. IMAGE_FSTYPES += "wic wic.bmap"
  4485. 2. *Get Your Image:* Either have your image ready (pre-built with the
  4486. :term:`IMAGE_FSTYPES`
  4487. setting previously mentioned) or take the step to build the image::
  4488. $ bitbake image
  4489. 3. *Flash the Device:* Flash the device with the image by using Bmaptool
  4490. depending on your particular setup. The following commands assume the
  4491. image resides in the Build Directory's ``deploy/images/`` area:
  4492. - If you have write access to the media, use this command form::
  4493. $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
  4494. - If you do not have write access to the media, set your permissions
  4495. first and then use the same command form::
  4496. $ sudo chmod 666 /dev/sdX
  4497. $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
  4498. For help on the ``bmaptool`` command, use the following command::
  4499. $ bmaptool --help
  4500. Making Images More Secure
  4501. =========================
  4502. Security is of increasing concern for embedded devices. Consider the
  4503. issues and problems discussed in just this sampling of work found across
  4504. the Internet:
  4505. - *"*\ `Security Risks of Embedded
  4506. Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"*
  4507. by Bruce Schneier
  4508. - *"*\ `Internet Census
  4509. 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna
  4510. Botnet
  4511. - *"*\ `Security Issues for Embedded
  4512. Devices <https://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"*
  4513. by Jake Edge
  4514. When securing your image is of concern, there are steps, tools, and
  4515. variables that you can consider to help you reach the security goals you
  4516. need for your particular device. Not all situations are identical when
  4517. it comes to making an image secure. Consequently, this section provides
  4518. some guidance and suggestions for consideration when you want to make
  4519. your image more secure.
  4520. .. note::
  4521. Because the security requirements and risks are different for every
  4522. type of device, this section cannot provide a complete reference on
  4523. securing your custom OS. It is strongly recommended that you also
  4524. consult other sources of information on embedded Linux system
  4525. hardening and on security.
  4526. General Considerations
  4527. ----------------------
  4528. There are general considerations that help you create more secure images.
  4529. You should consider the following suggestions to make your device
  4530. more secure:
  4531. - Scan additional code you are adding to the system (e.g. application
  4532. code) by using static analysis tools. Look for buffer overflows and
  4533. other potential security problems.
  4534. - Pay particular attention to the security for any web-based
  4535. administration interface.
  4536. Web interfaces typically need to perform administrative functions and
  4537. tend to need to run with elevated privileges. Thus, the consequences
  4538. resulting from the interface's security becoming compromised can be
  4539. serious. Look for common web vulnerabilities such as
  4540. cross-site-scripting (XSS), unvalidated inputs, and so forth.
  4541. As with system passwords, the default credentials for accessing a
  4542. web-based interface should not be the same across all devices. This
  4543. is particularly true if the interface is enabled by default as it can
  4544. be assumed that many end-users will not change the credentials.
  4545. - Ensure you can update the software on the device to mitigate
  4546. vulnerabilities discovered in the future. This consideration
  4547. especially applies when your device is network-enabled.
  4548. - Ensure you remove or disable debugging functionality before producing
  4549. the final image. For information on how to do this, see the
  4550. ":ref:`dev-manual/common-tasks:considerations specific to the openembedded build system`"
  4551. section.
  4552. - Ensure you have no network services listening that are not needed.
  4553. - Remove any software from the image that is not needed.
  4554. - Enable hardware support for secure boot functionality when your
  4555. device supports this functionality.
  4556. Security Flags
  4557. --------------
  4558. The Yocto Project has security flags that you can enable that help make
  4559. your build output more secure. The security flags are in the
  4560. ``meta/conf/distro/include/security_flags.inc`` file in your
  4561. :term:`Source Directory` (e.g. ``poky``).
  4562. .. note::
  4563. Depending on the recipe, certain security flags are enabled and
  4564. disabled by default.
  4565. Use the following line in your ``local.conf`` file or in your custom
  4566. distribution configuration file to enable the security compiler and
  4567. linker flags for your build::
  4568. require conf/distro/include/security_flags.inc
  4569. Considerations Specific to the OpenEmbedded Build System
  4570. --------------------------------------------------------
  4571. You can take some steps that are specific to the OpenEmbedded build
  4572. system to make your images more secure:
  4573. - Ensure "debug-tweaks" is not one of your selected
  4574. :term:`IMAGE_FEATURES`.
  4575. When creating a new project, the default is to provide you with an
  4576. initial ``local.conf`` file that enables this feature using the
  4577. :term:`EXTRA_IMAGE_FEATURES`
  4578. variable with the line::
  4579. EXTRA_IMAGE_FEATURES = "debug-tweaks"
  4580. To disable that feature, simply comment out that line in your
  4581. ``local.conf`` file, or make sure :term:`IMAGE_FEATURES` does not contain
  4582. "debug-tweaks" before producing your final image. Among other things,
  4583. leaving this in place sets the root password as blank, which makes
  4584. logging in for debugging or inspection easy during development but
  4585. also means anyone can easily log in during production.
  4586. - It is possible to set a root password for the image and also to set
  4587. passwords for any extra users you might add (e.g. administrative or
  4588. service type users). When you set up passwords for multiple images or
  4589. users, you should not duplicate passwords.
  4590. To set up passwords, use the
  4591. :ref:`extrausers <ref-classes-extrausers>`
  4592. class, which is the preferred method. For an example on how to set up
  4593. both root and user passwords, see the
  4594. ":ref:`extrausers.bbclass <ref-classes-extrausers>`"
  4595. section.
  4596. .. note::
  4597. When adding extra user accounts or setting a root password, be
  4598. cautious about setting the same password on every device. If you
  4599. do this, and the password you have set is exposed, then every
  4600. device is now potentially compromised. If you need this access but
  4601. want to ensure security, consider setting a different, random
  4602. password for each device. Typically, you do this as a separate
  4603. step after you deploy the image onto the device.
  4604. - Consider enabling a Mandatory Access Control (MAC) framework such as
  4605. SMACK or SELinux and tuning it appropriately for your device's usage.
  4606. You can find more information in the
  4607. :yocto_git:`meta-selinux </meta-selinux/>` layer.
  4608. Tools for Hardening Your Image
  4609. ------------------------------
  4610. The Yocto Project provides tools for making your image more secure. You
  4611. can find these tools in the ``meta-security`` layer of the
  4612. :yocto_git:`Yocto Project Source Repositories <>`.
  4613. Creating Your Own Distribution
  4614. ==============================
  4615. When you build an image using the Yocto Project and do not alter any
  4616. distribution :term:`Metadata`, you are
  4617. creating a Poky distribution. If you wish to gain more control over
  4618. package alternative selections, compile-time options, and other
  4619. low-level configurations, you can create your own distribution.
  4620. To create your own distribution, the basic steps consist of creating
  4621. your own distribution layer, creating your own distribution
  4622. configuration file, and then adding any needed code and Metadata to the
  4623. layer. The following steps provide some more detail:
  4624. - *Create a layer for your new distro:* Create your distribution layer
  4625. so that you can keep your Metadata and code for the distribution
  4626. separate. It is strongly recommended that you create and use your own
  4627. layer for configuration and code. Using your own layer as compared to
  4628. just placing configurations in a ``local.conf`` configuration file
  4629. makes it easier to reproduce the same build configuration when using
  4630. multiple build machines. See the
  4631. ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
  4632. section for information on how to quickly set up a layer.
  4633. - *Create the distribution configuration file:* The distribution
  4634. configuration file needs to be created in the ``conf/distro``
  4635. directory of your layer. You need to name it using your distribution
  4636. name (e.g. ``mydistro.conf``).
  4637. .. note::
  4638. The :term:`DISTRO` variable in your ``local.conf`` file determines the
  4639. name of your distribution.
  4640. You can split out parts of your configuration file into include files
  4641. and then "require" them from within your distribution configuration
  4642. file. Be sure to place the include files in the
  4643. ``conf/distro/include`` directory of your layer. A common example
  4644. usage of include files would be to separate out the selection of
  4645. desired version and revisions for individual recipes.
  4646. Your configuration file needs to set the following required
  4647. variables:
  4648. - :term:`DISTRO_NAME`
  4649. - :term:`DISTRO_VERSION`
  4650. These following variables are optional and you typically set them
  4651. from the distribution configuration file:
  4652. - :term:`DISTRO_FEATURES`
  4653. - :term:`DISTRO_EXTRA_RDEPENDS`
  4654. - :term:`DISTRO_EXTRA_RRECOMMENDS`
  4655. - :term:`TCLIBC`
  4656. .. tip::
  4657. If you want to base your distribution configuration file on the
  4658. very basic configuration from OE-Core, you can use
  4659. ``conf/distro/defaultsetup.conf`` as a reference and just include
  4660. variables that differ as compared to ``defaultsetup.conf``.
  4661. Alternatively, you can create a distribution configuration file
  4662. from scratch using the ``defaultsetup.conf`` file or configuration files
  4663. from other distributions such as Poky or Angstrom as references.
  4664. - *Provide miscellaneous variables:* Be sure to define any other
  4665. variables for which you want to create a default or enforce as part
  4666. of the distribution configuration. You can include nearly any
  4667. variable from the ``local.conf`` file. The variables you use are not
  4668. limited to the list in the previous bulleted item.
  4669. - *Point to Your distribution configuration file:* In your
  4670. ``local.conf`` file in the :term:`Build Directory`,
  4671. set your
  4672. :term:`DISTRO` variable to point to
  4673. your distribution's configuration file. For example, if your
  4674. distribution's configuration file is named ``mydistro.conf``, then
  4675. you point to it as follows::
  4676. DISTRO = "mydistro"
  4677. - *Add more to the layer if necessary:* Use your layer to hold other
  4678. information needed for the distribution:
  4679. - Add recipes for installing distro-specific configuration files
  4680. that are not already installed by another recipe. If you have
  4681. distro-specific configuration files that are included by an
  4682. existing recipe, you should add an append file (``.bbappend``) for
  4683. those. For general information and recommendations on how to add
  4684. recipes to your layer, see the
  4685. ":ref:`dev-manual/common-tasks:creating your own layer`" and
  4686. ":ref:`dev-manual/common-tasks:following best practices when creating layers`"
  4687. sections.
  4688. - Add any image recipes that are specific to your distribution.
  4689. - Add a ``psplash`` append file for a branded splash screen. For
  4690. information on append files, see the
  4691. ":ref:`dev-manual/common-tasks:using .bbappend files in your layer`"
  4692. section.
  4693. - Add any other append files to make custom changes that are
  4694. specific to individual recipes.
  4695. Creating a Custom Template Configuration Directory
  4696. ==================================================
  4697. If you are producing your own customized version of the build system for
  4698. use by other users, you might want to customize the message shown by the
  4699. setup script or you might want to change the template configuration
  4700. files (i.e. ``local.conf`` and ``bblayers.conf``) that are created in a
  4701. new build directory.
  4702. The OpenEmbedded build system uses the environment variable
  4703. ``TEMPLATECONF`` to locate the directory from which it gathers
  4704. configuration information that ultimately ends up in the
  4705. :term:`Build Directory` ``conf`` directory.
  4706. By default, ``TEMPLATECONF`` is set as follows in the ``poky``
  4707. repository::
  4708. TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
  4709. This is the
  4710. directory used by the build system to find templates from which to build
  4711. some key configuration files. If you look at this directory, you will
  4712. see the ``bblayers.conf.sample``, ``local.conf.sample``, and
  4713. ``conf-notes.txt`` files. The build system uses these files to form the
  4714. respective ``bblayers.conf`` file, ``local.conf`` file, and display the
  4715. list of BitBake targets when running the setup script.
  4716. To override these default configuration files with configurations you
  4717. want used within every new Build Directory, simply set the
  4718. ``TEMPLATECONF`` variable to your directory. The ``TEMPLATECONF``
  4719. variable is set in the ``.templateconf`` file, which is in the top-level
  4720. :term:`Source Directory` folder
  4721. (e.g. ``poky``). Edit the ``.templateconf`` so that it can locate your
  4722. directory.
  4723. Best practices dictate that you should keep your template configuration
  4724. directory in your custom distribution layer. For example, suppose you
  4725. have a layer named ``meta-mylayer`` located in your home directory and
  4726. you want your template configuration directory named ``myconf``.
  4727. Changing the ``.templateconf`` as follows causes the OpenEmbedded build
  4728. system to look in your directory and base its configuration files on the
  4729. ``*.sample`` configuration files it finds. The final configuration files
  4730. (i.e. ``local.conf`` and ``bblayers.conf`` ultimately still end up in
  4731. your Build Directory, but they are based on your ``*.sample`` files.
  4732. ::
  4733. TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
  4734. Aside from the ``*.sample`` configuration files, the ``conf-notes.txt``
  4735. also resides in the default ``meta-poky/conf`` directory. The script
  4736. that sets up the build environment (i.e.
  4737. :ref:`structure-core-script`) uses this file to
  4738. display BitBake targets as part of the script output. Customizing this
  4739. ``conf-notes.txt`` file is a good way to make sure your list of custom
  4740. targets appears as part of the script's output.
  4741. Here is the default list of targets displayed as a result of running
  4742. either of the setup scripts::
  4743. You can now run 'bitbake <target>'
  4744. Common targets are:
  4745. core-image-minimal
  4746. core-image-sato
  4747. meta-toolchain
  4748. meta-ide-support
  4749. Changing the listed common targets is as easy as editing your version of
  4750. ``conf-notes.txt`` in your custom template configuration directory and
  4751. making sure you have ``TEMPLATECONF`` set to your directory.
  4752. Conserving Disk Space During Builds
  4753. ===================================
  4754. To help conserve disk space during builds, you can add the following
  4755. statement to your project's ``local.conf`` configuration file found in
  4756. the :term:`Build Directory`::
  4757. INHERIT += "rm_work"
  4758. Adding this statement deletes the work directory used for
  4759. building a recipe once the recipe is built. For more information on
  4760. "rm_work", see the
  4761. :ref:`rm_work <ref-classes-rm-work>` class in the
  4762. Yocto Project Reference Manual.
  4763. Working with Packages
  4764. =====================
  4765. This section describes a few tasks that involve packages:
  4766. - :ref:`dev-manual/common-tasks:excluding packages from an image`
  4767. - :ref:`dev-manual/common-tasks:incrementing a package version`
  4768. - :ref:`dev-manual/common-tasks:handling optional module packaging`
  4769. - :ref:`dev-manual/common-tasks:using runtime package management`
  4770. - :ref:`dev-manual/common-tasks:generating and using signed packages`
  4771. - :ref:`Setting up and running package test
  4772. (ptest) <dev-manual/common-tasks:testing packages with ptest>`
  4773. - :ref:`dev-manual/common-tasks:creating node package manager (npm) packages`
  4774. - :ref:`dev-manual/common-tasks:adding custom metadata to packages`
  4775. Excluding Packages from an Image
  4776. --------------------------------
  4777. You might find it necessary to prevent specific packages from being
  4778. installed into an image. If so, you can use several variables to direct
  4779. the build system to essentially ignore installing recommended packages
  4780. or to not install a package at all.
  4781. The following list introduces variables you can use to prevent packages
  4782. from being installed into your image. Each of these variables only works
  4783. with IPK and RPM package types, not for Debian packages.
  4784. Also, you can use these variables from your ``local.conf`` file
  4785. or attach them to a specific image recipe by using a recipe name
  4786. override. For more detail on the variables, see the descriptions in the
  4787. Yocto Project Reference Manual's glossary chapter.
  4788. - :term:`BAD_RECOMMENDATIONS`:
  4789. Use this variable to specify "recommended-only" packages that you do
  4790. not want installed.
  4791. - :term:`NO_RECOMMENDATIONS`:
  4792. Use this variable to prevent all "recommended-only" packages from
  4793. being installed.
  4794. - :term:`PACKAGE_EXCLUDE`:
  4795. Use this variable to prevent specific packages from being installed
  4796. regardless of whether they are "recommended-only" or not. You need to
  4797. realize that the build process could fail with an error when you
  4798. prevent the installation of a package whose presence is required by
  4799. an installed package.
  4800. Incrementing a Package Version
  4801. ------------------------------
  4802. This section provides some background on how binary package versioning
  4803. is accomplished and presents some of the services, variables, and
  4804. terminology involved.
  4805. In order to understand binary package versioning, you need to consider
  4806. the following:
  4807. - Binary Package: The binary package that is eventually built and
  4808. installed into an image.
  4809. - Binary Package Version: The binary package version is composed of two
  4810. components - a version and a revision.
  4811. .. note::
  4812. Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved
  4813. but this discussion for the most part ignores :term:`PE`.
  4814. The version and revision are taken from the
  4815. :term:`PV` and
  4816. :term:`PR` variables, respectively.
  4817. - :term:`PV`: The recipe version. :term:`PV` represents the version of the
  4818. software being packaged. Do not confuse :term:`PV` with the binary
  4819. package version.
  4820. - :term:`PR`: The recipe revision.
  4821. - :term:`SRCPV`: The OpenEmbedded
  4822. build system uses this string to help define the value of :term:`PV` when
  4823. the source code revision needs to be included in it.
  4824. - :yocto_wiki:`PR Service </PR_Service>`: A
  4825. network-based service that helps automate keeping package feeds
  4826. compatible with existing package manager applications such as RPM,
  4827. APT, and OPKG.
  4828. Whenever the binary package content changes, the binary package version
  4829. must change. Changing the binary package version is accomplished by
  4830. changing or "bumping" the :term:`PR` and/or :term:`PV` values. Increasing these
  4831. values occurs one of two ways:
  4832. - Automatically using a Package Revision Service (PR Service).
  4833. - Manually incrementing the :term:`PR` and/or :term:`PV` variables.
  4834. Given a primary challenge of any build system and its users is how to
  4835. maintain a package feed that is compatible with existing package manager
  4836. applications such as RPM, APT, and OPKG, using an automated system is
  4837. much preferred over a manual system. In either system, the main
  4838. requirement is that binary package version numbering increases in a
  4839. linear fashion and that there is a number of version components that
  4840. support that linear progression. For information on how to ensure
  4841. package revisioning remains linear, see the
  4842. ":ref:`dev-manual/common-tasks:automatically incrementing a package version number`"
  4843. section.
  4844. The following three sections provide related information on the PR
  4845. Service, the manual method for "bumping" :term:`PR` and/or :term:`PV`, and on
  4846. how to ensure binary package revisioning remains linear.
  4847. Working With a PR Service
  4848. ~~~~~~~~~~~~~~~~~~~~~~~~~
  4849. As mentioned, attempting to maintain revision numbers in the
  4850. :term:`Metadata` is error prone, inaccurate,
  4851. and causes problems for people submitting recipes. Conversely, the PR
  4852. Service automatically generates increasing numbers, particularly the
  4853. revision field, which removes the human element.
  4854. .. note::
  4855. For additional information on using a PR Service, you can see the
  4856. :yocto_wiki:`PR Service </PR_Service>` wiki page.
  4857. The Yocto Project uses variables in order of decreasing priority to
  4858. facilitate revision numbering (i.e.
  4859. :term:`PE`,
  4860. :term:`PV`, and
  4861. :term:`PR` for epoch, version, and
  4862. revision, respectively). The values are highly dependent on the policies
  4863. and procedures of a given distribution and package feed.
  4864. Because the OpenEmbedded build system uses
  4865. ":ref:`signatures <overview-manual/concepts:checksums (signatures)>`", which are
  4866. unique to a given build, the build system knows when to rebuild
  4867. packages. All the inputs into a given task are represented by a
  4868. signature, which can trigger a rebuild when different. Thus, the build
  4869. system itself does not rely on the :term:`PR`, :term:`PV`, and :term:`PE` numbers to
  4870. trigger a rebuild. The signatures, however, can be used to generate
  4871. these values.
  4872. The PR Service works with both ``OEBasic`` and ``OEBasicHash``
  4873. generators. The value of :term:`PR` bumps when the checksum changes and the
  4874. different generator mechanisms change signatures under different
  4875. circumstances.
  4876. As implemented, the build system includes values from the PR Service
  4877. into the :term:`PR` field as an addition using the form "``.x``" so ``r0``
  4878. becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing
  4879. :term:`PR` values to be used for whatever reasons, which include manual
  4880. :term:`PR` bumps, should it be necessary.
  4881. By default, the PR Service is not enabled or running. Thus, the packages
  4882. generated are just "self consistent". The build system adds and removes
  4883. packages and there are no guarantees about upgrade paths but images will
  4884. be consistent and correct with the latest changes.
  4885. The simplest form for a PR Service is for a single host
  4886. development system that builds the package feed (building system). For
  4887. this scenario, you can enable a local PR Service by setting
  4888. :term:`PRSERV_HOST` in your
  4889. ``local.conf`` file in the :term:`Build Directory`::
  4890. PRSERV_HOST = "localhost:0"
  4891. Once the service is started, packages will automatically
  4892. get increasing :term:`PR` values and BitBake takes care of starting and
  4893. stopping the server.
  4894. If you have a more complex setup where multiple host development systems
  4895. work against a common, shared package feed, you have a single PR Service
  4896. running and it is connected to each building system. For this scenario,
  4897. you need to start the PR Service using the ``bitbake-prserv`` command::
  4898. bitbake-prserv --host ip --port port --start
  4899. In addition to
  4900. hand-starting the service, you need to update the ``local.conf`` file of
  4901. each building system as described earlier so each system points to the
  4902. server and port.
  4903. It is also recommended you use build history, which adds some sanity
  4904. checks to binary package versions, in conjunction with the server that
  4905. is running the PR Service. To enable build history, add the following to
  4906. each building system's ``local.conf`` file::
  4907. # It is recommended to activate "buildhistory" for testing the PR service
  4908. INHERIT += "buildhistory"
  4909. BUILDHISTORY_COMMIT = "1"
  4910. For information on build
  4911. history, see the
  4912. ":ref:`dev-manual/common-tasks:maintaining build output quality`" section.
  4913. .. note::
  4914. The OpenEmbedded build system does not maintain :term:`PR` information as
  4915. part of the shared state (sstate) packages. If you maintain an sstate
  4916. feed, it's expected that either all your building systems that
  4917. contribute to the sstate feed use a shared PR Service, or you do not
  4918. run a PR Service on any of your building systems. Having some systems
  4919. use a PR Service while others do not leads to obvious problems.
  4920. For more information on shared state, see the
  4921. ":ref:`overview-manual/concepts:shared state cache`"
  4922. section in the Yocto Project Overview and Concepts Manual.
  4923. Manually Bumping PR
  4924. ~~~~~~~~~~~~~~~~~~~
  4925. The alternative to setting up a PR Service is to manually "bump" the
  4926. :term:`PR` variable.
  4927. If a committed change results in changing the package output, then the
  4928. value of the PR variable needs to be increased (or "bumped") as part of
  4929. that commit. For new recipes you should add the :term:`PR` variable and set
  4930. its initial value equal to "r0", which is the default. Even though the
  4931. default value is "r0", the practice of adding it to a new recipe makes
  4932. it harder to forget to bump the variable when you make changes to the
  4933. recipe in future.
  4934. If you are sharing a common ``.inc`` file with multiple recipes, you can
  4935. also use the :term:`INC_PR` variable to ensure that the recipes sharing the
  4936. ``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The
  4937. ``.inc`` file must set :term:`INC_PR` (initially to "r0"), and all recipes
  4938. referring to it should set :term:`PR` to "${INC_PR}.0" initially,
  4939. incrementing the last number when the recipe is changed. If the ``.inc``
  4940. file is changed then its :term:`INC_PR` should be incremented.
  4941. When upgrading the version of a binary package, assuming the :term:`PV`
  4942. changes, the :term:`PR` variable should be reset to "r0" (or "${INC_PR}.0"
  4943. if you are using :term:`INC_PR`).
  4944. Usually, version increases occur only to binary packages. However, if
  4945. for some reason :term:`PV` changes but does not increase, you can increase
  4946. the :term:`PE` variable (Package Epoch). The :term:`PE` variable defaults to
  4947. "0".
  4948. Binary package version numbering strives to follow the `Debian Version
  4949. Field Policy
  4950. Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__.
  4951. These guidelines define how versions are compared and what "increasing"
  4952. a version means.
  4953. Automatically Incrementing a Package Version Number
  4954. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4955. When fetching a repository, BitBake uses the
  4956. :term:`SRCREV` variable to determine
  4957. the specific source code revision from which to build. You set the
  4958. :term:`SRCREV` variable to
  4959. :term:`AUTOREV` to cause the
  4960. OpenEmbedded build system to automatically use the latest revision of
  4961. the software::
  4962. SRCREV = "${AUTOREV}"
  4963. Furthermore, you need to reference :term:`SRCPV` in :term:`PV` in order to
  4964. automatically update the version whenever the revision of the source
  4965. code changes. Here is an example::
  4966. PV = "1.0+git${SRCPV}"
  4967. The OpenEmbedded build system substitutes :term:`SRCPV` with the following:
  4968. .. code-block:: none
  4969. AUTOINC+source_code_revision
  4970. The build system replaces the ``AUTOINC``
  4971. with a number. The number used depends on the state of the PR Service:
  4972. - If PR Service is enabled, the build system increments the number,
  4973. which is similar to the behavior of
  4974. :term:`PR`. This behavior results in
  4975. linearly increasing package versions, which is desirable. Here is an
  4976. example:
  4977. .. code-block:: none
  4978. hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
  4979. hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
  4980. - If PR Service is not enabled, the build system replaces the
  4981. ``AUTOINC`` placeholder with zero (i.e. "0"). This results in
  4982. changing the package version since the source revision is included.
  4983. However, package versions are not increased linearly. Here is an
  4984. example:
  4985. .. code-block:: none
  4986. hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
  4987. hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
  4988. In summary, the OpenEmbedded build system does not track the history of
  4989. binary package versions for this purpose. ``AUTOINC``, in this case, is
  4990. comparable to :term:`PR`. If PR server is not enabled, ``AUTOINC`` in the
  4991. package version is simply replaced by "0". If PR server is enabled, the
  4992. build system keeps track of the package versions and bumps the number
  4993. when the package revision changes.
  4994. Handling Optional Module Packaging
  4995. ----------------------------------
  4996. Many pieces of software split functionality into optional modules (or
  4997. plugins) and the plugins that are built might depend on configuration
  4998. options. To avoid having to duplicate the logic that determines what
  4999. modules are available in your recipe or to avoid having to package each
  5000. module by hand, the OpenEmbedded build system provides functionality to
  5001. handle module packaging dynamically.
  5002. To handle optional module packaging, you need to do two things:
  5003. - Ensure the module packaging is actually done.
  5004. - Ensure that any dependencies on optional modules from other recipes
  5005. are satisfied by your recipe.
  5006. Making Sure the Packaging is Done
  5007. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5008. To ensure the module packaging actually gets done, you use the
  5009. ``do_split_packages`` function within the ``populate_packages`` Python
  5010. function in your recipe. The ``do_split_packages`` function searches for
  5011. a pattern of files or directories under a specified path and creates a
  5012. package for each one it finds by appending to the
  5013. :term:`PACKAGES` variable and
  5014. setting the appropriate values for ``FILES_packagename``,
  5015. ``RDEPENDS_packagename``, ``DESCRIPTION_packagename``, and so forth.
  5016. Here is an example from the ``lighttpd`` recipe::
  5017. python populate_packages_prepend () {
  5018. lighttpd_libdir = d.expand('${libdir}')
  5019. do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$',
  5020. 'lighttpd-module-%s', 'Lighttpd module for %s',
  5021. extra_depends='')
  5022. }
  5023. The previous example specifies a number of things in the call to
  5024. ``do_split_packages``.
  5025. - A directory within the files installed by your recipe through
  5026. ``do_install`` in which to search.
  5027. - A regular expression used to match module files in that directory. In
  5028. the example, note the parentheses () that mark the part of the
  5029. expression from which the module name should be derived.
  5030. - A pattern to use for the package names.
  5031. - A description for each package.
  5032. - An empty string for ``extra_depends``, which disables the default
  5033. dependency on the main ``lighttpd`` package. Thus, if a file in
  5034. ``${libdir}`` called ``mod_alias.so`` is found, a package called
  5035. ``lighttpd-module-alias`` is created for it and the
  5036. :term:`DESCRIPTION` is set to
  5037. "Lighttpd module for alias".
  5038. Often, packaging modules is as simple as the previous example. However,
  5039. there are more advanced options that you can use within
  5040. ``do_split_packages`` to modify its behavior. And, if you need to, you
  5041. can add more logic by specifying a hook function that is called for each
  5042. package. It is also perfectly acceptable to call ``do_split_packages``
  5043. multiple times if you have more than one set of modules to package.
  5044. For more examples that show how to use ``do_split_packages``, see the
  5045. ``connman.inc`` file in the ``meta/recipes-connectivity/connman/``
  5046. directory of the ``poky`` :ref:`source repository <overview-manual/development-environment:yocto project source repositories>`. You can
  5047. also find examples in ``meta/classes/kernel.bbclass``.
  5048. Following is a reference that shows ``do_split_packages`` mandatory and
  5049. optional arguments::
  5050. Mandatory arguments
  5051. root
  5052. The path in which to search
  5053. file_regex
  5054. Regular expression to match searched files.
  5055. Use parentheses () to mark the part of this
  5056. expression that should be used to derive the
  5057. module name (to be substituted where %s is
  5058. used in other function arguments as noted below)
  5059. output_pattern
  5060. Pattern to use for the package names. Must
  5061. include %s.
  5062. description
  5063. Description to set for each package. Must
  5064. include %s.
  5065. Optional arguments
  5066. postinst
  5067. Postinstall script to use for all packages
  5068. (as a string)
  5069. recursive
  5070. True to perform a recursive search - default
  5071. False
  5072. hook
  5073. A hook function to be called for every match.
  5074. The function will be called with the following
  5075. arguments (in the order listed):
  5076. f
  5077. Full path to the file/directory match
  5078. pkg
  5079. The package name
  5080. file_regex
  5081. As above
  5082. output_pattern
  5083. As above
  5084. modulename
  5085. The module name derived using file_regex
  5086. extra_depends
  5087. Extra runtime dependencies (RDEPENDS) to be
  5088. set for all packages. The default value of None
  5089. causes a dependency on the main package
  5090. (${PN}) - if you do not want this, pass empty
  5091. string '' for this parameter.
  5092. aux_files_pattern
  5093. Extra item(s) to be added to FILES for each
  5094. package. Can be a single string item or a list
  5095. of strings for multiple items. Must include %s.
  5096. postrm
  5097. postrm script to use for all packages (as a
  5098. string)
  5099. allow_dirs
  5100. True to allow directories to be matched -
  5101. default False
  5102. prepend
  5103. If True, prepend created packages to PACKAGES
  5104. instead of the default False which appends them
  5105. match_path
  5106. match file_regex on the whole relative path to
  5107. the root rather than just the file name
  5108. aux_files_pattern_verbatim
  5109. Extra item(s) to be added to FILES for each
  5110. package, using the actual derived module name
  5111. rather than converting it to something legal
  5112. for a package name. Can be a single string item
  5113. or a list of strings for multiple items. Must
  5114. include %s.
  5115. allow_links
  5116. True to allow symlinks to be matched - default
  5117. False
  5118. summary
  5119. Summary to set for each package. Must include %s;
  5120. defaults to description if not set.
  5121. Satisfying Dependencies
  5122. ~~~~~~~~~~~~~~~~~~~~~~~
  5123. The second part for handling optional module packaging is to ensure that
  5124. any dependencies on optional modules from other recipes are satisfied by
  5125. your recipe. You can be sure these dependencies are satisfied by using
  5126. the :term:`PACKAGES_DYNAMIC`
  5127. variable. Here is an example that continues with the ``lighttpd`` recipe
  5128. shown earlier::
  5129. PACKAGES_DYNAMIC = "lighttpd-module-.*"
  5130. The name
  5131. specified in the regular expression can of course be anything. In this
  5132. example, it is ``lighttpd-module-`` and is specified as the prefix to
  5133. ensure that any :term:`RDEPENDS` and
  5134. :term:`RRECOMMENDS` on a package
  5135. name starting with the prefix are satisfied during build time. If you
  5136. are using ``do_split_packages`` as described in the previous section,
  5137. the value you put in :term:`PACKAGES_DYNAMIC` should correspond to the name
  5138. pattern specified in the call to ``do_split_packages``.
  5139. Using Runtime Package Management
  5140. --------------------------------
  5141. During a build, BitBake always transforms a recipe into one or more
  5142. packages. For example, BitBake takes the ``bash`` recipe and produces a
  5143. number of packages (e.g. ``bash``, ``bash-bashbug``,
  5144. ``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``,
  5145. ``bash-completion-extra``, ``bash-dbg``, and so forth). Not all
  5146. generated packages are included in an image.
  5147. In several situations, you might need to update, add, remove, or query
  5148. the packages on a target device at runtime (i.e. without having to
  5149. generate a new image). Examples of such situations include:
  5150. - You want to provide in-the-field updates to deployed devices (e.g.
  5151. security updates).
  5152. - You want to have a fast turn-around development cycle for one or more
  5153. applications that run on your device.
  5154. - You want to temporarily install the "debug" packages of various
  5155. applications on your device so that debugging can be greatly improved
  5156. by allowing access to symbols and source debugging.
  5157. - You want to deploy a more minimal package selection of your device
  5158. but allow in-the-field updates to add a larger selection for
  5159. customization.
  5160. In all these situations, you have something similar to a more
  5161. traditional Linux distribution in that in-field devices are able to
  5162. receive pre-compiled packages from a server for installation or update.
  5163. Being able to install these packages on a running, in-field device is
  5164. what is termed "runtime package management".
  5165. In order to use runtime package management, you need a host or server
  5166. machine that serves up the pre-compiled packages plus the required
  5167. metadata. You also need package manipulation tools on the target. The
  5168. build machine is a likely candidate to act as the server. However, that
  5169. machine does not necessarily have to be the package server. The build
  5170. machine could push its artifacts to another machine that acts as the
  5171. server (e.g. Internet-facing). In fact, doing so is advantageous for a
  5172. production environment as getting the packages away from the development
  5173. system's build directory prevents accidental overwrites.
  5174. A simple build that targets just one device produces more than one
  5175. package database. In other words, the packages produced by a build are
  5176. separated out into a couple of different package groupings based on
  5177. criteria such as the target's CPU architecture, the target board, or the
  5178. C library used on the target. For example, a build targeting the
  5179. ``qemux86`` device produces the following three package databases:
  5180. ``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86``
  5181. device to be aware of all the packages that were available to it, you
  5182. would need to point it to each of these databases individually. In a
  5183. similar way, a traditional Linux distribution usually is configured to
  5184. be aware of a number of software repositories from which it retrieves
  5185. packages.
  5186. Using runtime package management is completely optional and not required
  5187. for a successful build or deployment in any way. But if you want to make
  5188. use of runtime package management, you need to do a couple things above
  5189. and beyond the basics. The remainder of this section describes what you
  5190. need to do.
  5191. Build Considerations
  5192. ~~~~~~~~~~~~~~~~~~~~
  5193. This section describes build considerations of which you need to be
  5194. aware in order to provide support for runtime package management.
  5195. When BitBake generates packages, it needs to know what format or formats
  5196. to use. In your configuration, you use the
  5197. :term:`PACKAGE_CLASSES`
  5198. variable to specify the format:
  5199. 1. Open the ``local.conf`` file inside your
  5200. :term:`Build Directory` (e.g.
  5201. ``poky/build/conf/local.conf``).
  5202. 2. Select the desired package format as follows::
  5203. PACKAGE_CLASSES ?= "package_packageformat"
  5204. where packageformat can be "ipk", "rpm",
  5205. "deb", or "tar" which are the supported package formats.
  5206. .. note::
  5207. Because the Yocto Project supports four different package formats,
  5208. you can set the variable with more than one argument. However, the
  5209. OpenEmbedded build system only uses the first argument when
  5210. creating an image or Software Development Kit (SDK).
  5211. If you would like your image to start off with a basic package database
  5212. containing the packages in your current build as well as to have the
  5213. relevant tools available on the target for runtime package management,
  5214. you can include "package-management" in the
  5215. :term:`IMAGE_FEATURES`
  5216. variable. Including "package-management" in this configuration variable
  5217. ensures that when the image is assembled for your target, the image
  5218. includes the currently-known package databases as well as the
  5219. target-specific tools required for runtime package management to be
  5220. performed on the target. However, this is not strictly necessary. You
  5221. could start your image off without any databases but only include the
  5222. required on-target package tool(s). As an example, you could include
  5223. "opkg" in your
  5224. :term:`IMAGE_INSTALL` variable
  5225. if you are using the IPK package format. You can then initialize your
  5226. target's package database(s) later once your image is up and running.
  5227. Whenever you perform any sort of build step that can potentially
  5228. generate a package or modify existing package, it is always a good idea
  5229. to re-generate the package index after the build by using the following
  5230. command::
  5231. $ bitbake package-index
  5232. It might be tempting to build the
  5233. package and the package index at the same time with a command such as
  5234. the following::
  5235. $ bitbake some-package package-index
  5236. Do not do this as
  5237. BitBake does not schedule the package index for after the completion of
  5238. the package you are building. Consequently, you cannot be sure of the
  5239. package index including information for the package you just built.
  5240. Thus, be sure to run the package update step separately after building
  5241. any packages.
  5242. You can use the
  5243. :term:`PACKAGE_FEED_ARCHS`,
  5244. :term:`PACKAGE_FEED_BASE_PATHS`,
  5245. and
  5246. :term:`PACKAGE_FEED_URIS`
  5247. variables to pre-configure target images to use a package feed. If you
  5248. do not define these variables, then manual steps as described in the
  5249. subsequent sections are necessary to configure the target. You should
  5250. set these variables before building the image in order to produce a
  5251. correctly configured image.
  5252. When your build is complete, your packages reside in the
  5253. ``${TMPDIR}/deploy/packageformat`` directory. For example, if
  5254. ``${``\ :term:`TMPDIR`\ ``}`` is
  5255. ``tmp`` and your selected package type is RPM, then your RPM packages
  5256. are available in ``tmp/deploy/rpm``.
  5257. Host or Server Machine Setup
  5258. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5259. Although other protocols are possible, a server using HTTP typically
  5260. serves packages. If you want to use HTTP, then set up and configure a
  5261. web server such as Apache 2, lighttpd, or Python web server on the
  5262. machine serving the packages.
  5263. To keep things simple, this section describes how to set up a
  5264. Python web server to share package feeds from the developer's
  5265. machine. Although this server might not be the best for a production
  5266. environment, the setup is simple and straight forward. Should you want
  5267. to use a different server more suited for production (e.g. Apache 2,
  5268. Lighttpd, or Nginx), take the appropriate steps to do so.
  5269. From within the build directory where you have built an image based on
  5270. your packaging choice (i.e. the
  5271. :term:`PACKAGE_CLASSES`
  5272. setting), simply start the server. The following example assumes a build
  5273. directory of ``poky/build/tmp/deploy/rpm`` and a :term:`PACKAGE_CLASSES`
  5274. setting of "package_rpm"::
  5275. $ cd poky/build/tmp/deploy/rpm
  5276. $ python3 -m http.server
  5277. Target Setup
  5278. ~~~~~~~~~~~~
  5279. Setting up the target differs depending on the package management
  5280. system. This section provides information for RPM, IPK, and DEB.
  5281. Using RPM
  5282. ^^^^^^^^^
  5283. The `Dandified Packaging
  5284. Tool <https://en.wikipedia.org/wiki/DNF_(software)>`__ (DNF) performs
  5285. runtime package management of RPM packages. In order to use DNF for
  5286. runtime package management, you must perform an initial setup on the
  5287. target machine for cases where the ``PACKAGE_FEED_*`` variables were not
  5288. set as part of the image that is running on the target. This means if
  5289. you built your image and did not use these variables as part of the
  5290. build and your image is now running on the target, you need to perform
  5291. the steps in this section if you want to use runtime package management.
  5292. .. note::
  5293. For information on the ``PACKAGE_FEED_*`` variables, see
  5294. :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and
  5295. :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables
  5296. glossary.
  5297. On the target, you must inform DNF that package databases are available.
  5298. You do this by creating a file named
  5299. ``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``.
  5300. As an example, assume the target is able to use the following package
  5301. databases: ``all``, ``i586``, and ``qemux86`` from a server named
  5302. ``my.server``. The specifics for setting up the web server are up to
  5303. you. The critical requirement is that the URIs in the target repository
  5304. configuration point to the correct remote location for the feeds.
  5305. .. note::
  5306. For development purposes, you can point the web server to the build
  5307. system's ``deploy`` directory. However, for production use, it is better to
  5308. copy the package directories to a location outside of the build area and use
  5309. that location. Doing so avoids situations where the build system
  5310. overwrites or changes the ``deploy`` directory.
  5311. When telling DNF where to look for the package databases, you must
  5312. declare individual locations per architecture or a single location used
  5313. for all architectures. You cannot do both:
  5314. - *Create an Explicit List of Architectures:* Define individual base
  5315. URLs to identify where each package database is located:
  5316. .. code-block:: none
  5317. [oe-packages]
  5318. baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
  5319. This example
  5320. informs DNF about individual package databases for all three
  5321. architectures.
  5322. - *Create a Single (Full) Package Index:* Define a single base URL that
  5323. identifies where a full package database is located::
  5324. [oe-packages]
  5325. baseurl=http://my.server/rpm
  5326. This example informs DNF about a single
  5327. package database that contains all the package index information for
  5328. all supported architectures.
  5329. Once you have informed DNF where to find the package databases, you need
  5330. to fetch them:
  5331. .. code-block:: none
  5332. # dnf makecache
  5333. DNF is now able to find, install, and
  5334. upgrade packages from the specified repository or repositories.
  5335. .. note::
  5336. See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for
  5337. additional information.
  5338. Using IPK
  5339. ^^^^^^^^^
  5340. The ``opkg`` application performs runtime package management of IPK
  5341. packages. You must perform an initial setup for ``opkg`` on the target
  5342. machine if the
  5343. :term:`PACKAGE_FEED_ARCHS`,
  5344. :term:`PACKAGE_FEED_BASE_PATHS`,
  5345. and
  5346. :term:`PACKAGE_FEED_URIS`
  5347. variables have not been set or the target image was built before the
  5348. variables were set.
  5349. The ``opkg`` application uses configuration files to find available
  5350. package databases. Thus, you need to create a configuration file inside
  5351. the ``/etc/opkg/`` direction, which informs ``opkg`` of any repository
  5352. you want to use.
  5353. As an example, suppose you are serving packages from a ``ipk/``
  5354. directory containing the ``i586``, ``all``, and ``qemux86`` databases
  5355. through an HTTP server named ``my.server``. On the target, create a
  5356. configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/``
  5357. directory containing the following:
  5358. .. code-block:: none
  5359. src/gz all http://my.server/ipk/all
  5360. src/gz i586 http://my.server/ipk/i586
  5361. src/gz qemux86 http://my.server/ipk/qemux86
  5362. Next, instruct ``opkg`` to fetch the
  5363. repository information:
  5364. .. code-block:: none
  5365. # opkg update
  5366. The ``opkg`` application is now able to find, install, and upgrade packages
  5367. from the specified repository.
  5368. Using DEB
  5369. ^^^^^^^^^
  5370. The ``apt`` application performs runtime package management of DEB
  5371. packages. This application uses a source list file to find available
  5372. package databases. You must perform an initial setup for ``apt`` on the
  5373. target machine if the
  5374. :term:`PACKAGE_FEED_ARCHS`,
  5375. :term:`PACKAGE_FEED_BASE_PATHS`,
  5376. and
  5377. :term:`PACKAGE_FEED_URIS`
  5378. variables have not been set or the target image was built before the
  5379. variables were set.
  5380. To inform ``apt`` of the repository you want to use, you might create a
  5381. list file (e.g. ``my_repo.list``) inside the
  5382. ``/etc/apt/sources.list.d/`` directory. As an example, suppose you are
  5383. serving packages from a ``deb/`` directory containing the ``i586``,
  5384. ``all``, and ``qemux86`` databases through an HTTP server named
  5385. ``my.server``. The list file should contain:
  5386. .. code-block:: none
  5387. deb http://my.server/deb/all ./
  5388. deb http://my.server/deb/i586 ./
  5389. deb http://my.server/deb/qemux86 ./
  5390. Next, instruct the ``apt`` application
  5391. to fetch the repository information:
  5392. .. code-block:: none
  5393. # apt-get update
  5394. After this step,
  5395. ``apt`` is able to find, install, and upgrade packages from the
  5396. specified repository.
  5397. Generating and Using Signed Packages
  5398. ------------------------------------
  5399. In order to add security to RPM packages used during a build, you can
  5400. take steps to securely sign them. Once a signature is verified, the
  5401. OpenEmbedded build system can use the package in the build. If security
  5402. fails for a signed package, the build system aborts the build.
  5403. This section describes how to sign RPM packages during a build and how
  5404. to use signed package feeds (repositories) when doing a build.
  5405. Signing RPM Packages
  5406. ~~~~~~~~~~~~~~~~~~~~
  5407. To enable signing RPM packages, you must set up the following
  5408. configurations in either your ``local.config`` or ``distro.config``
  5409. file::
  5410. # Inherit sign_rpm.bbclass to enable signing functionality
  5411. INHERIT += " sign_rpm"
  5412. # Define the GPG key that will be used for signing.
  5413. RPM_GPG_NAME = "key_name"
  5414. # Provide passphrase for the key
  5415. RPM_GPG_PASSPHRASE = "passphrase"
  5416. .. note::
  5417. Be sure to supply appropriate values for both `key_name` and
  5418. `passphrase`.
  5419. Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in
  5420. the previous example, two optional variables related to signing are available:
  5421. - *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed
  5422. when the package is signed.
  5423. - *GPG_PATH:* Specifies the ``gpg`` home directory used when the
  5424. package is signed.
  5425. Processing Package Feeds
  5426. ~~~~~~~~~~~~~~~~~~~~~~~~
  5427. In addition to being able to sign RPM packages, you can also enable
  5428. signed package feeds for IPK and RPM packages.
  5429. The steps you need to take to enable signed package feed use are similar
  5430. to the steps used to sign RPM packages. You must define the following in
  5431. your ``local.config`` or ``distro.config`` file::
  5432. INHERIT += "sign_package_feed"
  5433. PACKAGE_FEED_GPG_NAME = "key_name"
  5434. PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase"
  5435. For signed package feeds, the passphrase must be specified in a separate file,
  5436. which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE``
  5437. variable. Regarding security, keeping a plain text passphrase out of the
  5438. configuration is more secure.
  5439. Aside from the ``PACKAGE_FEED_GPG_NAME`` and
  5440. ``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables
  5441. related to signed package feeds are available:
  5442. - *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed
  5443. when the package is signed.
  5444. - *GPG_PATH:* Specifies the ``gpg`` home directory used when the
  5445. package is signed.
  5446. - *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg``
  5447. signature. This variable applies only to RPM and IPK package feeds.
  5448. Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are
  5449. "ASC", which is the default and specifies ascii armored, and "BIN",
  5450. which specifies binary.
  5451. Testing Packages With ptest
  5452. ---------------------------
  5453. A Package Test (ptest) runs tests against packages built by the
  5454. OpenEmbedded build system on the target machine. A ptest contains at
  5455. least two items: the actual test, and a shell script (``run-ptest``)
  5456. that starts the test. The shell script that starts the test must not
  5457. contain the actual test - the script only starts the test. On the other
  5458. hand, the test can be anything from a simple shell script that runs a
  5459. binary and checks the output to an elaborate system of test binaries and
  5460. data files.
  5461. The test generates output in the format used by Automake::
  5462. result: testname
  5463. where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and
  5464. the testname can be any identifying string.
  5465. For a list of Yocto Project recipes that are already enabled with ptest,
  5466. see the :yocto_wiki:`Ptest </Ptest>` wiki page.
  5467. .. note::
  5468. A recipe is "ptest-enabled" if it inherits the
  5469. :ref:`ptest <ref-classes-ptest>` class.
  5470. Adding ptest to Your Build
  5471. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  5472. To add package testing to your build, add the
  5473. :term:`DISTRO_FEATURES` and
  5474. :term:`EXTRA_IMAGE_FEATURES`
  5475. variables to your ``local.conf`` file, which is found in the
  5476. :term:`Build Directory`::
  5477. DISTRO_FEATURES_append = " ptest"
  5478. EXTRA_IMAGE_FEATURES += "ptest-pkgs"
  5479. Once your build is complete, the ptest files are installed into the
  5480. ``/usr/lib/package/ptest`` directory within the image, where ``package``
  5481. is the name of the package.
  5482. Running ptest
  5483. ~~~~~~~~~~~~~
  5484. The ``ptest-runner`` package installs a shell script that loops through
  5485. all installed ptest test suites and runs them in sequence. Consequently,
  5486. you might want to add this package to your image.
  5487. Getting Your Package Ready
  5488. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  5489. In order to enable a recipe to run installed ptests on target hardware,
  5490. you need to prepare the recipes that build the packages you want to
  5491. test. Here is what you have to do for each recipe:
  5492. - *Be sure the recipe inherits
  5493. the* :ref:`ptest <ref-classes-ptest>` *class:*
  5494. Include the following line in each recipe::
  5495. inherit ptest
  5496. - *Create run-ptest:* This script starts your test. Locate the
  5497. script where you will refer to it using
  5498. :term:`SRC_URI`. Here is an
  5499. example that starts a test for ``dbus``::
  5500. #!/bin/sh
  5501. cd test
  5502. make -k runtest-TESTS
  5503. - *Ensure dependencies are met:* If the test adds build or runtime
  5504. dependencies that normally do not exist for the package (such as
  5505. requiring "make" to run the test suite), use the
  5506. :term:`DEPENDS` and
  5507. :term:`RDEPENDS` variables in
  5508. your recipe in order for the package to meet the dependencies. Here
  5509. is an example where the package has a runtime dependency on "make"::
  5510. RDEPENDS_${PN}-ptest += "make"
  5511. - *Add a function to build the test suite:* Not many packages support
  5512. cross-compilation of their test suites. Consequently, you usually
  5513. need to add a cross-compilation function to the package.
  5514. Many packages based on Automake compile and run the test suite by
  5515. using a single command such as ``make check``. However, the host
  5516. ``make check`` builds and runs on the same computer, while
  5517. cross-compiling requires that the package is built on the host but
  5518. executed for the target architecture (though often, as in the case
  5519. for ptest, the execution occurs on the host). The built version of
  5520. Automake that ships with the Yocto Project includes a patch that
  5521. separates building and execution. Consequently, packages that use the
  5522. unaltered, patched version of ``make check`` automatically
  5523. cross-compiles.
  5524. Regardless, you still must add a ``do_compile_ptest`` function to
  5525. build the test suite. Add a function similar to the following to your
  5526. recipe::
  5527. do_compile_ptest() {
  5528. oe_runmake buildtest-TESTS
  5529. }
  5530. - *Ensure special configurations are set:* If the package requires
  5531. special configurations prior to compiling the test code, you must
  5532. insert a ``do_configure_ptest`` function into the recipe.
  5533. - *Install the test suite:* The ``ptest`` class automatically copies
  5534. the file ``run-ptest`` to the target and then runs make
  5535. ``install-ptest`` to run the tests. If this is not enough, you need
  5536. to create a ``do_install_ptest`` function and make sure it gets
  5537. called after the "make install-ptest" completes.
  5538. Creating Node Package Manager (NPM) Packages
  5539. --------------------------------------------
  5540. `NPM <https://en.wikipedia.org/wiki/Npm_(software)>`__ is a package
  5541. manager for the JavaScript programming language. The Yocto Project
  5542. supports the NPM :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>`. You can
  5543. use this fetcher in combination with
  5544. :doc:`devtool </ref-manual/devtool-reference>` to create
  5545. recipes that produce NPM packages.
  5546. There are two workflows that allow you to create NPM packages using
  5547. ``devtool``: the NPM registry modules method and the NPM project code
  5548. method.
  5549. .. note::
  5550. While it is possible to create NPM recipes manually, using
  5551. ``devtool`` is far simpler.
  5552. Additionally, some requirements and caveats exist.
  5553. Requirements and Caveats
  5554. ~~~~~~~~~~~~~~~~~~~~~~~~
  5555. You need to be aware of the following before using ``devtool`` to create
  5556. NPM packages:
  5557. - Of the two methods that you can use ``devtool`` to create NPM
  5558. packages, the registry approach is slightly simpler. However, you
  5559. might consider the project approach because you do not have to
  5560. publish your module in the NPM registry
  5561. (`npm-registry <https://docs.npmjs.com/misc/registry>`_), which
  5562. is NPM's public registry.
  5563. - Be familiar with
  5564. :doc:`devtool </ref-manual/devtool-reference>`.
  5565. - The NPM host tools need the native ``nodejs-npm`` package, which is
  5566. part of the OpenEmbedded environment. You need to get the package by
  5567. cloning the https://github.com/openembedded/meta-openembedded
  5568. repository out of GitHub. Be sure to add the path to your local copy
  5569. to your ``bblayers.conf`` file.
  5570. - ``devtool`` cannot detect native libraries in module dependencies.
  5571. Consequently, you must manually add packages to your recipe.
  5572. - While deploying NPM packages, ``devtool`` cannot determine which
  5573. dependent packages are missing on the target (e.g. the node runtime
  5574. ``nodejs``). Consequently, you need to find out what files are
  5575. missing and be sure they are on the target.
  5576. - Although you might not need NPM to run your node package, it is
  5577. useful to have NPM on your target. The NPM package name is
  5578. ``nodejs-npm``.
  5579. Using the Registry Modules Method
  5580. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5581. This section presents an example that uses the ``cute-files`` module,
  5582. which is a file browser web application.
  5583. .. note::
  5584. You must know the ``cute-files`` module version.
  5585. The first thing you need to do is use ``devtool`` and the NPM fetcher to
  5586. create the recipe::
  5587. $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2"
  5588. The
  5589. ``devtool add`` command runs ``recipetool create`` and uses the same
  5590. fetch URI to download each dependency and capture license details where
  5591. possible. The result is a generated recipe.
  5592. The recipe file is fairly simple and contains every license that
  5593. ``recipetool`` finds and includes the licenses in the recipe's
  5594. :term:`LIC_FILES_CHKSUM`
  5595. variables. You need to examine the variables and look for those with
  5596. "unknown" in the :term:`LICENSE`
  5597. field. You need to track down the license information for "unknown"
  5598. modules and manually add the information to the recipe.
  5599. ``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap
  5600. files capture the version of all dependent modules. Many packages do not
  5601. provide shrinkwrap files. ``recipetool`` create a shrinkwrap file as it
  5602. runs.
  5603. .. note::
  5604. A package is created for each sub-module. This policy is the only
  5605. practical way to have the licenses for all of the dependencies
  5606. represented in the license manifest of the image.
  5607. The ``devtool edit-recipe`` command lets you take a look at the recipe::
  5608. $ devtool edit-recipe cute-files
  5609. SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
  5610. LICENSE = "MIT & ISC & Unknown"
  5611. LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
  5612. file://node_modules/toidentifier/LICENSE;md5=1a261071a044d02eb6f2bb47f51a3502 \
  5613. file://node_modules/debug/LICENSE;md5=ddd815a475e7338b0be7a14d8ee35a99 \
  5614. ...
  5615. SRC_URI = " \
  5616. npm://registry.npmjs.org/;package=cute-files;version=${PV} \
  5617. npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
  5618. "
  5619. S = "${WORKDIR}/npm"
  5620. inherit npm LICENSE_${PN} = "MIT"
  5621. LICENSE_${PN}-accepts = "MIT"
  5622. LICENSE_${PN}-array-flatten = "MIT"
  5623. ...
  5624. LICENSE_${PN}-vary = "MIT"
  5625. Here are three key points in the previous example:
  5626. - :term:`SRC_URI` uses the NPM
  5627. scheme so that the NPM fetcher is used.
  5628. - ``recipetool`` collects all the license information. If a
  5629. sub-module's license is unavailable, the sub-module's name appears in
  5630. the comments.
  5631. - The ``inherit npm`` statement causes the
  5632. :ref:`npm <ref-classes-npm>` class to package
  5633. up all the modules.
  5634. You can run the following command to build the ``cute-files`` package::
  5635. $ devtool build cute-files
  5636. Remember that ``nodejs`` must be installed on
  5637. the target before your package.
  5638. Assuming 192.168.7.2 for the target's IP address, use the following
  5639. command to deploy your package::
  5640. $ devtool deploy-target -s cute-files root@192.168.7.2
  5641. Once the package is installed on the target, you can
  5642. test the application:
  5643. .. note::
  5644. Because of a known issue, you cannot simply run ``cute-files`` as you would
  5645. if you had run ``npm install``.
  5646. ::
  5647. $ cd /usr/lib/node_modules/cute-files
  5648. $ node cute-files.js
  5649. On a browser,
  5650. go to ``http://192.168.7.2:3000`` and you see the following:
  5651. .. image:: figures/cute-files-npm-example.png
  5652. :align: center
  5653. You can find the recipe in ``workspace/recipes/cute-files``. You can use
  5654. the recipe in any layer you choose.
  5655. Using the NPM Projects Code Method
  5656. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5657. Although it is useful to package modules already in the NPM registry,
  5658. adding ``node.js`` projects under development is a more common developer
  5659. use case.
  5660. This section covers the NPM projects code method, which is very similar
  5661. to the "registry" approach described in the previous section. In the NPM
  5662. projects method, you provide ``devtool`` with an URL that points to the
  5663. source files.
  5664. Replicating the same example, (i.e. ``cute-files``) use the following
  5665. command::
  5666. $ devtool add https://github.com/martinaglv/cute-files.git
  5667. The
  5668. recipe this command generates is very similar to the recipe created in
  5669. the previous section. However, the :term:`SRC_URI` looks like the following::
  5670. SRC_URI = " \
  5671. git://github.com/martinaglv/cute-files.git;protocol=https \
  5672. npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
  5673. "
  5674. In this example,
  5675. the main module is taken from the Git repository and dependencies are
  5676. taken from the NPM registry. Other than those differences, the recipe is
  5677. basically the same between the two methods. You can build and deploy the
  5678. package exactly as described in the previous section that uses the
  5679. registry modules method.
  5680. Adding custom metadata to packages
  5681. ----------------------------------
  5682. The variable
  5683. :term:`PACKAGE_ADD_METADATA`
  5684. can be used to add additional metadata to packages. This is reflected in
  5685. the package control/spec file. To take the ipk format for example, the
  5686. CONTROL file stored inside would contain the additional metadata as
  5687. additional lines.
  5688. The variable can be used in multiple ways, including using suffixes to
  5689. set it for a specific package type and/or package. Note that the order
  5690. of precedence is the same as this list:
  5691. - ``PACKAGE_ADD_METADATA_<PKGTYPE>_<PN>``
  5692. - ``PACKAGE_ADD_METADATA_<PKGTYPE>``
  5693. - ``PACKAGE_ADD_METADATA_<PN>``
  5694. - :term:`PACKAGE_ADD_METADATA`
  5695. `<PKGTYPE>` is a parameter and expected to be a distinct name of specific
  5696. package type:
  5697. - IPK for .ipk packages
  5698. - DEB for .deb packages
  5699. - RPM for .rpm packages
  5700. `<PN>` is a parameter and expected to be a package name.
  5701. The variable can contain multiple [one-line] metadata fields separated
  5702. by the literal sequence '\\n'. The separator can be redefined using the
  5703. variable flag ``separator``.
  5704. Here is an example that adds two custom fields for ipk
  5705. packages::
  5706. PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets"
  5707. Efficiently Fetching Source Files During a Build
  5708. ================================================
  5709. The OpenEmbedded build system works with source files located through
  5710. the :term:`SRC_URI` variable. When
  5711. you build something using BitBake, a big part of the operation is
  5712. locating and downloading all the source tarballs. For images,
  5713. downloading all the source for various packages can take a significant
  5714. amount of time.
  5715. This section shows you how you can use mirrors to speed up fetching
  5716. source files and how you can pre-fetch files all of which leads to more
  5717. efficient use of resources and time.
  5718. Setting up Effective Mirrors
  5719. ----------------------------
  5720. A good deal that goes into a Yocto Project build is simply downloading
  5721. all of the source tarballs. Maybe you have been working with another
  5722. build system (OpenEmbedded or Angstrom) for which you have built up a
  5723. sizable directory of source tarballs. Or, perhaps someone else has such
  5724. a directory for which you have read access. If so, you can save time by
  5725. adding statements to your configuration file so that the build process
  5726. checks local directories first for existing tarballs before checking the
  5727. Internet.
  5728. Here is an efficient way to set it up in your ``local.conf`` file::
  5729. SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
  5730. INHERIT += "own-mirrors"
  5731. BB_GENERATE_MIRROR_TARBALLS = "1"
  5732. # BB_NO_NETWORK = "1"
  5733. In the previous example, the
  5734. :term:`BB_GENERATE_MIRROR_TARBALLS`
  5735. variable causes the OpenEmbedded build system to generate tarballs of
  5736. the Git repositories and store them in the
  5737. :term:`DL_DIR` directory. Due to
  5738. performance reasons, generating and storing these tarballs is not the
  5739. build system's default behavior.
  5740. You can also use the
  5741. :term:`PREMIRRORS` variable. For
  5742. an example, see the variable's glossary entry in the Yocto Project
  5743. Reference Manual.
  5744. Getting Source Files and Suppressing the Build
  5745. ----------------------------------------------
  5746. Another technique you can use to ready yourself for a successive string
  5747. of build operations, is to pre-fetch all the source files without
  5748. actually starting a build. This technique lets you work through any
  5749. download issues and ultimately gathers all the source files into your
  5750. download directory :ref:`structure-build-downloads`,
  5751. which is located with :term:`DL_DIR`.
  5752. Use the following BitBake command form to fetch all the necessary
  5753. sources without starting the build::
  5754. $ bitbake target --runall=fetch
  5755. This
  5756. variation of the BitBake command guarantees that you have all the
  5757. sources for that BitBake target should you disconnect from the Internet
  5758. and want to do the build later offline.
  5759. Selecting an Initialization Manager
  5760. ===================================
  5761. By default, the Yocto Project uses SysVinit as the initialization
  5762. manager. However, there is also support for systemd, which is a full
  5763. replacement for init with parallel starting of services, reduced shell
  5764. overhead and other features that are used by many distributions.
  5765. Within the system, SysVinit treats system components as services. These
  5766. services are maintained as shell scripts stored in the ``/etc/init.d/``
  5767. directory. Services organize into different run levels. This
  5768. organization is maintained by putting links to the services in the
  5769. ``/etc/rcN.d/`` directories, where `N/` is one of the following options:
  5770. "S", "0", "1", "2", "3", "4", "5", or "6".
  5771. .. note::
  5772. Each runlevel has a dependency on the previous runlevel. This
  5773. dependency allows the services to work properly.
  5774. In comparison, systemd treats components as units. Using units is a
  5775. broader concept as compared to using a service. A unit includes several
  5776. different types of entities. Service is one of the types of entities.
  5777. The runlevel concept in SysVinit corresponds to the concept of a target
  5778. in systemd, where target is also a type of supported unit.
  5779. In a SysVinit-based system, services load sequentially (i.e. one by one)
  5780. during init and parallelization is not supported. With systemd, services
  5781. start in parallel. Needless to say, the method can have an impact on
  5782. system startup performance.
  5783. If you want to use SysVinit, you do not have to do anything. But, if you
  5784. want to use systemd, you must take some steps as described in the
  5785. following sections.
  5786. Using systemd Exclusively
  5787. -------------------------
  5788. Set these variables in your distribution configuration file as follows::
  5789. DISTRO_FEATURES_append = " systemd"
  5790. VIRTUAL-RUNTIME_init_manager = "systemd"
  5791. You can also prevent the SysVinit distribution feature from
  5792. being automatically enabled as follows::
  5793. DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
  5794. Doing so removes any
  5795. redundant SysVinit scripts.
  5796. To remove initscripts from your image altogether, set this variable
  5797. also::
  5798. VIRTUAL-RUNTIME_initscripts = ""
  5799. For information on the backfill variable, see
  5800. :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`.
  5801. Using systemd for the Main Image and Using SysVinit for the Rescue Image
  5802. ------------------------------------------------------------------------
  5803. Set these variables in your distribution configuration file as follows::
  5804. DISTRO_FEATURES_append = " systemd"
  5805. VIRTUAL-RUNTIME_init_manager = "systemd"
  5806. Doing so causes your main image to use the
  5807. ``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal
  5808. image cannot use this package group. However, it can install SysVinit
  5809. and the appropriate packages will have support for both systemd and
  5810. SysVinit.
  5811. Selecting a Device Manager
  5812. ==========================
  5813. The Yocto Project provides multiple ways to manage the device manager
  5814. (``/dev``):
  5815. - Persistent and Pre-Populated\ ``/dev``: For this case, the ``/dev``
  5816. directory is persistent and the required device nodes are created
  5817. during the build.
  5818. - Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev``
  5819. directory is provided by the kernel as an in-memory file system and
  5820. is automatically populated by the kernel at runtime. Additional
  5821. configuration of device nodes is done in user space by a device
  5822. manager like ``udev`` or ``busybox-mdev``.
  5823. Using Persistent and Pre-Populated\ ``/dev``
  5824. --------------------------------------------
  5825. To use the static method for device population, you need to set the
  5826. :term:`USE_DEVFS` variable to "0"
  5827. as follows::
  5828. USE_DEVFS = "0"
  5829. The content of the resulting ``/dev`` directory is defined in a Device
  5830. Table file. The
  5831. :term:`IMAGE_DEVICE_TABLES`
  5832. variable defines the Device Table to use and should be set in the
  5833. machine or distro configuration file. Alternatively, you can set this
  5834. variable in your ``local.conf`` configuration file.
  5835. If you do not define the :term:`IMAGE_DEVICE_TABLES` variable, the default
  5836. ``device_table-minimal.txt`` is used::
  5837. IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
  5838. The population is handled by the ``makedevs`` utility during image
  5839. creation:
  5840. Using ``devtmpfs`` and a Device Manager
  5841. ---------------------------------------
  5842. To use the dynamic method for device population, you need to use (or be
  5843. sure to set) the :term:`USE_DEVFS`
  5844. variable to "1", which is the default::
  5845. USE_DEVFS = "1"
  5846. With this
  5847. setting, the resulting ``/dev`` directory is populated by the kernel
  5848. using ``devtmpfs``. Make sure the corresponding kernel configuration
  5849. variable ``CONFIG_DEVTMPFS`` is set when building you build a Linux
  5850. kernel.
  5851. All devices created by ``devtmpfs`` will be owned by ``root`` and have
  5852. permissions ``0600``.
  5853. To have more control over the device nodes, you can use a device manager
  5854. like ``udev`` or ``busybox-mdev``. You choose the device manager by
  5855. defining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or
  5856. distro configuration file. Alternatively, you can set this variable in
  5857. your ``local.conf`` configuration file::
  5858. VIRTUAL-RUNTIME_dev_manager = "udev"
  5859. # Some alternative values
  5860. # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
  5861. # VIRTUAL-RUNTIME_dev_manager = "systemd"
  5862. Using an External SCM
  5863. =====================
  5864. If you're working on a recipe that pulls from an external Source Code
  5865. Manager (SCM), it is possible to have the OpenEmbedded build system
  5866. notice new recipe changes added to the SCM and then build the resulting
  5867. packages that depend on the new recipes by using the latest versions.
  5868. This only works for SCMs from which it is possible to get a sensible
  5869. revision number for changes. Currently, you can do this with Apache
  5870. Subversion (SVN), Git, and Bazaar (BZR) repositories.
  5871. To enable this behavior, the :term:`PV` of
  5872. the recipe needs to reference
  5873. :term:`SRCPV`. Here is an example::
  5874. PV = "1.2.3+git${SRCPV}"
  5875. Then, you can add the following to your
  5876. ``local.conf``::
  5877. SRCREV_pn-PN = "${AUTOREV}"
  5878. :term:`PN` is the name of the recipe for
  5879. which you want to enable automatic source revision updating.
  5880. If you do not want to update your local configuration file, you can add
  5881. the following directly to the recipe to finish enabling the feature::
  5882. SRCREV = "${AUTOREV}"
  5883. The Yocto Project provides a distribution named ``poky-bleeding``, whose
  5884. configuration file contains the line::
  5885. require conf/distro/include/poky-floating-revisions.inc
  5886. This line pulls in the
  5887. listed include file that contains numerous lines of exactly that form::
  5888. #SRCREV_pn-opkg-native ?= "${AUTOREV}"
  5889. #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
  5890. #SRCREV_pn-opkg ?= "${AUTOREV}"
  5891. #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
  5892. #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
  5893. SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
  5894. SRCREV_pn-matchbox-common ?= "${AUTOREV}"
  5895. SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
  5896. SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
  5897. SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
  5898. SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
  5899. SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
  5900. SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
  5901. SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
  5902. SRCREV_pn-settings-daemon ?= "${AUTOREV}"
  5903. SRCREV_pn-screenshot ?= "${AUTOREV}"
  5904. . . .
  5905. These lines allow you to
  5906. experiment with building a distribution that tracks the latest
  5907. development source for numerous packages.
  5908. .. note::
  5909. The ``poky-bleeding`` distribution is not tested on a regular basis. Keep
  5910. this in mind if you use it.
  5911. Creating a Read-Only Root Filesystem
  5912. ====================================
  5913. Suppose, for security reasons, you need to disable your target device's
  5914. root filesystem's write permissions (i.e. you need a read-only root
  5915. filesystem). Or, perhaps you are running the device's operating system
  5916. from a read-only storage device. For either case, you can customize your
  5917. image for that behavior.
  5918. .. note::
  5919. Supporting a read-only root filesystem requires that the system and
  5920. applications do not try to write to the root filesystem. You must
  5921. configure all parts of the target system to write elsewhere, or to
  5922. gracefully fail in the event of attempting to write to the root
  5923. filesystem.
  5924. Creating the Root Filesystem
  5925. ----------------------------
  5926. To create the read-only root filesystem, simply add the
  5927. "read-only-rootfs" feature to your image, normally in one of two ways.
  5928. The first way is to add the "read-only-rootfs" image feature in the
  5929. image's recipe file via the :term:`IMAGE_FEATURES` variable::
  5930. IMAGE_FEATURES += "read-only-rootfs"
  5931. As an alternative, you can add the same feature
  5932. from within your build directory's ``local.conf`` file with the
  5933. associated :term:`EXTRA_IMAGE_FEATURES` variable, as in::
  5934. EXTRA_IMAGE_FEATURES = "read-only-rootfs"
  5935. For more information on how to use these variables, see the
  5936. ":ref:`dev-manual/common-tasks:Customizing Images Using Custom \`\`IMAGE_FEATURES\`\` and \`\`EXTRA_IMAGE_FEATURES\`\``"
  5937. section. For information on the variables, see
  5938. :term:`IMAGE_FEATURES` and
  5939. :term:`EXTRA_IMAGE_FEATURES`.
  5940. Post-Installation Scripts and Read-Only Root Filesystem
  5941. -------------------------------------------------------
  5942. It is very important that you make sure all post-Installation
  5943. (``pkg_postinst``) scripts for packages that are installed into the
  5944. image can be run at the time when the root filesystem is created during
  5945. the build on the host system. These scripts cannot attempt to run during
  5946. first-boot on the target device. With the "read-only-rootfs" feature
  5947. enabled, the build system checks during root filesystem creation to make
  5948. sure all post-installation scripts succeed. If any of these scripts
  5949. still need to be run after the root filesystem is created, the build
  5950. immediately fails. These build-time checks ensure that the build fails
  5951. rather than the target device fails later during its initial boot
  5952. operation.
  5953. Most of the common post-installation scripts generated by the build
  5954. system for the out-of-the-box Yocto Project are engineered so that they
  5955. can run during root filesystem creation (e.g. post-installation scripts
  5956. for caching fonts). However, if you create and add custom scripts, you
  5957. need to be sure they can be run during this file system creation.
  5958. Here are some common problems that prevent post-installation scripts
  5959. from running during root filesystem creation:
  5960. - *Not using $D in front of absolute paths:* The build system defines
  5961. ``$``\ :term:`D` when the root
  5962. filesystem is created. Furthermore, ``$D`` is blank when the script
  5963. is run on the target device. This implies two purposes for ``$D``:
  5964. ensuring paths are valid in both the host and target environments,
  5965. and checking to determine which environment is being used as a method
  5966. for taking appropriate actions.
  5967. - *Attempting to run processes that are specific to or dependent on the
  5968. target architecture:* You can work around these attempts by using
  5969. native tools, which run on the host system, to accomplish the same
  5970. tasks, or by alternatively running the processes under QEMU, which
  5971. has the ``qemu_run_binary`` function. For more information, see the
  5972. :ref:`qemu <ref-classes-qemu>` class.
  5973. Areas With Write Access
  5974. -----------------------
  5975. With the "read-only-rootfs" feature enabled, any attempt by the target
  5976. to write to the root filesystem at runtime fails. Consequently, you must
  5977. make sure that you configure processes and applications that attempt
  5978. these types of writes do so to directories with write access (e.g.
  5979. ``/tmp`` or ``/var/run``).
  5980. Maintaining Build Output Quality
  5981. ================================
  5982. Many factors can influence the quality of a build. For example, if you
  5983. upgrade a recipe to use a new version of an upstream software package or
  5984. you experiment with some new configuration options, subtle changes can
  5985. occur that you might not detect until later. Consider the case where
  5986. your recipe is using a newer version of an upstream package. In this
  5987. case, a new version of a piece of software might introduce an optional
  5988. dependency on another library, which is auto-detected. If that library
  5989. has already been built when the software is building, the software will
  5990. link to the built library and that library will be pulled into your
  5991. image along with the new software even if you did not want the library.
  5992. The :ref:`buildhistory <ref-classes-buildhistory>`
  5993. class helps you maintain the quality of your build output. You
  5994. can use the class to highlight unexpected and possibly unwanted changes
  5995. in the build output. When you enable build history, it records
  5996. information about the contents of each package and image and then
  5997. commits that information to a local Git repository where you can examine
  5998. the information.
  5999. The remainder of this section describes the following:
  6000. - :ref:`How you can enable and disable build history <dev-manual/common-tasks:enabling and disabling build history>`
  6001. - :ref:`How to understand what the build history contains <dev-manual/common-tasks:understanding what the build history contains>`
  6002. - :ref:`How to limit the information used for build history <dev-manual/common-tasks:using build history to gather image information only>`
  6003. - :ref:`How to examine the build history from both a command-line and web interface <dev-manual/common-tasks:examining build history information>`
  6004. Enabling and Disabling Build History
  6005. ------------------------------------
  6006. Build history is disabled by default. To enable it, add the following
  6007. :term:`INHERIT` statement and set the
  6008. :term:`BUILDHISTORY_COMMIT`
  6009. variable to "1" at the end of your ``conf/local.conf`` file found in the
  6010. :term:`Build Directory`::
  6011. INHERIT += "buildhistory"
  6012. BUILDHISTORY_COMMIT = "1"
  6013. Enabling build history as
  6014. previously described causes the OpenEmbedded build system to collect
  6015. build output information and commit it as a single commit to a local
  6016. :ref:`overview-manual/development-environment:git` repository.
  6017. .. note::
  6018. Enabling build history increases your build times slightly,
  6019. particularly for images, and increases the amount of disk space used
  6020. during the build.
  6021. You can disable build history by removing the previous statements from
  6022. your ``conf/local.conf`` file.
  6023. Understanding What the Build History Contains
  6024. ---------------------------------------------
  6025. Build history information is kept in
  6026. ``${``\ :term:`TOPDIR`\ ``}/buildhistory``
  6027. in the Build Directory as defined by the
  6028. :term:`BUILDHISTORY_DIR`
  6029. variable. Here is an example abbreviated listing:
  6030. .. image:: figures/buildhistory.png
  6031. :align: center
  6032. At the top level, there is a ``metadata-revs`` file that lists the
  6033. revisions of the repositories for the enabled layers when the build was
  6034. produced. The rest of the data splits into separate ``packages``,
  6035. ``images`` and ``sdk`` directories, the contents of which are described
  6036. as follows.
  6037. Build History Package Information
  6038. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6039. The history for each package contains a text file that has name-value
  6040. pairs with information about the package. For example,
  6041. ``buildhistory/packages/i586-poky-linux/busybox/busybox/latest``
  6042. contains the following:
  6043. .. code-block:: none
  6044. PV = 1.22.1
  6045. PR = r32
  6046. RPROVIDES =
  6047. RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
  6048. RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
  6049. PKGSIZE = 540168
  6050. FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
  6051. /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
  6052. /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
  6053. /usr/share/pixmaps /usr/share/applications /usr/share/idl \
  6054. /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
  6055. FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
  6056. /etc/busybox.links.nosuid /etc/busybox.links.suid
  6057. Most of these
  6058. name-value pairs correspond to variables used to produce the package.
  6059. The exceptions are ``FILELIST``, which is the actual list of files in
  6060. the package, and ``PKGSIZE``, which is the total size of files in the
  6061. package in bytes.
  6062. There is also a file that corresponds to the recipe from which the package
  6063. came (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``):
  6064. .. code-block:: none
  6065. PV = 1.22.1
  6066. PR = r32
  6067. DEPENDS = initscripts kern-tools-native update-rc.d-native \
  6068. virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
  6069. virtual/libc virtual/update-alternatives
  6070. PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
  6071. busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
  6072. busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
  6073. Finally, for those recipes fetched from a version control system (e.g.,
  6074. Git), there is a file that lists source revisions that are specified in
  6075. the recipe and the actual revisions used during the build. Listed
  6076. and actual revisions might differ when
  6077. :term:`SRCREV` is set to
  6078. ${:term:`AUTOREV`}. Here is an
  6079. example assuming
  6080. ``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``)::
  6081. # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
  6082. SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
  6083. # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
  6084. SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f"
  6085. You can use the
  6086. ``buildhistory-collect-srcrevs`` command with the ``-a`` option to
  6087. collect the stored :term:`SRCREV` values from build history and report them
  6088. in a format suitable for use in global configuration (e.g.,
  6089. ``local.conf`` or a distro include file) to override floating
  6090. :term:`AUTOREV` values to a fixed set of revisions. Here is some example
  6091. output from this command::
  6092. $ buildhistory-collect-srcrevs -a
  6093. # i586-poky-linux
  6094. SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
  6095. SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
  6096. SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
  6097. SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
  6098. # x86_64-linux
  6099. SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
  6100. SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
  6101. SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
  6102. SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
  6103. SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
  6104. SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
  6105. SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
  6106. SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
  6107. SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
  6108. # qemux86-poky-linux
  6109. SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
  6110. SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
  6111. # all-poky-linux
  6112. SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
  6113. .. note::
  6114. Here are some notes on using the ``buildhistory-collect-srcrevs`` command:
  6115. - By default, only values where the :term:`SRCREV` was not hardcoded
  6116. (usually when :term:`AUTOREV` is used) are reported. Use the ``-a``
  6117. option to see all :term:`SRCREV` values.
  6118. - The output statements might not have any effect if overrides are
  6119. applied elsewhere in the build system configuration. Use the
  6120. ``-f`` option to add the ``forcevariable`` override to each output
  6121. line if you need to work around this restriction.
  6122. - The script does apply special handling when building for multiple
  6123. machines. However, the script does place a comment before each set
  6124. of values that specifies which triplet to which they belong as
  6125. previously shown (e.g., ``i586-poky-linux``).
  6126. Build History Image Information
  6127. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6128. The files produced for each image are as follows:
  6129. - ``image-files:`` A directory containing selected files from the root
  6130. filesystem. The files are defined by
  6131. :term:`BUILDHISTORY_IMAGE_FILES`.
  6132. - ``build-id.txt:`` Human-readable information about the build
  6133. configuration and metadata source revisions. This file contains the
  6134. full build header as printed by BitBake.
  6135. - ``*.dot:`` Dependency graphs for the image that are compatible with
  6136. ``graphviz``.
  6137. - ``files-in-image.txt:`` A list of files in the image with
  6138. permissions, owner, group, size, and symlink information.
  6139. - ``image-info.txt:`` A text file containing name-value pairs with
  6140. information about the image. See the following listing example for
  6141. more information.
  6142. - ``installed-package-names.txt:`` A list of installed packages by name
  6143. only.
  6144. - ``installed-package-sizes.txt:`` A list of installed packages ordered
  6145. by size.
  6146. - ``installed-packages.txt:`` A list of installed packages with full
  6147. package filenames.
  6148. .. note::
  6149. Installed package information is able to be gathered and produced
  6150. even if package management is disabled for the final image.
  6151. Here is an example of ``image-info.txt``:
  6152. .. code-block:: none
  6153. DISTRO = poky
  6154. DISTRO_VERSION = 1.7
  6155. USER_CLASSES = buildstats image-prelink
  6156. IMAGE_CLASSES = image_types
  6157. IMAGE_FEATURES = debug-tweaks
  6158. IMAGE_LINGUAS =
  6159. IMAGE_INSTALL = packagegroup-core-boot run-postinsts
  6160. BAD_RECOMMENDATIONS =
  6161. NO_RECOMMENDATIONS =
  6162. PACKAGE_EXCLUDE =
  6163. ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
  6164. write_image_manifest ; buildhistory_list_installed_image ; \
  6165. buildhistory_get_image_installed ; ssh_allow_empty_password; \
  6166. postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
  6167. IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
  6168. IMAGESIZE = 6900
  6169. Other than ``IMAGESIZE``,
  6170. which is the total size of the files in the image in Kbytes, the
  6171. name-value pairs are variables that may have influenced the content of
  6172. the image. This information is often useful when you are trying to
  6173. determine why a change in the package or file listings has occurred.
  6174. Using Build History to Gather Image Information Only
  6175. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6176. As you can see, build history produces image information, including
  6177. dependency graphs, so you can see why something was pulled into the
  6178. image. If you are just interested in this information and not interested
  6179. in collecting specific package or SDK information, you can enable
  6180. writing only image information without any history by adding the
  6181. following to your ``conf/local.conf`` file found in the
  6182. :term:`Build Directory`::
  6183. INHERIT += "buildhistory"
  6184. BUILDHISTORY_COMMIT = "0"
  6185. BUILDHISTORY_FEATURES = "image"
  6186. Here, you set the
  6187. :term:`BUILDHISTORY_FEATURES`
  6188. variable to use the image feature only.
  6189. Build History SDK Information
  6190. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6191. Build history collects similar information on the contents of SDKs (e.g.
  6192. ``bitbake -c populate_sdk imagename``) as compared to information it
  6193. collects for images. Furthermore, this information differs depending on
  6194. whether an extensible or standard SDK is being produced.
  6195. The following list shows the files produced for SDKs:
  6196. - ``files-in-sdk.txt:`` A list of files in the SDK with permissions,
  6197. owner, group, size, and symlink information. This list includes both
  6198. the host and target parts of the SDK.
  6199. - ``sdk-info.txt:`` A text file containing name-value pairs with
  6200. information about the SDK. See the following listing example for more
  6201. information.
  6202. - ``sstate-task-sizes.txt:`` A text file containing name-value pairs
  6203. with information about task group sizes (e.g. ``do_populate_sysroot``
  6204. tasks have a total size). The ``sstate-task-sizes.txt`` file exists
  6205. only when an extensible SDK is created.
  6206. - ``sstate-package-sizes.txt:`` A text file containing name-value pairs
  6207. with information for the shared-state packages and sizes in the SDK.
  6208. The ``sstate-package-sizes.txt`` file exists only when an extensible
  6209. SDK is created.
  6210. - ``sdk-files:`` A folder that contains copies of the files mentioned
  6211. in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output.
  6212. Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is
  6213. specific to the extensible SDK although you can set it differently if
  6214. you would like to pull in specific files from the standard SDK.
  6215. The default files are ``conf/local.conf``, ``conf/bblayers.conf``,
  6216. ``conf/auto.conf``, ``conf/locked-sigs.inc``, and
  6217. ``conf/devtool.conf``. Thus, for an extensible SDK, these files get
  6218. copied into the ``sdk-files`` directory.
  6219. - The following information appears under each of the ``host`` and
  6220. ``target`` directories for the portions of the SDK that run on the
  6221. host and on the target, respectively:
  6222. .. note::
  6223. The following files for the most part are empty when producing an
  6224. extensible SDK because this type of SDK is not constructed from
  6225. packages as is the standard SDK.
  6226. - ``depends.dot:`` Dependency graph for the SDK that is compatible
  6227. with ``graphviz``.
  6228. - ``installed-package-names.txt:`` A list of installed packages by
  6229. name only.
  6230. - ``installed-package-sizes.txt:`` A list of installed packages
  6231. ordered by size.
  6232. - ``installed-packages.txt:`` A list of installed packages with full
  6233. package filenames.
  6234. Here is an example of ``sdk-info.txt``:
  6235. .. code-block:: none
  6236. DISTRO = poky
  6237. DISTRO_VERSION = 1.3+snapshot-20130327
  6238. SDK_NAME = poky-glibc-i686-arm
  6239. SDK_VERSION = 1.3+snapshot
  6240. SDKMACHINE =
  6241. SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
  6242. BAD_RECOMMENDATIONS =
  6243. SDKSIZE = 352712
  6244. Other than ``SDKSIZE``, which is
  6245. the total size of the files in the SDK in Kbytes, the name-value pairs
  6246. are variables that might have influenced the content of the SDK. This
  6247. information is often useful when you are trying to determine why a
  6248. change in the package or file listings has occurred.
  6249. Examining Build History Information
  6250. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6251. You can examine build history output from the command line or from a web
  6252. interface.
  6253. To see any changes that have occurred (assuming you have
  6254. :term:`BUILDHISTORY_COMMIT` = "1"),
  6255. you can simply use any Git command that allows you to view the history
  6256. of a repository. Here is one method::
  6257. $ git log -p
  6258. You need to realize,
  6259. however, that this method does show changes that are not significant
  6260. (e.g. a package's size changing by a few bytes).
  6261. There is a command-line tool called ``buildhistory-diff``, though,
  6262. that queries the Git repository and prints just the differences that
  6263. might be significant in human-readable form. Here is an example::
  6264. $ poky/poky/scripts/buildhistory-diff . HEAD^
  6265. Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
  6266. /etc/anotherpkg.conf was added
  6267. /sbin/anotherpkg was added
  6268. * (installed-package-names.txt):
  6269. * anotherpkg was added
  6270. Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
  6271. anotherpkg was added
  6272. packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
  6273. * PR changed from "r0" to "r1"
  6274. * PV changed from "0.1.10" to "0.1.12"
  6275. packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
  6276. * PR changed from "r0" to "r1"
  6277. * PV changed from "0.1.10" to "0.1.12"
  6278. .. note::
  6279. The ``buildhistory-diff`` tool requires the ``GitPython``
  6280. package. Be sure to install it using Pip3 as follows::
  6281. $ pip3 install GitPython --user
  6282. Alternatively, you can install ``python3-git`` using the appropriate
  6283. distribution package manager (e.g. ``apt-get``, ``dnf``, or ``zipper``).
  6284. To see changes to the build history using a web interface, follow the
  6285. instruction in the ``README`` file
  6286. :yocto_git:`here </buildhistory-web/>`.
  6287. Here is a sample screenshot of the interface:
  6288. .. image:: figures/buildhistory-web.png
  6289. :align: center
  6290. Performing Automated Runtime Testing
  6291. ====================================
  6292. The OpenEmbedded build system makes available a series of automated
  6293. tests for images to verify runtime functionality. You can run these
  6294. tests on either QEMU or actual target hardware. Tests are written in
  6295. Python making use of the ``unittest`` module, and the majority of them
  6296. run commands on the target system over SSH. This section describes how
  6297. you set up the environment to use these tests, run available tests, and
  6298. write and add your own tests.
  6299. For information on the test and QA infrastructure available within the
  6300. Yocto Project, see the ":ref:`ref-manual/release-process:testing and quality assurance`"
  6301. section in the Yocto Project Reference Manual.
  6302. Enabling Tests
  6303. --------------
  6304. Depending on whether you are planning to run tests using QEMU or on the
  6305. hardware, you have to take different steps to enable the tests. See the
  6306. following subsections for information on how to enable both types of
  6307. tests.
  6308. Enabling Runtime Tests on QEMU
  6309. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6310. In order to run tests, you need to do the following:
  6311. - *Set up to avoid interaction with sudo for networking:* To
  6312. accomplish this, you must do one of the following:
  6313. - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all
  6314. commands or just for ``runqemu-ifup``. You must provide the full
  6315. path as that can change if you are using multiple clones of the
  6316. source repository.
  6317. .. note::
  6318. On some distributions, you also need to comment out "Defaults
  6319. requiretty" in ``/etc/sudoers``.
  6320. - Manually configure a tap interface for your system.
  6321. - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which
  6322. should generate a list of tap devices. This is the option
  6323. typically chosen for Autobuilder-type environments.
  6324. .. note::
  6325. - Be sure to use an absolute path when calling this script
  6326. with sudo.
  6327. - The package recipe ``qemu-helper-native`` is required to run
  6328. this script. Build the package using the following command::
  6329. $ bitbake qemu-helper-native
  6330. - *Set the DISPLAY variable:* You need to set this variable so that
  6331. you have an X server available (e.g. start ``vncserver`` for a
  6332. headless machine).
  6333. - *Be sure your host's firewall accepts incoming connections from
  6334. 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an
  6335. HTTP server on a random high number port, which is used to serve
  6336. files to the target. The DNF module serves
  6337. ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands.
  6338. That means your host's firewall must accept incoming connections from
  6339. 192.168.7.0/24, which is the default IP range used for tap devices by
  6340. ``runqemu``.
  6341. - *Be sure your host has the correct packages installed:* Depending
  6342. your host's distribution, you need to have the following packages
  6343. installed:
  6344. - Ubuntu and Debian: ``sysstat`` and ``iproute2``
  6345. - openSUSE: ``sysstat`` and ``iproute2``
  6346. - Fedora: ``sysstat`` and ``iproute``
  6347. - CentOS: ``sysstat`` and ``iproute``
  6348. Once you start running the tests, the following happens:
  6349. 1. A copy of the root filesystem is written to ``${WORKDIR}/testimage``.
  6350. 2. The image is booted under QEMU using the standard ``runqemu`` script.
  6351. 3. A default timeout of 500 seconds occurs to allow for the boot process
  6352. to reach the login prompt. You can change the timeout period by
  6353. setting
  6354. :term:`TEST_QEMUBOOT_TIMEOUT`
  6355. in the ``local.conf`` file.
  6356. 4. Once the boot process is reached and the login prompt appears, the
  6357. tests run. The full boot log is written to
  6358. ``${WORKDIR}/testimage/qemu_boot_log``.
  6359. 5. Each test module loads in the order found in :term:`TEST_SUITES`. You can
  6360. find the full output of the commands run over SSH in
  6361. ``${WORKDIR}/testimgage/ssh_target_log``.
  6362. 6. If no failures occur, the task running the tests ends successfully.
  6363. You can find the output from the ``unittest`` in the task log at
  6364. ``${WORKDIR}/temp/log.do_testimage``.
  6365. Enabling Runtime Tests on Hardware
  6366. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6367. The OpenEmbedded build system can run tests on real hardware, and for
  6368. certain devices it can also deploy the image to be tested onto the
  6369. device beforehand.
  6370. For automated deployment, a "master image" is installed onto the
  6371. hardware once as part of setup. Then, each time tests are to be run, the
  6372. following occurs:
  6373. 1. The master image is booted into and used to write the image to be
  6374. tested to a second partition.
  6375. 2. The device is then rebooted using an external script that you need to
  6376. provide.
  6377. 3. The device boots into the image to be tested.
  6378. When running tests (independent of whether the image has been deployed
  6379. automatically or not), the device is expected to be connected to a
  6380. network on a pre-determined IP address. You can either use static IP
  6381. addresses written into the image, or set the image to use DHCP and have
  6382. your DHCP server on the test network assign a known IP address based on
  6383. the MAC address of the device.
  6384. In order to run tests on hardware, you need to set :term:`TEST_TARGET` to an
  6385. appropriate value. For QEMU, you do not have to change anything, the
  6386. default value is "qemu". For running tests on hardware, the following
  6387. options are available:
  6388. - *"simpleremote":* Choose "simpleremote" if you are going to run tests
  6389. on a target system that is already running the image to be tested and
  6390. is available on the network. You can use "simpleremote" in
  6391. conjunction with either real hardware or an image running within a
  6392. separately started QEMU or any other virtual machine manager.
  6393. - *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is
  6394. an EFI-based machine with ``systemd-boot`` as bootloader and
  6395. ``core-image-testmaster`` (or something similar) is installed. Also,
  6396. your hardware under test must be in a DHCP-enabled network that gives
  6397. it the same IP address for each reboot.
  6398. If you choose "SystemdbootTarget", there are additional requirements
  6399. and considerations. See the
  6400. ":ref:`dev-manual/common-tasks:selecting systemdboottarget`" section, which
  6401. follows, for more information.
  6402. - *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying
  6403. images and running tests on the BeagleBone "Black" or original
  6404. "White" hardware. For information on how to use these tests, see the
  6405. comments at the top of the BeagleBoneTarget
  6406. ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file.
  6407. - *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying
  6408. images and running tests on the Ubiquiti Networks EdgeRouter Lite.
  6409. For information on how to use these tests, see the comments at the
  6410. top of the EdgeRouterTarget
  6411. ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file.
  6412. - *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running
  6413. tests on any generic PC that boots using GRUB. For information on how
  6414. to use these tests, see the comments at the top of the GrubTarget
  6415. ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file.
  6416. - *"your-target":* Create your own custom target if you want to run
  6417. tests when you are deploying images and running tests on a custom
  6418. machine within your BSP layer. To do this, you need to add a Python
  6419. unit that defines the target class under ``lib/oeqa/controllers/``
  6420. within your layer. You must also provide an empty ``__init__.py``.
  6421. For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``.
  6422. Selecting SystemdbootTarget
  6423. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6424. If you did not set :term:`TEST_TARGET` to "SystemdbootTarget", then you do
  6425. not need any information in this section. You can skip down to the
  6426. ":ref:`dev-manual/common-tasks:running tests`" section.
  6427. If you did set :term:`TEST_TARGET` to "SystemdbootTarget", you also need to
  6428. perform a one-time setup of your master image by doing the following:
  6429. 1. *Set EFI_PROVIDER:* Be sure that :term:`EFI_PROVIDER` is as follows::
  6430. EFI_PROVIDER = "systemd-boot"
  6431. 2. *Build the master image:* Build the ``core-image-testmaster`` image.
  6432. The ``core-image-testmaster`` recipe is provided as an example for a
  6433. "master" image and you can customize the image recipe as you would
  6434. any other recipe.
  6435. Here are the image recipe requirements:
  6436. - Inherits ``core-image`` so that kernel modules are installed.
  6437. - Installs normal linux utilities not BusyBox ones (e.g. ``bash``,
  6438. ``coreutils``, ``tar``, ``gzip``, and ``kmod``).
  6439. - Uses a custom Initial RAM Disk (initramfs) image with a custom
  6440. installer. A normal image that you can install usually creates a
  6441. single rootfs partition. This image uses another installer that
  6442. creates a specific partition layout. Not all Board Support
  6443. Packages (BSPs) can use an installer. For such cases, you need to
  6444. manually create the following partition layout on the target:
  6445. - First partition mounted under ``/boot``, labeled "boot".
  6446. - The main rootfs partition where this image gets installed,
  6447. which is mounted under ``/``.
  6448. - Another partition labeled "testrootfs" where test images get
  6449. deployed.
  6450. 3. *Install image:* Install the image that you just built on the target
  6451. system.
  6452. The final thing you need to do when setting :term:`TEST_TARGET` to
  6453. "SystemdbootTarget" is to set up the test image:
  6454. 1. *Set up your local.conf file:* Make sure you have the following
  6455. statements in your ``local.conf`` file::
  6456. IMAGE_FSTYPES += "tar.gz"
  6457. INHERIT += "testimage"
  6458. TEST_TARGET = "SystemdbootTarget"
  6459. TEST_TARGET_IP = "192.168.2.3"
  6460. 2. *Build your test image:* Use BitBake to build the image::
  6461. $ bitbake core-image-sato
  6462. Power Control
  6463. ~~~~~~~~~~~~~
  6464. For most hardware targets other than "simpleremote", you can control
  6465. power:
  6466. - You can use :term:`TEST_POWERCONTROL_CMD` together with
  6467. :term:`TEST_POWERCONTROL_EXTRA_ARGS` as a command that runs on the host
  6468. and does power cycling. The test code passes one argument to that
  6469. command: off, on or cycle (off then on). Here is an example that
  6470. could appear in your ``local.conf`` file::
  6471. TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
  6472. In this example, the expect
  6473. script does the following:
  6474. .. code-block:: shell
  6475. ssh test@10.11.12.1 "pyctl nuc1 arg"
  6476. It then runs a Python script that controls power for a label called
  6477. ``nuc1``.
  6478. .. note::
  6479. You need to customize :term:`TEST_POWERCONTROL_CMD` and
  6480. :term:`TEST_POWERCONTROL_EXTRA_ARGS` for your own setup. The one requirement
  6481. is that it accepts "on", "off", and "cycle" as the last argument.
  6482. - When no command is defined, it connects to the device over SSH and
  6483. uses the classic reboot command to reboot the device. Classic reboot
  6484. is fine as long as the machine actually reboots (i.e. the SSH test
  6485. has not failed). It is useful for scenarios where you have a simple
  6486. setup, typically with a single board, and where some manual
  6487. interaction is okay from time to time.
  6488. If you have no hardware to automatically perform power control but still
  6489. wish to experiment with automated hardware testing, you can use the
  6490. ``dialog-power-control`` script that shows a dialog prompting you to perform
  6491. the required power action. This script requires either KDialog or Zenity
  6492. to be installed. To use this script, set the
  6493. :term:`TEST_POWERCONTROL_CMD`
  6494. variable as follows::
  6495. TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
  6496. Serial Console Connection
  6497. ~~~~~~~~~~~~~~~~~~~~~~~~~
  6498. For test target classes requiring a serial console to interact with the
  6499. bootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget),
  6500. you need to specify a command to use to connect to the serial console of
  6501. the target machine by using the
  6502. :term:`TEST_SERIALCONTROL_CMD`
  6503. variable and optionally the
  6504. :term:`TEST_SERIALCONTROL_EXTRA_ARGS`
  6505. variable.
  6506. These cases could be a serial terminal program if the machine is
  6507. connected to a local serial port, or a ``telnet`` or ``ssh`` command
  6508. connecting to a remote console server. Regardless of the case, the
  6509. command simply needs to connect to the serial console and forward that
  6510. connection to standard input and output as any normal terminal program
  6511. does. For example, to use the picocom terminal program on serial device
  6512. ``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows::
  6513. TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
  6514. For local
  6515. devices where the serial port device disappears when the device reboots,
  6516. an additional "serdevtry" wrapper script is provided. To use this
  6517. wrapper, simply prefix the terminal command with
  6518. ``${COREBASE}/scripts/contrib/serdevtry``::
  6519. TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0"
  6520. Running Tests
  6521. -------------
  6522. You can start the tests automatically or manually:
  6523. - *Automatically running tests:* To run the tests automatically after
  6524. the OpenEmbedded build system successfully creates an image, first
  6525. set the
  6526. :term:`TESTIMAGE_AUTO`
  6527. variable to "1" in your ``local.conf`` file in the
  6528. :term:`Build Directory`::
  6529. TESTIMAGE_AUTO = "1"
  6530. Next, build your image. If the image successfully builds, the
  6531. tests run::
  6532. bitbake core-image-sato
  6533. - *Manually running tests:* To manually run the tests, first globally
  6534. inherit the
  6535. :ref:`testimage <ref-classes-testimage*>` class
  6536. by editing your ``local.conf`` file::
  6537. INHERIT += "testimage"
  6538. Next, use BitBake to run the tests::
  6539. bitbake -c testimage image
  6540. All test files reside in ``meta/lib/oeqa/runtime`` in the
  6541. :term:`Source Directory`. A test name maps
  6542. directly to a Python module. Each test module may contain a number of
  6543. individual tests. Tests are usually grouped together by the area tested
  6544. (e.g tests for systemd reside in ``meta/lib/oeqa/runtime/systemd.py``).
  6545. You can add tests to any layer provided you place them in the proper
  6546. area and you extend :term:`BBPATH` in
  6547. the ``local.conf`` file as normal. Be sure that tests reside in
  6548. ``layer/lib/oeqa/runtime``.
  6549. .. note::
  6550. Be sure that module names do not collide with module names used in
  6551. the default set of test modules in ``meta/lib/oeqa/runtime``.
  6552. You can change the set of tests run by appending or overriding
  6553. :term:`TEST_SUITES` variable in
  6554. ``local.conf``. Each name in :term:`TEST_SUITES` represents a required test
  6555. for the image. Test modules named within :term:`TEST_SUITES` cannot be
  6556. skipped even if a test is not suitable for an image (e.g. running the
  6557. RPM tests on an image without ``rpm``). Appending "auto" to
  6558. :term:`TEST_SUITES` causes the build system to try to run all tests that are
  6559. suitable for the image (i.e. each test module may elect to skip itself).
  6560. The order you list tests in :term:`TEST_SUITES` is important and influences
  6561. test dependencies. Consequently, tests that depend on other tests should
  6562. be added after the test on which they depend. For example, since the
  6563. ``ssh`` test depends on the ``ping`` test, "ssh" needs to come after
  6564. "ping" in the list. The test class provides no re-ordering or dependency
  6565. handling.
  6566. .. note::
  6567. Each module can have multiple classes with multiple test methods.
  6568. And, Python ``unittest`` rules apply.
  6569. Here are some things to keep in mind when running tests:
  6570. - The default tests for the image are defined as::
  6571. DEFAULT_TEST_SUITES_pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg"
  6572. - Add your own test to the list of the by using the following::
  6573. TEST_SUITES_append = " mytest"
  6574. - Run a specific list of tests as follows::
  6575. TEST_SUITES = "test1 test2 test3"
  6576. Remember, order is important. Be sure to place a test that is
  6577. dependent on another test later in the order.
  6578. Exporting Tests
  6579. ---------------
  6580. You can export tests so that they can run independently of the build
  6581. system. Exporting tests is required if you want to be able to hand the
  6582. test execution off to a scheduler. You can only export tests that are
  6583. defined in :term:`TEST_SUITES`.
  6584. If your image is already built, make sure the following are set in your
  6585. ``local.conf`` file::
  6586. INHERIT += "testexport"
  6587. TEST_TARGET_IP = "IP-address-for-the-test-target"
  6588. TEST_SERVER_IP = "IP-address-for-the-test-server"
  6589. You can then export the tests with the
  6590. following BitBake command form::
  6591. $ bitbake image -c testexport
  6592. Exporting the tests places them in the
  6593. :term:`Build Directory` in
  6594. ``tmp/testexport/``\ image, which is controlled by the
  6595. :term:`TEST_EXPORT_DIR` variable.
  6596. You can now run the tests outside of the build environment::
  6597. $ cd tmp/testexport/image
  6598. $ ./runexported.py testdata.json
  6599. Here is a complete example that shows IP addresses and uses the
  6600. ``core-image-sato`` image::
  6601. INHERIT += "testexport"
  6602. TEST_TARGET_IP = "192.168.7.2"
  6603. TEST_SERVER_IP = "192.168.7.1"
  6604. Use BitBake to export the tests::
  6605. $ bitbake core-image-sato -c testexport
  6606. Run the tests outside of
  6607. the build environment using the following::
  6608. $ cd tmp/testexport/core-image-sato
  6609. $ ./runexported.py testdata.json
  6610. Writing New Tests
  6611. -----------------
  6612. As mentioned previously, all new test files need to be in the proper
  6613. place for the build system to find them. New tests for additional
  6614. functionality outside of the core should be added to the layer that adds
  6615. the functionality, in ``layer/lib/oeqa/runtime`` (as long as
  6616. :term:`BBPATH` is extended in the
  6617. layer's ``layer.conf`` file as normal). Just remember the following:
  6618. - Filenames need to map directly to test (module) names.
  6619. - Do not use module names that collide with existing core tests.
  6620. - Minimally, an empty ``__init__.py`` file must be present in the runtime
  6621. directory.
  6622. To create a new test, start by copying an existing module (e.g.
  6623. ``syslog.py`` or ``gcc.py`` are good ones to use). Test modules can use
  6624. code from ``meta/lib/oeqa/utils``, which are helper classes.
  6625. .. note::
  6626. Structure shell commands such that you rely on them and they return a
  6627. single code for success. Be aware that sometimes you will need to
  6628. parse the output. See the ``df.py`` and ``date.py`` modules for examples.
  6629. You will notice that all test classes inherit ``oeRuntimeTest``, which
  6630. is found in ``meta/lib/oetest.py``. This base class offers some helper
  6631. attributes, which are described in the following sections:
  6632. Class Methods
  6633. ~~~~~~~~~~~~~
  6634. Class methods are as follows:
  6635. - *hasPackage(pkg):* Returns "True" if ``pkg`` is in the installed
  6636. package list of the image, which is based on the manifest file that
  6637. is generated during the ``do_rootfs`` task.
  6638. - *hasFeature(feature):* Returns "True" if the feature is in
  6639. :term:`IMAGE_FEATURES` or
  6640. :term:`DISTRO_FEATURES`.
  6641. Class Attributes
  6642. ~~~~~~~~~~~~~~~~
  6643. Class attributes are as follows:
  6644. - *pscmd:* Equals "ps -ef" if ``procps`` is installed in the image.
  6645. Otherwise, ``pscmd`` equals "ps" (busybox).
  6646. - *tc:* The called test context, which gives access to the
  6647. following attributes:
  6648. - *d:* The BitBake datastore, which allows you to use stuff such
  6649. as ``oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")``.
  6650. - *testslist and testsrequired:* Used internally. The tests
  6651. do not need these.
  6652. - *filesdir:* The absolute path to
  6653. ``meta/lib/oeqa/runtime/files``, which contains helper files for
  6654. tests meant for copying on the target such as small files written
  6655. in C for compilation.
  6656. - *target:* The target controller object used to deploy and
  6657. start an image on a particular target (e.g. Qemu, SimpleRemote,
  6658. and SystemdbootTarget). Tests usually use the following:
  6659. - *ip:* The target's IP address.
  6660. - *server_ip:* The host's IP address, which is usually used
  6661. by the DNF test suite.
  6662. - *run(cmd, timeout=None):* The single, most used method.
  6663. This command is a wrapper for: ``ssh root@host "cmd"``. The
  6664. command returns a tuple: (status, output), which are what their
  6665. names imply - the return code of "cmd" and whatever output it
  6666. produces. The optional timeout argument represents the number
  6667. of seconds the test should wait for "cmd" to return. If the
  6668. argument is "None", the test uses the default instance's
  6669. timeout period, which is 300 seconds. If the argument is "0",
  6670. the test runs until the command returns.
  6671. - *copy_to(localpath, remotepath):*
  6672. ``scp localpath root@ip:remotepath``.
  6673. - *copy_from(remotepath, localpath):*
  6674. ``scp root@host:remotepath localpath``.
  6675. Instance Attributes
  6676. ~~~~~~~~~~~~~~~~~~~
  6677. There is a single instance attribute, which is ``target``. The ``target``
  6678. instance attribute is identical to the class attribute of the same name,
  6679. which is described in the previous section. This attribute exists as
  6680. both an instance and class attribute so tests can use
  6681. ``self.target.run(cmd)`` in instance methods instead of
  6682. ``oeRuntimeTest.tc.target.run(cmd)``.
  6683. Installing Packages in the DUT Without the Package Manager
  6684. ----------------------------------------------------------
  6685. When a test requires a package built by BitBake, it is possible to
  6686. install that package. Installing the package does not require a package
  6687. manager be installed in the device under test (DUT). It does, however,
  6688. require an SSH connection and the target must be using the
  6689. ``sshcontrol`` class.
  6690. .. note::
  6691. This method uses ``scp`` to copy files from the host to the target, which
  6692. causes permissions and special attributes to be lost.
  6693. A JSON file is used to define the packages needed by a test. This file
  6694. must be in the same path as the file used to define the tests.
  6695. Furthermore, the filename must map directly to the test module name with
  6696. a ``.json`` extension.
  6697. The JSON file must include an object with the test name as keys of an
  6698. object or an array. This object (or array of objects) uses the following
  6699. data:
  6700. - "pkg" - A mandatory string that is the name of the package to be
  6701. installed.
  6702. - "rm" - An optional boolean, which defaults to "false", that specifies
  6703. to remove the package after the test.
  6704. - "extract" - An optional boolean, which defaults to "false", that
  6705. specifies if the package must be extracted from the package format.
  6706. When set to "true", the package is not automatically installed into
  6707. the DUT.
  6708. Following is an example JSON file that handles test "foo" installing
  6709. package "bar" and test "foobar" installing packages "foo" and "bar".
  6710. Once the test is complete, the packages are removed from the DUT.
  6711. ::
  6712. {
  6713. "foo": {
  6714. "pkg": "bar"
  6715. },
  6716. "foobar": [
  6717. {
  6718. "pkg": "foo",
  6719. "rm": true
  6720. },
  6721. {
  6722. "pkg": "bar",
  6723. "rm": true
  6724. }
  6725. ]
  6726. }
  6727. Debugging Tools and Techniques
  6728. ==============================
  6729. The exact method for debugging build failures depends on the nature of
  6730. the problem and on the system's area from which the bug originates.
  6731. Standard debugging practices such as comparison against the last known
  6732. working version with examination of the changes and the re-application
  6733. of steps to identify the one causing the problem are valid for the Yocto
  6734. Project just as they are for any other system. Even though it is
  6735. impossible to detail every possible potential failure, this section
  6736. provides some general tips to aid in debugging given a variety of
  6737. situations.
  6738. .. note::
  6739. A useful feature for debugging is the error reporting tool.
  6740. Configuring the Yocto Project to use this tool causes the
  6741. OpenEmbedded build system to produce error reporting commands as part
  6742. of the console output. You can enter the commands after the build
  6743. completes to log error information into a common database, that can
  6744. help you figure out what might be going wrong. For information on how
  6745. to enable and use this feature, see the
  6746. ":ref:`dev-manual/common-tasks:using the error reporting tool`"
  6747. section.
  6748. The following list shows the debugging topics in the remainder of this
  6749. section:
  6750. - ":ref:`dev-manual/common-tasks:viewing logs from failed tasks`" describes
  6751. how to find and view logs from tasks that failed during the build
  6752. process.
  6753. - ":ref:`dev-manual/common-tasks:viewing variable values`" describes how to
  6754. use the BitBake ``-e`` option to examine variable values after a
  6755. recipe has been parsed.
  6756. - ":ref:`dev-manual/common-tasks:viewing package information with \`\`oe-pkgdata-util\`\``"
  6757. describes how to use the ``oe-pkgdata-util`` utility to query
  6758. :term:`PKGDATA_DIR` and
  6759. display package-related information for built packages.
  6760. - ":ref:`dev-manual/common-tasks:viewing dependencies between recipes and tasks`"
  6761. describes how to use the BitBake ``-g`` option to display recipe
  6762. dependency information used during the build.
  6763. - ":ref:`dev-manual/common-tasks:viewing task variable dependencies`" describes
  6764. how to use the ``bitbake-dumpsig`` command in conjunction with key
  6765. subdirectories in the
  6766. :term:`Build Directory` to determine
  6767. variable dependencies.
  6768. - ":ref:`dev-manual/common-tasks:running specific tasks`" describes
  6769. how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``)
  6770. to run specific tasks in the build chain. It can be useful to run
  6771. tasks "out-of-order" when trying isolate build issues.
  6772. - ":ref:`dev-manual/common-tasks:general bitbake problems`" describes how
  6773. to use BitBake's ``-D`` debug output option to reveal more about what
  6774. BitBake is doing during the build.
  6775. - ":ref:`dev-manual/common-tasks:building with no dependencies`"
  6776. describes how to use the BitBake ``-b`` option to build a recipe
  6777. while ignoring dependencies.
  6778. - ":ref:`dev-manual/common-tasks:recipe logging mechanisms`"
  6779. describes how to use the many recipe logging functions to produce
  6780. debugging output and report errors and warnings.
  6781. - ":ref:`dev-manual/common-tasks:debugging parallel make races`"
  6782. describes how to debug situations where the build consists of several
  6783. parts that are run simultaneously and when the output or result of
  6784. one part is not ready for use with a different part of the build that
  6785. depends on that output.
  6786. - ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) remotely`"
  6787. describes how to use GDB to allow you to examine running programs, which can
  6788. help you fix problems.
  6789. - ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) on the target`"
  6790. describes how to use GDB directly on target hardware for debugging.
  6791. - ":ref:`dev-manual/common-tasks:other debugging tips`" describes
  6792. miscellaneous debugging tips that can be useful.
  6793. Viewing Logs from Failed Tasks
  6794. ------------------------------
  6795. You can find the log for a task in the file
  6796. ``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`.
  6797. For example, the log for the
  6798. :ref:`ref-tasks-compile` task of the
  6799. QEMU minimal image for the x86 machine (``qemux86``) might be in
  6800. ``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``.
  6801. To see the commands :term:`BitBake` ran
  6802. to generate a log, look at the corresponding ``run.do_``\ `taskname` file
  6803. in the same directory.
  6804. ``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic
  6805. links to ``log.do_``\ `taskname`\ ``.``\ `pid` and
  6806. ``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had
  6807. when it ran. The symlinks always point to the files corresponding to the
  6808. most recent run.
  6809. Viewing Variable Values
  6810. -----------------------
  6811. Sometimes you need to know the value of a variable as a result of
  6812. BitBake's parsing step. This could be because some unexpected behavior
  6813. occurred in your project. Perhaps an attempt to :ref:`modify a variable
  6814. <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing
  6815. variables>` did not work out as expected.
  6816. BitBake's ``-e`` option is used to display variable values after
  6817. parsing. The following command displays the variable values after the
  6818. configuration files (i.e. ``local.conf``, ``bblayers.conf``,
  6819. ``bitbake.conf`` and so forth) have been parsed::
  6820. $ bitbake -e
  6821. The following command displays variable values after a specific recipe has
  6822. been parsed. The variables include those from the configuration as well::
  6823. $ bitbake -e recipename
  6824. .. note::
  6825. Each recipe has its own private set of variables (datastore).
  6826. Internally, after parsing the configuration, a copy of the resulting
  6827. datastore is made prior to parsing each recipe. This copying implies
  6828. that variables set in one recipe will not be visible to other
  6829. recipes.
  6830. Likewise, each task within a recipe gets a private datastore based on
  6831. the recipe datastore, which means that variables set within one task
  6832. will not be visible to other tasks.
  6833. In the output of ``bitbake -e``, each variable is preceded by a
  6834. description of how the variable got its value, including temporary
  6835. values that were later overridden. This description also includes
  6836. variable flags (varflags) set on the variable. The output can be very
  6837. helpful during debugging.
  6838. Variables that are exported to the environment are preceded by
  6839. ``export`` in the output of ``bitbake -e``. See the following example::
  6840. export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
  6841. In addition to variable values, the output of the ``bitbake -e`` and
  6842. ``bitbake -e`` recipe commands includes the following information:
  6843. - The output starts with a tree listing all configuration files and
  6844. classes included globally, recursively listing the files they include
  6845. or inherit in turn. Much of the behavior of the OpenEmbedded build
  6846. system (including the behavior of the :ref:`ref-manual/tasks:normal recipe build tasks`) is
  6847. implemented in the
  6848. :ref:`base <ref-classes-base>` class and the
  6849. classes it inherits, rather than being built into BitBake itself.
  6850. - After the variable values, all functions appear in the output. For
  6851. shell functions, variables referenced within the function body are
  6852. expanded. If a function has been modified using overrides or using
  6853. override-style operators like ``_append`` and ``_prepend``, then the
  6854. final assembled function body appears in the output.
  6855. Viewing Package Information with ``oe-pkgdata-util``
  6856. ----------------------------------------------------
  6857. You can use the ``oe-pkgdata-util`` command-line utility to query
  6858. :term:`PKGDATA_DIR` and display
  6859. various package-related information. When you use the utility, you must
  6860. use it to view information on packages that have already been built.
  6861. Following are a few of the available ``oe-pkgdata-util`` subcommands.
  6862. .. note::
  6863. You can use the standard \* and ? globbing wildcards as part of
  6864. package names and paths.
  6865. - ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages
  6866. that have been built, optionally limiting the match to packages that
  6867. match pattern.
  6868. - ``oe-pkgdata-util list-pkg-files package ...``: Lists the
  6869. files and directories contained in the given packages.
  6870. .. note::
  6871. A different way to view the contents of a package is to look at
  6872. the
  6873. ``${``\ :term:`WORKDIR`\ ``}/packages-split``
  6874. directory of the recipe that generates the package. This directory
  6875. is created by the
  6876. :ref:`ref-tasks-package` task
  6877. and has one subdirectory for each package the recipe generates,
  6878. which contains the files stored in that package.
  6879. If you want to inspect the ``${WORKDIR}/packages-split``
  6880. directory, make sure that
  6881. :ref:`rm_work <ref-classes-rm-work>` is not
  6882. enabled when you build the recipe.
  6883. - ``oe-pkgdata-util find-path path ...``: Lists the names of
  6884. the packages that contain the given paths. For example, the following
  6885. tells us that ``/usr/share/man/man1/make.1`` is contained in the
  6886. ``make-doc`` package::
  6887. $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
  6888. make-doc: /usr/share/man/man1/make.1
  6889. - ``oe-pkgdata-util lookup-recipe package ...``: Lists the name
  6890. of the recipes that produce the given packages.
  6891. For more information on the ``oe-pkgdata-util`` command, use the help
  6892. facility::
  6893. $ oe-pkgdata-util --help
  6894. $ oe-pkgdata-util subcommand --help
  6895. Viewing Dependencies Between Recipes and Tasks
  6896. ----------------------------------------------
  6897. Sometimes it can be hard to see why BitBake wants to build other recipes
  6898. before the one you have specified. Dependency information can help you
  6899. understand why a recipe is built.
  6900. To generate dependency information for a recipe, run the following
  6901. command::
  6902. $ bitbake -g recipename
  6903. This command writes the following files in the current directory:
  6904. - ``pn-buildlist``: A list of recipes/targets involved in building
  6905. `recipename`. "Involved" here means that at least one task from the
  6906. recipe needs to run when building `recipename` from scratch. Targets
  6907. that are in
  6908. :term:`ASSUME_PROVIDED`
  6909. are not listed.
  6910. - ``task-depends.dot``: A graph showing dependencies between tasks.
  6911. The graphs are in
  6912. `DOT <https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29>`__
  6913. format and can be converted to images (e.g. using the ``dot`` tool from
  6914. `Graphviz <https://www.graphviz.org/>`__).
  6915. .. note::
  6916. - DOT files use a plain text format. The graphs generated using the
  6917. ``bitbake -g`` command are often so large as to be difficult to
  6918. read without special pruning (e.g. with Bitbake's ``-I`` option)
  6919. and processing. Despite the form and size of the graphs, the
  6920. corresponding ``.dot`` files can still be possible to read and
  6921. provide useful information.
  6922. As an example, the ``task-depends.dot`` file contains lines such
  6923. as the following::
  6924. "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
  6925. The above example line reveals that the
  6926. :ref:`ref-tasks-configure`
  6927. task in ``libxslt`` depends on the
  6928. :ref:`ref-tasks-populate_sysroot`
  6929. task in ``libxml2``, which is a normal
  6930. :term:`DEPENDS` dependency
  6931. between the two recipes.
  6932. - For an example of how ``.dot`` files can be processed, see the
  6933. ``scripts/contrib/graph-tool`` Python script, which finds and
  6934. displays paths between graph nodes.
  6935. You can use a different method to view dependency information by using
  6936. the following command::
  6937. $ bitbake -g -u taskexp recipename
  6938. This command
  6939. displays a GUI window from which you can view build-time and runtime
  6940. dependencies for the recipes involved in building recipename.
  6941. Viewing Task Variable Dependencies
  6942. ----------------------------------
  6943. As mentioned in the
  6944. ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake
  6945. User Manual, BitBake tries to automatically determine what variables a
  6946. task depends on so that it can rerun the task if any values of the
  6947. variables change. This determination is usually reliable. However, if
  6948. you do things like construct variable names at runtime, then you might
  6949. have to manually declare dependencies on those variables using
  6950. ``vardeps`` as described in the
  6951. ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake
  6952. User Manual.
  6953. If you are unsure whether a variable dependency is being picked up
  6954. automatically for a given task, you can list the variable dependencies
  6955. BitBake has determined by doing the following:
  6956. 1. Build the recipe containing the task::
  6957. $ bitbake recipename
  6958. 2. Inside the :term:`STAMPS_DIR`
  6959. directory, find the signature data (``sigdata``) file that
  6960. corresponds to the task. The ``sigdata`` files contain a pickled
  6961. Python database of all the metadata that went into creating the input
  6962. checksum for the task. As an example, for the
  6963. :ref:`ref-tasks-fetch` task of the
  6964. ``db`` recipe, the ``sigdata`` file might be found in the following
  6965. location::
  6966. ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
  6967. For tasks that are accelerated through the shared state
  6968. (:ref:`sstate <overview-manual/concepts:shared state cache>`) cache, an
  6969. additional ``siginfo`` file is written into
  6970. :term:`SSTATE_DIR` along with
  6971. the cached task output. The ``siginfo`` files contain exactly the
  6972. same information as ``sigdata`` files.
  6973. 3. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here
  6974. is an example::
  6975. $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
  6976. In the output of the above command, you will find a line like the
  6977. following, which lists all the (inferred) variable dependencies for
  6978. the task. This list also includes indirect dependencies from
  6979. variables depending on other variables, recursively.
  6980. ::
  6981. Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
  6982. .. note::
  6983. Functions (e.g. ``base_do_fetch``) also count as variable dependencies.
  6984. These functions in turn depend on the variables they reference.
  6985. The output of ``bitbake-dumpsig`` also includes the value each
  6986. variable had, a list of dependencies for each variable, and
  6987. :term:`bitbake:BB_HASHBASE_WHITELIST`
  6988. information.
  6989. There is also a ``bitbake-diffsigs`` command for comparing two
  6990. ``siginfo`` or ``sigdata`` files. This command can be helpful when
  6991. trying to figure out what changed between two versions of a task. If you
  6992. call ``bitbake-diffsigs`` with just one file, the command behaves like
  6993. ``bitbake-dumpsig``.
  6994. You can also use BitBake to dump out the signature construction
  6995. information without executing tasks by using either of the following
  6996. BitBake command-line options::
  6997. ‐‐dump-signatures=SIGNATURE_HANDLER
  6998. -S SIGNATURE_HANDLER
  6999. .. note::
  7000. Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which
  7001. dump only the signature or compare the dumped signature with the cached one,
  7002. respectively.
  7003. Using BitBake with either of these options causes BitBake to dump out
  7004. ``sigdata`` files in the ``stamps`` directory for every task it would
  7005. have executed instead of building the specified target package.
  7006. Viewing Metadata Used to Create the Input Signature of a Shared State Task
  7007. --------------------------------------------------------------------------
  7008. Seeing what metadata went into creating the input signature of a shared
  7009. state (sstate) task can be a useful debugging aid. This information is
  7010. available in signature information (``siginfo``) files in
  7011. :term:`SSTATE_DIR`. For
  7012. information on how to view and interpret information in ``siginfo``
  7013. files, see the
  7014. ":ref:`dev-manual/common-tasks:viewing task variable dependencies`" section.
  7015. For conceptual information on shared state, see the
  7016. ":ref:`overview-manual/concepts:shared state`"
  7017. section in the Yocto Project Overview and Concepts Manual.
  7018. Invalidating Shared State to Force a Task to Run
  7019. ------------------------------------------------
  7020. The OpenEmbedded build system uses
  7021. :ref:`checksums <overview-manual/concepts:checksums (signatures)>` and
  7022. :ref:`overview-manual/concepts:shared state` cache to avoid unnecessarily
  7023. rebuilding tasks. Collectively, this scheme is known as "shared state
  7024. code".
  7025. As with all schemes, this one has some drawbacks. It is possible that
  7026. you could make implicit changes to your code that the checksum
  7027. calculations do not take into account. These implicit changes affect a
  7028. task's output but do not trigger the shared state code into rebuilding a
  7029. recipe. Consider an example during which a tool changes its output.
  7030. Assume that the output of ``rpmdeps`` changes. The result of the change
  7031. should be that all the ``package`` and ``package_write_rpm`` shared
  7032. state cache items become invalid. However, because the change to the
  7033. output is external to the code and therefore implicit, the associated
  7034. shared state cache items do not become invalidated. In this case, the
  7035. build process uses the cached items rather than running the task again.
  7036. Obviously, these types of implicit changes can cause problems.
  7037. To avoid these problems during the build, you need to understand the
  7038. effects of any changes you make. Realize that changes you make directly
  7039. to a function are automatically factored into the checksum calculation.
  7040. Thus, these explicit changes invalidate the associated area of shared
  7041. state cache. However, you need to be aware of any implicit changes that
  7042. are not obvious changes to the code and could affect the output of a
  7043. given task.
  7044. When you identify an implicit change, you can easily take steps to
  7045. invalidate the cache and force the tasks to run. The steps you can take
  7046. are as simple as changing a function's comments in the source code. For
  7047. example, to invalidate package shared state files, change the comment
  7048. statements of
  7049. :ref:`ref-tasks-package` or the
  7050. comments of one of the functions it calls. Even though the change is
  7051. purely cosmetic, it causes the checksum to be recalculated and forces
  7052. the build system to run the task again.
  7053. .. note::
  7054. For an example of a commit that makes a cosmetic change to invalidate
  7055. shared state, see this
  7056. :yocto_git:`commit </poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`.
  7057. Running Specific Tasks
  7058. ----------------------
  7059. Any given recipe consists of a set of tasks. The standard BitBake
  7060. behavior in most cases is: ``do_fetch``, ``do_unpack``, ``do_patch``,
  7061. ``do_configure``, ``do_compile``, ``do_install``, ``do_package``,
  7062. ``do_package_write_*``, and ``do_build``. The default task is
  7063. ``do_build`` and any tasks on which it depends build first. Some tasks,
  7064. such as ``do_devshell``, are not part of the default build chain. If you
  7065. wish to run a task that is not part of the default build chain, you can
  7066. use the ``-c`` option in BitBake. Here is an example::
  7067. $ bitbake matchbox-desktop -c devshell
  7068. The ``-c`` option respects task dependencies, which means that all other
  7069. tasks (including tasks from other recipes) that the specified task
  7070. depends on will be run before the task. Even when you manually specify a
  7071. task to run with ``-c``, BitBake will only run the task if it considers
  7072. it "out of date". See the
  7073. ":ref:`overview-manual/concepts:stamp files and the rerunning of tasks`"
  7074. section in the Yocto Project Overview and Concepts Manual for how
  7075. BitBake determines whether a task is "out of date".
  7076. If you want to force an up-to-date task to be rerun (e.g. because you
  7077. made manual modifications to the recipe's
  7078. :term:`WORKDIR` that you want to try
  7079. out), then you can use the ``-f`` option.
  7080. .. note::
  7081. The reason ``-f`` is never required when running the
  7082. :ref:`ref-tasks-devshell` task is because the
  7083. [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ]
  7084. variable flag is already set for the task.
  7085. The following example shows one way you can use the ``-f`` option::
  7086. $ bitbake matchbox-desktop
  7087. .
  7088. .
  7089. make some changes to the source code in the work directory
  7090. .
  7091. .
  7092. $ bitbake matchbox-desktop -c compile -f
  7093. $ bitbake matchbox-desktop
  7094. This sequence first builds and then recompiles ``matchbox-desktop``. The
  7095. last command reruns all tasks (basically the packaging tasks) after the
  7096. compile. BitBake recognizes that the ``do_compile`` task was rerun and
  7097. therefore understands that the other tasks also need to be run again.
  7098. Another, shorter way to rerun a task and all
  7099. :ref:`ref-manual/tasks:normal recipe build tasks`
  7100. that depend on it is to use the ``-C`` option.
  7101. .. note::
  7102. This option is upper-cased and is separate from the ``-c``
  7103. option, which is lower-cased.
  7104. Using this option invalidates the given task and then runs the
  7105. :ref:`ref-tasks-build` task, which is
  7106. the default task if no task is given, and the tasks on which it depends.
  7107. You could replace the final two commands in the previous example with
  7108. the following single command::
  7109. $ bitbake matchbox-desktop -C compile
  7110. Internally, the ``-f`` and ``-C`` options work by tainting (modifying)
  7111. the input checksum of the specified task. This tainting indirectly
  7112. causes the task and its dependent tasks to be rerun through the normal
  7113. task dependency mechanisms.
  7114. .. note::
  7115. BitBake explicitly keeps track of which tasks have been tainted in
  7116. this fashion, and will print warnings such as the following for
  7117. builds involving such tasks:
  7118. .. code-block:: none
  7119. WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
  7120. The purpose of the warning is to let you know that the work directory
  7121. and build output might not be in the clean state they would be in for
  7122. a "normal" build, depending on what actions you took. To get rid of
  7123. such warnings, you can remove the work directory and rebuild the
  7124. recipe, as follows::
  7125. $ bitbake matchbox-desktop -c clean
  7126. $ bitbake matchbox-desktop
  7127. You can view a list of tasks in a given package by running the
  7128. ``do_listtasks`` task as follows::
  7129. $ bitbake matchbox-desktop -c listtasks
  7130. The results appear as output to the console and are also in
  7131. the file ``${WORKDIR}/temp/log.do_listtasks``.
  7132. General BitBake Problems
  7133. ------------------------
  7134. You can see debug output from BitBake by using the ``-D`` option. The
  7135. debug output gives more information about what BitBake is doing and the
  7136. reason behind it. Each ``-D`` option you use increases the logging
  7137. level. The most common usage is ``-DDD``.
  7138. The output from ``bitbake -DDD -v targetname`` can reveal why BitBake
  7139. chose a certain version of a package or why BitBake picked a certain
  7140. provider. This command could also help you in a situation where you
  7141. think BitBake did something unexpected.
  7142. Building with No Dependencies
  7143. -----------------------------
  7144. To build a specific recipe (``.bb`` file), you can use the following
  7145. command form::
  7146. $ bitbake -b somepath/somerecipe.bb
  7147. This command form does
  7148. not check for dependencies. Consequently, you should use it only when
  7149. you know existing dependencies have been met.
  7150. .. note::
  7151. You can also specify fragments of the filename. In this case, BitBake
  7152. checks for a unique match.
  7153. Recipe Logging Mechanisms
  7154. -------------------------
  7155. The Yocto Project provides several logging functions for producing
  7156. debugging output and reporting errors and warnings. For Python
  7157. functions, the following logging functions are available. All of these functions
  7158. log to ``${T}/log.do_``\ `task`, and can also log to standard output
  7159. (stdout) with the right settings:
  7160. - ``bb.plain(msg)``: Writes msg as is to the log while also
  7161. logging to stdout.
  7162. - ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to
  7163. stdout if BitBake is called with "-v".
  7164. - ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the
  7165. log. Also logs to stdout if the log level is greater than or equal to
  7166. level. See the ":ref:`-D <bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax>`" option
  7167. in the BitBake User Manual for more information.
  7168. - ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also
  7169. logging to stdout.
  7170. - ``bb.error(msg)``: Writes "ERROR: msg" to the log while also
  7171. logging to standard out (stdout).
  7172. .. note::
  7173. Calling this function does not cause the task to fail.
  7174. - ``bb.fatal(``\ msg\ ``)``: This logging function is similar to
  7175. ``bb.error(``\ msg\ ``)`` but also causes the calling task to fail.
  7176. .. note::
  7177. ``bb.fatal()`` raises an exception, which means you do not need to put a
  7178. "return" statement after the function.
  7179. The same logging functions are also available in shell functions, under
  7180. the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``,
  7181. and ``bbfatal``. The
  7182. :ref:`logging <ref-classes-logging>` class
  7183. implements these functions. See that class in the ``meta/classes``
  7184. folder of the :term:`Source Directory` for information.
  7185. Logging With Python
  7186. ~~~~~~~~~~~~~~~~~~~
  7187. When creating recipes using Python and inserting code that handles build
  7188. logs, keep in mind the goal is to have informative logs while keeping
  7189. the console as "silent" as possible. Also, if you want status messages
  7190. in the log, use the "debug" loglevel.
  7191. Following is an example written in Python. The code handles logging for
  7192. a function that determines the number of tasks needed to be run. See the
  7193. ":ref:`ref-tasks-listtasks`"
  7194. section for additional information::
  7195. python do_listtasks() {
  7196. bb.debug(2, "Starting to figure out the task list")
  7197. if noteworthy_condition:
  7198. bb.note("There are 47 tasks to run")
  7199. bb.debug(2, "Got to point xyz")
  7200. if warning_trigger:
  7201. bb.warn("Detected warning_trigger, this might be a problem later.")
  7202. if recoverable_error:
  7203. bb.error("Hit recoverable_error, you really need to fix this!")
  7204. if fatal_error:
  7205. bb.fatal("fatal_error detected, unable to print the task list")
  7206. bb.plain("The tasks present are abc")
  7207. bb.debug(2, "Finished figuring out the tasklist")
  7208. }
  7209. Logging With Bash
  7210. ~~~~~~~~~~~~~~~~~
  7211. When creating recipes using Bash and inserting code that handles build
  7212. logs, you have the same goals - informative with minimal console output.
  7213. The syntax you use for recipes written in Bash is similar to that of
  7214. recipes written in Python described in the previous section.
  7215. Following is an example written in Bash. The code logs the progress of
  7216. the ``do_my_function`` function.
  7217. ::
  7218. do_my_function() {
  7219. bbdebug 2 "Running do_my_function"
  7220. if [ exceptional_condition ]; then
  7221. bbnote "Hit exceptional_condition"
  7222. fi
  7223. bbdebug 2 "Got to point xyz"
  7224. if [ warning_trigger ]; then
  7225. bbwarn "Detected warning_trigger, this might cause a problem later."
  7226. fi
  7227. if [ recoverable_error ]; then
  7228. bberror "Hit recoverable_error, correcting"
  7229. fi
  7230. if [ fatal_error ]; then
  7231. bbfatal "fatal_error detected"
  7232. fi
  7233. bbdebug 2 "Completed do_my_function"
  7234. }
  7235. Debugging Parallel Make Races
  7236. -----------------------------
  7237. A parallel ``make`` race occurs when the build consists of several parts
  7238. that are run simultaneously and a situation occurs when the output or
  7239. result of one part is not ready for use with a different part of the
  7240. build that depends on that output. Parallel make races are annoying and
  7241. can sometimes be difficult to reproduce and fix. However, there are some simple
  7242. tips and tricks that can help you debug and fix them. This section
  7243. presents a real-world example of an error encountered on the Yocto
  7244. Project autobuilder and the process used to fix it.
  7245. .. note::
  7246. If you cannot properly fix a ``make`` race condition, you can work around it
  7247. by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST`
  7248. variables.
  7249. The Failure
  7250. ~~~~~~~~~~~
  7251. For this example, assume that you are building an image that depends on
  7252. the "neard" package. And, during the build, BitBake runs into problems
  7253. and creates the following output.
  7254. .. note::
  7255. This example log file has longer lines artificially broken to make
  7256. the listing easier to read.
  7257. If you examine the output or the log file, you see the failure during
  7258. ``make``:
  7259. .. code-block:: none
  7260. | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
  7261. | DEBUG: Executing shell function do_compile
  7262. | NOTE: make -j 16
  7263. | make --no-print-directory all-am
  7264. | /bin/mkdir -p include/near
  7265. | /bin/mkdir -p include/near
  7266. | /bin/mkdir -p include/near
  7267. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7268. 0.14-r0/neard-0.14/include/types.h include/near/types.h
  7269. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7270. 0.14-r0/neard-0.14/include/log.h include/near/log.h
  7271. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7272. 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
  7273. | /bin/mkdir -p include/near
  7274. | /bin/mkdir -p include/near
  7275. | /bin/mkdir -p include/near
  7276. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7277. 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
  7278. | /bin/mkdir -p include/near
  7279. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7280. 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
  7281. | /bin/mkdir -p include/near
  7282. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7283. 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
  7284. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7285. 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
  7286. | /bin/mkdir -p include/near
  7287. | /bin/mkdir -p include/near
  7288. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7289. 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
  7290. | /bin/mkdir -p include/near
  7291. | /bin/mkdir -p include/near
  7292. | /bin/mkdir -p include/near
  7293. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7294. 0.14-r0/neard-0.14/include/device.h include/near/device.h
  7295. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7296. 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
  7297. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7298. 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
  7299. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7300. 0.14-r0/neard-0.14/include/version.h include/near/version.h
  7301. | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  7302. 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
  7303. | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
  7304. | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
  7305. build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
  7306. yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
  7307. -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
  7308. lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
  7309. tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
  7310. nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
  7311. yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
  7312. -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
  7313. -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
  7314. -o tools/snep-send.o tools/snep-send.c
  7315. | In file included from tools/snep-send.c:16:0:
  7316. | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
  7317. | #include <near/dbus.h>
  7318. | ^
  7319. | compilation terminated.
  7320. | make[1]: *** [tools/snep-send.o] Error 1
  7321. | make[1]: *** Waiting for unfinished jobs....
  7322. | make: *** [all] Error 2
  7323. | ERROR: oe_runmake failed
  7324. Reproducing the Error
  7325. ~~~~~~~~~~~~~~~~~~~~~
  7326. Because race conditions are intermittent, they do not manifest
  7327. themselves every time you do the build. In fact, most times the build
  7328. will complete without problems even though the potential race condition
  7329. exists. Thus, once the error surfaces, you need a way to reproduce it.
  7330. In this example, compiling the "neard" package is causing the problem.
  7331. So the first thing to do is build "neard" locally. Before you start the
  7332. build, set the
  7333. :term:`PARALLEL_MAKE` variable
  7334. in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a
  7335. high value for :term:`PARALLEL_MAKE` increases the chances of the race
  7336. condition showing up::
  7337. $ bitbake neard
  7338. Once the local build for "neard" completes, start a ``devshell`` build::
  7339. $ bitbake neard -c devshell
  7340. For information on how to use a ``devshell``, see the
  7341. ":ref:`dev-manual/common-tasks:using a development shell`" section.
  7342. In the ``devshell``, do the following::
  7343. $ make clean
  7344. $ make tools/snep-send.o
  7345. The ``devshell`` commands cause the failure to clearly
  7346. be visible. In this case, there is a missing dependency for the ``neard``
  7347. Makefile target. Here is some abbreviated, sample output with the
  7348. missing dependency clearly visible at the end::
  7349. i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
  7350. .
  7351. .
  7352. .
  7353. tools/snep-send.c
  7354. In file included from tools/snep-send.c:16:0:
  7355. tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
  7356. #include <near/dbus.h>
  7357. ^
  7358. compilation terminated.
  7359. make: *** [tools/snep-send.o] Error 1
  7360. $
  7361. Creating a Patch for the Fix
  7362. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7363. Because there is a missing dependency for the Makefile target, you need
  7364. to patch the ``Makefile.am`` file, which is generated from
  7365. ``Makefile.in``. You can use Quilt to create the patch::
  7366. $ quilt new parallelmake.patch
  7367. Patch patches/parallelmake.patch is now on top
  7368. $ quilt add Makefile.am
  7369. File Makefile.am added to patch patches/parallelmake.patch
  7370. For more information on using Quilt, see the
  7371. ":ref:`dev-manual/common-tasks:using quilt in your workflow`" section.
  7372. At this point you need to make the edits to ``Makefile.am`` to add the
  7373. missing dependency. For our example, you have to add the following line
  7374. to the file::
  7375. tools/snep-send.$(OBJEXT): include/near/dbus.h
  7376. Once you have edited the file, use the ``refresh`` command to create the
  7377. patch::
  7378. $ quilt refresh
  7379. Refreshed patch patches/parallelmake.patch
  7380. Once the patch file is created, you need to add it back to the originating
  7381. recipe folder. Here is an example assuming a top-level
  7382. :term:`Source Directory` named ``poky``::
  7383. $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
  7384. The final thing you need to do to implement the fix in the build is to
  7385. update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the
  7386. :term:`SRC_URI` statement includes
  7387. the patch file. The recipe file is in the folder above the patch. Here
  7388. is what the edited :term:`SRC_URI` statement would look like::
  7389. SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
  7390. file://neard.in \
  7391. file://neard.service.in \
  7392. file://parallelmake.patch \
  7393. "
  7394. With the patch complete and moved to the correct folder and the
  7395. :term:`SRC_URI` statement updated, you can exit the ``devshell``::
  7396. $ exit
  7397. Testing the Build
  7398. ~~~~~~~~~~~~~~~~~
  7399. With everything in place, you can get back to trying the build again
  7400. locally::
  7401. $ bitbake neard
  7402. This build should succeed.
  7403. Now you can open up a ``devshell`` again and repeat the clean and make
  7404. operations as follows::
  7405. $ bitbake neard -c devshell
  7406. $ make clean
  7407. $ make tools/snep-send.o
  7408. The build should work without issue.
  7409. As with all solved problems, if they originated upstream, you need to
  7410. submit the fix for the recipe in OE-Core and upstream so that the
  7411. problem is taken care of at its source. See the
  7412. ":ref:`dev-manual/common-tasks:submitting a change to the yocto project`"
  7413. section for more information.
  7414. Debugging With the GNU Project Debugger (GDB) Remotely
  7415. ------------------------------------------------------
  7416. GDB allows you to examine running programs, which in turn helps you to
  7417. understand and fix problems. It also allows you to perform post-mortem
  7418. style analysis of program crashes. GDB is available as a package within
  7419. the Yocto Project and is installed in SDK images by default. See the
  7420. ":ref:`ref-manual/images:Images`" chapter in the Yocto
  7421. Project Reference Manual for a description of these images. You can find
  7422. information on GDB at https://sourceware.org/gdb/.
  7423. .. note::
  7424. For best results, install debug (``-dbg``) packages for the applications you
  7425. are going to debug. Doing so makes extra debug symbols available that give
  7426. you more meaningful output.
  7427. Sometimes, due to memory or disk space constraints, it is not possible
  7428. to use GDB directly on the remote target to debug applications. These
  7429. constraints arise because GDB needs to load the debugging information
  7430. and the binaries of the process being debugged. Additionally, GDB needs
  7431. to perform many computations to locate information such as function
  7432. names, variable names and values, stack traces and so forth - even
  7433. before starting the debugging process. These extra computations place
  7434. more load on the target system and can alter the characteristics of the
  7435. program being debugged.
  7436. To help get past the previously mentioned constraints, there are two
  7437. methods you can use: running a debuginfod server and using gdbserver.
  7438. Using the debuginfod server method
  7439. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7440. ``debuginfod`` from ``elfutils`` is a way to distribute ``debuginfo`` files.
  7441. Running a ``debuginfod`` server makes debug symbols readily available,
  7442. which means you don't need to download debugging information
  7443. and the binaries of the process being debugged. You can just fetch
  7444. debug symbols from the server.
  7445. To run a ``debuginfod`` server, you need to do the following:
  7446. - Ensure that ``debuginfod`` is present in :term:`DISTRO_FEATURES`
  7447. (it already is in ``OpenEmbedded-core`` defaults and ``poky`` reference distribution).
  7448. If not, set in your distro config file or in ``local.conf``::
  7449. DISTRO_FEATURES_append = " debuginfod"
  7450. This distro feature enables the server and client library in ``elfutils``,
  7451. and enables ``debuginfod`` support in clients (at the moment, ``gdb`` and ``binutils``).
  7452. - Run the following commands to launch the ``debuginfod`` server on the host::
  7453. $ oe-debuginfod
  7454. - To use ``debuginfod`` on the target, you need to know the ip:port where
  7455. ``debuginfod`` is listening on the host (port defaults to 8002), and export
  7456. that into the shell environment, for example in ``qemu``::
  7457. root@qemux86-64:~# export DEBUGINFOD_URLS="http://192.168.7.1:8002/"
  7458. - Then debug info fetching should simply work when running the target ``gdb``,
  7459. ``readelf`` or ``objdump``, for example::
  7460. root@qemux86-64:~# gdb /bin/cat
  7461. ...
  7462. Reading symbols from /bin/cat...
  7463. Downloading separate debug info for /bin/cat...
  7464. Reading symbols from /home/root/.cache/debuginfod_client/923dc4780cfbc545850c616bffa884b6b5eaf322/debuginfo...
  7465. - It's also possible to use ``debuginfod-find`` to just query the server::
  7466. root@qemux86-64:~# debuginfod-find debuginfo /bin/ls
  7467. /home/root/.cache/debuginfod_client/356edc585f7f82d46f94fcb87a86a3fe2d2e60bd/debuginfo
  7468. Using the gdbserver method
  7469. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7470. gdbserver, which runs on the remote target and does not load any
  7471. debugging information from the debugged process. Instead, a GDB instance
  7472. processes the debugging information that is run on a remote computer -
  7473. the host GDB. The host GDB then sends control commands to gdbserver to
  7474. make it stop or start the debugged program, as well as read or write
  7475. memory regions of that debugged program. All the debugging information
  7476. loaded and processed as well as all the heavy debugging is done by the
  7477. host GDB. Offloading these processes gives the gdbserver running on the
  7478. target a chance to remain small and fast.
  7479. Because the host GDB is responsible for loading the debugging
  7480. information and for doing the necessary processing to make actual
  7481. debugging happen, you have to make sure the host can access the
  7482. unstripped binaries complete with their debugging information and also
  7483. be sure the target is compiled with no optimizations. The host GDB must
  7484. also have local access to all the libraries used by the debugged
  7485. program. Because gdbserver does not need any local debugging
  7486. information, the binaries on the remote target can remain stripped.
  7487. However, the binaries must also be compiled without optimization so they
  7488. match the host's binaries.
  7489. To remain consistent with GDB documentation and terminology, the binary
  7490. being debugged on the remote target machine is referred to as the
  7491. "inferior" binary. For documentation on GDB see the `GDB
  7492. site <https://sourceware.org/gdb/documentation/>`__.
  7493. The following steps show you how to debug using the GNU project
  7494. debugger.
  7495. 1. *Configure your build system to construct the companion debug
  7496. filesystem:*
  7497. In your ``local.conf`` file, set the following::
  7498. IMAGE_GEN_DEBUGFS = "1"
  7499. IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
  7500. These options cause the
  7501. OpenEmbedded build system to generate a special companion filesystem
  7502. fragment, which contains the matching source and debug symbols to
  7503. your deployable filesystem. The build system does this by looking at
  7504. what is in the deployed filesystem, and pulling the corresponding
  7505. ``-dbg`` packages.
  7506. The companion debug filesystem is not a complete filesystem, but only
  7507. contains the debug fragments. This filesystem must be combined with
  7508. the full filesystem for debugging. Subsequent steps in this procedure
  7509. show how to combine the partial filesystem with the full filesystem.
  7510. 2. *Configure the system to include gdbserver in the target filesystem:*
  7511. Make the following addition in either your ``local.conf`` file or in
  7512. an image recipe::
  7513. IMAGE_INSTALL_append = " gdbserver"
  7514. The change makes
  7515. sure the ``gdbserver`` package is included.
  7516. 3. *Build the environment:*
  7517. Use the following command to construct the image and the companion
  7518. Debug Filesystem::
  7519. $ bitbake image
  7520. Build the cross GDB component and
  7521. make it available for debugging. Build the SDK that matches the
  7522. image. Building the SDK is best for a production build that can be
  7523. used later for debugging, especially during long term maintenance::
  7524. $ bitbake -c populate_sdk image
  7525. Alternatively, you can build the minimal toolchain components that
  7526. match the target. Doing so creates a smaller than typical SDK and
  7527. only contains a minimal set of components with which to build simple
  7528. test applications, as well as run the debugger::
  7529. $ bitbake meta-toolchain
  7530. A final method is to build Gdb itself within the build system::
  7531. $ bitbake gdb-cross-<architecture>
  7532. Doing so produces a temporary copy of
  7533. ``cross-gdb`` you can use for debugging during development. While
  7534. this is the quickest approach, the two previous methods in this step
  7535. are better when considering long-term maintenance strategies.
  7536. .. note::
  7537. If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests
  7538. the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the
  7539. actual name you want to use.
  7540. 4. *Set up the* ``debugfs``\ *:*
  7541. Run the following commands to set up the ``debugfs``::
  7542. $ mkdir debugfs
  7543. $ cd debugfs
  7544. $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image.rootfs.tar.bz2
  7545. $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image-dbg.rootfs.tar.bz2
  7546. 5. *Set up GDB:*
  7547. Install the SDK (if you built one) and then source the correct
  7548. environment file. Sourcing the environment file puts the SDK in your
  7549. ``PATH`` environment variable.
  7550. If you are using the build system, Gdb is located in
  7551. `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb``
  7552. 6. *Boot the target:*
  7553. For information on how to run QEMU, see the `QEMU
  7554. Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__.
  7555. .. note::
  7556. Be sure to verify that your host can access the target via TCP.
  7557. 7. *Debug a program:*
  7558. Debugging a program involves running gdbserver on the target and then
  7559. running Gdb on the host. The example in this step debugs ``gzip``:
  7560. .. code-block:: shell
  7561. root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
  7562. For
  7563. additional gdbserver options, see the `GDB Server
  7564. Documentation <https://www.gnu.org/software/gdb/documentation/>`__.
  7565. After running gdbserver on the target, you need to run Gdb on the
  7566. host and configure it and connect to the target. Use these commands::
  7567. $ cd directory-holding-the-debugfs-directory
  7568. $ arch-gdb
  7569. (gdb) set sysroot debugfs
  7570. (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
  7571. (gdb) target remote IP-of-target:1234
  7572. At this
  7573. point, everything should automatically load (i.e. matching binaries,
  7574. symbols and headers).
  7575. .. note::
  7576. The Gdb ``set`` commands in the previous example can be placed into the
  7577. users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever
  7578. commands are in that file.
  7579. 8. *Deploying without a full image rebuild:*
  7580. In many cases, during development you want a quick method to deploy a
  7581. new binary to the target and debug it, without waiting for a full
  7582. image build.
  7583. One approach to solving this situation is to just build the component
  7584. you want to debug. Once you have built the component, copy the
  7585. executable directly to both the target and the host ``debugfs``.
  7586. If the binary is processed through the debug splitting in
  7587. OpenEmbedded, you should also copy the debug items (i.e. ``.debug``
  7588. contents and corresponding ``/usr/src/debug`` files) from the work
  7589. directory. Here is an example::
  7590. $ bitbake bash
  7591. $ bitbake -c devshell bash
  7592. $ cd ..
  7593. $ scp packages-split/bash/bin/bash target:/bin/bash
  7594. $ cp -a packages-split/bash-dbg/\* path/debugfs
  7595. Debugging with the GNU Project Debugger (GDB) on the Target
  7596. -----------------------------------------------------------
  7597. The previous section addressed using GDB remotely for debugging
  7598. purposes, which is the most usual case due to the inherent hardware
  7599. limitations on many embedded devices. However, debugging in the target
  7600. hardware itself is also possible with more powerful devices. This
  7601. section describes what you need to do in order to support using GDB to
  7602. debug on the target hardware.
  7603. To support this kind of debugging, you need do the following:
  7604. - Ensure that GDB is on the target. You can do this by adding "gdb" to
  7605. :term:`IMAGE_INSTALL`::
  7606. IMAGE_INSTALL_append = " gdb"
  7607. Alternatively, you can add "tools-debug" to :term:`IMAGE_FEATURES`::
  7608. IMAGE_FEATURES_append = " tools-debug"
  7609. - Ensure that debug symbols are present. You can make sure these
  7610. symbols are present by installing ``-dbg``::
  7611. IMAGE_INSTALL_append = "packagename-dbg"
  7612. Alternatively, you can do the following to include
  7613. all the debug symbols::
  7614. IMAGE_FEATURES_append = " dbg-pkgs"
  7615. .. note::
  7616. To improve the debug information accuracy, you can reduce the level
  7617. of optimization used by the compiler. For example, when adding the
  7618. following line to your ``local.conf`` file, you will reduce optimization
  7619. from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION`
  7620. of "-O -fno-omit-frame-pointer"::
  7621. DEBUG_BUILD = "1"
  7622. Consider that this will reduce the application's performance and is
  7623. recommended only for debugging purposes.
  7624. Other Debugging Tips
  7625. --------------------
  7626. Here are some other tips that you might find useful:
  7627. - When adding new packages, it is worth watching for undesirable items
  7628. making their way into compiler command lines. For example, you do not
  7629. want references to local system files like ``/usr/lib/`` or
  7630. ``/usr/include/``.
  7631. - If you want to remove the ``psplash`` boot splashscreen, add
  7632. ``psplash=false`` to the kernel command line. Doing so prevents
  7633. ``psplash`` from loading and thus allows you to see the console. It
  7634. is also possible to switch out of the splashscreen by switching the
  7635. virtual console (e.g. Fn+Left or Fn+Right on a Zaurus).
  7636. - Removing :term:`TMPDIR` (usually
  7637. ``tmp/``, within the
  7638. :term:`Build Directory`) can often fix
  7639. temporary build issues. Removing :term:`TMPDIR` is usually a relatively
  7640. cheap operation, because task output will be cached in
  7641. :term:`SSTATE_DIR` (usually
  7642. ``sstate-cache/``, which is also in the Build Directory).
  7643. .. note::
  7644. Removing :term:`TMPDIR` might be a workaround rather than a fix.
  7645. Consequently, trying to determine the underlying cause of an issue before
  7646. removing the directory is a good idea.
  7647. - Understanding how a feature is used in practice within existing
  7648. recipes can be very helpful. It is recommended that you configure
  7649. some method that allows you to quickly search through files.
  7650. Using GNU Grep, you can use the following shell function to
  7651. recursively search through common recipe-related files, skipping
  7652. binary files, ``.git`` directories, and the Build Directory (assuming
  7653. its name starts with "build")::
  7654. g() {
  7655. grep -Ir \
  7656. --exclude-dir=.git \
  7657. --exclude-dir='build*' \
  7658. --include='*.bb*' \
  7659. --include='*.inc*' \
  7660. --include='*.conf*' \
  7661. --include='*.py*' \
  7662. "$@"
  7663. }
  7664. Following are some usage examples::
  7665. $ g FOO # Search recursively for "FOO"
  7666. $ g -i foo # Search recursively for "foo", ignoring case
  7667. $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
  7668. If figuring
  7669. out how some feature works requires a lot of searching, it might
  7670. indicate that the documentation should be extended or improved. In
  7671. such cases, consider filing a documentation bug using the Yocto
  7672. Project implementation of
  7673. :yocto_bugs:`Bugzilla <>`. For information on
  7674. how to submit a bug against the Yocto Project, see the Yocto Project
  7675. Bugzilla :yocto_wiki:`wiki page </Bugzilla_Configuration_and_Bug_Tracking>`
  7676. and the
  7677. ":ref:`dev-manual/common-tasks:submitting a defect against the yocto project`"
  7678. section.
  7679. .. note::
  7680. The manuals might not be the right place to document variables
  7681. that are purely internal and have a limited scope (e.g. internal
  7682. variables used to implement a single ``.bbclass`` file).
  7683. Making Changes to the Yocto Project
  7684. ===================================
  7685. Because the Yocto Project is an open-source, community-based project,
  7686. you can effect changes to the project. This section presents procedures
  7687. that show you how to submit a defect against the project and how to
  7688. submit a change.
  7689. Submitting a Defect Against the Yocto Project
  7690. ---------------------------------------------
  7691. Use the Yocto Project implementation of
  7692. `Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug)
  7693. against the Yocto Project. For additional information on this
  7694. implementation of Bugzilla see the ":ref:`Yocto Project
  7695. Bugzilla <resources-bugtracker>`" section in the
  7696. Yocto Project Reference Manual. For more detail on any of the following
  7697. steps, see the Yocto Project
  7698. :yocto_wiki:`Bugzilla wiki page </Bugzilla_Configuration_and_Bug_Tracking>`.
  7699. Use the following general steps to submit a bug:
  7700. 1. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`.
  7701. 2. Click "File a Bug" to enter a new bug.
  7702. 3. Choose the appropriate "Classification", "Product", and "Component"
  7703. for which the bug was found. Bugs for the Yocto Project fall into
  7704. one of several classifications, which in turn break down into
  7705. several products and components. For example, for a bug against the
  7706. ``meta-intel`` layer, you would choose "Build System, Metadata &
  7707. Runtime", "BSPs", and "bsps-meta-intel", respectively.
  7708. 4. Choose the "Version" of the Yocto Project for which you found the
  7709. bug (e.g. &DISTRO;).
  7710. 5. Determine and select the "Severity" of the bug. The severity
  7711. indicates how the bug impacted your work.
  7712. 6. Choose the "Hardware" that the bug impacts.
  7713. 7. Choose the "Architecture" that the bug impacts.
  7714. 8. Choose a "Documentation change" item for the bug. Fixing a bug might
  7715. or might not affect the Yocto Project documentation. If you are
  7716. unsure of the impact to the documentation, select "Don't Know".
  7717. 9. Provide a brief "Summary" of the bug. Try to limit your summary to
  7718. just a line or two and be sure to capture the essence of the bug.
  7719. 10. Provide a detailed "Description" of the bug. You should provide as
  7720. much detail as you can about the context, behavior, output, and so
  7721. forth that surrounds the bug. You can even attach supporting files
  7722. for output from logs by using the "Add an attachment" button.
  7723. 11. Click the "Submit Bug" button submit the bug. A new Bugzilla number
  7724. is assigned to the bug and the defect is logged in the bug tracking
  7725. system.
  7726. Once you file a bug, the bug is processed by the Yocto Project Bug
  7727. Triage Team and further details concerning the bug are assigned (e.g.
  7728. priority and owner). You are the "Submitter" of the bug and any further
  7729. categorization, progress, or comments on the bug result in Bugzilla
  7730. sending you an automated email concerning the particular change or
  7731. progress to the bug.
  7732. Submitting a Change to the Yocto Project
  7733. ----------------------------------------
  7734. Contributions to the Yocto Project and OpenEmbedded are very welcome.
  7735. Because the system is extremely configurable and flexible, we recognize
  7736. that developers will want to extend, configure or optimize it for their
  7737. specific uses.
  7738. The Yocto Project uses a mailing list and a patch-based workflow that is
  7739. similar to the Linux kernel but contains important differences. In
  7740. general, there is a mailing list through which you can submit patches. You
  7741. should send patches to the appropriate mailing list so that they can be
  7742. reviewed and merged by the appropriate maintainer. The specific mailing
  7743. list you need to use depends on the location of the code you are
  7744. changing. Each component (e.g. layer) should have a ``README`` file that
  7745. indicates where to send the changes and which process to follow.
  7746. You can send the patch to the mailing list using whichever approach you
  7747. feel comfortable with to generate the patch. Once sent, the patch is
  7748. usually reviewed by the community at large. If somebody has concerns
  7749. with the patch, they will usually voice their concern over the mailing
  7750. list. If a patch does not receive any negative reviews, the maintainer
  7751. of the affected layer typically takes the patch, tests it, and then
  7752. based on successful testing, merges the patch.
  7753. The "poky" repository, which is the Yocto Project's reference build
  7754. environment, is a hybrid repository that contains several individual
  7755. pieces (e.g. BitBake, Metadata, documentation, and so forth) built using
  7756. the combo-layer tool. The upstream location used for submitting changes
  7757. varies by component:
  7758. - *Core Metadata:* Send your patch to the
  7759. :oe_lists:`openembedded-core </g/openembedded-core>`
  7760. mailing list. For example, a change to anything under the ``meta`` or
  7761. ``scripts`` directories should be sent to this mailing list.
  7762. - *BitBake:* For changes to BitBake (i.e. anything under the
  7763. ``bitbake`` directory), send your patch to the
  7764. :oe_lists:`bitbake-devel </g/bitbake-devel>`
  7765. mailing list.
  7766. - *"meta-\*" trees:* These trees contain Metadata. Use the
  7767. :yocto_lists:`poky </g/poky>` mailing list.
  7768. - *Documentation*: For changes to the Yocto Project documentation, use the
  7769. :yocto_lists:`docs </g/docs>` mailing list.
  7770. For changes to other layers hosted in the Yocto Project source
  7771. repositories (i.e. ``yoctoproject.org``) and tools use the
  7772. :yocto_lists:`Yocto Project </g/yocto/>` general mailing list.
  7773. .. note::
  7774. Sometimes a layer's documentation specifies to use a particular
  7775. mailing list. If so, use that list.
  7776. For additional recipes that do not fit into the core Metadata, you
  7777. should determine which layer the recipe should go into and submit the
  7778. change in the manner recommended by the documentation (e.g. the
  7779. ``README`` file) supplied with the layer. If in doubt, please ask on the
  7780. Yocto general mailing list or on the openembedded-devel mailing list.
  7781. You can also push a change upstream and request a maintainer to pull the
  7782. change into the component's upstream repository. You do this by pushing
  7783. to a contribution repository that is upstream. See the
  7784. ":ref:`overview-manual/development-environment:git workflows and the yocto project`"
  7785. section in the Yocto Project Overview and Concepts Manual for additional
  7786. concepts on working in the Yocto Project development environment.
  7787. Maintainers commonly use ``-next`` branches to test submissions prior to
  7788. merging patches. Thus, you can get an idea of the status of a patch based on
  7789. whether the patch has been merged into one of these branches. The commonly
  7790. used testing branches for OpenEmbedded-Core are as follows:
  7791. - *openembedded-core "master-next" branch:* This branch is part of the
  7792. :oe_git:`openembedded-core </openembedded-core/>` repository and contains
  7793. proposed changes to the core metadata.
  7794. - *poky "master-next" branch:* This branch is part of the
  7795. :yocto_git:`poky </poky/>` repository and combines proposed
  7796. changes to bitbake, the core metadata and the poky distro.
  7797. Similarly, stable branches maintained by the project may have corresponding
  7798. ``-next`` branches which collect proposed changes. For example,
  7799. ``&DISTRO_NAME_NO_CAP;-next`` and ``&DISTRO_NAME_NO_CAP_MINUS_ONE;-next``
  7800. branches in both the "openembdedded-core" and "poky" repositories.
  7801. Other layers may have similar testing branches but there is no formal
  7802. requirement or standard for these so please check the documentation for the
  7803. layers you are contributing to.
  7804. The following sections provide procedures for submitting a change.
  7805. Preparing Changes for Submission
  7806. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7807. 1. *Make Your Changes Locally:* Make your changes in your local Git
  7808. repository. You should make small, controlled, isolated changes.
  7809. Keeping changes small and isolated aids review, makes
  7810. merging/rebasing easier and keeps the change history clean should
  7811. anyone need to refer to it in future.
  7812. 2. *Stage Your Changes:* Stage your changes by using the ``git add``
  7813. command on each file you changed.
  7814. 3. *Commit Your Changes:* Commit the change by using the ``git commit``
  7815. command. Make sure your commit information follows standards by
  7816. following these accepted conventions:
  7817. - Be sure to include a "Signed-off-by:" line in the same style as
  7818. required by the Linux kernel. Adding this line signifies that you,
  7819. the submitter, have agreed to the Developer's Certificate of
  7820. Origin 1.1 as follows:
  7821. .. code-block:: none
  7822. Developer's Certificate of Origin 1.1
  7823. By making a contribution to this project, I certify that:
  7824. (a) The contribution was created in whole or in part by me and I
  7825. have the right to submit it under the open source license
  7826. indicated in the file; or
  7827. (b) The contribution is based upon previous work that, to the best
  7828. of my knowledge, is covered under an appropriate open source
  7829. license and I have the right under that license to submit that
  7830. work with modifications, whether created in whole or in part
  7831. by me, under the same open source license (unless I am
  7832. permitted to submit under a different license), as indicated
  7833. in the file; or
  7834. (c) The contribution was provided directly to me by some other
  7835. person who certified (a), (b) or (c) and I have not modified
  7836. it.
  7837. (d) I understand and agree that this project and the contribution
  7838. are public and that a record of the contribution (including all
  7839. personal information I submit with it, including my sign-off) is
  7840. maintained indefinitely and may be redistributed consistent with
  7841. this project or the open source license(s) involved.
  7842. - Provide a single-line summary of the change and, if more
  7843. explanation is needed, provide more detail in the body of the
  7844. commit. This summary is typically viewable in the "shortlist" of
  7845. changes. Thus, providing something short and descriptive that
  7846. gives the reader a summary of the change is useful when viewing a
  7847. list of many commits. You should prefix this short description
  7848. with the recipe name (if changing a recipe), or else with the
  7849. short form path to the file being changed.
  7850. - For the body of the commit message, provide detailed information
  7851. that describes what you changed, why you made the change, and the
  7852. approach you used. It might also be helpful if you mention how you
  7853. tested the change. Provide as much detail as you can in the body
  7854. of the commit message.
  7855. .. note::
  7856. You do not need to provide a more detailed explanation of a
  7857. change if the change is minor to the point of the single line
  7858. summary providing all the information.
  7859. - If the change addresses a specific bug or issue that is associated
  7860. with a bug-tracking ID, include a reference to that ID in your
  7861. detailed description. For example, the Yocto Project uses a
  7862. specific convention for bug references - any commit that addresses
  7863. a specific bug should use the following form for the detailed
  7864. description. Be sure to use the actual bug-tracking ID from
  7865. Bugzilla for bug-id::
  7866. Fixes [YOCTO #bug-id]
  7867. detailed description of change
  7868. Using Email to Submit a Patch
  7869. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7870. Depending on the components changed, you need to submit the email to a
  7871. specific mailing list. For some guidance on which mailing list to use,
  7872. see the
  7873. :ref:`list <dev-manual/common-tasks:submitting a change to the yocto project>`
  7874. at the beginning of this section. For a description of all the available
  7875. mailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the
  7876. Yocto Project Reference Manual.
  7877. Here is the general procedure on how to submit a patch through email
  7878. without using the scripts once the steps in
  7879. :ref:`dev-manual/common-tasks:preparing changes for submission` have been followed:
  7880. 1. *Format the Commit:* Format the commit into an email message. To
  7881. format commits, use the ``git format-patch`` command. When you
  7882. provide the command, you must include a revision list or a number of
  7883. patches as part of the command. For example, either of these two
  7884. commands takes your most recent single commit and formats it as an
  7885. email message in the current directory::
  7886. $ git format-patch -1
  7887. or ::
  7888. $ git format-patch HEAD~
  7889. After the command is run, the current directory contains a numbered
  7890. ``.patch`` file for the commit.
  7891. If you provide several commits as part of the command, the
  7892. ``git format-patch`` command produces a series of numbered files in
  7893. the current directory – one for each commit. If you have more than
  7894. one patch, you should also use the ``--cover`` option with the
  7895. command, which generates a cover letter as the first "patch" in the
  7896. series. You can then edit the cover letter to provide a description
  7897. for the series of patches. For information on the
  7898. ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed
  7899. using the ``man git-format-patch`` command.
  7900. .. note::
  7901. If you are or will be a frequent contributor to the Yocto Project
  7902. or to OpenEmbedded, you might consider requesting a contrib area
  7903. and the necessary associated rights.
  7904. 2. *Send the patches via email:* Send the patches to the recipients and
  7905. relevant mailing lists by using the ``git send-email`` command.
  7906. .. note::
  7907. In order to use ``git send-email``, you must have the proper Git packages
  7908. installed on your host.
  7909. For Ubuntu, Debian, and Fedora the package is ``git-email``.
  7910. The ``git send-email`` command sends email by using a local or remote
  7911. Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or
  7912. through a direct ``smtp`` configuration in your Git ``~/.gitconfig``
  7913. file. If you are submitting patches through email only, it is very
  7914. important that you submit them without any whitespace or HTML
  7915. formatting that either you or your mailer introduces. The maintainer
  7916. that receives your patches needs to be able to save and apply them
  7917. directly from your emails. A good way to verify that what you are
  7918. sending will be applicable by the maintainer is to do a dry run and
  7919. send them to yourself and then save and apply them as the maintainer
  7920. would.
  7921. The ``git send-email`` command is the preferred method for sending
  7922. your patches using email since there is no risk of compromising
  7923. whitespace in the body of the message, which can occur when you use
  7924. your own mail client. The command also has several options that let
  7925. you specify recipients and perform further editing of the email
  7926. message. For information on how to use the ``git send-email``
  7927. command, see ``GIT-SEND-EMAIL(1)`` displayed using the
  7928. ``man git-send-email`` command.
  7929. The Yocto Project uses a `Patchwork instance <https://patchwork.openembedded.org/>`__
  7930. to track the status of patches submitted to the various mailing lists and to
  7931. support automated patch testing. Each submitted patch is checked for common
  7932. mistakes and deviations from the expected patch format and submitters are
  7933. notified by patchtest if such mistakes are found. This process helps to
  7934. reduce the burden of patch review on maintainers.
  7935. .. note::
  7936. This system is imperfect and changes can sometimes get lost in the flow.
  7937. Asking about the status of a patch or change is reasonable if the change
  7938. has been idle for a while with no feedback.
  7939. Using Scripts to Push a Change Upstream and Request a Pull
  7940. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7941. For larger patch series it is preferable to send a pull request which not
  7942. only includes the patch but also a pointer to a branch that can be pulled
  7943. from. This involves making a local branch for your changes, pushing this
  7944. branch to an accessible repository and then using the ``create-pull-request``
  7945. and ``send-pull-request`` scripts from openembedded-core to create and send a
  7946. patch series with a link to the branch for review.
  7947. Follow this procedure to push a change to an upstream "contrib" Git
  7948. repository once the steps in :ref:`dev-manual/common-tasks:preparing changes for submission` have
  7949. been followed:
  7950. .. note::
  7951. You can find general Git information on how to push a change upstream
  7952. in the
  7953. `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__.
  7954. 1. *Push Your Commits to a "Contrib" Upstream:* If you have arranged for
  7955. permissions to push to an upstream contrib repository, push the
  7956. change to that repository::
  7957. $ git push upstream_remote_repo local_branch_name
  7958. For example, suppose you have permissions to push
  7959. into the upstream ``meta-intel-contrib`` repository and you are
  7960. working in a local branch named `your_name`\ ``/README``. The following
  7961. command pushes your local commits to the ``meta-intel-contrib``
  7962. upstream repository and puts the commit in a branch named
  7963. `your_name`\ ``/README``::
  7964. $ git push meta-intel-contrib your_name/README
  7965. 2. *Determine Who to Notify:* Determine the maintainer or the mailing
  7966. list that you need to notify for the change.
  7967. Before submitting any change, you need to be sure who the maintainer
  7968. is or what mailing list that you need to notify. Use either these
  7969. methods to find out:
  7970. - *Maintenance File:* Examine the ``maintainers.inc`` file, which is
  7971. located in the :term:`Source Directory` at
  7972. ``meta/conf/distro/include``, to see who is responsible for code.
  7973. - *Search by File:* Using :ref:`overview-manual/development-environment:git`, you can
  7974. enter the following command to bring up a short list of all
  7975. commits against a specific file::
  7976. git shortlog -- filename
  7977. Just provide the name of the file for which you are interested. The
  7978. information returned is not ordered by history but does include a
  7979. list of everyone who has committed grouped by name. From the list,
  7980. you can see who is responsible for the bulk of the changes against
  7981. the file.
  7982. - *Examine the List of Mailing Lists:* For a list of the Yocto
  7983. Project and related mailing lists, see the ":ref:`Mailing
  7984. lists <resources-mailinglist>`" section in
  7985. the Yocto Project Reference Manual.
  7986. 3. *Make a Pull Request:* Notify the maintainer or the mailing list that
  7987. you have pushed a change by making a pull request.
  7988. The Yocto Project provides two scripts that conveniently let you
  7989. generate and send pull requests to the Yocto Project. These scripts
  7990. are ``create-pull-request`` and ``send-pull-request``. You can find
  7991. these scripts in the ``scripts`` directory within the
  7992. :term:`Source Directory` (e.g.
  7993. ``poky/scripts``).
  7994. Using these scripts correctly formats the requests without
  7995. introducing any whitespace or HTML formatting. The maintainer that
  7996. receives your patches either directly or through the mailing list
  7997. needs to be able to save and apply them directly from your emails.
  7998. Using these scripts is the preferred method for sending patches.
  7999. First, create the pull request. For example, the following command
  8000. runs the script, specifies the upstream repository in the contrib
  8001. directory into which you pushed the change, and provides a subject
  8002. line in the created patch files::
  8003. $ poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
  8004. Running this script forms ``*.patch`` files in a folder named
  8005. ``pull-``\ `PID` in the current directory. One of the patch files is a
  8006. cover letter.
  8007. Before running the ``send-pull-request`` script, you must edit the
  8008. cover letter patch to insert information about your change. After
  8009. editing the cover letter, send the pull request. For example, the
  8010. following command runs the script and specifies the patch directory
  8011. and email address. In this example, the email address is a mailing
  8012. list::
  8013. $ poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
  8014. You need to follow the prompts as the script is interactive.
  8015. .. note::
  8016. For help on using these scripts, simply provide the ``-h``
  8017. argument as follows::
  8018. $ poky/scripts/create-pull-request -h
  8019. $ poky/scripts/send-pull-request -h
  8020. Responding to Patch Review
  8021. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  8022. You may get feedback on your submitted patches from other community members
  8023. or from the automated patchtest service. If issues are identified in your
  8024. patch then it is usually necessary to address these before the patch will be
  8025. accepted into the project. In this case you should amend the patch according
  8026. to the feedback and submit an updated version to the relevant mailing list,
  8027. copying in the reviewers who provided feedback to the previous version of the
  8028. patch.
  8029. The patch should be amended using ``git commit --amend`` or perhaps ``git
  8030. rebase`` for more expert git users. You should also modify the ``[PATCH]``
  8031. tag in the email subject line when sending the revised patch to mark the new
  8032. iteration as ``[PATCH v2]``, ``[PATCH v3]``, etc as appropriate. This can be
  8033. done by passing the ``-v`` argument to ``git format-patch`` with a version
  8034. number.
  8035. Lastly please ensure that you also test your revised changes. In particular
  8036. please don't just edit the patch file written out by ``git format-patch`` and
  8037. resend it.
  8038. Submitting Changes to Stable Release Branches
  8039. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8040. The process for proposing changes to a Yocto Project stable branch differs
  8041. from the steps described above. Changes to a stable branch must address
  8042. identified bugs or CVEs and should be made carefully in order to avoid the
  8043. risk of introducing new bugs or breaking backwards compatibility. Typically
  8044. bug fixes must already be accepted into the master branch before they can be
  8045. backported to a stable branch unless the bug in question does not affect the
  8046. master branch or the fix on the master branch is unsuitable for backporting.
  8047. The list of stable branches along with the status and maintainer for each
  8048. branch can be obtained from the
  8049. :yocto_wiki:`Releases wiki page </Releases>`.
  8050. .. note::
  8051. Changes will not typically be accepted for branches which are marked as
  8052. End-Of-Life (EOL).
  8053. With this in mind, the steps to submit a change for a stable branch are as
  8054. follows:
  8055. 1. *Identify the bug or CVE to be fixed:* This information should be
  8056. collected so that it can be included in your submission.
  8057. 2. *Check if the fix is already present in the master branch:* This will
  8058. result in the most straightforward path into the stable branch for the
  8059. fix.
  8060. a. *If the fix is present in the master branch - Submit a backport request
  8061. by email:* You should send an email to the relevant stable branch
  8062. maintainer and the mailing list with details of the bug or CVE to be
  8063. fixed, the commit hash on the master branch that fixes the issue and
  8064. the stable branches which you would like this fix to be backported to.
  8065. b. *If the fix is not present in the master branch - Submit the fix to the
  8066. master branch first:* This will ensure that the fix passes through the
  8067. project's usual patch review and test processes before being accepted.
  8068. It will also ensure that bugs are not left unresolved in the master
  8069. branch itself. Once the fix is accepted in the master branch a backport
  8070. request can be submitted as above.
  8071. c. *If the fix is unsuitable for the master branch - Submit a patch
  8072. directly for the stable branch:* This method should be considered as a
  8073. last resort. It is typically necessary when the master branch is using
  8074. a newer version of the software which includes an upstream fix for the
  8075. issue or when the issue has been fixed on the master branch in a way
  8076. that introduces backwards incompatible changes. In this case follow the
  8077. steps in :ref:`dev-manual/common-tasks:preparing changes for submission` and
  8078. :ref:`dev-manual/common-tasks:using email to submit a patch` but modify the subject header of your patch
  8079. email to include the name of the stable branch which you are
  8080. targetting. This can be done using the ``--subject-prefix`` argument to
  8081. ``git format-patch``, for example to submit a patch to the dunfell
  8082. branch use
  8083. ``git format-patch --subject-prefix='&DISTRO_NAME_NO_CAP_MINUS_ONE;][PATCH' ...``.
  8084. Working With Licenses
  8085. =====================
  8086. As mentioned in the ":ref:`overview-manual/development-environment:licensing`"
  8087. section in the Yocto Project Overview and Concepts Manual, open source
  8088. projects are open to the public and they consequently have different
  8089. licensing structures in place. This section describes the mechanism by
  8090. which the :term:`OpenEmbedded Build System`
  8091. tracks changes to
  8092. licensing text and covers how to maintain open source license compliance
  8093. during your project's lifecycle. The section also describes how to
  8094. enable commercially licensed recipes, which by default are disabled.
  8095. Tracking License Changes
  8096. ------------------------
  8097. The license of an upstream project might change in the future. In order
  8098. to prevent these changes going unnoticed, the
  8099. :term:`LIC_FILES_CHKSUM`
  8100. variable tracks changes to the license text. The checksums are validated
  8101. at the end of the configure step, and if the checksums do not match, the
  8102. build will fail.
  8103. Specifying the ``LIC_FILES_CHKSUM`` Variable
  8104. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8105. The :term:`LIC_FILES_CHKSUM` variable contains checksums of the license text
  8106. in the source code for the recipe. Following is an example of how to
  8107. specify :term:`LIC_FILES_CHKSUM`::
  8108. LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
  8109. file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
  8110. file://licfile2.txt;endline=50;md5=zzzz \
  8111. ..."
  8112. .. note::
  8113. - When using "beginline" and "endline", realize that line numbering
  8114. begins with one and not zero. Also, the included lines are
  8115. inclusive (i.e. lines five through and including 29 in the
  8116. previous example for ``licfile1.txt``).
  8117. - When a license check fails, the selected license text is included
  8118. as part of the QA message. Using this output, you can determine
  8119. the exact start and finish for the needed license text.
  8120. The build system uses the :term:`S`
  8121. variable as the default directory when searching files listed in
  8122. :term:`LIC_FILES_CHKSUM`. The previous example employs the default
  8123. directory.
  8124. Consider this next example::
  8125. LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
  8126. md5=bb14ed3c4cda583abc85401304b5cd4e"
  8127. LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
  8128. The first line locates a file in ``${S}/src/ls.c`` and isolates lines
  8129. five through 16 as license text. The second line refers to a file in
  8130. :term:`WORKDIR`.
  8131. Note that :term:`LIC_FILES_CHKSUM` variable is mandatory for all recipes,
  8132. unless the :term:`LICENSE` variable is set to "CLOSED".
  8133. Explanation of Syntax
  8134. ~~~~~~~~~~~~~~~~~~~~~
  8135. As mentioned in the previous section, the :term:`LIC_FILES_CHKSUM` variable
  8136. lists all the important files that contain the license text for the
  8137. source code. It is possible to specify a checksum for an entire file, or
  8138. a specific section of a file (specified by beginning and ending line
  8139. numbers with the "beginline" and "endline" parameters, respectively).
  8140. The latter is useful for source files with a license notice header,
  8141. README documents, and so forth. If you do not use the "beginline"
  8142. parameter, then it is assumed that the text begins on the first line of
  8143. the file. Similarly, if you do not use the "endline" parameter, it is
  8144. assumed that the license text ends with the last line of the file.
  8145. The "md5" parameter stores the md5 checksum of the license text. If the
  8146. license text changes in any way as compared to this parameter then a
  8147. mismatch occurs. This mismatch triggers a build failure and notifies the
  8148. developer. Notification allows the developer to review and address the
  8149. license text changes. Also note that if a mismatch occurs during the
  8150. build, the correct md5 checksum is placed in the build log and can be
  8151. easily copied to the recipe.
  8152. There is no limit to how many files you can specify using the
  8153. :term:`LIC_FILES_CHKSUM` variable. Generally, however, every project
  8154. requires a few specifications for license tracking. Many projects have a
  8155. "COPYING" file that stores the license information for all the source
  8156. code files. This practice allows you to just track the "COPYING" file as
  8157. long as it is kept up to date.
  8158. .. note::
  8159. - If you specify an empty or invalid "md5" parameter,
  8160. :term:`BitBake` returns an md5
  8161. mis-match error and displays the correct "md5" parameter value
  8162. during the build. The correct parameter is also captured in the
  8163. build log.
  8164. - If the whole file contains only license text, you do not need to
  8165. use the "beginline" and "endline" parameters.
  8166. Enabling Commercially Licensed Recipes
  8167. --------------------------------------
  8168. By default, the OpenEmbedded build system disables components that have
  8169. commercial or other special licensing requirements. Such requirements
  8170. are defined on a recipe-by-recipe basis through the
  8171. :term:`LICENSE_FLAGS` variable
  8172. definition in the affected recipe. For instance, the
  8173. ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe
  8174. contains the following statement::
  8175. LICENSE_FLAGS = "commercial"
  8176. Here is a
  8177. slightly more complicated example that contains both an explicit recipe
  8178. name and version (after variable expansion)::
  8179. LICENSE_FLAGS = "license_${PN}_${PV}"
  8180. In order for a component restricted by a
  8181. :term:`LICENSE_FLAGS` definition to be enabled and included in an image, it
  8182. needs to have a matching entry in the global
  8183. :term:`LICENSE_FLAGS_WHITELIST`
  8184. variable, which is a variable typically defined in your ``local.conf``
  8185. file. For example, to enable the
  8186. ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you
  8187. could add either the string "commercial_gst-plugins-ugly" or the more
  8188. general string "commercial" to :term:`LICENSE_FLAGS_WHITELIST`. See the
  8189. ":ref:`dev-manual/common-tasks:license flag matching`" section for a full
  8190. explanation of how :term:`LICENSE_FLAGS` matching works. Here is the
  8191. example::
  8192. LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
  8193. Likewise, to additionally enable the package built from the recipe
  8194. containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that
  8195. the actual recipe name was ``emgd_1.10.bb``, the following string would
  8196. enable that package as well as the original ``gst-plugins-ugly``
  8197. package::
  8198. LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
  8199. As a convenience, you do not need to specify the
  8200. complete license string in the whitelist for every package. You can use
  8201. an abbreviated form, which consists of just the first portion or
  8202. portions of the license string before the initial underscore character
  8203. or characters. A partial string will match any license that contains the
  8204. given string as the first portion of its license. For example, the
  8205. following whitelist string will also match both of the packages
  8206. previously mentioned as well as any other packages that have licenses
  8207. starting with "commercial" or "license".
  8208. ::
  8209. LICENSE_FLAGS_WHITELIST = "commercial license"
  8210. License Flag Matching
  8211. ~~~~~~~~~~~~~~~~~~~~~
  8212. License flag matching allows you to control what recipes the
  8213. OpenEmbedded build system includes in the build. Fundamentally, the
  8214. build system attempts to match :term:`LICENSE_FLAGS` strings found in
  8215. recipes against :term:`LICENSE_FLAGS_WHITELIST` strings found in the
  8216. whitelist. A match causes the build system to include a recipe in the
  8217. build, while failure to find a match causes the build system to exclude
  8218. a recipe.
  8219. In general, license flag matching is simple. However, understanding some
  8220. concepts will help you correctly and effectively use matching.
  8221. Before a flag defined by a particular recipe is tested against the
  8222. contents of the whitelist, the expanded string ``_${PN}`` is appended to
  8223. the flag. This expansion makes each :term:`LICENSE_FLAGS` value
  8224. recipe-specific. After expansion, the string is then matched against the
  8225. whitelist. Thus, specifying ``LICENSE_FLAGS = "commercial"`` in recipe
  8226. "foo", for example, results in the string ``"commercial_foo"``. And, to
  8227. create a match, that string must appear in the whitelist.
  8228. Judicious use of the :term:`LICENSE_FLAGS` strings and the contents of the
  8229. :term:`LICENSE_FLAGS_WHITELIST` variable allows you a lot of flexibility for
  8230. including or excluding recipes based on licensing. For example, you can
  8231. broaden the matching capabilities by using license flags string subsets
  8232. in the whitelist.
  8233. .. note::
  8234. When using a string subset, be sure to use the part of the expanded
  8235. string that precedes the appended underscore character (e.g.
  8236. ``usethispart_1.3``, ``usethispart_1.4``, and so forth).
  8237. For example, simply specifying the string "commercial" in the whitelist
  8238. matches any expanded :term:`LICENSE_FLAGS` definition that starts with the
  8239. string "commercial" such as "commercial_foo" and "commercial_bar", which
  8240. are the strings the build system automatically generates for
  8241. hypothetical recipes named "foo" and "bar" assuming those recipes simply
  8242. specify the following::
  8243. LICENSE_FLAGS = "commercial"
  8244. Thus, you can choose
  8245. to exhaustively enumerate each license flag in the whitelist and allow
  8246. only specific recipes into the image, or you can use a string subset
  8247. that causes a broader range of matches to allow a range of recipes into
  8248. the image.
  8249. This scheme works even if the :term:`LICENSE_FLAGS` string already has
  8250. ``_${PN}`` appended. For example, the build system turns the license
  8251. flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match
  8252. both the general "commercial" and the specific "commercial_1.2_foo"
  8253. strings found in the whitelist, as expected.
  8254. Here are some other scenarios:
  8255. - You can specify a versioned string in the recipe such as
  8256. "commercial_foo_1.2" in a "foo" recipe. The build system expands this
  8257. string to "commercial_foo_1.2_foo". Combine this license flag with a
  8258. whitelist that has the string "commercial" and you match the flag
  8259. along with any other flag that starts with the string "commercial".
  8260. - Under the same circumstances, you can use "commercial_foo" in the
  8261. whitelist and the build system not only matches "commercial_foo_1.2"
  8262. but also matches any license flag with the string "commercial_foo",
  8263. regardless of the version.
  8264. - You can be very specific and use both the package and version parts
  8265. in the whitelist (e.g. "commercial_foo_1.2") to specifically match a
  8266. versioned recipe.
  8267. Other Variables Related to Commercial Licenses
  8268. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8269. There are other helpful variables related to commercial license handling,
  8270. defined in the
  8271. ``poky/meta/conf/distro/include/default-distrovars.inc`` file::
  8272. COMMERCIAL_AUDIO_PLUGINS ?= ""
  8273. COMMERCIAL_VIDEO_PLUGINS ?= ""
  8274. If you
  8275. want to enable these components, you can do so by making sure you have
  8276. statements similar to the following in your ``local.conf`` configuration
  8277. file::
  8278. COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
  8279. gst-plugins-ugly-mpegaudioparse"
  8280. COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
  8281. gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
  8282. LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
  8283. Of course, you could also create a matching whitelist for those
  8284. components using the more general "commercial" in the whitelist, but
  8285. that would also enable all the other packages with :term:`LICENSE_FLAGS`
  8286. containing "commercial", which you may or may not want::
  8287. LICENSE_FLAGS_WHITELIST = "commercial"
  8288. Specifying audio and video plugins as part of the
  8289. ``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements
  8290. (along with the enabling :term:`LICENSE_FLAGS_WHITELIST`) includes the
  8291. plugins or components into built images, thus adding support for media
  8292. formats or components.
  8293. Maintaining Open Source License Compliance During Your Product's Lifecycle
  8294. --------------------------------------------------------------------------
  8295. One of the concerns for a development organization using open source
  8296. software is how to maintain compliance with various open source
  8297. licensing during the lifecycle of the product. While this section does
  8298. not provide legal advice or comprehensively cover all scenarios, it does
  8299. present methods that you can use to assist you in meeting the compliance
  8300. requirements during a software release.
  8301. With hundreds of different open source licenses that the Yocto Project
  8302. tracks, it is difficult to know the requirements of each and every
  8303. license. However, the requirements of the major FLOSS licenses can begin
  8304. to be covered by assuming that there are three main areas of concern:
  8305. - Source code must be provided.
  8306. - License text for the software must be provided.
  8307. - Compilation scripts and modifications to the source code must be
  8308. provided.
  8309. - spdx files can be provided.
  8310. There are other requirements beyond the scope of these three and the
  8311. methods described in this section (e.g. the mechanism through which
  8312. source code is distributed).
  8313. As different organizations have different methods of complying with open
  8314. source licensing, this section is not meant to imply that there is only
  8315. one single way to meet your compliance obligations, but rather to
  8316. describe one method of achieving compliance. The remainder of this
  8317. section describes methods supported to meet the previously mentioned
  8318. three requirements. Once you take steps to meet these requirements, and
  8319. prior to releasing images, sources, and the build system, you should
  8320. audit all artifacts to ensure completeness.
  8321. .. note::
  8322. The Yocto Project generates a license manifest during image creation
  8323. that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp`
  8324. to assist with any audits.
  8325. Providing the Source Code
  8326. ~~~~~~~~~~~~~~~~~~~~~~~~~
  8327. Compliance activities should begin before you generate the final image.
  8328. The first thing you should look at is the requirement that tops the list
  8329. for most compliance groups - providing the source. The Yocto Project has
  8330. a few ways of meeting this requirement.
  8331. One of the easiest ways to meet this requirement is to provide the
  8332. entire :term:`DL_DIR` used by the
  8333. build. This method, however, has a few issues. The most obvious is the
  8334. size of the directory since it includes all sources used in the build
  8335. and not just the source used in the released image. It will include
  8336. toolchain source, and other artifacts, which you would not generally
  8337. release. However, the more serious issue for most companies is
  8338. accidental release of proprietary software. The Yocto Project provides
  8339. an :ref:`archiver <ref-classes-archiver>` class to
  8340. help avoid some of these concerns.
  8341. Before you employ :term:`DL_DIR` or the ``archiver`` class, you need to
  8342. decide how you choose to provide source. The source ``archiver`` class
  8343. can generate tarballs and SRPMs and can create them with various levels
  8344. of compliance in mind.
  8345. One way of doing this (but certainly not the only way) is to release
  8346. just the source as a tarball. You can do this by adding the following to
  8347. the ``local.conf`` file found in the
  8348. :term:`Build Directory`::
  8349. INHERIT += "archiver"
  8350. ARCHIVER_MODE[src] = "original"
  8351. During the creation of your
  8352. image, the source from all recipes that deploy packages to the image is
  8353. placed within subdirectories of ``DEPLOY_DIR/sources`` based on the
  8354. :term:`LICENSE` for each recipe.
  8355. Releasing the entire directory enables you to comply with requirements
  8356. concerning providing the unmodified source. It is important to note that
  8357. the size of the directory can get large.
  8358. A way to help mitigate the size issue is to only release tarballs for
  8359. licenses that require the release of source. Let us assume you are only
  8360. concerned with GPL code as identified by running the following script:
  8361. .. code-block:: shell
  8362. # Script to archive a subset of packages matching specific license(s)
  8363. # Source and license files are copied into sub folders of package folder
  8364. # Must be run from build folder
  8365. #!/bin/bash
  8366. src_release_dir="source-release"
  8367. mkdir -p $src_release_dir
  8368. for a in tmp/deploy/sources/*; do
  8369. for d in $a/*; do
  8370. # Get package name from path
  8371. p=`basename $d`
  8372. p=${p%-*}
  8373. p=${p%-*}
  8374. # Only archive GPL packages (update *GPL* regex for your license check)
  8375. numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
  8376. if [ $numfiles -gt 1 ]; then
  8377. echo Archiving $p
  8378. mkdir -p $src_release_dir/$p/source
  8379. cp $d/* $src_release_dir/$p/source 2> /dev/null
  8380. mkdir -p $src_release_dir/$p/license
  8381. cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
  8382. fi
  8383. done
  8384. done
  8385. At this point, you
  8386. could create a tarball from the ``gpl_source_release`` directory and
  8387. provide that to the end user. This method would be a step toward
  8388. achieving compliance with section 3a of GPLv2 and with section 6 of
  8389. GPLv3.
  8390. Providing License Text
  8391. ~~~~~~~~~~~~~~~~~~~~~~
  8392. One requirement that is often overlooked is inclusion of license text.
  8393. This requirement also needs to be dealt with prior to generating the
  8394. final image. Some licenses require the license text to accompany the
  8395. binary. You can achieve this by adding the following to your
  8396. ``local.conf`` file::
  8397. COPY_LIC_MANIFEST = "1"
  8398. COPY_LIC_DIRS = "1"
  8399. LICENSE_CREATE_PACKAGE = "1"
  8400. Adding these statements to the
  8401. configuration file ensures that the licenses collected during package
  8402. generation are included on your image.
  8403. .. note::
  8404. Setting all three variables to "1" results in the image having two
  8405. copies of the same license file. One copy resides in
  8406. ``/usr/share/common-licenses`` and the other resides in
  8407. ``/usr/share/license``.
  8408. The reason for this behavior is because
  8409. :term:`COPY_LIC_DIRS` and
  8410. :term:`COPY_LIC_MANIFEST`
  8411. add a copy of the license when the image is built but do not offer a
  8412. path for adding licenses for newly installed packages to an image.
  8413. :term:`LICENSE_CREATE_PACKAGE`
  8414. adds a separate package and an upgrade path for adding licenses to an
  8415. image.
  8416. As the source ``archiver`` class has already archived the original
  8417. unmodified source that contains the license files, you would have
  8418. already met the requirements for inclusion of the license information
  8419. with source as defined by the GPL and other open source licenses.
  8420. Providing Compilation Scripts and Source Code Modifications
  8421. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8422. At this point, we have addressed all we need to prior to generating the
  8423. image. The next two requirements are addressed during the final
  8424. packaging of the release.
  8425. By releasing the version of the OpenEmbedded build system and the layers
  8426. used during the build, you will be providing both compilation scripts
  8427. and the source code modifications in one step.
  8428. If the deployment team has a :ref:`overview-manual/concepts:bsp layer`
  8429. and a distro layer, and those
  8430. those layers are used to patch, compile, package, or modify (in any way)
  8431. any open source software included in your released images, you might be
  8432. required to release those layers under section 3 of GPLv2 or section 1
  8433. of GPLv3. One way of doing that is with a clean checkout of the version
  8434. of the Yocto Project and layers used during your build. Here is an
  8435. example:
  8436. .. code-block:: shell
  8437. # We built using the dunfell branch of the poky repo
  8438. $ git clone -b dunfell git://git.yoctoproject.org/poky
  8439. $ cd poky
  8440. # We built using the release_branch for our layers
  8441. $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
  8442. $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
  8443. # clean up the .git repos
  8444. $ find . -name ".git" -type d -exec rm -rf {} \;
  8445. One
  8446. thing a development organization might want to consider for end-user
  8447. convenience is to modify ``meta-poky/conf/bblayers.conf.sample`` to
  8448. ensure that when the end user utilizes the released build system to
  8449. build an image, the development organization's layers are included in
  8450. the ``bblayers.conf`` file automatically::
  8451. # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
  8452. # changes incompatibly
  8453. POKY_BBLAYERS_CONF_VERSION = "2"
  8454. BBPATH = "${TOPDIR}"
  8455. BBFILES ?= ""
  8456. BBLAYERS ?= " \
  8457. ##OEROOT##/meta \
  8458. ##OEROOT##/meta-poky \
  8459. ##OEROOT##/meta-yocto-bsp \
  8460. ##OEROOT##/meta-mylayer \
  8461. "
  8462. Creating and
  8463. providing an archive of the :term:`Metadata`
  8464. layers (recipes, configuration files, and so forth) enables you to meet
  8465. your requirements to include the scripts to control compilation as well
  8466. as any modifications to the original source.
  8467. Providing spdx files
  8468. ~~~~~~~~~~~~~~~~~~~~~~~~~
  8469. The spdx module has been integrated to a layer named meta-spdxscanner.
  8470. meta-spdxscanner provides several kinds of scanner. If you want to enable
  8471. this function, you have to follow the following steps:
  8472. 1. Add meta-spdxscanner layer into ``bblayers.conf``.
  8473. 2. Refer to the README in meta-spdxscanner to setup the environment (e.g,
  8474. setup a fossology server) needed for the scanner.
  8475. 3. Meta-spdxscanner provides several methods within the bbclass to create spdx files.
  8476. Please choose one that you want to use and enable the spdx task. You have to
  8477. add some config options in ``local.conf`` file in your :term:`Build
  8478. Directory`. Here is an example showing how to generate spdx files
  8479. during bitbake using the fossology-python.bbclass::
  8480. # Select fossology-python.bbclass.
  8481. INHERIT += "fossology-python"
  8482. # For fossology-python.bbclass, TOKEN is necessary, so, after setup a
  8483. # Fossology server, you have to create a token.
  8484. TOKEN = "eyJ0eXAiO..."
  8485. # The fossology server is necessary for fossology-python.bbclass.
  8486. FOSSOLOGY_SERVER = "http://xx.xx.xx.xx:8081/repo"
  8487. # If you want to upload the source code to a special folder:
  8488. FOLDER_NAME = "xxxx" //Optional
  8489. # If you don't want to put spdx files in tmp/deploy/spdx, you can enable:
  8490. SPDX_DEPLOY_DIR = "${DEPLOY_DIR}" //Optional
  8491. For more usage information refer to :yocto_git:`the meta-spdxscanner repository
  8492. </meta-spdxscanner/>`.
  8493. Copying Licenses that Do Not Exist
  8494. ----------------------------------
  8495. Some packages, such as the linux-firmware package, have many licenses
  8496. that are not in any way common. You can avoid adding a lot of these
  8497. types of common license files, which are only applicable to a specific
  8498. package, by using the
  8499. :term:`NO_GENERIC_LICENSE`
  8500. variable. Using this variable also avoids QA errors when you use a
  8501. non-common, non-CLOSED license in a recipe.
  8502. Here is an example that uses the ``LICENSE.Abilis.txt`` file as
  8503. the license from the fetched source::
  8504. NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
  8505. Using the Error Reporting Tool
  8506. ==============================
  8507. The error reporting tool allows you to submit errors encountered during
  8508. builds to a central database. Outside of the build environment, you can
  8509. use a web interface to browse errors, view statistics, and query for
  8510. errors. The tool works using a client-server system where the client
  8511. portion is integrated with the installed Yocto Project
  8512. :term:`Source Directory` (e.g. ``poky``).
  8513. The server receives the information collected and saves it in a
  8514. database.
  8515. There is a live instance of the error reporting server at
  8516. https://errors.yoctoproject.org.
  8517. When you want to get help with build failures, you can submit all of the
  8518. information on the failure easily and then point to the URL in your bug
  8519. report or send an email to the mailing list.
  8520. .. note::
  8521. If you send error reports to this server, the reports become publicly
  8522. visible.
  8523. Enabling and Using the Tool
  8524. ---------------------------
  8525. By default, the error reporting tool is disabled. You can enable it by
  8526. inheriting the
  8527. :ref:`report-error <ref-classes-report-error>`
  8528. class by adding the following statement to the end of your
  8529. ``local.conf`` file in your
  8530. :term:`Build Directory`.
  8531. ::
  8532. INHERIT += "report-error"
  8533. By default, the error reporting feature stores information in
  8534. ``${``\ :term:`LOG_DIR`\ ``}/error-report``.
  8535. However, you can specify a directory to use by adding the following to
  8536. your ``local.conf`` file::
  8537. ERR_REPORT_DIR = "path"
  8538. Enabling error
  8539. reporting causes the build process to collect the errors and store them
  8540. in a file as previously described. When the build system encounters an
  8541. error, it includes a command as part of the console output. You can run
  8542. the command to send the error file to the server. For example, the
  8543. following command sends the errors to an upstream server::
  8544. $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
  8545. In the previous example, the errors are sent to a public database
  8546. available at https://errors.yoctoproject.org, which is used by the
  8547. entire community. If you specify a particular server, you can send the
  8548. errors to a different database. Use the following command for more
  8549. information on available options::
  8550. $ send-error-report --help
  8551. When sending the error file, you are prompted to review the data being
  8552. sent as well as to provide a name and optional email address. Once you
  8553. satisfy these prompts, the command returns a link from the server that
  8554. corresponds to your entry in the database. For example, here is a
  8555. typical link: https://errors.yoctoproject.org/Errors/Details/9522/
  8556. Following the link takes you to a web interface where you can browse,
  8557. query the errors, and view statistics.
  8558. Disabling the Tool
  8559. ------------------
  8560. To disable the error reporting feature, simply remove or comment out the
  8561. following statement from the end of your ``local.conf`` file in your
  8562. :term:`Build Directory`.
  8563. ::
  8564. INHERIT += "report-error"
  8565. Setting Up Your Own Error Reporting Server
  8566. ------------------------------------------
  8567. If you want to set up your own error reporting server, you can obtain
  8568. the code from the Git repository at :yocto_git:`/error-report-web/`.
  8569. Instructions on how to set it up are in the README document.
  8570. Using Wayland and Weston
  8571. ========================
  8572. `Wayland <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)>`__
  8573. is a computer display server protocol that provides a method for
  8574. compositing window managers to communicate directly with applications
  8575. and video hardware and expects them to communicate with input hardware
  8576. using other libraries. Using Wayland with supporting targets can result
  8577. in better control over graphics frame rendering than an application
  8578. might otherwise achieve.
  8579. The Yocto Project provides the Wayland protocol libraries and the
  8580. reference
  8581. `Weston <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston>`__
  8582. compositor as part of its release. You can find the integrated packages
  8583. in the ``meta`` layer of the :term:`Source Directory`.
  8584. Specifically, you
  8585. can find the recipes that build both Wayland and Weston at
  8586. ``meta/recipes-graphics/wayland``.
  8587. You can build both the Wayland and Weston packages for use only with
  8588. targets that accept the `Mesa 3D and Direct Rendering
  8589. Infrastructure <https://en.wikipedia.org/wiki/Mesa_(computer_graphics)>`__,
  8590. which is also known as Mesa DRI. This implies that you cannot build and
  8591. use the packages if your target uses, for example, the Intel Embedded
  8592. Media and Graphics Driver (Intel EMGD) that overrides Mesa DRI.
  8593. .. note::
  8594. Due to lack of EGL support, Weston 1.0.3 will not run directly on the
  8595. emulated QEMU hardware. However, this version of Weston will run
  8596. under X emulation without issues.
  8597. This section describes what you need to do to implement Wayland and use
  8598. the Weston compositor when building an image for a supporting target.
  8599. Enabling Wayland in an Image
  8600. ----------------------------
  8601. To enable Wayland, you need to enable it to be built and enable it to be
  8602. included (installed) in the image.
  8603. Building Wayland
  8604. ~~~~~~~~~~~~~~~~
  8605. To cause Mesa to build the ``wayland-egl`` platform and Weston to build
  8606. Wayland with Kernel Mode Setting
  8607. (`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__)
  8608. support, include the "wayland" flag in the
  8609. :term:`DISTRO_FEATURES`
  8610. statement in your ``local.conf`` file::
  8611. DISTRO_FEATURES_append = " wayland"
  8612. .. note::
  8613. If X11 has been enabled elsewhere, Weston will build Wayland with X11
  8614. support
  8615. Installing Wayland and Weston
  8616. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8617. To install the Wayland feature into an image, you must include the
  8618. following
  8619. :term:`CORE_IMAGE_EXTRA_INSTALL`
  8620. statement in your ``local.conf`` file::
  8621. CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
  8622. Running Weston
  8623. --------------
  8624. To run Weston inside X11, enabling it as described earlier and building
  8625. a Sato image is sufficient. If you are running your image under Sato, a
  8626. Weston Launcher appears in the "Utility" category.
  8627. Alternatively, you can run Weston through the command-line interpretor
  8628. (CLI), which is better suited for development work. To run Weston under
  8629. the CLI, you need to do the following after your image is built:
  8630. 1. Run these commands to export ``XDG_RUNTIME_DIR``::
  8631. mkdir -p /tmp/$USER-weston
  8632. chmod 0700 /tmp/$USER-weston
  8633. export XDG_RUNTIME_DIR=/tmp/$USER-weston
  8634. 2. Launch Weston in the shell::
  8635. weston