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