extendpoky.xml 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  2. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
  3. <chapter id='extendpoky'>
  4. <title>Extending Poky</title>
  5. <para>
  6. This section gives information about how to extend the functionality
  7. already present in Poky, documenting standard tasks such as adding new
  8. software packages, extending or customising images or porting poky to
  9. new hardware (adding a new machine). It also contains advice about how
  10. to manage the process of making changes to Poky to achieve best results.
  11. </para>
  12. <section id='usingpoky-extend-addpkg'>
  13. <title>Adding a Package</title>
  14. <para>
  15. To add package into Poky you need to write a recipe for it.
  16. Writing a recipe means creating a .bb file which sets various
  17. variables. The variables
  18. useful for recipes are detailed in the <link linkend='ref-varlocality-recipe-required'>
  19. recipe reference</link> section along with more detailed information
  20. about issues such as recipe naming.
  21. </para>
  22. <para>
  23. Before writing a recipe from scratch it is often useful to check
  24. someone else hasn't written one already. OpenEmbedded is a good place
  25. to look as it has a wider scope and hence a wider range of packages.
  26. Poky aims to be compatible with OpenEmbedded so most recipes should
  27. just work in Poky.
  28. </para>
  29. <para>
  30. For new packages, the simplest way to add a recipe is to base it on a similar
  31. pre-existing recipe. There are some examples below of how to add
  32. standard types of packages:
  33. </para>
  34. <section id='usingpoky-extend-addpkg-singlec'>
  35. <title>Single .c File Package (Hello World!)</title>
  36. <para>
  37. To build an application from a single file stored locally requires a
  38. recipe which has the file listed in the <glossterm><link
  39. linkend='var-SRC_URI'>SRC_URI</link></glossterm> variable. In addition
  40. the <function>do_compile</function> and <function>do_install</function>
  41. tasks need to be manually written. The <glossterm><link linkend='var-S'>
  42. S</link></glossterm> variable defines the directory containing the source
  43. code which in this case is set equal to <glossterm><link linkend='var-WORKDIR'>
  44. WORKDIR</link></glossterm>, the directory BitBake uses for the build.
  45. </para>
  46. <programlisting>
  47. DESCRIPTION = "Simple helloworld application"
  48. SECTION = "examples"
  49. LICENSE = "MIT"
  50. LIC_FILES_CHKSUM = "file://COPYING;md5=ae764cfda68da96df20af9fbf9fe49bd"
  51. SRC_URI = "file://helloworld.c"
  52. S = "${WORKDIR}"
  53. do_compile() {
  54. ${CC} helloworld.c -o helloworld
  55. }
  56. do_install() {
  57. install -d ${D}${bindir}
  58. install -m 0755 helloworld ${D}${bindir}
  59. }
  60. </programlisting>
  61. <para>
  62. As a result of the build process "helloworld" and "helloworld-dbg"
  63. packages will be built.
  64. </para>
  65. </section>
  66. <section id='usingpoky-extend-addpkg-autotools'>
  67. <title>Autotooled Package</title>
  68. <para>
  69. Applications which use autotools (autoconf, automake)
  70. require a recipe which has a source archive listed in
  71. <glossterm><link
  72. linkend='var-SRC_URI'>SRC_URI</link></glossterm> and
  73. <command>inherit autotools</command> to instruct BitBake to use the
  74. <filename>autotools.bbclass</filename> which has
  75. definitions of all the steps
  76. needed to build an autotooled application.
  77. The result of the build will be automatically packaged and if
  78. the application uses NLS to localise then packages with
  79. locale information will be generated (one package per
  80. language).
  81. </para>
  82. <programlisting>
  83. DESCRIPTION = "GNU Helloworld application"
  84. SECTION = "examples"
  85. LICENSE = "GPLv2"
  86. LIC_FILES_CHKSUM = "file://COPYING;md5=ae764cfda68da96df20af9fbf9fe49bd"
  87. SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.bz2"
  88. inherit autotools
  89. </programlisting>
  90. </section>
  91. <section id='usingpoky-extend-addpkg-makefile'>
  92. <title>Makefile-Based Package</title>
  93. <para>
  94. Applications which use GNU make require a recipe which has
  95. the source archive listed in <glossterm><link
  96. linkend='var-SRC_URI'>SRC_URI</link></glossterm>.
  97. Adding a <function>do_compile</function> step
  98. is not needed as by default BitBake will start the "make"
  99. command to compile the application. If there is a need for
  100. additional options to make then they should be stored in the
  101. <glossterm><link
  102. linkend='var-EXTRA_OEMAKE'>EXTRA_OEMAKE</link></glossterm> variable - BitBake
  103. will pass them into the GNU
  104. make invocation. A <function>do_install</function> task is required
  105. - otherwise BitBake will run an empty <function>do_install</function>
  106. task by default.
  107. </para>
  108. <para>
  109. Some applications may require extra parameters to be passed to
  110. the compiler, for example an additional header path. This can
  111. be done buy adding to the <glossterm><link
  112. linkend='var-CFLAGS'>CFLAGS</link></glossterm> variable, as in the example below.
  113. </para>
  114. <programlisting>
  115. DESCRIPTION = "Tools for managing memory technology devices."
  116. SECTION = "base"
  117. DEPENDS = "zlib"
  118. HOMEPAGE = "http://www.linux-mtd.infradead.org/"
  119. LICENSE = "GPLv2"
  120. LIC_FILES_CHKSUM = "file://COPYING;md5=ae764cfda68da96df20af9fbf9fe49bd"
  121. SRC_URI = "ftp://ftp.infradead.org/pub/mtd-utils/mtd-utils-${PV}.tar.gz"
  122. CFLAGS_prepend = "-I ${S}/include "
  123. do_install() {
  124. oe_runmake install DESTDIR=${D}
  125. }
  126. </programlisting>
  127. </section>
  128. <section id='usingpoky-extend-addpkg-files'>
  129. <title>Controlling packages content</title>
  130. <para>
  131. The variables <glossterm><link
  132. linkend='var-PACKAGES'>PACKAGES</link></glossterm> and
  133. <glossterm><link linkend='var-FILES'>FILES</link></glossterm> are used to split an
  134. application into multiple packages.
  135. </para>
  136. <para>
  137. Below the "libXpm" recipe is used as an example. By
  138. default the "libXpm" recipe generates one package
  139. which contains the library
  140. and also a few binaries. The recipe can be adapted to
  141. split the binaries into separate packages.
  142. </para>
  143. <programlisting>
  144. require xorg-lib-common.inc
  145. DESCRIPTION = "X11 Pixmap library"
  146. LICENSE = "X-BSD"
  147. LIC_FILES_CHKSUM = "file://COPYING;md5=ae764cfda68da96df20af9fbf9fe49bd"
  148. DEPENDS += "libxext"
  149. XORG_PN = "libXpm"
  150. PACKAGES =+ "sxpm cxpm"
  151. FILES_cxpm = "${bindir}/cxpm"
  152. FILES_sxpm = "${bindir}/sxpm"
  153. </programlisting>
  154. <para>
  155. In this example we want to ship the "sxpm" and "cxpm" binaries
  156. in separate packages. Since "bindir" would be packaged into the
  157. main <glossterm><link linkend='var-PN'>PN</link></glossterm>
  158. package as standard we prepend the <glossterm><link
  159. linkend='var-PACKAGES'>PACKAGES</link></glossterm> variable so
  160. additional package names are added to the start of list. The
  161. extra <glossterm><link linkend='var-PN'>FILES</link></glossterm>_*
  162. variables then contain information to specify which files and
  163. directories goes into which package.
  164. </para>
  165. </section>
  166. <section id='usingpoky-extend-addpkg-postinstalls'>
  167. <title>Post Install Scripts</title>
  168. <para>
  169. To add a post-installation script to a package, add
  170. a <function>pkg_postinst_PACKAGENAME()</function>
  171. function to the .bb file
  172. where PACKAGENAME is the name of the package to attach
  173. the postinst script to. A post-installation function has the following structure:
  174. </para>
  175. <programlisting>
  176. pkg_postinst_PACKAGENAME () {
  177. #!/bin/sh -e
  178. # Commands to carry out
  179. }
  180. </programlisting>
  181. <para>
  182. The script defined in the post installation function
  183. gets called when the rootfs is made. If the script succeeds,
  184. the package is marked as installed. If the script fails,
  185. the package is marked as unpacked and the script will be
  186. executed again on the first boot of the image.
  187. </para>
  188. <para>
  189. Sometimes it is necessary that the execution of a post-installation
  190. script is delayed until the first boot, because the script
  191. needs to be executed on the device itself. To delay script execution
  192. until boot time, the post-installation function should have the
  193. following structure:
  194. </para>
  195. <programlisting>
  196. pkg_postinst_PACKAGENAME () {
  197. #!/bin/sh -e
  198. if [ x"$D" = "x" ]; then
  199. # Actions to carry out on the device go here
  200. else
  201. exit 1
  202. fi
  203. }
  204. </programlisting>
  205. <para>
  206. The structure above delays execution until first boot
  207. because the <glossterm><link
  208. linkend='var-D'>D</link></glossterm> variable points
  209. to the 'image'
  210. directory when the rootfs is being made at build time but
  211. is unset when executed on the first boot.
  212. </para>
  213. </section>
  214. </section>
  215. <section id='usingpoky-extend-customimage'>
  216. <title>Customising Images</title>
  217. <para>
  218. Poky images can be customised to satisfy
  219. particular requirements. Several methods are detailed below
  220. along with guidelines of when to use them.
  221. </para>
  222. <section id='usingpoky-extend-customimage-custombb'>
  223. <title>Customising Images through a custom image .bb files</title>
  224. <para>
  225. One way to get additional software into an image is by creating a
  226. custom image. The recipe will contain two lines:
  227. </para>
  228. <programlisting>
  229. IMAGE_INSTALL = "task-poky-x11-base package1 package2"
  230. inherit poky-image
  231. </programlisting>
  232. <para>
  233. By creating a custom image, a developer has total control
  234. over the contents of the image. It is important to use
  235. the correct names of packages in the <glossterm><link
  236. linkend='var-IMAGE_INSTALL'>IMAGE_INSTALL</link></glossterm> variable.
  237. The names must be in
  238. the OpenEmbedded notation instead of Debian notation, for example
  239. "glibc-dev" instead of "libc6-dev" etc.
  240. </para>
  241. <para>
  242. The other method of creating a new image is by modifying
  243. an existing image. For example if a developer wants to add
  244. "strace" into "poky-image-sato" the following recipe can
  245. be used:
  246. </para>
  247. <programlisting>
  248. require poky-image-sato.bb
  249. IMAGE_INSTALL += "strace"
  250. </programlisting>
  251. </section>
  252. <section id='usingpoky-extend-customimage-customtasks'>
  253. <title>Customising Images through custom tasks</title>
  254. <para>
  255. For complex custom images, the best approach is to create a custom
  256. task package which is then used to build the image (or images). A good
  257. example of a tasks package is <filename>meta/packages/tasks/task-poky.bb
  258. </filename>. The <glossterm><link linkend='var-PACKAGES'>PACKAGES</link></glossterm>
  259. variable lists the task packages to build (along with the complementary
  260. -dbg and -dev packages). For each package added,
  261. <glossterm><link linkend='var-PACKAGES'>RDEPENDS</link></glossterm> and
  262. <glossterm><link linkend='var-PACKAGES'>RRECOMMENDS</link></glossterm>
  263. entries can then be added each containing a list of packages the parent
  264. task package should contain. An example would be:
  265. </para>
  266. <para>
  267. <programlisting>
  268. DESCRIPTION = "My Custom Tasks"
  269. PACKAGES = "\
  270. task-custom-apps \
  271. task-custom-apps-dbg \
  272. task-custom-apps-dev \
  273. task-custom-tools \
  274. task-custom-tools-dbg \
  275. task-custom-tools-dev \
  276. "
  277. RDEPENDS_task-custom-apps = "\
  278. dropbear \
  279. portmap \
  280. psplash"
  281. RDEPENDS_task-custom-tools = "\
  282. oprofile \
  283. oprofileui-server \
  284. lttng-control \
  285. lttng-viewer"
  286. RRECOMMENDS_task-custom-tools = "\
  287. kernel-module-oprofile"
  288. </programlisting>
  289. </para>
  290. <para>
  291. In this example, two tasks packages are created, task-custom-apps and
  292. task-custom-tools with the dependencies and recommended package dependencies
  293. listed. To build an image using these task packages, you would then add
  294. "task-custom-apps" and/or "task-custom-tools" to <glossterm><link
  295. linkend='var-IMAGE_INSTALL'>IMAGE_INSTALL</link></glossterm> or other forms
  296. of image dependencies as described in other areas of this section.
  297. </para>
  298. </section>
  299. <section id='usingpoky-extend-customimage-imagefeatures'>
  300. <title>Customising Images through custom <glossterm><link linkend='var-IMAGE_FEATURES'>IMAGE_FEATURES</link></glossterm></title>
  301. <para>
  302. Ultimately users may want to add extra image "features" as used by Poky with the
  303. <glossterm><link linkend='var-IMAGE_FEATURES'>IMAGE_FEATURES</link></glossterm>
  304. variable. To create these, the best reference is <filename>meta/classes/poky-image.bbclass</filename>
  305. which illustrates how poky achieves this. In summary, the file looks at the contents of the
  306. <glossterm><link linkend='var-IMAGE_FEATURES'>IMAGE_FEATURES</link></glossterm>
  307. variable and based on this generates the <glossterm><link linkend='var-IMAGE_INSTALL'>
  308. IMAGE_INSTALL</link></glossterm> variable automatically. Extra features can be added by
  309. extending the class or creating a custom class for use with specialised image .bb files.
  310. </para>
  311. </section>
  312. <section id='usingpoky-extend-customimage-localconf'>
  313. <title>Customising Images through local.conf</title>
  314. <para>
  315. It is possible to customise image contents by abusing
  316. variables used by distribution maintainers in local.conf.
  317. This method only allows the addition of packages and
  318. is not recommended.
  319. </para>
  320. <para>
  321. To add an "strace" package into the image the following is
  322. added to local.conf:
  323. </para>
  324. <programlisting>
  325. DISTRO_EXTRA_RDEPENDS += "strace"
  326. </programlisting>
  327. <para>
  328. However, since the <glossterm><link linkend='var-DISTRO_EXTRA_RDEPENDS'>
  329. DISTRO_EXTRA_RDEPENDS</link></glossterm> variable is for
  330. distribution maintainers this method does not make
  331. adding packages as simple as a custom .bb file. Using
  332. this method, a few packages will need to be recreated
  333. and the the image built.
  334. </para>
  335. <programlisting>
  336. bitbake -cclean task-boot task-base task-poky
  337. bitbake poky-image-sato
  338. </programlisting>
  339. <para>
  340. Cleaning task-* packages is required because they use the
  341. <glossterm><link linkend='var-DISTRO_EXTRA_RDEPENDS'>
  342. DISTRO_EXTRA_RDEPENDS</link></glossterm> variable. There is no need to
  343. build them by hand as Poky images depend on the packages they contain so
  344. dependencies will be built automatically. For this reason we don't use the
  345. "rebuild" task in this case since "rebuild" does not care about
  346. dependencies - it only rebuilds the specified package.
  347. </para>
  348. </section>
  349. </section>
  350. <section id="platdev-newmachine">
  351. <title>Porting Poky to a new machine</title>
  352. <para>
  353. Adding a new machine to Poky is a straightforward process and
  354. this section gives an idea of the changes that are needed. This guide is
  355. meant to cover adding machines similar to those Poky already supports.
  356. Adding a totally new architecture might require gcc/glibc changes as
  357. well as updates to the site information and, whilst well within Poky's
  358. capabilities, is outside the scope of this section.
  359. </para>
  360. <section id="platdev-newmachine-conffile">
  361. <title>Adding the machine configuration file</title>
  362. <para>
  363. A .conf file needs to be added to conf/machine/ with details of the
  364. device being added. The name of the file determines the name Poky will
  365. use to reference this machine.
  366. </para>
  367. <para>
  368. The most important variables to set in this file are <glossterm>
  369. <link linkend='var-TARGET_ARCH'>TARGET_ARCH</link></glossterm>
  370. (e.g. "arm"), <glossterm><link linkend='var-PREFERRED_PROVIDER'>
  371. PREFERRED_PROVIDER</link></glossterm>_virtual/kernel (see below) and
  372. <glossterm><link linkend='var-MACHINE_FEATURES'>MACHINE_FEATURES
  373. </link></glossterm> (e.g. "kernel26 apm screen wifi"). Other variables
  374. like <glossterm><link linkend='var-SERIAL_CONSOLE'>SERIAL_CONSOLE
  375. </link></glossterm> (e.g. "115200 ttyS0"), <glossterm>
  376. <link linkend='var-KERNEL_IMAGETYPE'>KERNEL_IMAGETYPE</link>
  377. </glossterm> (e.g. "zImage") and <glossterm><link linkend='var-IMAGE_FSTYPES'>
  378. IMAGE_FSTYPES</link></glossterm> (e.g. "tar.gz jffs2") might also be
  379. needed. Full details on what these variables do and the meaning of
  380. their contents is available through the links.
  381. </para>
  382. </section>
  383. <section id="platdev-newmachine-kernel">
  384. <title>Adding a kernel for the machine</title>
  385. <para>
  386. Poky needs to be able to build a kernel for the machine. You need
  387. to either create a new kernel recipe for this machine or extend an
  388. existing recipe. There are plenty of kernel examples in the
  389. packages/linux directory which can be used as references.
  390. </para>
  391. <para>
  392. If creating a new recipe the "normal" recipe writing rules apply
  393. for setting up a <glossterm><link linkend='var-SRC_URI'>SRC_URI
  394. </link></glossterm> including any patches and setting <glossterm>
  395. <link linkend='var-S'>S</link></glossterm> to point at the source
  396. code. You will need to create a configure task which configures the
  397. unpacked kernel with a defconfig be that through a "make defconfig"
  398. command or more usually though copying in a suitable defconfig and
  399. running "make oldconfig". By making use of "inherit kernel" and also
  400. maybe some of the linux-*.inc files, most other functionality is
  401. centralised and the the defaults of the class normally work well.
  402. </para>
  403. <para>
  404. If extending an existing kernel it is usually a case of adding a
  405. suitable defconfig file in a location similar to that used by other
  406. machine's defconfig files in a given kernel, possibly listing it in
  407. the SRC_URI and adding the machine to the expression in <glossterm>
  408. <link linkend='var-COMPATIBLE_MACHINE'>COMPATIBLE_MACHINE</link>
  409. </glossterm>.
  410. </para>
  411. </section>
  412. <section id="platdev-newmachine-formfactor">
  413. <title>Adding a formfactor configuration file</title>
  414. <para>
  415. A formfactor configuration file provides information about the
  416. target hardware on which Poky is running, and that Poky cannot
  417. obtain from other sources such as the kernel. Some examples of
  418. information contained in a formfactor configuration file include
  419. framebuffer orientation, whether or not the system has a keyboard,
  420. the positioning of the keyboard in relation to the screen, and
  421. screen resolution.
  422. </para>
  423. <para>
  424. Sane defaults should be used in most cases, but if customisation is
  425. necessary you need to create a <filename>machconfig</filename> file
  426. under <filename>meta/packages/formfactor/files/MACHINENAME/</filename>
  427. where <literal>MACHINENAME</literal> is the name for which this infomation
  428. applies. For information about the settings available and the defaults, please see
  429. <filename>meta/packages/formfactor/files/config</filename>.
  430. </para>
  431. </section>
  432. </section>
  433. <section id='usingpoky-changes'>
  434. <title>Making and Maintaining Changes</title>
  435. <para>
  436. We recognise that people will want to extend/configure/optimise Poky for
  437. their specific uses, especially due to the extreme configurability and
  438. flexibility Poky offers. To ensure ease of keeping pace with future
  439. changes in Poky we recommend making changes to Poky in a controlled way.
  440. </para>
  441. <para>
  442. Poky supports the idea of <link
  443. linkend='usingpoky-changes-layers'>"layers"</link> which when used
  444. properly can massively ease future upgrades and allow segregation
  445. between the Poky core and a given developer's changes. Some other advice on
  446. managing changes to Poky is also given in the following section.
  447. </para>
  448. <section id="usingpoky-changes-layers">
  449. <title>Bitbake Layers</title>
  450. <para>
  451. Often, people want to extend Poky either through adding packages
  452. or overriding files contained within Poky to add their own
  453. functionality. Bitbake has a powerful mechanism called
  454. layers which provides a way to handle this extension in a fully
  455. supported and non-invasive fashion.
  456. </para>
  457. <para>
  458. The Poky tree includes two additional layers which demonstrate
  459. this functionality, meta-moblin and meta-extras.
  460. The meta-extras repostory is not enabled by default but enabling
  461. it is as easy as adding the layers path to the BBLAYERS variable in
  462. your bblayers.conf, this is how all layers are enabled in Poky builds:
  463. </para>
  464. <para>
  465. <literallayout class='monospaced'>LCONF_VERSION = "1"
  466. BBFILES ?= ""
  467. BBLAYERS = " \
  468. /path/to/poky/meta \
  469. /path/to/poky/meta-moblin \
  470. /path/to/poky/meta-extras \
  471. "
  472. </literallayout>
  473. </para>
  474. <para>
  475. Bitbake parses the conf/layer.conf of each of the layers in BBLAYERS
  476. to add the layers packages, classes and configuration to Poky.
  477. To create your own layer, independent of the main Poky repository,
  478. you need only create a directory with a conf/layer.conf file and
  479. add the directory to your bblayers.conf.
  480. </para>
  481. <para>
  482. The meta-extras layer.conf demonstrates the required syntax:
  483. <literallayout class='monospaced'># We have a conf and classes directory, add to BBPATH
  484. BBPATH := "${BBPATH}${LAYERDIR}"
  485. # We have a packages directory, add to BBFILES
  486. BBFILES := "${BBFILES} ${LAYERDIR}/packages/*/*.bb"
  487. BBFILE_COLLECTIONS += "extras"
  488. BBFILE_PATTERN_extras := "^${LAYERDIR}/"
  489. BBFILE_PRIORITY_extras = "5"
  490. require conf/distro/include/poky-extras-src-revisions.inc
  491. </literallayout>
  492. </para>
  493. <para>
  494. As can be seen, the layers recipes are added to BBFILES. The
  495. BBFILE_COLLECTIONS variable is then appended to with the
  496. layer name. The BBFILE_PATTERN variable is immediately expanded
  497. with a regular expression used to match files from BBFILES into
  498. a particular layer, in this case by using the base pathname.
  499. The BBFILE_PRIORITY variable then assigns different
  500. priorities to the files in different layers. This is useful
  501. in situations where the same package might appear in multiple
  502. layers and allows you to choose which layer should 'win'.
  503. Note the use of LAYERDIR with the immediate expansion operator.
  504. LAYERDIR expands to the directory of the current layer and
  505. requires use of the immediate expansion operator so that Bitbake
  506. does not lazily expand the variable when it's parsing a
  507. different directory.
  508. </para>
  509. <para>
  510. Extra bbclasses and configuration are added to the BBPATH
  511. environment variable. In this case, the first file with the
  512. matching name found in BBPATH is the one that is used, just
  513. like the PATH variable for binaries. It is therefore recommended
  514. that you use unique bbclass and configuration file names in your
  515. custom layer.
  516. </para>
  517. <para>
  518. The recommended approach for custom layers is to store them in a
  519. git repository of the format meta-prvt-XXXX and have this repository
  520. cloned alongside the other meta directories in the Poky tree.
  521. This way you can keep your Poky tree and it's configuration entirely
  522. inside POKYBASE.
  523. </para>
  524. </section>
  525. <section id='usingpoky-changes-commits'>
  526. <title>Committing Changes</title>
  527. <para>
  528. Modifications to Poky are often managed under some kind of source
  529. revision control system. The policy for committing to such systems
  530. is important as some simple policy can significantly improve
  531. usability. The tips below are based on the policy followed for the
  532. Poky core.
  533. </para>
  534. <para>
  535. It helps to use a consistent style for commit messages when committing
  536. changes. We've found a style where the first line of a commit message
  537. summarises the change and starts with the name of any package affected
  538. work well. Not all changes are to specific packages so the prefix could
  539. also be a machine name or class name instead. If a change needs a longer
  540. description this should follow the summary.
  541. </para>
  542. <para>
  543. Any commit should be self contained in that it should leave the
  544. metadata in a consistent state, buildable before and after the
  545. commit. This helps ensure the autobuilder test results are valid
  546. but is good practice regardless.
  547. </para>
  548. </section>
  549. <section id='usingpoky-changes-prbump'>
  550. <title>Package Revision Incrementing</title>
  551. <para>
  552. If a committed change will result in changing the package output
  553. then the value of the <glossterm><link linkend='var-PR'>PR</link>
  554. </glossterm> variable needs to be increased (commonly referred to
  555. as 'bumped') as part of that commit. Only integer values are used
  556. and <glossterm><link linkend='var-PR'>PR</link></glossterm> =
  557. "r0" should be added into new recipes as, while this is the
  558. default value, not having the variable defined in a recipe makes
  559. it easy to miss incrementing it when updating the recipe.
  560. When upgrading the version of a package (<glossterm><link
  561. linkend='var-PV'>PV</link></glossterm>), the <glossterm><link
  562. linkend='var-PR'>PR</link></glossterm> variable should be removed.
  563. </para>
  564. <para>
  565. The aim is that the package version will only ever increase. If
  566. for some reason <glossterm><link linkend='var-PV'>PV</link></glossterm>
  567. will change and but not increase, the <glossterm><link
  568. linkend='var-PE'>PE</link></glossterm> (Package Epoch) can
  569. be increased (it defaults to '0'). The version numbers aim to
  570. follow the <ulink url='http://www.debian.org/doc/debian-policy/ch-controlfields.html'>
  571. Debian Version Field Policy Guidelines</ulink> which define how
  572. versions are compared and hence what "increasing" means.
  573. </para>
  574. <para>
  575. There are two reasons for doing this, the first is to ensure that
  576. when a developer updates and rebuilds, they get all the changes to
  577. the repository and don't have to remember to rebuild any sections.
  578. The second is to ensure that target users are able to upgrade their
  579. devices via their package manager such as with the <command>
  580. opkg update;opkg upgrade</command> commands (or similar for
  581. dpkg/apt or rpm based systems). The aim is to ensure Poky has
  582. upgradable packages in all cases.
  583. </para>
  584. </section>
  585. <section id='usingpoky-changes-collaborate'>
  586. <title>Using Poky in a Team Environment</title>
  587. <para>
  588. It may not be immediately clear how Poky can work in a team environment,
  589. or scale to a large team of developers. The specifics of any situation
  590. will determine the best solution and poky offers immense flexibility in
  591. that aspect but there are some practises that experience has shown to work
  592. well.
  593. </para>
  594. <para>
  595. The core component of any development effort with Poky is often an
  596. automated build testing framework and image generation process. This
  597. can be used to check that the metadata is buildable, highlight when
  598. commits break the builds and provide up to date images allowing people
  599. to test the end result and use them as a base platform for further
  600. development. Experience shows that buildbot is a good fit for this role
  601. and that it works well to configure it to make two types of build -
  602. incremental builds and 'from scratch'/full builds. The incremental builds
  603. can be tied to a commit hook which triggers them each time a commit is
  604. made to the metadata and are a useful acid test of whether a given commit
  605. breaks the build in some serious way. They catch lots of simple errors
  606. and whilst they won't catch 100% of failures, the tests are fast so
  607. developers can get feedback on their changes quickly. The full builds
  608. are builds that build everything from the ground up and test everything.
  609. They usually happen at preset times such as at night when the machine
  610. load isn't high from the incremental builds.
  611. </para>
  612. <para>
  613. Most teams have pieces of software undergoing active development. It is of
  614. significant benefit to put these under control of a source control system
  615. compatible with Poky such as git or svn. The autobuilder can then be set to
  616. pull the latest revisions of these packages so the latest commits get tested
  617. by the builds allowing any issues to be highlighted quickly. Poky easily
  618. supports configurations where there is both a stable known good revision
  619. and a floating revision to test. Poky can also only take changes from specific
  620. source control branches giving another way it can be used to track/test only
  621. specified changes.
  622. </para>
  623. <para>
  624. Perhaps the hardest part of setting this up is the policy that surrounds
  625. the different source control systems, be them software projects or the Poky
  626. metadata itself. The circumstances will be different in each case but this is
  627. one of Poky's advantages - the system itself doesn't force any particular policy
  628. unlike a lot of build systems, allowing the best policy to be chosen for the
  629. circumstances.
  630. </para>
  631. </section>
  632. <section id='usingpoky-changes-updatingimages'>
  633. <title>Updating Existing Images</title>
  634. <para>
  635. Often, rather than reflashing a new image you might wish to install updated
  636. packages into an existing running system. This can be done by sharing the <filename class="directory">tmp/deploy/ipk/</filename> directory through a web server and then on the device, changing <filename>/etc/opkg/base-feeds.conf</filename> to point at this server, for example by adding:
  637. </para>
  638. <literallayout class='monospaced'>
  639. src/gz all http://www.mysite.com/somedir/deploy/ipk/all
  640. src/gz armv7a http://www.mysite.com/somedir/deploy/ipk/armv7a
  641. src/gz beagleboard http://www.mysite.com/somedir/deploy/ipk/beagleboard</literallayout>
  642. </section>
  643. </section>
  644. <section id='usingpoky-modifing-packages'>
  645. <title>Modifying Package Source Code</title>
  646. <para>
  647. Poky is usually used to build software rather than modifying
  648. it. However, there are ways Poky can be used to modify software.
  649. </para>
  650. <para>
  651. During building, the sources are available in <glossterm><link
  652. linkend='var-WORKDIR'>WORKDIR</link></glossterm> directory.
  653. Where exactly this is depends on the type of package and the
  654. architecture of target device. For a standard recipe not
  655. related to <glossterm><link
  656. linkend='var-MACHINE'>MACHINE</link></glossterm> it will be
  657. <filename>tmp/work/PACKAGE_ARCH-poky-TARGET_OS/PN-PV-PR/</filename>.
  658. Target device dependent packages use <glossterm><link
  659. linkend='var-MACHINE'>MACHINE
  660. </link></glossterm>
  661. instead of <glossterm><link linkend='var-PACKAGE_ARCH'>PACKAGE_ARCH
  662. </link></glossterm>
  663. in the directory name.
  664. </para>
  665. <tip>
  666. <para>
  667. Check the package recipe sets the <glossterm><link
  668. linkend='var-S'>S</link></glossterm> variable to something
  669. other than standard <filename>WORKDIR/PN-PV/</filename> value.
  670. </para>
  671. </tip>
  672. <para>
  673. After building a package, a user can modify the package source code
  674. without problem. The easiest way to test changes is by calling the
  675. "compile" task:
  676. </para>
  677. <programlisting>
  678. bitbake --cmd compile --force NAME_OF_PACKAGE
  679. </programlisting>
  680. <para>
  681. Other tasks may also be called this way.
  682. </para>
  683. <section id='usingpoky-modifying-packages-quilt'>
  684. <title>Modifying Package Source Code with quilt</title>
  685. <para>
  686. By default Poky uses <ulink
  687. url='http://savannah.nongnu.org/projects/quilt'>quilt</ulink>
  688. to manage patches in <function>do_patch</function> task.
  689. It is a powerful tool which can be used to track all
  690. modifications done to package sources.
  691. </para>
  692. <para>
  693. Before modifying source code it is important to
  694. notify quilt so it will track changes into new patch
  695. file:
  696. <programlisting>
  697. quilt new NAME-OF-PATCH.patch
  698. </programlisting>
  699. Then add all files which will be modified into that
  700. patch:
  701. <programlisting>
  702. quilt add file1 file2 file3
  703. </programlisting>
  704. Now start editing. At the end quilt needs to be used
  705. to generate final patch which will contain all
  706. modifications:
  707. <programlisting>
  708. quilt refresh
  709. </programlisting>
  710. The resulting patch file can be found in the
  711. <filename class="directory">patches/</filename> subdirectory of the source
  712. (<glossterm><link linkend='var-S'>S</link></glossterm>) directory. For future builds it
  713. should be copied into
  714. Poky metadata and added into <glossterm><link
  715. linkend='var-SRC_URI'>SRC_URI</link></glossterm> of a recipe:
  716. <programlisting>
  717. SRC_URI += "file://NAME-OF-PATCH.patch"
  718. </programlisting>
  719. This also requires a bump of <glossterm><link
  720. linkend='var-PR'>PR</link></glossterm> value in the same recipe as we changed resulting packages.
  721. </para>
  722. </section>
  723. </section>
  724. <section id='usingpoky-configuring-LIC_FILES_CHKSUM'>
  725. <title>Configuring the LIC_FILES_CHKSUM variable</title>
  726. <para>
  727. The changes in the license text inside source code files is tracked
  728. using the LIC_FILES_CHKSUM metadata variable.
  729. </para>
  730. <section id='usingpoky-specifying-LIC_FILES_CHKSUM'>
  731. <title>Specifying the LIC_FILES_CHKSUM variable </title>
  732. <programlisting>
  733. LIC_FILES_CHKSUM = "file://COPYING; md5=xxxx \
  734. file://licfile1.txt; beginline=5; endline=29;md5=yyyy \
  735. file://licfile2.txt; endline=50;md5=zzzz \
  736. ..."
  737. </programlisting>
  738. </section>
  739. <section id='usingpoky-LIC_FILES_CHKSUM-explanation-of-syntax'>
  740. <title>Explanation of syntax</title>
  741. <para>
  742. This parameter lists all the important files containing the text
  743. of licenses for the
  744. source code. It is also possible to specify on which line the license text
  745. starts and on which line it ends within that file using the "beginline" and
  746. "endline" parameters. If the "beginline" parameter is not specified then license
  747. text begins from the 1st line is assumed. Similarly if "endline" parameter is
  748. not specified then the license text ends at the last line in the file is
  749. assumed. So if a file contains only licensing information, then there is no need
  750. to specify "beginline" and "endline" parameters.
  751. </para>
  752. <para>
  753. The "md5" parameter stores the md5 checksum of the license text. So if
  754. the license text changes in any way from a file, then it's md5 sum will differ and will not
  755. match with the previously stored md5 checksum. This mismatch will trigger build
  756. failure, notifying developer about the license text md5 mismatch, and allowing
  757. the developer to review the license text changes. Also note that if md5 checksum
  758. is not matched while building, the correct md5 checksum is printed in the build
  759. log.
  760. </para>
  761. <para>
  762. There is no limit on how many files can be specified on this parameter. But generally every
  763. project would need specifying of just one or two files for license tracking.
  764. Many projects would have a "COPYING" file which will store all the
  765. license information for all the source code files. If the "COPYING" file
  766. is valid then tracking only that file would be enough.
  767. </para>
  768. <tip>
  769. <para>
  770. 1. If you specify empty or invalid "md5" parameter; then while building
  771. the package, bitbake will give md5 not matched error, and also show the correct
  772. "md5" parameter value in the build log
  773. </para>
  774. <para>
  775. 2. If the whole file contains only license text, then there is no need to
  776. specify "beginline" and "endline" parameters.
  777. </para>
  778. </tip>
  779. </section>
  780. </section>
  781. <section id='usingpoky-configuring-DISTRO_PN_ALIAS'>
  782. <title>Configuring the DISTRO_PN_ALIAS variable</title>
  783. <para>
  784. Sometimes the names of the same packages are different in different
  785. linux distributions; and that can becomes an issue for the distro_check
  786. task to check if the given recipe package exists in other linux distros.
  787. This issue is avoided by defining per distro recipe name alias:
  788. DISTRO_PN_ALIAS
  789. </para>
  790. <section id='usingpoky-specifying-DISTRO_PN_ALIAS'>
  791. <title>Specifying the DISTRO_PN_ALIAS variable </title>
  792. <programlisting>
  793. DISTRO_PN_ALIAS = "distro1=package_name_alias1; distro2=package_name_alias2 \
  794. distro3=package_name_alias3; \
  795. ..."
  796. </programlisting>
  797. <para>
  798. Look at the meta/packages/xorg-app/xset_1.0.4.bb recipe file for an example.
  799. </para>
  800. <tip>
  801. <para>
  802. The current code can check if the src package for a recipe exists in the latest
  803. releases of these distributions automatically.
  804. </para>
  805. <programlisting>
  806. Fedora, OpenSuSE, Debian, Ubuntu, Mandriva
  807. </programlisting>
  808. <para>
  809. For example, this command will generate a report, listing which linux distros include the
  810. sources for each of the poky recipe.
  811. </para>
  812. <programlisting>
  813. bitbake world -f -c distro_check
  814. </programlisting>
  815. <para>
  816. The results will be stored in the build/tmp/log/distro_check-${DATETIME}.results file.
  817. </para>
  818. </tip>
  819. </section>
  820. </section>
  821. </chapter>
  822. <!--
  823. vim: expandtab tw=80 ts=4
  824. -->