[PATCH 2/2] firmware_loader: Enable compressed files in EXTRA_FIRMWARE

Kevin Martin posted 2 patches 2 years ago
There is a newer version of this series
[PATCH 2/2] firmware_loader: Enable compressed files in EXTRA_FIRMWARE
Posted by Kevin Martin 2 years ago
The linux-firmware packages on Gentoo, Fedora, Arch, and others compress
the firmware files. This works well with CONFIG_FW_LOADER_COMPRESS, but
does not work with CONFIG_EXTRA_FIRMWARE. This patch allows the build
system to decompress firmware files specified by CONFIG_EXTRA_FIRMWARE.
Uncompressed files are used first, then the compressed files are used.

Signed-off-by: Kevin Martin <kevinmbecause@gmail.com>
---
 drivers/base/firmware_loader/Kconfig          |  5 ++++-
 drivers/base/firmware_loader/builtin/Makefile | 16 ++++++++++++----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/base/firmware_loader/Kconfig b/drivers/base/firmware_loader/Kconfig
index 5ca00e02f..b7a908bff 100644
--- a/drivers/base/firmware_loader/Kconfig
+++ b/drivers/base/firmware_loader/Kconfig
@@ -76,7 +76,10 @@ config EXTRA_FIRMWARE
 	  image since it combines both GPL and non-GPL work. You should
 	  consult a lawyer of your own before distributing such an image.
 
-	  NOTE: Compressed files are not supported in EXTRA_FIRMWARE.
+	  NOTE: Compressed files are supported by EXTRA_FIRMWARE. The build
+	  system will look for uncompressed files first then fall back to
+	  searching for compressed files in a similar way to
+	  CONFIG_FW_LOADER_COMPRESS.
 
 config EXTRA_FIRMWARE_DIR
 	string "Firmware blobs root directory"
diff --git a/drivers/base/firmware_loader/builtin/Makefile b/drivers/base/firmware_loader/builtin/Makefile
index 6c067dedc..cc60eb441 100644
--- a/drivers/base/firmware_loader/builtin/Makefile
+++ b/drivers/base/firmware_loader/builtin/Makefile
@@ -20,7 +20,7 @@ filechk_fwbin = \
 	echo "    .section .rodata"				;\
 	echo "    .p2align 4"					;\
 	echo "_fw_$(FWSTR)_bin:"				;\
-	echo "    .incbin \"$(fwdir)/$(FWNAME)\""		;\
+	echo "    .incbin \"$(obj)/$(FWNAME)\""		;\
 	echo "_fw_end:"						;\
 	echo "    .section .rodata.str,\"aMS\",$(PROGBITS),1"	;\
 	echo "    .p2align $(ASM_ALIGN)"			;\
@@ -36,7 +36,15 @@ $(obj)/%.gen.S: FORCE
 	$(call filechk,fwbin)
 
 # The .o files depend on the binaries directly; the .S files don't.
-$(addprefix $(obj)/, $(firmware)): $(obj)/%.gen.o: $(fwdir)/%
+$(addprefix $(obj)/, $(firmware)): $(obj)/%.gen.o: $(obj)/%
 
-targets := $(patsubst $(obj)/%,%, \
-                                $(shell find $(obj) -name \*.gen.S 2>/dev/null))
+$(obj)/% : $(fwdir)/% FORCE
+	$(call if_changed,copy)
+
+$(obj)/% : $(fwdir)/%.xz FORCE
+	$(call if_changed,xzdec)
+
+$(obj)/% : $(fwdir)/%.zst FORCE
+	$(call if_changed,zstddec)
+
+targets := $(patsubst %.gen.o, %.gen.S, $(firmware)) $(CONFIG_EXTRA_FIRMWARE)
-- 
2.41.0
Re: [PATCH 2/2] firmware_loader: Enable compressed files in EXTRA_FIRMWARE
Posted by Masahiro Yamada 1 year, 11 months ago
On Wed, Dec 20, 2023 at 7:33 PM Kevin Martin <kevinmbecause@gmail.com> wrote:
>
> The linux-firmware packages on Gentoo, Fedora, Arch, and others compress
> the firmware files. This works well with CONFIG_FW_LOADER_COMPRESS, but
> does not work with CONFIG_EXTRA_FIRMWARE. This patch allows the build
> system to decompress firmware files specified by CONFIG_EXTRA_FIRMWARE.
> Uncompressed files are used first, then the compressed files are used.







>
> Signed-off-by: Kevin Martin <kevinmbecause@gmail.com>
> ---
>  drivers/base/firmware_loader/Kconfig          |  5 ++++-
>  drivers/base/firmware_loader/builtin/Makefile | 16 ++++++++++++----
>  2 files changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/base/firmware_loader/Kconfig b/drivers/base/firmware_loader/Kconfig
> index 5ca00e02f..b7a908bff 100644
> --- a/drivers/base/firmware_loader/Kconfig
> +++ b/drivers/base/firmware_loader/Kconfig
> @@ -76,7 +76,10 @@ config EXTRA_FIRMWARE
>           image since it combines both GPL and non-GPL work. You should
>           consult a lawyer of your own before distributing such an image.
>
> -         NOTE: Compressed files are not supported in EXTRA_FIRMWARE.
> +         NOTE: Compressed files are supported by EXTRA_FIRMWARE. The build
> +         system will look for uncompressed files first then fall back to
> +         searching for compressed files in a similar way to
> +         CONFIG_FW_LOADER_COMPRESS.
>
>  config EXTRA_FIRMWARE_DIR
>         string "Firmware blobs root directory"
> diff --git a/drivers/base/firmware_loader/builtin/Makefile b/drivers/base/firmware_loader/builtin/Makefile
> index 6c067dedc..cc60eb441 100644
> --- a/drivers/base/firmware_loader/builtin/Makefile
> +++ b/drivers/base/firmware_loader/builtin/Makefile
> @@ -20,7 +20,7 @@ filechk_fwbin = \
>         echo "    .section .rodata"                             ;\
>         echo "    .p2align 4"                                   ;\
>         echo "_fw_$(FWSTR)_bin:"                                ;\
> -       echo "    .incbin \"$(fwdir)/$(FWNAME)\""               ;\
> +       echo "    .incbin \"$(obj)/$(FWNAME)\""         ;\




Insert a tab to keep the alignment of ";\"




Also, please update the .gitignore because
any arbitrary firmware file might be copied to
this directory.
All files except the 3 check-in files must be
ignored.



@@ -1,2 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
-*.gen.S
+*
+!.gitignore
+!Makefile
+!main.c









--
Best Regards
Masahiro Yamada
Re: [PATCH 2/2] firmware_loader: Enable compressed files in EXTRA_FIRMWARE
Posted by Nicolas Schier 1 year, 12 months ago
On Wed, Dec 20, 2023 at 05:29:33AM -0500, Kevin Martin wrote:
> The linux-firmware packages on Gentoo, Fedora, Arch, and others compress
> the firmware files. This works well with CONFIG_FW_LOADER_COMPRESS, but
> does not work with CONFIG_EXTRA_FIRMWARE. This patch allows the build
> system to decompress firmware files specified by CONFIG_EXTRA_FIRMWARE.
> Uncompressed files are used first, then the compressed files are used.
> 
> Signed-off-by: Kevin Martin <kevinmbecause@gmail.com>
> ---

Tested-by: Nicolas Schier <n.schier@avm.de>