licenses.rst 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. Working With Licenses
  3. *********************
  4. As mentioned in the ":ref:`overview-manual/development-environment:licensing`"
  5. section in the Yocto Project Overview and Concepts Manual, open source
  6. projects are open to the public and they consequently have different
  7. licensing structures in place. This section describes the mechanism by
  8. which the :term:`OpenEmbedded Build System`
  9. tracks changes to
  10. licensing text and covers how to maintain open source license compliance
  11. during your project's lifecycle. The section also describes how to
  12. enable commercially licensed recipes, which by default are disabled.
  13. Tracking License Changes
  14. ========================
  15. The license of an upstream project might change in the future. In order
  16. to prevent these changes going unnoticed, the
  17. :term:`LIC_FILES_CHKSUM`
  18. variable tracks changes to the license text. The checksums are validated
  19. at the end of the configure step, and if the checksums do not match, the
  20. build will fail.
  21. Specifying the ``LIC_FILES_CHKSUM`` Variable
  22. --------------------------------------------
  23. The :term:`LIC_FILES_CHKSUM` variable contains checksums of the license text
  24. in the source code for the recipe. Here is an example of how to
  25. specify :term:`LIC_FILES_CHKSUM`::
  26. LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
  27. file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
  28. file://licfile2.txt;endline=50;md5=zzzz \
  29. ..."
  30. .. note::
  31. - When using "beginline" and "endline", realize that line numbering
  32. begins with one and not zero. Also, the included lines are
  33. inclusive (i.e. lines five through and including 29 in the
  34. previous example for ``licfile1.txt``).
  35. - When a license check fails, the selected license text is included
  36. as part of the QA message. Using this output, you can determine
  37. the exact start and finish for the needed license text.
  38. The build system uses the :term:`S`
  39. variable as the default directory when searching files listed in
  40. :term:`LIC_FILES_CHKSUM`. The previous example employs the default
  41. directory.
  42. Consider this next example::
  43. LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
  44. md5=bb14ed3c4cda583abc85401304b5cd4e"
  45. LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
  46. The first line locates a file in ``${S}/src/ls.c`` and isolates lines
  47. five through 16 as license text. The second line refers to a file in
  48. :term:`WORKDIR`.
  49. Note that :term:`LIC_FILES_CHKSUM` variable is mandatory for all recipes,
  50. unless the :term:`LICENSE` variable is set to "CLOSED".
  51. Explanation of Syntax
  52. ---------------------
  53. As mentioned in the previous section, the :term:`LIC_FILES_CHKSUM` variable
  54. lists all the important files that contain the license text for the
  55. source code. It is possible to specify a checksum for an entire file, or
  56. a specific section of a file (specified by beginning and ending line
  57. numbers with the "beginline" and "endline" parameters, respectively).
  58. The latter is useful for source files with a license notice header,
  59. README documents, and so forth. If you do not use the "beginline"
  60. parameter, then it is assumed that the text begins on the first line of
  61. the file. Similarly, if you do not use the "endline" parameter, it is
  62. assumed that the license text ends with the last line of the file.
  63. The "md5" parameter stores the md5 checksum of the license text. If the
  64. license text changes in any way as compared to this parameter then a
  65. mismatch occurs. This mismatch triggers a build failure and notifies the
  66. developer. Notification allows the developer to review and address the
  67. license text changes. Also note that if a mismatch occurs during the
  68. build, the correct md5 checksum is placed in the build log and can be
  69. easily copied to the recipe.
  70. There is no limit to how many files you can specify using the
  71. :term:`LIC_FILES_CHKSUM` variable. Generally, however, every project
  72. requires a few specifications for license tracking. Many projects have a
  73. "COPYING" file that stores the license information for all the source
  74. code files. This practice allows you to just track the "COPYING" file as
  75. long as it is kept up to date.
  76. .. note::
  77. - If you specify an empty or invalid "md5" parameter,
  78. :term:`BitBake` returns an md5
  79. mis-match error and displays the correct "md5" parameter value
  80. during the build. The correct parameter is also captured in the
  81. build log.
  82. - If the whole file contains only license text, you do not need to
  83. use the "beginline" and "endline" parameters.
  84. Enabling Commercially Licensed Recipes
  85. ======================================
  86. By default, the OpenEmbedded build system disables components that have
  87. commercial or other special licensing requirements. Such requirements
  88. are defined on a recipe-by-recipe basis through the
  89. :term:`LICENSE_FLAGS` variable
  90. definition in the affected recipe. For instance, the
  91. ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe
  92. contains the following statement::
  93. LICENSE_FLAGS = "commercial"
  94. Here is a
  95. slightly more complicated example that contains both an explicit recipe
  96. name and version (after variable expansion)::
  97. LICENSE_FLAGS = "license_${PN}_${PV}"
  98. It is possible to give more details about a specific license
  99. using flags on the :term:`LICENSE_FLAGS_DETAILS` variable::
  100. LICENSE_FLAGS_DETAILS[my-eula-license] = "For further details, see https://example.com/eula."
  101. If set, this will be displayed to the user if the license hasn't been accepted.
  102. In order for a component restricted by a
  103. :term:`LICENSE_FLAGS` definition to be enabled and included in an image, it
  104. needs to have a matching entry in the global
  105. :term:`LICENSE_FLAGS_ACCEPTED`
  106. variable, which is a variable typically defined in your ``local.conf``
  107. file. For example, to enable the
  108. ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you
  109. could add either the string "commercial_gst-plugins-ugly" or the more
  110. general string "commercial" to :term:`LICENSE_FLAGS_ACCEPTED`. See the
  111. ":ref:`dev-manual/licenses:license flag matching`" section for a full
  112. explanation of how :term:`LICENSE_FLAGS` matching works. Here is the
  113. example::
  114. LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly"
  115. Likewise, to additionally enable the package built from the recipe
  116. containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that
  117. the actual recipe name was ``emgd_1.10.bb``, the following string would
  118. enable that package as well as the original ``gst-plugins-ugly``
  119. package::
  120. LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly license_emgd_1.10"
  121. As a convenience, you do not need to specify the
  122. complete license string for every package. You can use
  123. an abbreviated form, which consists of just the first portion or
  124. portions of the license string before the initial underscore character
  125. or characters. A partial string will match any license that contains the
  126. given string as the first portion of its license. For example, the
  127. following value will also match both of the packages
  128. previously mentioned as well as any other packages that have licenses
  129. starting with "commercial" or "license"::
  130. LICENSE_FLAGS_ACCEPTED = "commercial license"
  131. License Flag Matching
  132. ---------------------
  133. License flag matching allows you to control what recipes the
  134. OpenEmbedded build system includes in the build. Fundamentally, the
  135. build system attempts to match :term:`LICENSE_FLAGS` strings found in
  136. recipes against strings found in :term:`LICENSE_FLAGS_ACCEPTED`.
  137. A match causes the build system to include a recipe in the
  138. build, while failure to find a match causes the build system to exclude
  139. a recipe.
  140. In general, license flag matching is simple. However, understanding some
  141. concepts will help you correctly and effectively use matching.
  142. Before a flag defined by a particular recipe is tested against the
  143. entries of :term:`LICENSE_FLAGS_ACCEPTED`, the expanded
  144. string ``_${PN}`` is appended to the flag. This expansion makes each
  145. :term:`LICENSE_FLAGS` value recipe-specific. After expansion, the
  146. string is then matched against the entries. Thus, specifying
  147. ``LICENSE_FLAGS = "commercial"`` in recipe "foo", for example, results
  148. in the string ``"commercial_foo"``. And, to create a match, that string
  149. must appear among the entries of :term:`LICENSE_FLAGS_ACCEPTED`.
  150. Judicious use of the :term:`LICENSE_FLAGS` strings and the contents of the
  151. :term:`LICENSE_FLAGS_ACCEPTED` variable allows you a lot of flexibility for
  152. including or excluding recipes based on licensing. For example, you can
  153. broaden the matching capabilities by using license flags string subsets
  154. in :term:`LICENSE_FLAGS_ACCEPTED`.
  155. .. note::
  156. When using a string subset, be sure to use the part of the expanded
  157. string that precedes the appended underscore character (e.g.
  158. ``usethispart_1.3``, ``usethispart_1.4``, and so forth).
  159. For example, simply specifying the string "commercial" in the
  160. :term:`LICENSE_FLAGS_ACCEPTED` variable matches any expanded
  161. :term:`LICENSE_FLAGS` definition that starts with the string
  162. "commercial" such as "commercial_foo" and "commercial_bar", which
  163. are the strings the build system automatically generates for
  164. hypothetical recipes named "foo" and "bar" assuming those recipes simply
  165. specify the following::
  166. LICENSE_FLAGS = "commercial"
  167. Thus, you can choose to exhaustively enumerate each license flag in the
  168. list and allow only specific recipes into the image, or you can use a
  169. string subset that causes a broader range of matches to allow a range of
  170. recipes into the image.
  171. This scheme works even if the :term:`LICENSE_FLAGS` string already has
  172. ``_${PN}`` appended. For example, the build system turns the license
  173. flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match
  174. both the general "commercial" and the specific "commercial_1.2_foo"
  175. strings found in the :term:`LICENSE_FLAGS_ACCEPTED` variable, as expected.
  176. Here are some other scenarios:
  177. - You can specify a versioned string in the recipe such as
  178. "commercial_foo_1.2" in a "foo" recipe. The build system expands this
  179. string to "commercial_foo_1.2_foo". Combine this license flag with a
  180. :term:`LICENSE_FLAGS_ACCEPTED` variable that has the string
  181. "commercial" and you match the flag along with any other flag that
  182. starts with the string "commercial".
  183. - Under the same circumstances, you can add "commercial_foo" in the
  184. :term:`LICENSE_FLAGS_ACCEPTED` variable and the build system not only
  185. matches "commercial_foo_1.2" but also matches any license flag with
  186. the string "commercial_foo", regardless of the version.
  187. - You can be very specific and use both the package and version parts
  188. in the :term:`LICENSE_FLAGS_ACCEPTED` list (e.g.
  189. "commercial_foo_1.2") to specifically match a versioned recipe.
  190. Other Variables Related to Commercial Licenses
  191. ----------------------------------------------
  192. There are other helpful variables related to commercial license handling,
  193. defined in the
  194. ``poky/meta/conf/distro/include/default-distrovars.inc`` file::
  195. COMMERCIAL_AUDIO_PLUGINS ?= ""
  196. COMMERCIAL_VIDEO_PLUGINS ?= ""
  197. If you want to enable these components, you can do so by making sure you have
  198. statements similar to the following in your ``local.conf`` configuration file::
  199. COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
  200. gst-plugins-ugly-mpegaudioparse"
  201. COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
  202. gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
  203. LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
  204. Of course, you could also create a matching list for those components using the
  205. more general "commercial" string in the :term:`LICENSE_FLAGS_ACCEPTED` variable,
  206. but that would also enable all the other packages with :term:`LICENSE_FLAGS`
  207. containing "commercial", which you may or may not want::
  208. LICENSE_FLAGS_ACCEPTED = "commercial"
  209. Specifying audio and video plugins as part of the
  210. :term:`COMMERCIAL_AUDIO_PLUGINS` and :term:`COMMERCIAL_VIDEO_PLUGINS` statements
  211. (along with :term:`LICENSE_FLAGS_ACCEPTED`) includes the plugins or
  212. components into built images, thus adding support for media formats or
  213. components.
  214. .. note::
  215. GStreamer "ugly" and "bad" plugins are actually available through
  216. open source licenses. However, the "ugly" ones can be subject to software
  217. patents in some countries, making it necessary to pay licensing fees
  218. to distribute them. The "bad" ones are just deemed unreliable by the
  219. GStreamer community and should therefore be used with care.
  220. Maintaining Open Source License Compliance During Your Product's Lifecycle
  221. ==========================================================================
  222. One of the concerns for a development organization using open source
  223. software is how to maintain compliance with various open source
  224. licensing during the lifecycle of the product. While this section does
  225. not provide legal advice or comprehensively cover all scenarios, it does
  226. present methods that you can use to assist you in meeting the compliance
  227. requirements during a software release.
  228. With hundreds of different open source licenses that the Yocto Project
  229. tracks, it is difficult to know the requirements of each and every
  230. license. However, the requirements of the major FLOSS licenses can begin
  231. to be covered by assuming that there are three main areas of concern:
  232. - Source code must be provided.
  233. - License text for the software must be provided.
  234. - Compilation scripts and modifications to the source code must be
  235. provided.
  236. There are other requirements beyond the scope of these three and the
  237. methods described in this section (e.g. the mechanism through which
  238. source code is distributed).
  239. As different organizations have different ways of releasing software,
  240. there can be multiple ways of meeting license obligations. At
  241. least, we describe here two methods for achieving compliance:
  242. - The first method is to use OpenEmbedded's ability to provide
  243. the source code, provide a list of licenses, as well as
  244. compilation scripts and source code modifications.
  245. The remainder of this section describes supported methods to meet
  246. the previously mentioned three requirements.
  247. - The second method is to generate a *Software Bill of Materials*
  248. (:term:`SBoM`), as described in the ":doc:`/dev-manual/sbom`" section.
  249. Not only do you generate :term:`SPDX` output which can be used meet
  250. license compliance requirements (except for sharing the build system
  251. and layers sources for the time being), but this output also includes
  252. component version and patch information which can be used
  253. for vulnerability assessment.
  254. Whatever method you choose, prior to releasing images, sources,
  255. and the build system, you should audit all artifacts to ensure
  256. completeness.
  257. .. note::
  258. The Yocto Project generates a license manifest during image creation
  259. that is located in
  260. ``${DEPLOY_DIR}/licenses/${SSTATE_PKGARCH}/<image-name>-<machine>.rootfs-<datestamp>/``
  261. to assist with any audits.
  262. Providing the Source Code
  263. -------------------------
  264. Compliance activities should begin before you generate the final image.
  265. The first thing you should look at is the requirement that tops the list
  266. for most compliance groups --- providing the source. The Yocto Project has
  267. a few ways of meeting this requirement.
  268. One of the easiest ways to meet this requirement is to provide the
  269. entire :term:`DL_DIR` used by the
  270. build. This method, however, has a few issues. The most obvious is the
  271. size of the directory since it includes all sources used in the build
  272. and not just the source used in the released image. It will include
  273. toolchain source, and other artifacts, which you would not generally
  274. release. However, the more serious issue for most companies is
  275. accidental release of proprietary software. The Yocto Project provides
  276. an :ref:`ref-classes-archiver` class to help avoid some of these concerns.
  277. Before you employ :term:`DL_DIR` or the :ref:`ref-classes-archiver` class, you
  278. need to decide how you choose to provide source. The source
  279. :ref:`ref-classes-archiver` class can generate tarballs and SRPMs and can
  280. create them with various levels of compliance in mind.
  281. One way of doing this (but certainly not the only way) is to release
  282. just the source as a tarball. You can do this by adding the following to
  283. the ``local.conf`` file found in the :term:`Build Directory`::
  284. INHERIT += "archiver"
  285. ARCHIVER_MODE[src] = "original"
  286. During the creation of your
  287. image, the source from all recipes that deploy packages to the image is
  288. placed within subdirectories of ``DEPLOY_DIR/sources`` based on the
  289. :term:`LICENSE` for each recipe.
  290. Releasing the entire directory enables you to comply with requirements
  291. concerning providing the unmodified source. It is important to note that
  292. the size of the directory can get large.
  293. A way to help mitigate the size issue is to only release tarballs for
  294. licenses that require the release of source. Let us assume you are only
  295. concerned with GPL code as identified by running the following script:
  296. .. code-block:: shell
  297. # Script to archive a subset of packages matching specific license(s)
  298. # Source and license files are copied into sub folders of package folder
  299. # Must be run from build folder
  300. #!/bin/bash
  301. src_release_dir="source-release"
  302. mkdir -p $src_release_dir
  303. for a in tmp/deploy/sources/*; do
  304. for d in $a/*; do
  305. # Get package name from path
  306. p=`basename $d`
  307. p=${p%-*}
  308. p=${p%-*}
  309. # Only archive GPL packages (update *GPL* regex for your license check)
  310. numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
  311. if [ $numfiles -ge 1 ]; then
  312. echo Archiving $p
  313. mkdir -p $src_release_dir/$p/source
  314. cp $d/* $src_release_dir/$p/source 2> /dev/null
  315. mkdir -p $src_release_dir/$p/license
  316. cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
  317. fi
  318. done
  319. done
  320. At this point, you
  321. could create a tarball from the ``gpl_source_release`` directory and
  322. provide that to the end user. This method would be a step toward
  323. achieving compliance with section 3a of GPLv2 and with section 6 of
  324. GPLv3.
  325. Providing License Text
  326. ----------------------
  327. One requirement that is often overlooked is inclusion of license text.
  328. This requirement also needs to be dealt with prior to generating the
  329. final image. Some licenses require the license text to accompany the
  330. binary. You can achieve this by adding the following to your
  331. ``local.conf`` file::
  332. COPY_LIC_MANIFEST = "1"
  333. COPY_LIC_DIRS = "1"
  334. LICENSE_CREATE_PACKAGE = "1"
  335. Adding these statements to the
  336. configuration file ensures that the licenses collected during package
  337. generation are included on your image.
  338. .. note::
  339. Setting all three variables to "1" results in the image having two
  340. copies of the same license file. One copy resides in
  341. ``/usr/share/common-licenses`` and the other resides in
  342. ``/usr/share/license``.
  343. The reason for this behavior is because
  344. :term:`COPY_LIC_DIRS` and
  345. :term:`COPY_LIC_MANIFEST`
  346. add a copy of the license when the image is built but do not offer a
  347. path for adding licenses for newly installed packages to an image.
  348. :term:`LICENSE_CREATE_PACKAGE`
  349. adds a separate package and an upgrade path for adding licenses to an
  350. image.
  351. As the source :ref:`ref-classes-archiver` class has already archived the
  352. original unmodified source that contains the license files, you would have
  353. already met the requirements for inclusion of the license information
  354. with source as defined by the GPL and other open source licenses.
  355. Providing Compilation Scripts and Source Code Modifications
  356. -----------------------------------------------------------
  357. At this point, we have addressed all we need prior to generating the
  358. image. The next two requirements are addressed during the final
  359. packaging of the release.
  360. By releasing the version of the OpenEmbedded build system and the layers
  361. used during the build, you will be providing both compilation scripts
  362. and the source code modifications in one step.
  363. If the deployment team has a :ref:`overview-manual/concepts:bsp layer`
  364. and a distro layer, and those
  365. those layers are used to patch, compile, package, or modify (in any way)
  366. any open source software included in your released images, you might be
  367. required to release those layers under section 3 of GPLv2 or section 1
  368. of GPLv3. One way of doing that is with a clean checkout of the version
  369. of the Yocto Project and layers used during your build. Here is an
  370. example:
  371. .. code-block:: shell
  372. # We built using the dunfell branch of the poky repo
  373. $ git clone -b dunfell git://git.yoctoproject.org/poky
  374. $ cd poky
  375. # We built using the release_branch for our layers
  376. $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
  377. $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
  378. # clean up the .git repos
  379. $ find . -name ".git" -type d -exec rm -rf {} \;
  380. One thing a development organization might want to consider for end-user
  381. convenience is to modify
  382. ``meta-poky/conf/templates/default/bblayers.conf.sample`` to ensure that when
  383. the end user utilizes the released build system to build an image, the
  384. development organization's layers are included in the ``bblayers.conf`` file
  385. automatically::
  386. # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
  387. # changes incompatibly
  388. POKY_BBLAYERS_CONF_VERSION = "2"
  389. BBPATH = "${TOPDIR}"
  390. BBFILES ?= ""
  391. BBLAYERS ?= " \
  392. ##OEROOT##/meta \
  393. ##OEROOT##/meta-poky \
  394. ##OEROOT##/meta-yocto-bsp \
  395. ##OEROOT##/meta-mylayer \
  396. "
  397. Creating and
  398. providing an archive of the :term:`Metadata`
  399. layers (recipes, configuration files, and so forth) enables you to meet
  400. your requirements to include the scripts to control compilation as well
  401. as any modifications to the original source.
  402. Compliance Limitations with Executables Built from Static Libraries
  403. -------------------------------------------------------------------
  404. When package A is added to an image via the :term:`RDEPENDS` or :term:`RRECOMMENDS`
  405. mechanisms as well as explicitly included in the image recipe with
  406. :term:`IMAGE_INSTALL`, and depends on a static linked library recipe B
  407. (``DEPENDS += "B"``), package B will neither appear in the generated license
  408. manifest nor in the generated source tarballs. This occurs as the
  409. :ref:`ref-classes-license` and :ref:`ref-classes-archiver` classes assume that
  410. only packages included via :term:`RDEPENDS` or :term:`RRECOMMENDS`
  411. end up in the image.
  412. As a result, potential obligations regarding license compliance for package B
  413. may not be met.
  414. The Yocto Project doesn't enable static libraries by default, in part because
  415. of this issue. Before a solution to this limitation is found, you need to
  416. keep in mind that if your root filesystem is built from static libraries,
  417. you will need to manually ensure that your deliveries are compliant
  418. with the licenses of these libraries.
  419. Copying Non Standard Licenses
  420. =============================
  421. Some packages, such as the linux-firmware package, have many licenses
  422. that are not in any way common. You can avoid adding a lot of these
  423. types of common license files, which are only applicable to a specific
  424. package, by using the
  425. :term:`NO_GENERIC_LICENSE`
  426. variable. Using this variable also avoids QA errors when you use a
  427. non-common, non-CLOSED license in a recipe.
  428. Here is an example that uses the ``LICENSE.Abilis.txt`` file as
  429. the license from the fetched source::
  430. NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"