technical-details.xml 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  1. <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  2. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
  3. [<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
  4. <chapter id='technical-details'>
  5. <title>Technical Details</title>
  6. <para>
  7. This chapter provides technical details for various parts of the Yocto Project.
  8. Currently, topics include Yocto Project components and shared state (sstate) cache.
  9. </para>
  10. <section id='usingpoky-components'>
  11. <title>Yocto Project Components</title>
  12. <para>
  13. The BitBake task executor together with various types of configuration files form the
  14. Yocto Project core.
  15. This section overviews the BitBake task executor and the
  16. configuration files by describing what they are used for and how they interact.
  17. </para>
  18. <para>
  19. BitBake handles the parsing and execution of the data files.
  20. The data itself is of various types:
  21. <itemizedlist>
  22. <listitem><para><emphasis>Recipes:</emphasis> Provides details about particular
  23. pieces of software</para></listitem>
  24. <listitem><para><emphasis>Class Data:</emphasis> An abstraction of common build
  25. information (e.g. how to build a Linux kernel).</para></listitem>
  26. <listitem><para><emphasis>Configuration Data:</emphasis> Defines machine-specific settings,
  27. policy decisions, etc.
  28. Configuration data acts as the glue to bind everything together.</para></listitem>
  29. </itemizedlist>
  30. For more information on data, see the
  31. "<ulink url='&YOCTO_DOCS_DEV_URL;#yocto-project-terms'>Yocto Project Terms</ulink>"
  32. section in the Yocto Project Development Manual.
  33. </para>
  34. <para>
  35. BitBake knows how to combine multiple data sources together and refers to each data source
  36. as a layer.
  37. For information on layers, see the
  38. "<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and
  39. Creating Layers</ulink>" section of the Yocto Project Development Manual.
  40. </para>
  41. <para>
  42. Following are some brief details on these core components.
  43. For more detailed information on these components see the
  44. "<link linkend='ref-structure'>Reference: Directory Structure</link>" appendix.
  45. </para>
  46. <section id='usingpoky-components-bitbake'>
  47. <title>BitBake</title>
  48. <para>
  49. BitBake is the tool at the heart of the Yocto Project and is responsible
  50. for parsing the metadata, generating a list of tasks from it,
  51. and then executing those tasks.
  52. To see a list of the options BitBake supports, use the following help command:
  53. <literallayout class='monospaced'>
  54. $ bitbake --help
  55. </literallayout>
  56. </para>
  57. <para>
  58. The most common usage for BitBake is <filename>bitbake &lt;packagename&gt;</filename>, where
  59. <filename>packagename</filename> is the name of the package you want to build
  60. (referred to as the "target" in this manual).
  61. The target often equates to the first part of a <filename>.bb</filename> filename.
  62. So, to run the <filename>matchbox-desktop_1.2.3.bb</filename> file, you
  63. might type the following:
  64. <literallayout class='monospaced'>
  65. $ bitbake matchbox-desktop
  66. </literallayout>
  67. Several different versions of <filename>matchbox-desktop</filename> might exist.
  68. BitBake chooses the one selected by the distribution configuration.
  69. You can get more details about how BitBake chooses between different
  70. target versions and providers in the
  71. "<link linkend='ref-bitbake-providers'>Preferences and Providers</link>" section.
  72. </para>
  73. <para>
  74. BitBake also tries to execute any dependent tasks first.
  75. So for example, before building <filename>matchbox-desktop</filename>, BitBake
  76. would build a cross compiler and <filename>eglibc</filename> if they had not already
  77. been built.
  78. <note>This release of the Yocto Project does not support the <filename>glibc</filename>
  79. GNU version of the Unix standard C library. By default, the Yocto Project builds with
  80. <filename>eglibc</filename>.</note>
  81. </para>
  82. <para>
  83. A useful BitBake option to consider is the <filename>-k</filename> or
  84. <filename>--continue</filename> option.
  85. This option instructs BitBake to try and continue processing the job as much
  86. as possible even after encountering an error.
  87. When an error occurs, the target that
  88. failed and those that depend on it cannot be remade.
  89. However, when you use this option other dependencies can still be processed.
  90. </para>
  91. </section>
  92. <section id='usingpoky-components-metadata'>
  93. <title>Metadata (Recipes)</title>
  94. <para>
  95. The <filename>.bb</filename> files are usually referred to as "recipes."
  96. In general, a recipe contains information about a single piece of software.
  97. The information includes the location from which to download the source patches
  98. (if any are needed), which special configuration options to apply,
  99. how to compile the source files, and how to package the compiled output.
  100. </para>
  101. <para>
  102. The term "package" can also be used to describe recipes.
  103. However, since the same word is used for the packaged output from the Yocto
  104. Project (i.e. <filename>.ipk</filename> or <filename>.deb</filename> files),
  105. this document avoids using the term "package" when referring to recipes.
  106. </para>
  107. </section>
  108. <section id='usingpoky-components-classes'>
  109. <title>Classes</title>
  110. <para>
  111. Class files (<filename>.bbclass</filename>) contain information that is useful to share
  112. between metadata files.
  113. An example is the Autotools class, which contains
  114. common settings for any application that Autotools uses.
  115. The "<link linkend='ref-classes'>Reference: Classes</link>" appendix provides details
  116. about common classes and how to use them.
  117. </para>
  118. </section>
  119. <section id='usingpoky-components-configuration'>
  120. <title>Configuration</title>
  121. <para>
  122. The configuration files (<filename>.conf</filename>) define various configuration variables
  123. that govern the Yocto Project build process.
  124. These files fall into several areas that define machine configuration options,
  125. distribution configuration options, compiler tuning options, general common configuration
  126. options and user configuration options (<filename>local.conf</filename>, which is found
  127. in the Yocto Project files build directory).
  128. </para>
  129. </section>
  130. </section>
  131. <section id="shared-state-cache">
  132. <title>Shared State Cache</title>
  133. <para>
  134. By design, the Yocto Project build system builds everything from scratch unless
  135. BitBake can determine that parts don't need to be rebuilt.
  136. Fundamentally, building from scratch is attractive as it means all parts are
  137. built fresh and there is no possibility of stale data causing problems.
  138. When developers hit problems, they typically default back to building from scratch
  139. so they know the state of things from the start.
  140. </para>
  141. <para>
  142. Building an image from scratch is both an advantage and a disadvantage to the process.
  143. As mentioned in the previous paragraph, building from scratch ensures that
  144. everything is current and starts from a known state.
  145. However, building from scratch also takes much longer as it generally means
  146. rebuilding things that don't necessarily need rebuilt.
  147. </para>
  148. <para>
  149. The Yocto Project implements shared state code that supports incremental builds.
  150. The implementation of the shared state code answers the following questions that
  151. were fundamental roadblocks within the Yocto Project incremental build support system:
  152. <itemizedlist>
  153. <listitem>What pieces of the system have changed and what pieces have not changed?</listitem>
  154. <listitem>How are changed pieces of software removed and replaced?</listitem>
  155. <listitem>How are pre-built components that don't need to be rebuilt from scratch
  156. used when they are available?</listitem>
  157. </itemizedlist>
  158. </para>
  159. <para>
  160. For the first question, the build system detects changes in the "inputs" to a given task by
  161. creating a checksum (or signature) of the task's inputs.
  162. If the checksum changes, the system assumes the inputs have changed and the task needs to be
  163. rerun.
  164. For the second question, the shared state (sstate) code tracks which tasks add which output
  165. to the build process.
  166. This means the output from a given task can be removed, upgraded or otherwise manipulated.
  167. The third question is partly addressed by the solution for the second question
  168. assuming the build system can fetch the sstate objects from remote locations and
  169. install them if they are deemed to be valid.
  170. </para>
  171. <para>
  172. The rest of this section goes into detail about the overall incremental build
  173. architecture, the checksums (signatures), shared state, and some tips and tricks.
  174. </para>
  175. <section id='overall-architecture'>
  176. <title>Overall Architecture</title>
  177. <para>
  178. When determining what parts of the system need to be built, BitBake
  179. uses a per-task basis and does not use a per-recipe basis.
  180. You might wonder why using a per-task basis is preferred over a per-recipe basis.
  181. To help explain, consider having the IPK packaging backend enabled and then switching to DEB.
  182. In this case, <filename>do_install</filename> and <filename>do_package</filename>
  183. output are still valid.
  184. However, with a per-recipe approach, the build would not include the
  185. <filename>.deb</filename> files.
  186. Consequently, you would have to invalidate the whole build and rerun it.
  187. Rerunning everything is not the best situation.
  188. Also in this case, the core must be "taught" much about specific tasks.
  189. This methodology does not scale well and does not allow users to easily add new tasks
  190. in layers or as external recipes without touching the packaged-staging core.
  191. </para>
  192. </section>
  193. <section id='checksums'>
  194. <title>Checksums (Signatures)</title>
  195. <para>
  196. The shared state code uses a checksum, which is a unique signature of a task's
  197. inputs, to determine if a task needs to be run again.
  198. Because it is a change in a task's inputs that triggers a rerun, the process
  199. needs to detect all the inputs to a given task.
  200. For shell tasks, this turns out to be fairly easy because
  201. the build process generates a "run" shell script for each task and
  202. it is possible to create a checksum that gives you a good idea of when
  203. the task's data changes.
  204. </para>
  205. <para>
  206. To complicate the problem, there are things that should not be included in
  207. the checksum.
  208. First, there is the actual specific build path of a given task -
  209. the <filename>WORKDIR</filename>.
  210. It does not matter if the working directory changes because it should not
  211. affect the output for target packages.
  212. Also, the build process has the objective of making native/cross packages relocatable.
  213. The checksum therefore needs to exclude <filename>WORKDIR</filename>.
  214. The simplistic approach for excluding the working directory is to set
  215. <filename>WORKDIR</filename> to some fixed value and create the checksum
  216. for the "run" script.
  217. </para>
  218. <para>
  219. Another problem results from the "run" scripts containing functions that
  220. might or might not get called.
  221. The incremental build solution contains code that figures out dependencies
  222. between shell functions.
  223. This code is used to prune the "run" scripts down to the minimum set,
  224. thereby alleviating this problem and making the "run" scripts much more
  225. readable as a bonus.
  226. </para>
  227. <para>
  228. So far we have solutions for shell scripts.
  229. What about python tasks?
  230. The same approach applies even though these tasks are more difficult.
  231. The process needs to figure out what variables a python function accesses
  232. and what functions it calls.
  233. Again, the incremental build solution contains code that first figures out
  234. the variable and function dependencies, and then creates a checksum for the data
  235. used as the input to the task.
  236. </para>
  237. <para>
  238. Like the <filename>WORKDIR</filename> case, situations exist where dependencies
  239. should be ignored.
  240. For these cases, you can instruct the build process to ignore a dependency
  241. by using a line like the following:
  242. <literallayout class='monospaced'>
  243. PACKAGE_ARCHS[vardepsexclude] = "MACHINE"
  244. </literallayout>
  245. This example ensures that the <filename>PACKAGE_ARCHS</filename> variable does not
  246. depend on the value of <filename>MACHINE</filename>, even if it does reference it.
  247. </para>
  248. <para>
  249. Equally, there are cases where we need to add dependencies BitBake is not able to find.
  250. You can accomplish this by using a line like the following:
  251. <literallayout class='monospaced'>
  252. PACKAGE_ARCHS[vardeps] = "MACHINE"
  253. </literallayout>
  254. This example explicitly adds the <filename>MACHINE</filename> variable as a
  255. dependency for <filename>PACKAGE_ARCHS</filename>.
  256. </para>
  257. <para>
  258. Consider a case with inline python, for example, where BitBake is not
  259. able to figure out dependencies.
  260. When running in debug mode (i.e. using <filename>-DDD</filename>), BitBake
  261. produces output when it discovers something for which it cannot figure out
  262. dependencies.
  263. The Yocto Project team has currently not managed to cover those dependencies
  264. in detail and is aware of the need to fix this situation.
  265. </para>
  266. <para>
  267. Thus far, this section has limited discussion to the direct inputs into a task.
  268. Information based on direct inputs is referred to as the "basehash" in the
  269. code.
  270. However, there is still the question of a task's indirect inputs - the
  271. things that were already built and present in the build directory.
  272. The checksum (or signature) for a particular task needs to add the hashes
  273. of all the tasks on which the particular task depends.
  274. Choosing which dependencies to add is a policy decision.
  275. However, the effect is to generate a master checksum that combines the basehash
  276. and the hashes of the task's dependencies.
  277. </para>
  278. <para>
  279. At the code level, there are a variety of ways both the basehash and the
  280. dependent task hashes can be influenced.
  281. Within the BitBake configuration file, we can give BitBake some extra information
  282. to help it construct the basehash.
  283. The following statements effectively result in a list of global variable
  284. dependency excludes - variables never included in any checksum:
  285. <literallayout class='monospaced'>
  286. BB_HASHBASE_WHITELIST ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH"
  287. BB_HASHBASE_WHITELIST += "DL_DIR SSTATE_DIR THISDIR FILESEXTRAPATHS"
  288. BB_HASHBASE_WHITELIST += "FILE_DIRNAME HOME LOGNAME SHELL TERM USER"
  289. BB_HASHBASE_WHITELIST += "FILESPATH USERNAME STAGING_DIR_HOST STAGING_DIR_TARGET"
  290. </literallayout>
  291. The previous example actually excludes
  292. <link linkend='var-WORKDIR'><filename>WORKDIR</filename></link>
  293. since it is actually constructed as a path within
  294. <link linkend='var-TMPDIR'><filename>TMPDIR</filename></link>, which is on
  295. the whitelist.
  296. </para>
  297. <para>
  298. The rules for deciding which hashes of dependent tasks to include through
  299. dependency chains are more complex and are generally accomplished with a
  300. python function.
  301. The code in <filename>meta/lib/oe/sstatesig.py</filename> shows two examples
  302. of this and also illustrates how you can insert your own policy into the system
  303. if so desired.
  304. This file defines the two basic signature generators <filename>OE-Core</filename>
  305. uses: "OEBasic" and "OEBasicHash".
  306. By default, there is a dummy "noop" signature handler enabled in BitBake.
  307. This means that behavior is unchanged from previous versions.
  308. <filename>OE-Core</filename> uses the "OEBasic" signature handler by default
  309. through this setting in the <filename>bitbake.conf</filename> file:
  310. <literallayout class='monospaced'>
  311. BB_SIGNATURE_HANDLER ?= "OEBasic"
  312. </literallayout>
  313. The "OEBasicHash" <filename>BB_SIGNATURE_HANDLER</filename> is the same as the
  314. "OEBasic" version but adds the task hash to the stamp files.
  315. This results in any metadata change that changes the task hash, automatically
  316. causing the task to be run again.
  317. This removes the need to bump <link linkend='var-PR'><filename>PR</filename></link>
  318. values and changes to metadata automatically ripple across the build.
  319. Currently, this behavior is not the default behavior for <filename>OE-Core</filename>
  320. but is the default in <filename>poky</filename>.
  321. </para>
  322. <para>
  323. It is also worth noting that the end result of these signature generators is to
  324. make some dependency and hash information available to the build.
  325. This information includes:
  326. <literallayout class='monospaced'>
  327. BB_BASEHASH_task-&lt;taskname&gt; - the base hashes for each task in the recipe
  328. BB_BASEHASH_&lt;filename:taskname&gt; - the base hashes for each dependent task
  329. BBHASHDEPS_&lt;filename:taskname&gt; - The task dependencies for each task
  330. BB_TASKHASH - the hash of the currently running task
  331. </literallayout>
  332. </para>
  333. </section>
  334. <section id='shared-state'>
  335. <title>Shared State</title>
  336. <para>
  337. Checksums and dependencies, as discussed in the previous section, solve half the
  338. problem.
  339. The other part of the problem is being able to use checksum information during the build
  340. and being able to reuse or rebuild specific components.
  341. </para>
  342. <para>
  343. The shared state class (<filename>sstate.bbclass</filename>)
  344. is a relatively generic implementation of how to "capture" a snapshot of a given task.
  345. The idea is that the build process does not care about the source of a task's output.
  346. Output could be freshly built or it could be downloaded and unpacked from
  347. somewhere - the build process doesn't need to worry about its source.
  348. </para>
  349. <para>
  350. There are two types of output, one is just about creating a directory
  351. in <filename>WORKDIR</filename>.
  352. A good example is the output of either <filename>do_install</filename> or
  353. <filename>do_package</filename>.
  354. The other type of output occurs when a set of data is merged into a shared directory
  355. tree such as the sysroot.
  356. </para>
  357. <para>
  358. The Yocto Project team has tried to keep the details of the implementation hidden in
  359. <filename>sstate.bbclass</filename>.
  360. From a user's perspective, adding shared state wrapping to a task
  361. is as simple as this <filename>do_deploy</filename> example taken from
  362. <filename>do_deploy.bbclass</filename>:
  363. <literallayout class='monospaced'>
  364. DEPLOYDIR = "${WORKDIR}/deploy-${PN}"
  365. SSTATETASKS += "do_deploy"
  366. do_deploy[sstate-name] = "deploy"
  367. do_deploy[sstate-inputdirs] = "${DEPLOYDIR}"
  368. do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
  369. python do_deploy_setscene () {
  370. sstate_setscene(d)
  371. }
  372. addtask do_deploy_setscene
  373. </literallayout>
  374. In the example, we add some extra flags to the task, a name field ("deploy"), an
  375. input directory where the task sends data, and the output
  376. directory where the data from the task should eventually be copied.
  377. We also add a <filename>_setscene</filename> variant of the task and add the task
  378. name to the <filename>SSTATETASKS</filename> list.
  379. </para>
  380. <para>
  381. If you have a directory whose contents you need to preserve, you can do this with
  382. a line like the following:
  383. <literallayout class='monospaced'>
  384. do_package[sstate-plaindirs] = "${PKGD} ${PKGDEST}"
  385. </literallayout>
  386. This method, as well as the following example, also works for multiple directories.
  387. <literallayout class='monospaced'>
  388. do_package[sstate-inputdirs] = "${PKGDESTWORK} ${SHLIBSWORKDIR}"
  389. do_package[sstate-outputdirs] = "${PKGDATA_DIR} ${SHLIBSDIR}"
  390. do_package[sstate-lockfile] = "${PACKAGELOCK}"
  391. </literallayout>
  392. These methods also include the ability to take a lockfile when manipulating
  393. shared state directory structures since some cases are sensitive to file
  394. additions or removals.
  395. </para>
  396. <para>
  397. Behind the scenes, the shared state code works by looking in
  398. <filename>SSTATE_DIR</filename> and
  399. <filename>SSTATE_MIRRORS</filename> for shared state files.
  400. Here is an example:
  401. <literallayout class='monospaced'>
  402. SSTATE_MIRRORS ?= "\
  403. file://.* http://someserver.tld/share/sstate/ \n \
  404. file://.* file:///some/local/dir/sstate/"
  405. </literallayout>
  406. </para>
  407. <para>
  408. The shared state package validity can be detected just by looking at the
  409. filename since the filename contains the task checksum (or signature) as
  410. described earlier in this section.
  411. If a valid shared state package is found, the build process downloads it
  412. and uses it to accelerate the task.
  413. </para>
  414. <para>
  415. The build processes uses the <filename>*_setscene</filename> tasks
  416. for the task acceleration phase.
  417. BitBake goes through this phase before the main execution code and tries
  418. to accelerate any tasks for which it can find shared state packages.
  419. If a shared state package for a task is available, the shared state
  420. package is used.
  421. This means the task and any tasks on which it is dependent are not
  422. executed.
  423. </para>
  424. <para>
  425. As a real world example, the aim is when building an IPK-based image,
  426. only the <filename>do_package_write_ipk</filename> tasks would have their
  427. shared state packages fetched and extracted.
  428. Since the sysroot is not used, it would never get extracted.
  429. This is another reason why a task-based approach is preferred over a
  430. recipe-based approach, which would have to install the output from every task.
  431. </para>
  432. </section>
  433. <section id='tips-and-tricks'>
  434. <title>Tips and Tricks</title>
  435. <para>
  436. The code in the Yocto Project that supports incremental builds is not
  437. simple code.
  438. This section presents some tips and tricks that help you work around
  439. issues related to shared state code.
  440. </para>
  441. <section id='debugging'>
  442. <title>Debugging</title>
  443. <para>
  444. When things go wrong, debugging needs to be straightforward.
  445. Because of this, the Yocto Project team included strong debugging
  446. tools:
  447. <itemizedlist>
  448. <listitem><para>Whenever a shared state package is written out, so is a
  449. corresponding <filename>.siginfo</filename> file.
  450. This practice results in a pickled python database of all
  451. the metadata that went into creating the hash for a given shared state
  452. package.</para></listitem>
  453. <listitem><para>If BitBake is run with the <filename>--dump-signatures</filename>
  454. (or <filename>-S</filename>) option, BitBake dumps out
  455. <filename>.siginfo</filename> files in
  456. the stamp directory for every task it would have executed instead of
  457. building the specified target package.</para></listitem>
  458. <listitem><para>There is a <filename>bitbake-diffsigs</filename> command that
  459. can process these <filename>.siginfo</filename> files.
  460. If one file is specified, it will dump out the dependency
  461. information in the file.
  462. If two files are specified, it will compare the two files and dump out
  463. the differences between the two.
  464. This allows the question of "What changed between X and Y?" to be
  465. answered easily.</para></listitem>
  466. </itemizedlist>
  467. </para>
  468. </section>
  469. <section id='invalidating-shared-state'>
  470. <title>Invalidating Shared State</title>
  471. <para>
  472. The shared state code uses checksums and shared state memory
  473. cache to avoid unnecessarily rebuilding tasks.
  474. As with all schemes, this one has some drawbacks.
  475. It is possible that you could make implicit changes that are not factored
  476. into the checksum calculation, but do affect a task's output.
  477. A good example is perhaps when a tool changes its output.
  478. Let's say that the output of <filename>rpmdeps</filename> needed to change.
  479. The result of the change should be that all the "package", "package_write_rpm",
  480. and "package_deploy-rpm" shared state cache items would become invalid.
  481. But, because this is a change that is external to the code and therefore implicit,
  482. the associated shared state cache items do not become invalidated.
  483. In this case, the build process would use the cached items rather than running the
  484. task again.
  485. Obviously, these types of implicit changes can cause problems.
  486. </para>
  487. <para>
  488. To avoid these problems during the build, you need to understand the effects of any
  489. change you make.
  490. Note that any changes you make directly to a function automatically are factored into
  491. the checksum calculation and thus, will invalidate the associated area of sstate cache.
  492. You need to be aware of any implicit changes that are not obvious changes to the
  493. code and could affect the output of a given task.
  494. Once you are aware of such a change, you can take steps to invalidate the cache
  495. and force the task to run.
  496. The step to take is as simple as changing a function's comments in the source code.
  497. For example, to invalidate package shared state files, change the comment statements
  498. of <filename>do_package</filename> or the comments of one of the functions it calls.
  499. The change is purely cosmetic, but it causes the checksum to be recalculated and
  500. forces the task to be run again.
  501. </para>
  502. <note>
  503. For an example of a commit that makes a cosmetic change to invalidate
  504. a shared state, see this
  505. <ulink url='&YOCTO_GIT_URL;/cgit.cgi/poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54'>commit</ulink>.
  506. </note>
  507. </section>
  508. </section>
  509. </section>
  510. <section id='x32'>
  511. <title>x32</title>
  512. <para>
  513. x32 is a new processor-specific Application Binary Interface (psABI) for x86_64.
  514. An ABI defines the calling conventions between functions in a processing environment.
  515. The interface determines what registers are used and what the sizes are for various C data types.
  516. </para>
  517. <para>
  518. Some processing environments prefer using 32-bit applications even when running
  519. on Intel 64-bit platforms.
  520. Consider the i386 psABI, which is a very old 32-bit ABI for Intel 64-bit platforms.
  521. The i386 psABI does not provide efficient use and access of the Intel 64-bit processor resources,
  522. leaving the system underutilized.
  523. Now consider the x86_64 psABI.
  524. This ABI is newer and uses 64-bits for data sizes and program pointers.
  525. The extra bits increase the footprint size of the programs, libraries,
  526. and also increases the memory and file system size requirements.
  527. Executing under the x32 psABI enables user programs to utilize CPU and system resources
  528. more efficiently while keeping the memory footprint of the applications low.
  529. Extra bits are used for registers but not for addressing mechanisms.
  530. </para>
  531. <section id='support'>
  532. <title>Support</title>
  533. <para>
  534. While the x32 psABI specifications are not fully finalized, this Yocto Project
  535. release supports current development specifications of x32 psABI.
  536. As of this release of the Yocto Project, x32 psABI support exists as follows:
  537. <itemizedlist>
  538. <listitem><para>You can create packages and images in x32 psABI format on x86_64 architecture targets.
  539. </para></listitem>
  540. <listitem><para>You can use the x32 psABI support through the <filename>meta-x32</filename>
  541. layer on top of the OE-core/Yocto layer.</para></listitem>
  542. <listitem><para>The toolchain from the <filename>experimental/meta-x32</filename> layer
  543. is used for building x32 psABI program binaries.</para></listitem>
  544. <listitem><para>You can successfully build many recipes with the x32 toolchain.</para></listitem>
  545. <listitem><para>You can create and boot <filename>core-image-minimal</filename> and
  546. <filename>core-image-sato</filename> images.</para></listitem>
  547. </itemizedlist>
  548. </para>
  549. </section>
  550. <section id='future-development-and-limitations'>
  551. <title>Future Development and Limitations</title>
  552. <para>
  553. As of this Yocto Project release, the x32 psABI kernel and library interfaces
  554. specifications are not finalized.
  555. </para>
  556. <para>
  557. Future Plans for the x32 psABI in the Yocto Project include the following:
  558. <itemizedlist>
  559. <listitem><para>Enhance and fix the few remaining recipes so they
  560. work with and support x32 toolchains.</para></listitem>
  561. <listitem><para>Enhance RPM Package Manager (RPM) support for x32 binaries.</para></listitem>
  562. <listitem><para>Support larger images.</para></listitem>
  563. <listitem><para>Integrate x32 recipes, toolchain, and kernel changes from
  564. <filename>experimental/meta-x32</filename> into OE-core.</para></listitem>
  565. </itemizedlist>
  566. </para>
  567. </section>
  568. <section id='using-x32-right-now'>
  569. <title>Using x32 Right Now</title>
  570. <para>
  571. Despite the fact the x32 psABI support is in development state for this release of the
  572. Yocto Project, you can follow these steps to use the x32 spABI:
  573. <itemizedlist>
  574. <listitem><para>Add the <filename>experimental/meta-x32</filename> layer to your local
  575. <ulink url='&YOCTO_DOCS_DEV_URL;#yocto-project-build-directory'>Yocto Project
  576. Build Directory</ulink>.
  577. You can find the <filename>experimental/meta-x32</filename> source repository at
  578. <ulink url='&YOCTO_GIT_URL;'></ulink>.</para></listitem>
  579. <listitem><para>Edit your <filename>conf/bblayers.conf</filename> file so that it includes
  580. the <filename>meta-x32</filename>.
  581. Here is an example:
  582. <literallayout class='monospaced'>
  583. BBLAYERS ?= " \
  584. /home/nitin/prj/poky.git/meta \
  585. /home/nitin/prj/poky.git/meta-yocto \
  586. /home/nitin/prj/meta-x32.git \
  587. "
  588. </literallayout></para></listitem>
  589. <listitem><para>Enable the x32 psABI tuning file for <filename>x86_64</filename>
  590. machines by editing the <filename>conf/local.conf</filename> like this:
  591. <literallayout class='monospaced'>
  592. MACHINE = "qemux86-64"
  593. DEFAULTTUNE = "x86-64-x32"
  594. baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE', True) \
  595. or 'INVALID'), True) or 'lib'}"
  596. #MACHINE = "atom-pc"
  597. #DEFAULTTUNE = "core2-64-x32"
  598. </literallayout></para></listitem>
  599. <listitem><para>As usual, use BitBake to build an image that supports the x32 psABI.
  600. Here is an example:
  601. <literallayout class='monospaced'>
  602. $ bitake core-image-sato
  603. </literallayout></para></listitem>
  604. <listitem><para>As usual, run your image using QEMU:
  605. <literallayout class='monospaced'>
  606. $ runqemu qemux86-64 core-image-sato
  607. </literallayout></para></listitem>
  608. </itemizedlist>
  609. </para>
  610. </section>
  611. </section>
  612. <section id="licenses">
  613. <title>Licenses</title>
  614. <para>
  615. This section describes the mechanism by which the Yocto Project build system
  616. tracks changes to licensing text.
  617. The section also describes how to enable commercially licensed recipes,
  618. which by default are disabled.
  619. </para>
  620. <section id="usingpoky-configuring-LIC_FILES_CHKSUM">
  621. <title>Tracking License Changes</title>
  622. <para>
  623. The license of an upstream project might change in the future. In order to prevent these changes
  624. going unnoticed, the Yocto Project provides a
  625. <filename><link linkend='var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</link></filename>
  626. variable to track changes to the license text. The checksums are validated at the end of the
  627. configure step, and if the checksums do not match, the build will fail.
  628. </para>
  629. <section id="usingpoky-specifying-LIC_FILES_CHKSUM">
  630. <title>Specifying the <filename>LIC_FILES_CHKSUM</filename> Variable</title>
  631. <para>
  632. The <filename>LIC_FILES_CHKSUM</filename>
  633. variable contains checksums of the license text in the source code for the recipe.
  634. Following is an example of how to specify <filename>LIC_FILES_CHKSUM</filename>:
  635. <literallayout class='monospaced'>
  636. LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
  637. file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
  638. file://licfile2.txt;endline=50;md5=zzzz \
  639. ..."
  640. </literallayout>
  641. </para>
  642. <para>
  643. The Yocto Project uses the
  644. <filename><link linkend='var-S'>S</link></filename> variable as the
  645. default directory used when searching files listed in
  646. <filename>LIC_FILES_CHKSUM</filename>.
  647. The previous example employs the default directory.
  648. </para>
  649. <para>
  650. You can also use relative paths as shown in the following example:
  651. <literallayout class='monospaced'>
  652. LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
  653. md5=bb14ed3c4cda583abc85401304b5cd4e"
  654. LIC_FILES_CHKSUM = "file://../license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
  655. </literallayout>
  656. </para>
  657. <para>
  658. In this example, the first line locates a file in
  659. <filename>${S}/src/ls.c</filename>.
  660. The second line refers to a file in
  661. <filename><link linkend='var-WORKDIR'>WORKDIR</link></filename>, which is the parent
  662. of <filename><link linkend='var-S'>S</link></filename>.
  663. </para>
  664. <para>
  665. Note that this variable is mandatory for all recipes, unless the
  666. <filename>LICENSE</filename> variable is set to "CLOSED".
  667. </para>
  668. </section>
  669. <section id="usingpoky-LIC_FILES_CHKSUM-explanation-of-syntax">
  670. <title>Explanation of Syntax</title>
  671. <para>
  672. As mentioned in the previous section, the
  673. <filename>LIC_FILES_CHKSUM</filename> variable lists all the
  674. important files that contain the license text for the source code.
  675. It is possible to specify a checksum for an entire file, or a specific section of a
  676. file (specified by beginning and ending line numbers with the "beginline" and "endline"
  677. parameters, respectively).
  678. The latter is useful for source files with a license notice header,
  679. README documents, and so forth.
  680. If you do not use the "beginline" parameter, then it is assumed that the text begins on the
  681. first line of the file.
  682. Similarly, if you do not use the "endline" parameter, it is assumed that the license text
  683. ends with the last line of the file.
  684. </para>
  685. <para>
  686. The "md5" parameter stores the md5 checksum of the license text.
  687. If the license text changes in any way as compared to this parameter
  688. then a mismatch occurs.
  689. This mismatch triggers a build failure and notifies the developer.
  690. Notification allows the developer to review and address the license text changes.
  691. Also note that if a mismatch occurs during the build, the correct md5
  692. checksum is placed in the build log and can be easily copied to the recipe.
  693. </para>
  694. <para>
  695. There is no limit to how many files you can specify using the
  696. <filename>LIC_FILES_CHKSUM</filename> variable.
  697. Generally, however, every project requires a few specifications for license tracking.
  698. Many projects have a "COPYING" file that stores the license information for all the source
  699. code files.
  700. This practice allows you to just track the "COPYING" file as long as it is kept up to date.
  701. </para>
  702. <tip>
  703. If you specify an empty or invalid "md5" parameter, BitBake returns an md5 mis-match
  704. error and displays the correct "md5" parameter value during the build.
  705. The correct parameter is also captured in the build log.
  706. </tip>
  707. <tip>
  708. If the whole file contains only license text, you do not need to use the "beginline" and
  709. "endline" parameters.
  710. </tip>
  711. </section>
  712. </section>
  713. <section id="enabling-commercially-licensed-recipes">
  714. <title>Enabling Commercially Licensed Recipes</title>
  715. <para>
  716. By default, the Yocto Project build system disables
  717. components that have commercial or other special licensing
  718. requirements.
  719. Such requirements are defined on a
  720. recipe-by-recipe basis through the <filename>LICENSE_FLAGS</filename> variable
  721. definition in the affected recipe.
  722. For instance, the
  723. <filename>$HOME/poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
  724. recipe contains the following statement:
  725. <literallayout class='monospaced'>
  726. LICENSE_FLAGS = "commercial"
  727. </literallayout>
  728. Here is a slightly more complicated example that contains both an
  729. explicit package name and version (after variable expansion):
  730. <literallayout class='monospaced'>
  731. LICENSE_FLAGS = "license_${PN}_${PV}"
  732. </literallayout>
  733. In order for a component restricted by a <filename>LICENSE_FLAGS</filename>
  734. definition to be enabled and included in an image, it
  735. needs to have a matching entry in the global
  736. <filename>LICENSE_FLAGS_WHITELIST</filename> variable, which is a variable
  737. typically defined in your <filename>local.conf</filename> file.
  738. For example, to enable
  739. the <filename>$HOME/poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
  740. package, you could add either the string
  741. "commercial_gst-plugins-ugly" or the more general string
  742. "commercial" to <filename>LICENSE_FLAGS_WHITELIST</filename>.
  743. See the
  744. "<link linkend='license-flag-matching'>License Flag Matching</link>" section
  745. for a full explanation of how <filename>LICENSE_FLAGS</filename> matching works.
  746. Here is the example:
  747. <literallayout class='monospaced'>
  748. LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
  749. </literallayout>
  750. Likewise, to additionally enable the package containing
  751. <filename>LICENSE_FLAGS = "license_${PN}_${PV}"</filename>, and assuming
  752. that the actual recipe name was <filename>emgd_1.10.bb</filename>,
  753. the following string would enable that package as well as
  754. the original <filename>gst-plugins-ugly</filename> package:
  755. <literallayout class='monospaced'>
  756. LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
  757. </literallayout>
  758. As a convenience, you do not need to specify the complete license string
  759. in the whitelist for every package.
  760. you can use an abbreviated form, which consists
  761. of just the first portion or portions of the license string before
  762. the initial underscore character or characters.
  763. A partial string will match
  764. any license that contains the given string as the first
  765. portion of its license.
  766. For example, the following
  767. whitelist string will also match both of the packages
  768. previously mentioned as well as any other packages that have
  769. licenses starting with "commercial" or "license".
  770. <literallayout class='monospaced'>
  771. LICENSE_FLAGS_WHITELIST = "commercial license"
  772. </literallayout>
  773. </para>
  774. <section id="license-flag-matching">
  775. <title>License Flag Matching</title>
  776. <para>
  777. The definition of 'matching' in reference to a
  778. recipe's <filename>LICENSE_FLAGS</filename> setting is simple.
  779. However, some things exist that you should know about in order to
  780. correctly and effectively use it.
  781. </para>
  782. <para>
  783. Before a flag
  784. defined by a particular recipe is tested against the
  785. contents of the <filename>LICENSE_FLAGS_WHITELIST</filename> variable, the
  786. string <filename>_${PN}</filename> (with
  787. <link linkend='var-PN'><filename>PN</filename></link> expanded of course) is
  788. appended to the flag, thus automatically making each
  789. <filename>LICENSE_FLAGS</filename> value recipe-specific.
  790. That string is
  791. then matched against the whitelist.
  792. So if you specify <filename>LICENSE_FLAGS = "commercial"</filename> in recipe
  793. "foo" for example, the string <filename>"commercial_foo"</filename>
  794. would normally be what is specified in the whitelist in order for it to
  795. match.
  796. </para>
  797. <para>
  798. You can broaden the match by
  799. putting any "_"-separated beginning subset of a
  800. <filename>LICENSE_FLAGS</filename> flag in the whitelist, which will also
  801. match.
  802. For example, simply specifying "commercial" in
  803. the whitelist would match any expanded <filename>LICENSE_FLAGS</filename>
  804. definition starting with "commercial" such as
  805. "commercial_foo" and "commercial_bar", which are the
  806. strings that would be automatically generated for
  807. hypothetical "foo" and "bar" recipes assuming those
  808. recipes had simply specified the following:
  809. <literallayout class='monospaced'>
  810. LICENSE_FLAGS = "commercial"
  811. </literallayout>
  812. </para>
  813. <para>
  814. Broadening the match allows for a range of specificity for the items
  815. in the whitelist, from more general to perfectly
  816. specific.
  817. So you have the choice of exhaustively
  818. enumerating each license flag in the whitelist to
  819. allow only those specific recipes into the image, or
  820. of using a more general string to pick up anything
  821. matching just the first component or components of the specified
  822. string.
  823. </para>
  824. <para>
  825. This scheme works even if the flag already
  826. has <filename>_${PN}</filename> appended - the extra <filename>_${PN}</filename> is
  827. redundant, but does not affect the outcome.
  828. For example, a license flag of "commercial_1.2_foo" would
  829. turn into "commercial_1.2_foo_foo" and would match
  830. both the general "commercial" and the specific
  831. "commercial_1.2_foo", as expected.
  832. The flag would also match
  833. "commercial_1.2_foo_foo" and "commercial_1.2", which
  834. does not make much sense regarding use in the whitelist.
  835. </para>
  836. <para>
  837. For a versioned string, you could instead specify
  838. "commercial_foo_1.2", which would turn into
  839. "commercial_foo_1.2_foo".
  840. And, as expected, this flag allows
  841. you to pick up this package along with
  842. anything else "commercial" when you specify "commercial"
  843. in the whitelist.
  844. Or, the flag allows you to pick up this package along with anything "commercial_foo"
  845. regardless of version when you use "commercial_foo" in the whitelist.
  846. Finally, you can be completely specific about the package and version and specify
  847. "commercial_foo_1.2" package and version.
  848. </para>
  849. </section>
  850. <section id="other-variables-related-to-commercial-licenses">
  851. <title>Other Variables Related to Commercial Licenses</title>
  852. <para>
  853. Other helpful variables related to commercial
  854. license handling exist and are defined in the
  855. <filename>$HOME/poky/meta/conf/distro/include/default-distrovars.inc</filename> file:
  856. <literallayout class='monospaced'>
  857. COMMERCIAL_AUDIO_PLUGINS ?= ""
  858. COMMERCIAL_VIDEO_PLUGINS ?= ""
  859. COMMERCIAL_QT = ""
  860. </literallayout>
  861. If you want to enable these components, you can do so by making sure you have
  862. the following statements in your <filename>local.conf</filename> configuration file:
  863. <literallayout class='monospaced'>
  864. COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
  865. gst-plugins-ugly-mpegaudioparse"
  866. COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
  867. gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
  868. COMMERCIAL_QT ?= "qmmp"
  869. LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
  870. </literallayout>
  871. Of course, you could also create a matching whitelist
  872. for those components using the more general "commercial"
  873. in the whitelist, but that would also enable all the
  874. other packages with <filename>LICENSE_FLAGS</filename> containing
  875. "commercial", which you may or may not want:
  876. <literallayout class='monospaced'>
  877. LICENSE_FLAGS_WHITELIST = "commercial"
  878. </literallayout>
  879. </para>
  880. <para>
  881. Specifying audio and video plug-ins as part of the
  882. <filename>COMMERCIAL_AUDIO_PLUGINS</filename> and
  883. <filename>COMMERCIAL_VIDEO_PLUGINS</filename> statements
  884. or commercial qt components as part of
  885. the <filename>COMMERCIAL_QT</filename> statement (along
  886. with the enabling <filename>LICENSE_FLAGS_WHITELIST</filename>) includes the
  887. plug-ins or components into built images, thus adding
  888. support for media formats or components.
  889. </para>
  890. </section>
  891. </section>
  892. </section>
  893. </chapter>
  894. <!--
  895. vim: expandtab tw=80 ts=4
  896. -->