Skip to content

Improve license handling#662

Open
masami256 wants to merge 2 commits into
miraclelinux:emlinux3from
masami256:improve-license-handling
Open

Improve license handling#662
masami256 wants to merge 2 commits into
miraclelinux:emlinux3from
masami256:improve-license-handling

Conversation

@masami256

@masami256 masami256 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

This PR contains following 2 commits.

  1. scripts: Sort layer list by its priority
  2. sbom: Improbe license handling

Changes in "scripts: Sort layer list by its priority"

The find_layer() returns layer list that sort order is definition order in
bblayer.conf.
However, it would be useful that list is sorted by layer priority to know which
is most prioritized.

Changes in "sbom: Improbe license handling"

This commit improbe license handling with following changes.

  1. Allow dictionaly data in licenses.yml file
  2. Create extra license information by using external_references data
  3. Supoort to have licenses.yml file in each layers

The 1st change allow dictionary data in licenses.yml file to write license text into sbom file.
Current format is following list.

debian binary package name:
  licenses: [
    "LICENSE A",
    "LICENSE B"
  ]

New fommat allows following 3 formats.

A: Current format style

debian binary package name:
  licenses: [
    "LICENSE_A",
    "LICENSE_B"
  ]

B: Anather list format

debian binary package name:
  licenses:
    - LICENSE_A
    - LICENSE_B

C: Dictionary format

debian binary package name:
  licenses:
    license:
      - LICENSE_A
      - LICENSE_B
      - LICENSE_C
    text:
      LICENSE_C: <debian binary package name>/LICENSE_C.txt

A and B is same meaning that only diffrence is style.
So, C is new format.
If LICENSE_A and LICENSE_B is SPDX ID, you don't have to add license text in the sbom.
However, if LICENSE is not in SPDX ID list (https://spdx.org/licenses/), you need to add license text in the sbom.
Format C support this feature.

You can put license text file in /conf/licenses/license_texts directory. So, you need to create directory in the license_texts directory then put license text.
If path is not absolute path, script makes file path to /conf/licenses/license_texts//.
If path si absolute path, scripte read from it by given path.

For example, libbpf1 package contains License line "GPL-2 with Linux-syscall-note exception" which is not in the SPDX license id list.
So, we create extra license using LicenseRef- prefix.

"licenseConcluded": "(LGPL-2.1-only OR BSD-2-Clause) AND GPL-2.0-only AND LicenseRef-libbpf1-GPL-2-with-Linux-syscall-note-exception-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4 AND GPL-2.0-or-later",

Also, we insert license text into the sbom in hasExtractedLicensingInfos section in SPDX fomat sbom.

        {
            "extractedText": "NOTE! This copyright does *not* cover user programs that use kernel services\nby normal system calls - this is merely considered normal use of the kernel,\nand does *not* fall under
 the heading of \"derived work\". Also note that the\nGPL below is copyrighted by the Free Software Foundation, but the instance of\ncode that it refers to (the Linux kernel) is copyrighted by me and others who\
nactually wrote it.\n\nAlso note that the only valid version of the GPL as far as the kernel is\nconcerned is _this_ particular version of the license (ie v2, not v2.2 or v3.x\nor whatever), unless explicitly ot
herwise stated.\n\nLinus Torvalds\n\nThis program is free software; you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation; vers
ion 2 of the License.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program; if not, write to the Free Software Foundation, Inc.,\n51 Franklin
 St, Fifth Floor, Boston, MA 02110-1301, USA.\n\nOn Debian and systems the full text of the GNU General Public\nLicense version 2 can be found in the file\n\"/usr/share/common-licenses/GPL-2\".",
            "licenseId": "LicenseRef-libbpf1-GPL-2-with-Linux-syscall-note-exception-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
            "name": "Custom License for libbpf1 LicenseRef-libbpf1-GPL-2-with-Linux-syscall-note-exception-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4"
        },

CycloneDX format sbom also contains license text.

                {
                    "license": {
                        "name": "LicenseRef-libbpf1-GPL-2-with-Linux-syscall-note-exception-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
                        "text": {
                            "content": "NOTE! This copyright does *not* cover user programs that use kernel services\nby normal system calls - this is merely considered normal use of the kernel,\nand does *not* fall under the heading of \"derived work\". Also note that the\nGPL below is copyrighted by the Free Software Foundation, but the instance of\ncode that it refers to (the Linux kernel) is copyrighted by me and others who\nactually wrote it.\n\nAlso note that the only valid version of the GPL as far as the kernel is\nconcerned is _this_ particular version of the license (ie v2, not v2.2 or v3.x\nor whatever), unless explicitly otherwise stated.\n\nLinus Torvalds\n\nThis program is free software; you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation; version 2 of the License.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program; if not, write to the Free Software Foundation, Inc.,\n51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.\n\nOn Debian and systems the full text of the GNU General Public\nLicense version 2 can be found in the file\n\"/usr/share/common-licenses/GPL-2\".",
                            "contentType": "text/plain"
                        }
                    }
                }

We create above data as far as we can parse Debian's copyright file. If we cannot parse it, maybe copyright file format is old style, we need to license information in licenses.yml file.
Even if we cannot get license informaion from copyright file and licenses.yml file, we set license to "NOASSERTION".

By this improvement, even if we don't have licenses information from licenses directory, we can create sbom without errors.

For test, rename the licenses directory to any name then create sbom.

$ mv licenses/ aaa

Create SPDX format sbom.

2026-07-09 05:17:56,235:WARNING: x11-xkb-utils: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:17:56,235:WARNING: xkb-data: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:17:56,235:WARNING: xserver-common: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:17:56,235:WARNING: xwayland: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:17:56,235:WARNING: xwayland-init: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:17:56,405:INFO: Create spdx format sbom for emlinux-image-weston
2026-07-09 05:17:56,695:INFO: sbom was created to /home/build/work/build/tmp/deploy/sbom/emlinux-image-weston-emlinux-bookworm-imx8mpevk/emlinux-image-weston-spdx.json
build@235302c2d5ac:~/work$ view /home/build/work/build/tmp/deploy/sbom/emlinux-image-weston-emlinux-bookworm-imx8mpevk/emlinux-image-weston-spdx.json

Create CycloneDX format sbom.

2026-07-09 05:15:46,184:WARNING: x11-xkb-utils: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:15:46,184:WARNING: xkb-data: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:15:46,184:WARNING: xserver-common: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:15:46,184:WARNING: xwayland: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:15:46,184:WARNING: xwayland-init: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:15:46,355:INFO: Create spdx format sbom for emlinux-image-weston
2026-07-09 05:15:46,644:INFO: sbom was created to /home/build/work/build/tmp/deploy/sbom/emlinux-image-weston-emlinux-bookworm-imx8mpevk/emlinux-image-weston-spdx.json

Both show warnings because we couldn't read lincense information from copyright file, but sbom files were created.

Change 3 is support to have layer's own licenses.yml file to manage licneses for layer's own packages.
Direcotry structure is same as meta-emlinux's one.

In custom layer, you can have following data.

├── licenses.yml
└── license_texts
    └── bash
        └── FOO.txt

The licenses.yml is following text.

bash:
  licenses:
    license:
      - FOO
    text:
      FOO: bash/FOO.txt

Foo.txt file contains "Test LICENSE" in it.

So, sbom has following data.

        {
            "extractedText": "Test LICENSE\n",
            "licenseId": "LicenseRef-bash-FOO-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
            "name": "Custom License for bash LicenseRef-bash-FOO-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4"
        },
>>> snip <<<
            "licenseConcluded": "LicenseRef-bash-FOO-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
            "licenseDeclared": "LicenseRef-bash-FOO-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",

To do this, we collect license information and create license information. In the process we create license ids that are SPDX ID style license ID because CycloneDX allows SPDX style ID. Then, create SBOM for SPDX or CycloneDX.

Test

Create SPDX and CycloneDX sbom

Build emlinux-image-weston with following setting.

MACHINE="qemu-arm64"
DISTRO="emlinux-bookworm"

Then run following commands.

create_sbom.py
--distro bookworm
--image emlinux-image-weston
--supplier "Cybertrust Japan Co., Ltd."
--product EMLinux3
--sbom-format spdx

create_sbom.py \
    --distro bookworm \
    --image emlinux-image-weston \
    --supplier "Cybertrust Japan Co., Ltd." \
    --product EMLinux3 \
    --sbom-format cyclonedx

Build emlinux-image-weston with following setting.

MACHINE="qemu-arm64"
DISTRO="emlinux-trixie"

Then, run following commans.

create_sbom.py \
    --distro trixie \
    --image emlinux-image-weston \
    --supplier "Cybertrust Japan Co., Ltd." \
    --product EMLinux3 \
    --sbom-format spdx
create_sbom.py \
    --distro trixie \
    --image emlinux-image-weston \
    --supplier "Cybertrust Japan Co., Ltd." \
    --product EMLinux3 \
    --sbom-format cyclonedx

Check license text

This check doesn't matter what MACHINE and DISTRO pair, and sbom format are used.

After creating sbom files, check license text.

Create sbom without any license mapping file

This check doesn't matter what MACHINE and DISTRO pair is used.

Rename conf/licenses directory to conf/aaa in the meta-emlinux directory.
Then create sbom file.

Use user defined licenses file

This check doesn't matter what MACHINE and DISTRO pair, and sbom format are used.

Case 1, put licenses.yml in a custome layer

Prepare:

  1. Create meta-custom layer and add it to conf/bblayers.conf
    2 Setup following directory structure in meta-custom/conf.
├── licenses.yml
└── license_texts
    └── bash
        └── FOO.txt

The licenses.yml file is here.

bash:
  licenses:
    license:
      - FOO
    text:
      FOO: bash/FOO.txt

license_texts/bash/FOO.txt is here.

Test LICENSE

Then create sbom.

Case 2, pass path to the licenses.yml by command line argument

Prepare:

  1. Remove Case 1's setting.
  2. Create licenses.yml in any directory
  3. Create license text file in any direcotry

licenses.yml is here

bash:
  licenses:
    license:
      - FOO
    text:
      FOO: /home/build/work/FOO.txt

Foo.txt is here

User defined Test LICENSE

Then create sbom such as following command.

create_sbom.py \
    --distro trixie \
    --image emlinux-image-weston \
    --supplier "Cybertrust Japan Co., Ltd." \
    --product EMLinux3 \
    --sbom-format spdx \
    --licenses /home/build/work/licenses.yml

Use user defined license mapping file

This check doesn't matter what MACHINE and DISTRO pair, and sbom format are used.

Before create sbom, check dash's license from already created sbom. It has publi-comain license.

            "licenseConcluded": "BSD-3-Clause AND LicenseRef-dash-public-domain-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4 AND GPL-2.0-or-later AND BSD-3-Clause",

Case 1, put license-mapping.yml in a custom layer

Prepare:

  1. Create meta-custom layer and add it to conf/bblayers.conf
    2 Put license-mapping as meta-custom/conf/licenses/license-mapping.yml.

File is here. It replace public-domain to CC-BY-1.0.

"public-domain": "CC-BY-1.0" 

Then create sbom.

Case 2, use license-mapping.yml passing by command line

  1. Remove Case 1's setting.
  2. Create license-mapping.yml in any directory

File is here.

"public-domain": "CC-BY-2.0"

Then create sbom such as following command.

create_sbom.py \
    --distro trixie \
    --image emlinux-image-weston \
    --supplier "Cybertrust Japan Co., Ltd." \
    --product EMLinux3 \
    --sbom-format spdx \
    --license-mapping /home/build/work/license-mapping.yml

Test result

Create SPDX and CycloneDX sbom

Sbom files were created without any warnings.

SPDX sbom for emlinux-bookworm.

build@9767de56dc41:~/work$ create_sbom.py \
    --distro bookworm \
    --image emlinux-image-weston \
    --supplier "Cybertrust Japan Co., Ltd." \
    --product EMLinux3 \
    --sbom-format spdx
2026-07-09 23:57:42,360:INFO: Create spdx format sbom for emlinux-image-weston
2026-07-09 23:57:42,504:INFO: sbom was created to /home/build/work/build/tmp/deploy/sbom/emlinux-image-weston-emlinux-bookworm-qemu-arm64/emlinux-image-weston-spdx.json

CycloneDX sbom for emlinux-bookworm.

build@9767de56dc41:~/work$ create_sbom.py \
    --distro bookworm \
    --image emlinux-image-weston \
    --supplier "Cybertrust Japan Co., Ltd." \
    --product EMLinux3 \
    --sbom-format cyclonedx
2026-07-09 23:58:27,533:INFO: Create cyclonedx format sbom for emlinux-image-weston
2026-07-09 23:58:27,760:INFO: sbom was created to /home/build/work/build/tmp/deploy/sbom/emlinux-image-weston-emlinux-bookworm-qemu-arm64/emlinux-image-weston-cyclonedx.json

SPDX sbom for emlinux-trixie.

build@9767de56dc41:~/work$ create_sbom.py \
    --distro trixie \
    --image emlinux-image-weston \
    --supplier "Cybertrust Japan Co., Ltd." \
    --product EMLinux3 \
    --sbom-format spdx
2026-07-10 01:24:32,372:INFO: Create spdx format sbom for emlinux-image-weston
2026-07-10 01:24:32,546:INFO: sbom was created to /home/build/work/build/tmp/deploy/sbom/emlinux-image-weston-emlinux-trixie-qemu-arm64/emlinux-image-weston-spdx.json

CycloneDX sbom for emlinux-trixie.

build@9767de56dc41:~/work$ create_sbom.py \
    --distro trixie \
    --image emlinux-image-weston \
    --supplier "Cybertrust Japan Co., Ltd." \
    --product EMLinux3 \
    --sbom-format cyclonedx
2026-07-10 01:25:14,237:INFO: Create cyclonedx format sbom for emlinux-image-weston
2026-07-10 01:25:14,501:INFO: sbom was created to /home/build/work/build/tmp/deploy/sbom/emlinux-image-weston-emlinux-trixie-qemu-arm64/emlinux-image-weston-cyclonedx.json

Check license text

In the kmod package, there is no LicenseRef- ID.

SPDX sbom

            "licenseConcluded": "LGPL-2.1-or-later AND GPL-2.0-or-later",

CycloneDX sbom

                {
                    "expression": "LGPL-2.1-or-later AND GPL-2.0-or-later"
                }

In the systemd-sysv, there are license text are stored that are extracted from Copyright file.

SPDX sbom

        {
            "extractedText": "NOTE! This copyright does *not* cover user programs that use kernel services\nby normal system calls - this is merely considered normal use of the kernel,\nand does *not* fall under
 the heading of \"derived work\". Also note that the\nGPL below is copyrighted by the Free Software Foundation, but the instance of\ncode that it refers to (the Linux kernel) is copyrighted by me and others who\
nactually wrote it.\n\nAlso note that the only valid version of the GPL as far as the kernel is\nconcerned is _this_ particular version of the license (ie v2, not v2.2 or v3.x\nor whatever), unless explicitly ot
herwise stated.\n\nLinus Torvalds\n\nThis program is free software; you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation; vers
ion 2 of the License.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program; if not, write to the Free Software Foundation, Inc.,\n51 Franklin
 St, Fifth Floor, Boston, MA 02110-1301, USA.\n\nOn Debian and systems the full text of the GNU General Public\nLicense version 2 can be found in the file\n`/usr/share/common-licenses/GPL-2`",
            "licenseId": "LicenseRef-systemd-sysv-GPL-2-with-Linux-syscall-note-exception-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
            "name": "Custom License for systemd-sysv LicenseRef-systemd-sysv-GPL-2-with-Linux-syscall-note-exception-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4"
        },
        {
            "extractedText": "You can use this free for any purpose. It's in the public domain. It has no\nwarranty.",
            "licenseId": "LicenseRef-systemd-sysv-public-domain-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
            "name": "Custom License for systemd-sysv LicenseRef-systemd-sysv-public-domain-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4"
        },

>>> snip <<<
            "licenseConcluded": "LGPL-2.1-or-later AND CC0-1.0 AND LicenseRef-systemd-sysv-GPL-2-with-Linux-syscall-note-exception-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4 AND MIT AND LicenseRef-systemd-sysv-public-domain-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4 AND GPL-2.0-or-later",

CycloneDX sbom

                {
                    "license": {
                        "name": "LicenseRef-systemd-sysv-public-domain-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
                        "text": {
                            "content": "You can use this free for any purpose. It's in the public domain. It has no\nwarranty.",
                            "contentType": "text/plain"
                        }
                    }
                },
                {
                    "license": {
                        "name": "MIT"
                    }
                }

Create sbom without any license mapping file

In the libflite1, there are license text that copied from text file specified in the licenses.yml.

SPDX sbom

        {
            "extractedText": "Author:     Henry Spencer\n\nCopyright (c) 1986 by University of Toronto.\n\nLicense:\n\tPermission is granted to anyone to use this software for any\n   purpose on any computer system, and to redistribute it freely,\n   subject to the following restrictions:\n\n  1. The author is not responsible for the consequences of use of\n       this software, no matter how awful, even if they arise\n       from defects in it.\n\n  2. The origin of this software must not be misrepresented, either\n       by explicit claim or by omission.\n\n  3. Altered versions must be plainly marked as such, and must not\n       be misrepresented as being the original software.\n",
            "licenseId": "LicenseRef-libflite1-Henry-Spencer-Regexp-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
            "name": "Custom License for libflite1 LicenseRef-libflite1-Henry-Spencer-Regexp-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4"
        },

CycloneDX sbom

                    "license": {
                        "name": "LicenseRef-libflite1-Henry-Spencer-Regexp-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
                        "text": {
                            "content": "Author:     Henry Spencer\n\nCopyright (c) 1986 by University of Toronto.\n\nLicense:\n\tPermission is granted to anyone to use this software for any\n   purpose on any computer system, and to redistribute it freely,\n   subject to the following restrictions:\n\n  1. The author is not responsible for the consequences of use of\n       this software, no matter how awful, even if they arise\n       from defects in it.\n\n  2. The origin of this software must not be misrepresented, either\n       by explicit claim or by omission.\n\n  3. Altered versions must be plainly marked as such, and must not\n       be misrepresented as being the original software.\n",
                            "contentType": "text/plain"
                        }
                    }

Create sbom without any license mapping file

We got many warnings but sbom was created.

build@9767de56dc41:~/work$ mv repos/meta-emlinux/conf/licenses/ repos/meta-emlinux/conf/aaa
build@9767de56dc41:~/work$ create_sbom.py \
    --distro trixie \
    --image emlinux-image-weston \
    --supplier "Cybertrust Japan Co., Ltd." \
    --product EMLinux3 \
    --sbom-format spdx
>>> snip <<<
2026-07-10 01:38:47,483:WARNING: libgstreamer-plugins-base1.0-0: Cannot understand licence BSD (3 clause) so set 'NOASSERTION'
2026-07-10 01:38:47,483:WARNING: libgstreamer-plugins-base1.0-0: Cannot understand licence BSD (3 clause) so set 'NOASSERTION'
2026-07-10 01:38:47,484:WARNING: libgstreamer-plugins-base1.0-0: Cannot understand licence BSD (3 clause) so set 'NOASSERTION'
2026-07-10 01:38:47,484:WARNING: libgstreamer-plugins-base1.0-0: Cannot understand licence BSD (3 clause) so set 'NOASSERTION'
2026-07-10 01:38:47,484:WARNING: libgstreamer-plugins-base1.0-0: Cannot understand licence BSD (3 clause) so set 'NOASSERTION'
2026-07-10 01:38:47,484:WARNING: libgstreamer-plugins-base1.0-0: Cannot understand licence GPL-2+ so set 'NOASSERTION'
2026-07-10 01:38:47,486:WARNING: libgstreamer-plugins-base1.0-0: Cannot understand licence MIT/X11 (BSD like) LGPL-2+ so set 'NOASSERTION'
2026-07-10 01:38:47,486:WARNING: libgstreamer-plugins-base1.0-0: Cannot understand licence MIT/X11 (BSD like) LGPL-2+ so set 'NOASSERTION'
2026-07-10 01:38:47,486:WARNING: libgstreamer-plugins-base1.0-0: Cannot understand licence MIT/X11 (BSD like) LGPL-2+ so set 'NOASSERTION'
2026-07-10 01:38:47,557:INFO: Create spdx format sbom for emlinux-image-weston
2026-07-10 01:38:47,783:INFO: sbom was created to /home/build/work/build/tmp/deploy/sbom/emlinux-image-weston-emlinux-trixie-qemu-arm64/emlinux-image-weston-spdx.json

Some license is not parsed so these license is set to NOASSERTION in the sbom.

            "licenseConcluded": "LicenseRef-libgstreamer-plugins-base1.0-0-LGPL-2-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4 AND NOASSERTION AND CC-BY-SA-4.0 AND LicenseRef-libgstreamer-plugins-base1.0-0-public-domain-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4 AND LGPL-2.1-or-later AND BSD-3-Clause",

Use user defined licenses file

Case 1, put licenses.yml in a custome layer

bash's license was our test license.

        {
            "extractedText": "Test LICENSE\n",
            "licenseId": "LicenseRef-bash-FOO-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
            "name": "Custom License for bash LicenseRef-bash-FOO-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4"
        },
>>> snip <<<
            "licenseConcluded": "LicenseRef-bash-FOO-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",

Case 2, pass path to the licenses.yml by command line argument

bash's license was our test license.

        {
            "extractedText": "User defined Test LICENSE\n",
            "licenseId": "LicenseRef-bash-FOO-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
            "name": "Custom License for bash LicenseRef-bash-FOO-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4"
        },
>>> snip <<<
            "licenseConcluded": "LicenseRef-bash-FOO-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",

Use user defined license mapping file

Case 1, put license-mapping.yml in a custom layer

public-domain was replaced to CC-BY-1.0 in dash's license information

            "licenseConcluded": "BSD-3-Clause AND CC-BY-1.0 AND GPL-2.0-or-later AND BSD-3-Clause",

Case 2, use license-mapping.yml passing by command line

dash's license contains CC-BY-2.0 instead of public-domain.

            "licenseConcluded": "BSD-3-Clause AND CC-BY-2.0 AND GPL-2.0-or-later AND BSD-3-Clause",

The find_layer() returns layer list that sort order is definition order in
bblayer.conf.
However, it would be useful that list is sorted by layer priority to know which
is most prioritized.

Signed-off-by: Masami Ichikawa <masami.ichikawa@miraclelinux.com>
@masami256 masami256 force-pushed the improve-license-handling branch 5 times, most recently from 5bfc7d1 to f6af9dd Compare July 10, 2026 05:09
This commit improbe license handling with following changes.

1. Allow dictionaly data in licenses.yml file
2. Create extra license information by using external_references data
3. Supoort to have licenses.yml file in each layers

The 1st change allow dictionary data in licenses.yml file to write license text into sbom file.
Current format is following list.

```
debian binary package name:
  licenses: [
    "LICENSE A",
    "LICENSE B"
  ]
```

New fommat allows following 3 formats.

A: Current format style
```
debian binary package name:
  licenses: [
    "LICENSE_A",
    "LICENSE_B"
  ]
```

B: Anather list format

```
debian binary package name:
  licenses:
    - LICENSE_A
    - LICENSE_B
```

C: Dictionary format

```
debian binary package name:
  licenses:
    license:
      - LICENSE_A
      - LICENSE_B
      - LICENSE_C
    text:
      LICENSE_C: <debian binary package name>/LICENSE_C.txt
```

A and B is same meaning that only diffrence is style.
So, C is new format.
If LICENSE_A and LICENSE_B is SPDX ID, you don't have to add license text in the sbom.
However, if LICENSE is not in SPDX ID list (https://spdx.org/licenses/), you need to add license text in the sbom.
Format C support this feature.

You can put  license text file in <your layer>/conf/licenses/license_texts directory. So, you need to create directory in the license_texts directory then put license text.
If path is not absolute path, script makes file path to <your layer>/conf/licenses/license_texts/<debian package name>/<license text file name>.
If path si absolute path, scripte read from it by given path.

For example, libbpf1 package contains License line "GPL-2 with Linux-syscall-note exception" which is not in the SPDX license id list.
So, we create extra license using LicenseRef- prefix.

```
"licenseConcluded": "(LGPL-2.1-only OR BSD-2-Clause) AND GPL-2.0-only AND LicenseRef-libbpf1-GPL-2-with-Linux-syscall-note-exception-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4 AND GPL-2.0-or-later",
```

Also, we insert license text into the sbom in hasExtractedLicensingInfos section in SPDX fomat sbom.

```
        {
            "extractedText": "NOTE! This copyright does *not* cover user programs that use kernel services\nby normal system calls - this is merely considered normal use of the kernel,\nand does *not* fall under
 the heading of \"derived work\". Also note that the\nGPL below is copyrighted by the Free Software Foundation, but the instance of\ncode that it refers to (the Linux kernel) is copyrighted by me and others who\
nactually wrote it.\n\nAlso note that the only valid version of the GPL as far as the kernel is\nconcerned is _this_ particular version of the license (ie v2, not v2.2 or v3.x\nor whatever), unless explicitly ot
herwise stated.\n\nLinus Torvalds\n\nThis program is free software; you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation; vers
ion 2 of the License.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program; if not, write to the Free Software Foundation, Inc.,\n51 Franklin
 St, Fifth Floor, Boston, MA 02110-1301, USA.\n\nOn Debian and systems the full text of the GNU General Public\nLicense version 2 can be found in the file\n\"/usr/share/common-licenses/GPL-2\".",
            "licenseId": "LicenseRef-libbpf1-GPL-2-with-Linux-syscall-note-exception-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
            "name": "Custom License for libbpf1 LicenseRef-libbpf1-GPL-2-with-Linux-syscall-note-exception-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4"
        },
```

CycloneDX format sbom also contains license text.

```
                {
                    "license": {
                        "name": "LicenseRef-libbpf1-GPL-2-with-Linux-syscall-note-exception-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
                        "text": {
                            "content": "NOTE! This copyright does *not* cover user programs that use kernel services\nby normal system calls - this is merely considered normal use of the kernel,\nand does *not* fall under the heading of \"derived work\". Also note that the\nGPL below is copyrighted by the Free Software Foundation, but the instance of\ncode that it refers to (the Linux kernel) is copyrighted by me and others who\nactually wrote it.\n\nAlso note that the only valid version of the GPL as far as the kernel is\nconcerned is _this_ particular version of the license (ie v2, not v2.2 or v3.x\nor whatever), unless explicitly otherwise stated.\n\nLinus Torvalds\n\nThis program is free software; you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation; version 2 of the License.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program; if not, write to the Free Software Foundation, Inc.,\n51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.\n\nOn Debian and systems the full text of the GNU General Public\nLicense version 2 can be found in the file\n\"/usr/share/common-licenses/GPL-2\".",
                            "contentType": "text/plain"
                        }
                    }
                }
```

We create above data as far as we can parse Debian's copyright file. If we cannot parse it, maybe copyright file format is old style, we need to license information in licenses.yml file.
Even if we cannot get license informaion from copyright file and licenses.yml file, we set license to "NOASSERTION".

By this improvement, even if we don't have licenses information from licenses directory, we can create sbom without errors.

For test, rename the licenses directory to any name then create sbom.

```
$ mv licenses/ aaa
```

Create SPDX format sbom.

```
2026-07-09 05:17:56,235:WARNING: x11-xkb-utils: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:17:56,235:WARNING: xkb-data: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:17:56,235:WARNING: xserver-common: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:17:56,235:WARNING: xwayland: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:17:56,235:WARNING: xwayland-init: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:17:56,405:INFO: Create spdx format sbom for emlinux-image-weston
2026-07-09 05:17:56,695:INFO: sbom was created to /home/build/work/build/tmp/deploy/sbom/emlinux-image-weston-emlinux-bookworm-imx8mpevk/emlinux-image-weston-spdx.json
build@235302c2d5ac:~/work$ view /home/build/work/build/tmp/deploy/sbom/emlinux-image-weston-emlinux-bookworm-imx8mpevk/emlinux-image-weston-spdx.json
```

Create CycloneDX format sbom.

```
2026-07-09 05:15:46,184:WARNING: x11-xkb-utils: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:15:46,184:WARNING: xkb-data: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:15:46,184:WARNING: xserver-common: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:15:46,184:WARNING: xwayland: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:15:46,184:WARNING: xwayland-init: Cannot get licenses from Copyright file and user defined license mapping file. So, set NOASSERTION as license.
2026-07-09 05:15:46,355:INFO: Create spdx format sbom for emlinux-image-weston
2026-07-09 05:15:46,644:INFO: sbom was created to /home/build/work/build/tmp/deploy/sbom/emlinux-image-weston-emlinux-bookworm-imx8mpevk/emlinux-image-weston-spdx.json
```

Both show warnings because we couldn't read lincense information from copyright file, but sbom files were created.

Change 3 is support to have layer's own licenses.yml file to manage licneses for layer's own packages.
Direcotry structure is same as meta-emlinux's one.

In custom layer, you can have following data.

```
├── licenses.yml
└── license_texts
    └── bash
        └── FOO.txt
```

The licenses.yml is following text.

```
bash:
  licenses:
    license:
      - FOO
    text:
      FOO: bash/FOO.txt
```

Foo.txt file contains "Test LICENSE" in it.

So, sbom has following data.

```
        {
            "extractedText": "Test LICENSE\n",
            "licenseId": "LicenseRef-bash-FOO-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
            "name": "Custom License for bash LicenseRef-bash-FOO-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4"
        },
>>> snip <<<
            "licenseConcluded": "LicenseRef-bash-FOO-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
            "licenseDeclared": "LicenseRef-bash-FOO-d5d4d27955c443937234e4e20fd0c460abf55feca458146b2da47b4ab4bcd3e4",
```

Signed-off-by: Masami Ichikawa <masami.ichikawa@miraclelinux.com>
@masami256 masami256 force-pushed the improve-license-handling branch from f6af9dd to 8d351af Compare July 10, 2026 05:11
@masami256 masami256 marked this pull request as ready for review July 10, 2026 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant