layers.rst 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. Understanding and Creating Layers
  3. *********************************
  4. The OpenEmbedded build system supports organizing
  5. :term:`Metadata` into multiple layers.
  6. Layers allow you to isolate different types of customizations from each
  7. other. For introductory information on the Yocto Project Layer Model,
  8. see the
  9. ":ref:`overview-manual/yp-intro:the yocto project layer model`"
  10. section in the Yocto Project Overview and Concepts Manual.
  11. Creating Your Own Layer
  12. =======================
  13. .. note::
  14. It is very easy to create your own layers to use with the OpenEmbedded
  15. build system, as the Yocto Project ships with tools that speed up creating
  16. layers. This section describes the steps you perform by hand to create
  17. layers so that you can better understand them. For information about the
  18. layer-creation tools, see the
  19. ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
  20. section in the Yocto Project Board Support Package (BSP) Developer's
  21. Guide and the ":ref:`dev-manual/layers:creating a general layer using the \`\`bitbake-layers\`\` script`"
  22. section further down in this manual.
  23. Follow these general steps to create your layer without using tools:
  24. 1. *Check Existing Layers:* Before creating a new layer, you should be
  25. sure someone has not already created a layer containing the Metadata
  26. you need. You can see the :oe_layerindex:`OpenEmbedded Metadata Index <>`
  27. for a list of layers from the OpenEmbedded community that can be used in
  28. the Yocto Project. You could find a layer that is identical or close
  29. to what you need.
  30. 2. *Create a Directory:* Create the directory for your layer. When you
  31. create the layer, be sure to create the directory in an area not
  32. associated with the Yocto Project :term:`Source Directory`
  33. (e.g. the cloned ``poky`` repository).
  34. While not strictly required, prepend the name of the directory with
  35. the string "meta-". For example::
  36. meta-mylayer
  37. meta-GUI_xyz
  38. meta-mymachine
  39. With rare exceptions, a layer's name follows this form::
  40. meta-root_name
  41. Following this layer naming convention can save
  42. you trouble later when tools, components, or variables "assume" your
  43. layer name begins with "meta-". A notable example is in configuration
  44. files as shown in the following step where layer names without the
  45. "meta-" string are appended to several variables used in the
  46. configuration.
  47. 3. *Create a Layer Configuration File:* Inside your new layer folder,
  48. you need to create a ``conf/layer.conf`` file. It is easiest to take
  49. an existing layer configuration file and copy that to your layer's
  50. ``conf`` directory and then modify the file as needed.
  51. The ``meta-yocto-bsp/conf/layer.conf`` file in the Yocto Project
  52. :yocto_git:`Source Repositories </poky/tree/meta-yocto-bsp/conf>`
  53. demonstrates the required syntax. For your layer, you need to replace
  54. "yoctobsp" with a unique identifier for your layer (e.g. "machinexyz"
  55. for a layer named "meta-machinexyz")::
  56. # We have a conf and classes directory, add to BBPATH
  57. BBPATH .= ":${LAYERDIR}"
  58. # We have recipes-* directories, add to BBFILES
  59. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  60. ${LAYERDIR}/recipes-*/*/*.bbappend"
  61. BBFILE_COLLECTIONS += "yoctobsp"
  62. BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
  63. BBFILE_PRIORITY_yoctobsp = "5"
  64. LAYERVERSION_yoctobsp = "4"
  65. LAYERSERIES_COMPAT_yoctobsp = "dunfell"
  66. Following is an explanation of the layer configuration file:
  67. - :term:`BBPATH`: Adds the layer's
  68. root directory to BitBake's search path. Through the use of the
  69. :term:`BBPATH` variable, BitBake locates class files (``.bbclass``),
  70. configuration files, and files that are included with ``include``
  71. and ``require`` statements. For these cases, BitBake uses the
  72. first file that matches the name found in :term:`BBPATH`. This is
  73. similar to the way the ``PATH`` variable is used for binaries. It
  74. is recommended, therefore, that you use unique class and
  75. configuration filenames in your custom layer.
  76. - :term:`BBFILES`: Defines the
  77. location for all recipes in the layer.
  78. - :term:`BBFILE_COLLECTIONS`:
  79. Establishes the current layer through a unique identifier that is
  80. used throughout the OpenEmbedded build system to refer to the
  81. layer. In this example, the identifier "yoctobsp" is the
  82. representation for the container layer named "meta-yocto-bsp".
  83. - :term:`BBFILE_PATTERN`:
  84. Expands immediately during parsing to provide the directory of the
  85. layer.
  86. - :term:`BBFILE_PRIORITY`:
  87. Establishes a priority to use for recipes in the layer when the
  88. OpenEmbedded build finds recipes of the same name in different
  89. layers.
  90. - :term:`LAYERVERSION`:
  91. Establishes a version number for the layer. You can use this
  92. version number to specify this exact version of the layer as a
  93. dependency when using the
  94. :term:`LAYERDEPENDS`
  95. variable.
  96. - :term:`LAYERDEPENDS`:
  97. Lists all layers on which this layer depends (if any).
  98. - :term:`LAYERSERIES_COMPAT`:
  99. Lists the :yocto_wiki:`Yocto Project </Releases>`
  100. releases for which the current version is compatible. This
  101. variable is a good way to indicate if your particular layer is
  102. current.
  103. 4. *Add Content:* Depending on the type of layer, add the content. If
  104. the layer adds support for a machine, add the machine configuration
  105. in a ``conf/machine/`` file within the layer. If the layer adds
  106. distro policy, add the distro configuration in a ``conf/distro/``
  107. file within the layer. If the layer introduces new recipes, put the
  108. recipes you need in ``recipes-*`` subdirectories within the layer.
  109. .. note::
  110. For an explanation of layer hierarchy that is compliant with the
  111. Yocto Project, see the ":ref:`bsp-guide/bsp:example filesystem layout`"
  112. section in the Yocto Project Board Support Package (BSP) Developer's Guide.
  113. 5. *Optionally Test for Compatibility:* If you want permission to use
  114. the Yocto Project Compatibility logo with your layer or application
  115. that uses your layer, perform the steps to apply for compatibility.
  116. See the
  117. ":ref:`dev-manual/layers:making sure your layer is compatible with yocto project`"
  118. section for more information.
  119. Following Best Practices When Creating Layers
  120. =============================================
  121. To create layers that are easier to maintain and that will not impact
  122. builds for other machines, you should consider the information in the
  123. following list:
  124. - *Avoid "Overlaying" Entire Recipes from Other Layers in Your
  125. Configuration:* In other words, do not copy an entire recipe into
  126. your layer and then modify it. Rather, use an append file
  127. (``.bbappend``) to override only those parts of the original recipe
  128. you need to modify.
  129. - *Avoid Duplicating Include Files:* Use append files (``.bbappend``)
  130. for each recipe that uses an include file. Or, if you are introducing
  131. a new recipe that requires the included file, use the path relative
  132. to the original layer directory to refer to the file. For example,
  133. use ``require recipes-core/``\ `package`\ ``/``\ `file`\ ``.inc`` instead
  134. of ``require`` `file`\ ``.inc``. If you're finding you have to overlay
  135. the include file, it could indicate a deficiency in the include file
  136. in the layer to which it originally belongs. If this is the case, you
  137. should try to address that deficiency instead of overlaying the
  138. include file. For example, you could address this by getting the
  139. maintainer of the include file to add a variable or variables to make
  140. it easy to override the parts needing to be overridden.
  141. - *Structure Your Layers:* Proper use of overrides within append files
  142. and placement of machine-specific files within your layer can ensure
  143. that a build is not using the wrong Metadata and negatively impacting
  144. a build for a different machine. Following are some examples:
  145. - *Modify Variables to Support a Different Machine:* Suppose you
  146. have a layer named ``meta-one`` that adds support for building
  147. machine "one". To do so, you use an append file named
  148. ``base-files.bbappend`` and create a dependency on "foo" by
  149. altering the :term:`DEPENDS`
  150. variable::
  151. DEPENDS = "foo"
  152. The dependency is created during any
  153. build that includes the layer ``meta-one``. However, you might not
  154. want this dependency for all machines. For example, suppose you
  155. are building for machine "two" but your ``bblayers.conf`` file has
  156. the ``meta-one`` layer included. During the build, the
  157. ``base-files`` for machine "two" will also have the dependency on
  158. ``foo``.
  159. To make sure your changes apply only when building machine "one",
  160. use a machine override with the :term:`DEPENDS` statement::
  161. DEPENDS:one = "foo"
  162. You should follow the same strategy when using ``:append``
  163. and ``:prepend`` operations::
  164. DEPENDS:append:one = " foo"
  165. DEPENDS:prepend:one = "foo "
  166. As an actual example, here's a
  167. snippet from the generic kernel include file ``linux-yocto.inc``,
  168. wherein the kernel compile and link options are adjusted in the
  169. case of a subset of the supported architectures::
  170. DEPENDS:append:aarch64 = " libgcc"
  171. KERNEL_CC:append:aarch64 = " ${TOOLCHAIN_OPTIONS}"
  172. KERNEL_LD:append:aarch64 = " ${TOOLCHAIN_OPTIONS}"
  173. DEPENDS:append:nios2 = " libgcc"
  174. KERNEL_CC:append:nios2 = " ${TOOLCHAIN_OPTIONS}"
  175. KERNEL_LD:append:nios2 = " ${TOOLCHAIN_OPTIONS}"
  176. DEPENDS:append:arc = " libgcc"
  177. KERNEL_CC:append:arc = " ${TOOLCHAIN_OPTIONS}"
  178. KERNEL_LD:append:arc = " ${TOOLCHAIN_OPTIONS}"
  179. KERNEL_FEATURES:append:qemuall=" features/debug/printk.scc"
  180. - *Place Machine-Specific Files in Machine-Specific Locations:* When
  181. you have a base recipe, such as ``base-files.bb``, that contains a
  182. :term:`SRC_URI` statement to a
  183. file, you can use an append file to cause the build to use your
  184. own version of the file. For example, an append file in your layer
  185. at ``meta-one/recipes-core/base-files/base-files.bbappend`` could
  186. extend :term:`FILESPATH` using :term:`FILESEXTRAPATHS` as follows::
  187. FILESEXTRAPATHS:prepend := "${THISDIR}/${BPN}:"
  188. The build for machine "one" will pick up your machine-specific file as
  189. long as you have the file in
  190. ``meta-one/recipes-core/base-files/base-files/``. However, if you
  191. are building for a different machine and the ``bblayers.conf``
  192. file includes the ``meta-one`` layer and the location of your
  193. machine-specific file is the first location where that file is
  194. found according to :term:`FILESPATH`, builds for all machines will
  195. also use that machine-specific file.
  196. You can make sure that a machine-specific file is used for a
  197. particular machine by putting the file in a subdirectory specific
  198. to the machine. For example, rather than placing the file in
  199. ``meta-one/recipes-core/base-files/base-files/`` as shown above,
  200. put it in ``meta-one/recipes-core/base-files/base-files/one/``.
  201. Not only does this make sure the file is used only when building
  202. for machine "one", but the build process locates the file more
  203. quickly.
  204. In summary, you need to place all files referenced from
  205. :term:`SRC_URI` in a machine-specific subdirectory within the layer in
  206. order to restrict those files to machine-specific builds.
  207. - *Perform Steps to Apply for Yocto Project Compatibility:* If you want
  208. permission to use the Yocto Project Compatibility logo with your
  209. layer or application that uses your layer, perform the steps to apply
  210. for compatibility. See the
  211. ":ref:`dev-manual/layers:making sure your layer is compatible with yocto project`"
  212. section for more information.
  213. - *Follow the Layer Naming Convention:* Store custom layers in a Git
  214. repository that use the ``meta-layer_name`` format.
  215. - *Group Your Layers Locally:* Clone your repository alongside other
  216. cloned ``meta`` directories from the :term:`Source Directory`.
  217. Making Sure Your Layer is Compatible With Yocto Project
  218. =======================================================
  219. When you create a layer used with the Yocto Project, it is advantageous
  220. to make sure that the layer interacts well with existing Yocto Project
  221. layers (i.e. the layer is compatible with the Yocto Project). Ensuring
  222. compatibility makes the layer easy to be consumed by others in the Yocto
  223. Project community and could allow you permission to use the Yocto
  224. Project Compatible Logo.
  225. .. note::
  226. Only Yocto Project member organizations are permitted to use the
  227. Yocto Project Compatible Logo. The logo is not available for general
  228. use. For information on how to become a Yocto Project member
  229. organization, see the :yocto_home:`Yocto Project Website <>`.
  230. The Yocto Project Compatibility Program consists of a layer application
  231. process that requests permission to use the Yocto Project Compatibility
  232. Logo for your layer and application. The process consists of two parts:
  233. 1. Successfully passing a script (``yocto-check-layer``) that when run
  234. against your layer, tests it against constraints based on experiences
  235. of how layers have worked in the real world and where pitfalls have
  236. been found. Getting a "PASS" result from the script is required for
  237. successful compatibility registration.
  238. 2. Completion of an application acceptance form, which you can find at
  239. :yocto_home:`/webform/yocto-project-compatible-registration`.
  240. To be granted permission to use the logo, you need to satisfy the
  241. following:
  242. - Be able to check the box indicating that you got a "PASS" when
  243. running the script against your layer.
  244. - Answer "Yes" to the questions on the form or have an acceptable
  245. explanation for any questions answered "No".
  246. - Be a Yocto Project Member Organization.
  247. The remainder of this section presents information on the registration
  248. form and on the ``yocto-check-layer`` script.
  249. Yocto Project Compatible Program Application
  250. --------------------------------------------
  251. Use the form to apply for your layer's approval. Upon successful
  252. application, you can use the Yocto Project Compatibility Logo with your
  253. layer and the application that uses your layer.
  254. To access the form, use this link:
  255. :yocto_home:`/webform/yocto-project-compatible-registration`.
  256. Follow the instructions on the form to complete your application.
  257. The application consists of the following sections:
  258. - *Contact Information:* Provide your contact information as the fields
  259. require. Along with your information, provide the released versions
  260. of the Yocto Project for which your layer is compatible.
  261. - *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the
  262. items in the checklist. There is space at the bottom of the form for
  263. any explanations for items for which you answered "No".
  264. - *Recommendations:* Provide answers for the questions regarding Linux
  265. kernel use and build success.
  266. ``yocto-check-layer`` Script
  267. ----------------------------
  268. The ``yocto-check-layer`` script provides you a way to assess how
  269. compatible your layer is with the Yocto Project. You should run this
  270. script prior to using the form to apply for compatibility as described
  271. in the previous section. You need to achieve a "PASS" result in order to
  272. have your application form successfully processed.
  273. The script divides tests into three areas: COMMON, BSP, and DISTRO. For
  274. example, given a distribution layer (DISTRO), the layer must pass both
  275. the COMMON and DISTRO related tests. Furthermore, if your layer is a BSP
  276. layer, the layer must pass the COMMON and BSP set of tests.
  277. To execute the script, enter the following commands from your build
  278. directory::
  279. $ source oe-init-build-env
  280. $ yocto-check-layer your_layer_directory
  281. Be sure to provide the actual directory for your
  282. layer as part of the command.
  283. Entering the command causes the script to determine the type of layer
  284. and then to execute a set of specific tests against the layer. The
  285. following list overviews the test:
  286. - ``common.test_readme``: Tests if a ``README`` file exists in the
  287. layer and the file is not empty.
  288. - ``common.test_parse``: Tests to make sure that BitBake can parse the
  289. files without error (i.e. ``bitbake -p``).
  290. - ``common.test_show_environment``: Tests that the global or per-recipe
  291. environment is in order without errors (i.e. ``bitbake -e``).
  292. - ``common.test_world``: Verifies that ``bitbake world`` works.
  293. - ``common.test_signatures``: Tests to be sure that BSP and DISTRO
  294. layers do not come with recipes that change signatures.
  295. - ``common.test_layerseries_compat``: Verifies layer compatibility is
  296. set properly.
  297. - ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine
  298. configurations.
  299. - ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not
  300. set the machine when the layer is added.
  301. - ``bsp.test_machine_world``: Verifies that ``bitbake world`` works
  302. regardless of which machine is selected.
  303. - ``bsp.test_machine_signatures``: Verifies that building for a
  304. particular machine affects only the signature of tasks specific to
  305. that machine.
  306. - ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has
  307. distro configurations.
  308. - ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer
  309. does not set the distribution when the layer is added.
  310. Enabling Your Layer
  311. ===================
  312. Before the OpenEmbedded build system can use your new layer, you need to
  313. enable it. To enable your layer, simply add your layer's path to the
  314. :term:`BBLAYERS` variable in your ``conf/bblayers.conf`` file, which is
  315. found in the :term:`Build Directory`. The following example shows how to
  316. enable your new ``meta-mylayer`` layer (note how your new layer exists
  317. outside of the official ``poky`` repository which you would have checked
  318. out earlier)::
  319. # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
  320. # changes incompatibly
  321. POKY_BBLAYERS_CONF_VERSION = "2"
  322. BBPATH = "${TOPDIR}"
  323. BBFILES ?= ""
  324. BBLAYERS ?= " \
  325. /home/user/poky/meta \
  326. /home/user/poky/meta-poky \
  327. /home/user/poky/meta-yocto-bsp \
  328. /home/user/mystuff/meta-mylayer \
  329. "
  330. BitBake parses each ``conf/layer.conf`` file from the top down as
  331. specified in the :term:`BBLAYERS` variable within the ``conf/bblayers.conf``
  332. file. During the processing of each ``conf/layer.conf`` file, BitBake
  333. adds the recipes, classes and configurations contained within the
  334. particular layer to the source directory.
  335. Appending Other Layers Metadata With Your Layer
  336. ===============================================
  337. A recipe that appends Metadata to another recipe is called a BitBake
  338. append file. A BitBake append file uses the ``.bbappend`` file type
  339. suffix, while the corresponding recipe to which Metadata is being
  340. appended uses the ``.bb`` file type suffix.
  341. You can use a ``.bbappend`` file in your layer to make additions or
  342. changes to the content of another layer's recipe without having to copy
  343. the other layer's recipe into your layer. Your ``.bbappend`` file
  344. resides in your layer, while the main ``.bb`` recipe file to which you
  345. are appending Metadata resides in a different layer.
  346. Being able to append information to an existing recipe not only avoids
  347. duplication, but also automatically applies recipe changes from a
  348. different layer into your layer. If you were copying recipes, you would
  349. have to manually merge changes as they occur.
  350. When you create an append file, you must use the same root name as the
  351. corresponding recipe file. For example, the append file
  352. ``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This
  353. means the original recipe and append filenames are version
  354. number-specific. If the corresponding recipe is renamed to update to a
  355. newer version, you must also rename and possibly update the
  356. corresponding ``.bbappend`` as well. During the build process, BitBake
  357. displays an error on starting if it detects a ``.bbappend`` file that
  358. does not have a corresponding recipe with a matching name. See the
  359. :term:`BB_DANGLINGAPPENDS_WARNONLY`
  360. variable for information on how to handle this error.
  361. Overlaying a File Using Your Layer
  362. ----------------------------------
  363. As an example, consider the main formfactor recipe and a corresponding
  364. formfactor append file both from the :term:`Source Directory`.
  365. Here is the main
  366. formfactor recipe, which is named ``formfactor_0.0.bb`` and located in
  367. the "meta" layer at ``meta/recipes-bsp/formfactor``::
  368. SUMMARY = "Device formfactor information"
  369. DESCRIPTION = "A formfactor configuration file provides information about the \
  370. target hardware for which the image is being built and information that the \
  371. build system cannot obtain from other sources such as the kernel."
  372. SECTION = "base"
  373. LICENSE = "MIT"
  374. LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
  375. PR = "r45"
  376. SRC_URI = "file://config file://machconfig"
  377. S = "${WORKDIR}"
  378. PACKAGE_ARCH = "${MACHINE_ARCH}"
  379. INHIBIT_DEFAULT_DEPS = "1"
  380. do_install() {
  381. # Install file only if it has contents
  382. install -d ${D}${sysconfdir}/formfactor/
  383. install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
  384. if [ -s "${S}/machconfig" ]; then
  385. install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
  386. fi
  387. }
  388. In the main recipe, note the :term:`SRC_URI`
  389. variable, which tells the OpenEmbedded build system where to find files
  390. during the build.
  391. Following is the append file, which is named ``formfactor_0.0.bbappend``
  392. and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The
  393. file is in the layer at ``recipes-bsp/formfactor``::
  394. FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
  395. By default, the build system uses the
  396. :term:`FILESPATH` variable to
  397. locate files. This append file extends the locations by setting the
  398. :term:`FILESEXTRAPATHS`
  399. variable. Setting this variable in the ``.bbappend`` file is the most
  400. reliable and recommended method for adding directories to the search
  401. path used by the build system to find files.
  402. The statement in this example extends the directories to include
  403. ``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``,
  404. which resolves to a directory named ``formfactor`` in the same directory
  405. in which the append file resides (i.e.
  406. ``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must
  407. have the supporting directory structure set up that will contain any
  408. files or patches you will be including from the layer.
  409. Using the immediate expansion assignment operator ``:=`` is important
  410. because of the reference to :term:`THISDIR`. The trailing colon character is
  411. important as it ensures that items in the list remain colon-separated.
  412. .. note::
  413. BitBake automatically defines the :term:`THISDIR` variable. You should
  414. never set this variable yourself. Using ":prepend" as part of the
  415. :term:`FILESEXTRAPATHS` ensures your path will be searched prior to other
  416. paths in the final list.
  417. Also, not all append files add extra files. Many append files simply
  418. allow to add build options (e.g. ``systemd``). For these cases, your
  419. append file would not even use the :term:`FILESEXTRAPATHS` statement.
  420. The end result of this ``.bbappend`` file is that on a Raspberry Pi, where
  421. ``rpi`` will exist in the list of :term:`OVERRIDES`, the file
  422. ``meta-raspberrypi/recipes-bsp/formfactor/formfactor/rpi/machconfig`` will be
  423. used during :ref:`ref-tasks-fetch` and the test for a non-zero file size in
  424. :ref:`ref-tasks-install` will return true, and the file will be installed.
  425. Installing Additional Files Using Your Layer
  426. --------------------------------------------
  427. As another example, consider the main ``xserver-xf86-config`` recipe and a
  428. corresponding ``xserver-xf86-config`` append file both from the :term:`Source
  429. Directory`. Here is the main ``xserver-xf86-config`` recipe, which is named
  430. ``xserver-xf86-config_0.1.bb`` and located in the "meta" layer at
  431. ``meta/recipes-graphics/xorg-xserver``::
  432. SUMMARY = "X.Org X server configuration file"
  433. HOMEPAGE = "http://www.x.org"
  434. SECTION = "x11/base"
  435. LICENSE = "MIT"
  436. LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
  437. PR = "r33"
  438. SRC_URI = "file://xorg.conf"
  439. S = "${WORKDIR}"
  440. CONFFILES:${PN} = "${sysconfdir}/X11/xorg.conf"
  441. PACKAGE_ARCH = "${MACHINE_ARCH}"
  442. ALLOW_EMPTY:${PN} = "1"
  443. do_install () {
  444. if test -s ${WORKDIR}/xorg.conf; then
  445. install -d ${D}/${sysconfdir}/X11
  446. install -m 0644 ${WORKDIR}/xorg.conf ${D}/${sysconfdir}/X11/
  447. fi
  448. }
  449. Following is the append file, which is named ``xserver-xf86-config_%.bbappend``
  450. and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The
  451. file is in the layer at ``recipes-graphics/xorg-xserver``::
  452. FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
  453. SRC_URI:append:rpi = " \
  454. file://xorg.conf.d/98-pitft.conf \
  455. file://xorg.conf.d/99-calibration.conf \
  456. "
  457. do_install:append:rpi () {
  458. PITFT="${@bb.utils.contains("MACHINE_FEATURES", "pitft", "1", "0", d)}"
  459. if [ "${PITFT}" = "1" ]; then
  460. install -d ${D}/${sysconfdir}/X11/xorg.conf.d/
  461. install -m 0644 ${WORKDIR}/xorg.conf.d/98-pitft.conf ${D}/${sysconfdir}/X11/xorg.conf.d/
  462. install -m 0644 ${WORKDIR}/xorg.conf.d/99-calibration.conf ${D}/${sysconfdir}/X11/xorg.conf.d/
  463. fi
  464. }
  465. FILES:${PN}:append:rpi = " ${sysconfdir}/X11/xorg.conf.d/*"
  466. Building off of the previous example, we once again are setting the
  467. :term:`FILESEXTRAPATHS` variable. In this case we are also using
  468. :term:`SRC_URI` to list additional source files to use when ``rpi`` is found in
  469. the list of :term:`OVERRIDES`. The :ref:`ref-tasks-install` task will then perform a
  470. check for an additional :term:`MACHINE_FEATURES` that if set will cause these
  471. additional files to be installed. These additional files are listed in
  472. :term:`FILES` so that they will be packaged.
  473. Prioritizing Your Layer
  474. =======================
  475. Each layer is assigned a priority value. Priority values control which
  476. layer takes precedence if there are recipe files with the same name in
  477. multiple layers. For these cases, the recipe file from the layer with a
  478. higher priority number takes precedence. Priority values also affect the
  479. order in which multiple ``.bbappend`` files for the same recipe are
  480. applied. You can either specify the priority manually, or allow the
  481. build system to calculate it based on the layer's dependencies.
  482. To specify the layer's priority manually, use the
  483. :term:`BBFILE_PRIORITY`
  484. variable and append the layer's root name::
  485. BBFILE_PRIORITY_mylayer = "1"
  486. .. note::
  487. It is possible for a recipe with a lower version number
  488. :term:`PV` in a layer that has a higher
  489. priority to take precedence.
  490. Also, the layer priority does not currently affect the precedence
  491. order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake
  492. might address this.
  493. Managing Layers
  494. ===============
  495. You can use the BitBake layer management tool ``bitbake-layers`` to
  496. provide a view into the structure of recipes across a multi-layer
  497. project. Being able to generate output that reports on configured layers
  498. with their paths and priorities and on ``.bbappend`` files and their
  499. applicable recipes can help to reveal potential problems.
  500. For help on the BitBake layer management tool, use the following
  501. command::
  502. $ bitbake-layers --help
  503. The following list describes the available commands:
  504. - ``help:`` Displays general help or help on a specified command.
  505. - ``show-layers:`` Shows the current configured layers.
  506. - ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed
  507. when a recipe with the same name exists in another layer that has a
  508. higher layer priority.
  509. - ``show-recipes:`` Lists available recipes and the layers that
  510. provide them.
  511. - ``show-appends:`` Lists ``.bbappend`` files and the recipe files to
  512. which they apply.
  513. - ``show-cross-depends:`` Lists dependency relationships between
  514. recipes that cross layer boundaries.
  515. - ``add-layer:`` Adds a layer to ``bblayers.conf``.
  516. - ``remove-layer:`` Removes a layer from ``bblayers.conf``
  517. - ``flatten:`` Flattens the layer configuration into a separate
  518. output directory. Flattening your layer configuration builds a
  519. "flattened" directory that contains the contents of all layers, with
  520. any overlayed recipes removed and any ``.bbappend`` files appended to
  521. the corresponding recipes. You might have to perform some manual
  522. cleanup of the flattened layer as follows:
  523. - Non-recipe files (such as patches) are overwritten. The flatten
  524. command shows a warning for these files.
  525. - Anything beyond the normal layer setup has been added to the
  526. ``layer.conf`` file. Only the lowest priority layer's
  527. ``layer.conf`` is used.
  528. - Overridden and appended items from ``.bbappend`` files need to be
  529. cleaned up. The contents of each ``.bbappend`` end up in the
  530. flattened recipe. However, if there are appended or changed
  531. variable values, you need to tidy these up yourself. Consider the
  532. following example. Here, the ``bitbake-layers`` command adds the
  533. line ``#### bbappended ...`` so that you know where the following
  534. lines originate::
  535. ...
  536. DESCRIPTION = "A useful utility"
  537. ...
  538. EXTRA_OECONF = "--enable-something"
  539. ...
  540. #### bbappended from meta-anotherlayer ####
  541. DESCRIPTION = "Customized utility"
  542. EXTRA_OECONF += "--enable-somethingelse"
  543. Ideally, you would tidy up these utilities as follows::
  544. ...
  545. DESCRIPTION = "Customized utility"
  546. ...
  547. EXTRA_OECONF = "--enable-something --enable-somethingelse"
  548. ...
  549. - ``layerindex-fetch``: Fetches a layer from a layer index, along
  550. with its dependent layers, and adds the layers to the
  551. ``conf/bblayers.conf`` file.
  552. - ``layerindex-show-depends``: Finds layer dependencies from the
  553. layer index.
  554. - ``save-build-conf``: Saves the currently active build configuration
  555. (``conf/local.conf``, ``conf/bblayers.conf``) as a template into a layer.
  556. This template can later be used for setting up builds via :term:``TEMPLATECONF``.
  557. For information about saving and using configuration templates, see
  558. ":ref:`dev-manual/custom-template-configuration-directory:creating a custom template configuration directory`".
  559. - ``create-layer``: Creates a basic layer.
  560. - ``create-layers-setup``: Writes out a configuration file and/or a script that
  561. can replicate the directory structure and revisions of the layers in a current build.
  562. For more information, see ":ref:`dev-manual/layers:saving and restoring the layers setup`".
  563. Creating a General Layer Using the ``bitbake-layers`` Script
  564. ============================================================
  565. The ``bitbake-layers`` script with the ``create-layer`` subcommand
  566. simplifies creating a new general layer.
  567. .. note::
  568. - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`"
  569. section in the Yocto
  570. Project Board Specific (BSP) Developer's Guide.
  571. - In order to use a layer with the OpenEmbedded build system, you
  572. need to add the layer to your ``bblayers.conf`` configuration
  573. file. See the ":ref:`dev-manual/layers:adding a layer using the \`\`bitbake-layers\`\` script`"
  574. section for more information.
  575. The default mode of the script's operation with this subcommand is to
  576. create a layer with the following:
  577. - A layer priority of 6.
  578. - A ``conf`` subdirectory that contains a ``layer.conf`` file.
  579. - A ``recipes-example`` subdirectory that contains a further
  580. subdirectory named ``example``, which contains an ``example.bb``
  581. recipe file.
  582. - A ``COPYING.MIT``, which is the license statement for the layer. The
  583. script assumes you want to use the MIT license, which is typical for
  584. most layers, for the contents of the layer itself.
  585. - A ``README`` file, which is a file describing the contents of your
  586. new layer.
  587. In its simplest form, you can use the following command form to create a
  588. layer. The command creates a layer whose name corresponds to
  589. "your_layer_name" in the current directory::
  590. $ bitbake-layers create-layer your_layer_name
  591. As an example, the following command creates a layer named ``meta-scottrif``
  592. in your home directory::
  593. $ cd /usr/home
  594. $ bitbake-layers create-layer meta-scottrif
  595. NOTE: Starting bitbake server...
  596. Add your new layer with 'bitbake-layers add-layer meta-scottrif'
  597. If you want to set the priority of the layer to other than the default
  598. value of "6", you can either use the ``--priority`` option or you
  599. can edit the
  600. :term:`BBFILE_PRIORITY` value
  601. in the ``conf/layer.conf`` after the script creates it. Furthermore, if
  602. you want to give the example recipe file some name other than the
  603. default, you can use the ``--example-recipe-name`` option.
  604. The easiest way to see how the ``bitbake-layers create-layer`` command
  605. works is to experiment with the script. You can also read the usage
  606. information by entering the following::
  607. $ bitbake-layers create-layer --help
  608. NOTE: Starting bitbake server...
  609. usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
  610. [--example-recipe-name EXAMPLERECIPE]
  611. layerdir
  612. Create a basic layer
  613. positional arguments:
  614. layerdir Layer directory to create
  615. optional arguments:
  616. -h, --help show this help message and exit
  617. --priority PRIORITY, -p PRIORITY
  618. Layer directory to create
  619. --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
  620. Filename of the example recipe
  621. Adding a Layer Using the ``bitbake-layers`` Script
  622. ==================================================
  623. Once you create your general layer, you must add it to your
  624. ``bblayers.conf`` file. Adding the layer to this configuration file
  625. makes the OpenEmbedded build system aware of your layer so that it can
  626. search it for metadata.
  627. Add your layer by using the ``bitbake-layers add-layer`` command::
  628. $ bitbake-layers add-layer your_layer_name
  629. Here is an example that adds a
  630. layer named ``meta-scottrif`` to the configuration file. Following the
  631. command that adds the layer is another ``bitbake-layers`` command that
  632. shows the layers that are in your ``bblayers.conf`` file::
  633. $ bitbake-layers add-layer meta-scottrif
  634. NOTE: Starting bitbake server...
  635. Parsing recipes: 100% |##########################################################| Time: 0:00:49
  636. Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
  637. $ bitbake-layers show-layers
  638. NOTE: Starting bitbake server...
  639. layer path priority
  640. ==========================================================================
  641. meta /home/scottrif/poky/meta 5
  642. meta-poky /home/scottrif/poky/meta-poky 5
  643. meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
  644. workspace /home/scottrif/poky/build/workspace 99
  645. meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
  646. Adding the layer to this file
  647. enables the build system to locate the layer during the build.
  648. .. note::
  649. During a build, the OpenEmbedded build system looks in the layers
  650. from the top of the list down to the bottom in that order.
  651. Saving and restoring the layers setup
  652. =====================================
  653. Once you have a working build with the correct set of layers, it is beneficial
  654. to capture the layer setup --- what they are, which repositories they come from
  655. and which SCM revisions they're at --- into a configuration file, so that this
  656. setup can be easily replicated later, perhaps on a different machine. Here's
  657. how to do this::
  658. $ bitbake-layers create-layers-setup /srv/work/alex/meta-alex/
  659. NOTE: Starting bitbake server...
  660. NOTE: Created /srv/work/alex/meta-alex/setup-layers.json
  661. NOTE: Created /srv/work/alex/meta-alex/setup-layers
  662. The tool needs a single argument which tells where to place the output, consisting
  663. of a json formatted layer configuration, and a ``setup-layers`` script that can use that configuration
  664. to restore the layers in a different location, or on a different host machine. The argument
  665. can point to a custom layer (which is then deemed a "bootstrap" layer that needs to be
  666. checked out first), or into a completely independent location.
  667. The replication of the layers is performed by running the ``setup-layers`` script provided
  668. above:
  669. 1. Clone the bootstrap layer or some other repository to obtain
  670. the json config and the setup script that can use it.
  671. 2. Run the script directly with no options::
  672. alex@Zen2:/srv/work/alex/my-build$ meta-alex/setup-layers
  673. Note: not checking out source meta-alex, use --force-bootstraplayer-checkout to override.
  674. Setting up source meta-intel, revision 15.0-hardknott-3.3-310-g0a96edae, branch master
  675. Running 'git init -q /srv/work/alex/my-build/meta-intel'
  676. Running 'git remote remove origin > /dev/null 2>&1; git remote add origin git://git.yoctoproject.org/meta-intel' in /srv/work/alex/my-build/meta-intel
  677. Running 'git fetch -q origin || true' in /srv/work/alex/my-build/meta-intel
  678. Running 'git checkout -q 0a96edae609a3f48befac36af82cf1eed6786b4a' in /srv/work/alex/my-build/meta-intel
  679. Setting up source poky, revision 4.1_M1-372-g55483d28f2, branch akanavin/setup-layers
  680. Running 'git init -q /srv/work/alex/my-build/poky'
  681. Running 'git remote remove origin > /dev/null 2>&1; git remote add origin git://git.yoctoproject.org/poky' in /srv/work/alex/my-build/poky
  682. Running 'git fetch -q origin || true' in /srv/work/alex/my-build/poky
  683. Running 'git remote remove poky-contrib > /dev/null 2>&1; git remote add poky-contrib ssh://git@push.yoctoproject.org/poky-contrib' in /srv/work/alex/my-build/poky
  684. Running 'git fetch -q poky-contrib || true' in /srv/work/alex/my-build/poky
  685. Running 'git checkout -q 11db0390b02acac1324e0f827beb0e2e3d0d1d63' in /srv/work/alex/my-build/poky
  686. .. note::
  687. This will work to update an existing checkout as well.
  688. .. note::
  689. The script is self-sufficient and requires only python3
  690. and git on the build machine.
  691. .. note::
  692. Both the ``create-layers-setup`` and the ``setup-layers`` provided several additional options
  693. that customize their behavior - you are welcome to study them via ``--help`` command line parameter.