extendpoky.xml 47 KB

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