diff mbox series

linux: allow firmware to be included in kernel

Message ID 20210422202452.41704-1-sam.voss@rockwellcollins.com
State Superseded
Headers show
Series linux: allow firmware to be included in kernel | expand

Commit Message

Sam Voss April 22, 2021, 8:24 p.m. UTC
Add functionality to use the kernel's built-in options to allow binary
blobs to be included with the kernel. This is equivalent to the blobs
existing in /lib/firmware, however are available earlier in the boot
process. This may be useful in situations where a device probes before
the rootfs is fully available (such as a squashfs not being loaded
before a usb device probing).

Signed-off-by: Sam Voss <sam.voss@rockwellcollins.com>
---
 linux/Config.in | 13 +++++++++++++
 linux/linux.mk  |  7 ++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

Comments

Thomas Petazzoni April 22, 2021, 8:55 p.m. UTC | #1
Hello Sam,

On Thu, 22 Apr 2021 15:24:52 -0500
Sam Voss <sam.voss@rockwellcollins.com> wrote:

> Add functionality to use the kernel's built-in options to allow binary
> blobs to be included with the kernel. This is equivalent to the blobs
> existing in /lib/firmware, however are available earlier in the boot
> process. This may be useful in situations where a device probes before
> the rootfs is fully available (such as a squashfs not being loaded
> before a usb device probing).
> 
> Signed-off-by: Sam Voss <sam.voss@rockwellcollins.com>

Including firmware in the kernel itself has some serious licensing
implications: it only works for firmware files that have a license that
is compatible with the GPL. If their license is not GPL-compatible,
then you cannot redistribute your kernel image.

Here is the help text of the corresponding option in the Linux kernel:

          WARNING: If you include additional firmware files into your binary
          kernel image that are not available under the terms of the GPL,
          then it may be a violation of the GPL to distribute the resulting
          image since it combines both GPL and non-GPL work. You should
          consult a lawyer of your own before distributing such an image.

I am not a lawyer, but I think the wording is a bit unfortunate: I
think if the firmware is under a license that is compatible with the
GPL, it is fine. But if it has a non GPL-compatible license, it's a
no-go.

So I would be OK to include this, but with the appropriate warning in
the Buildroot options.

Best regards,

Thomas
Sam Voss April 22, 2021, 9 p.m. UTC | #2
Hey Thomas,

On Thu, Apr 22, 2021 at 3:55 PM Thomas Petazzoni
<thomas.petazzoni@bootlin.com> wrote:
>
> Hello Sam,
>
> On Thu, 22 Apr 2021 15:24:52 -0500
> Sam Voss <sam.voss@rockwellcollins.com> wrote:
>
> > Add functionality to use the kernel's built-in options to allow binary
> > blobs to be included with the kernel. This is equivalent to the blobs
> > existing in /lib/firmware, however are available earlier in the boot
> > process. This may be useful in situations where a device probes before
> > the rootfs is fully available (such as a squashfs not being loaded
> > before a usb device probing).
> >
> > Signed-off-by: Sam Voss <sam.voss@rockwellcollins.com>
>
> Including firmware in the kernel itself has some serious licensing
> implications: it only works for firmware files that have a license that
> is compatible with the GPL. If their license is not GPL-compatible,
> then you cannot redistribute your kernel image.
>
> Here is the help text of the corresponding option in the Linux kernel:
>
>           WARNING: If you include additional firmware files into your binary
>           kernel image that are not available under the terms of the GPL,
>           then it may be a violation of the GPL to distribute the resulting
>           image since it combines both GPL and non-GPL work. You should
>           consult a lawyer of your own before distributing such an image.
>
> I am not a lawyer, but I think the wording is a bit unfortunate: I
> think if the firmware is under a license that is compatible with the
> GPL, it is fine. But if it has a non GPL-compatible license, it's a
> no-go.

I completely agree with everything you said here - I had investigated
(based on the kernels warning text) my use case, but had not
considered wanting to propagate that warning out into the buildroot
option as well

>
> So I would be OK to include this, but with the appropriate warning in
> the Buildroot options.

I'll add that warning and send a v2 here momentarily.

Thanks for the quick review,
diff mbox series

Patch

diff --git a/linux/Config.in b/linux/Config.in
index 2460c3f124..ef0d9f79ea 100644
--- a/linux/Config.in
+++ b/linux/Config.in
@@ -479,6 +479,19 @@  config BR2_LINUX_KERNEL_NEEDS_HOST_LIBELF
 	  CONFIG_UNWINDER_ORC=y, please install libelf-dev,
 	  libelf-devel or elfutils-libelf-devel".
 
+config BR2_LINUX_KERNEL_EXTRA_FIRMWARE
+	bool "Build firmware binaries into the kernel"
+	help
+	  Include the firmware from linux-firmware into the kernel
+	  using the CONFIG_EXTRA_FIRMWARE option.
+
+config BR2_LINUX_KERNEL_EXTRA_FIRMWARE_BINARIES
+	string "External firmware blobs to build into the kernel binary"
+	depends on BR2_LINUX_KERNEL_EXTRA_FIRMWARE
+	help
+	  Space delimited list of firmware to be built into the kernel.
+	  These files must exist in the target's /lib/firmware.
+
 # Linux extensions
 source "linux/Config.ext.in"
 
diff --git a/linux/linux.mk b/linux/linux.mk
index b67f739ca0..d581dd7f5d 100644
--- a/linux/linux.mk
+++ b/linux/linux.mk
@@ -78,7 +78,8 @@  LINUX_MAKE_ENV = \
 
 LINUX_INSTALL_IMAGES = YES
 LINUX_DEPENDENCIES += host-kmod \
-	$(if $(BR2_PACKAGE_INTEL_MICROCODE),intel-microcode)
+	$(if $(BR2_PACKAGE_INTEL_MICROCODE),intel-microcode) \
+	$(if $(BR2_LINUX_KERNEL_EXTRA_FIRMWARE),linux-firmware)
 
 # Starting with 4.16, the generated kconfig paser code is no longer
 # shipped with the kernel sources, so we need flex and bison, but
@@ -384,6 +385,10 @@  define LINUX_KCONFIG_FIXUP_CMDS
 		$(call KCONFIG_ENABLE_OPT,CONFIG_FB)
 		$(call KCONFIG_ENABLE_OPT,CONFIG_LOGO)
 		$(call KCONFIG_ENABLE_OPT,CONFIG_LOGO_LINUX_CLUT224))
+	$(if $(BR2_LINUX_KERNEL_EXTRA_FIRMWARE),
+		$(call KCONFIG_ENABLE_OPT,CONFIG_FIRMWARE_IN_KERNEL)
+		$(call KCONFIG_SET_OPT,CONFIG_EXTRA_FIRMWARE,$(BR2_LINUX_KERNEL_EXTRA_FIRMWARE_BINARIES))
+		$(call KCONFIG_SET_OPT,CONFIG_EXTRA_FIRMWARE_DIR,"$(TARGET_DIR)/lib/firmware"))
 	$(call KCONFIG_DISABLE_OPT,CONFIG_GCC_PLUGINS)
 	$(PACKAGES_LINUX_CONFIG_FIXUPS)