[PATCH 2/2] firmware_loader: builtin: fail build on empty firmware

From: Dmitry Torokhov

Date: Sun Apr 26 2026 - 00:31:00 EST


If an empty firmware file is supplied via CONFIG_EXTRA_FIRMWARE, the
build currently succeeds but creates an empty section. While the
firmware loader will not return such sections it is better to avoid
adding them in the first place.

Add a compile-time size check to the filechk_fwbin macro to abort the
build early if a 0-size firmware is encountered.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
drivers/base/firmware_loader/builtin/Makefile | 32 +++++++++++--------
1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/drivers/base/firmware_loader/builtin/Makefile b/drivers/base/firmware_loader/builtin/Makefile
index 6c067dedc01e..af5b1bbb31e4 100644
--- a/drivers/base/firmware_loader/builtin/Makefile
+++ b/drivers/base/firmware_loader/builtin/Makefile
@@ -16,20 +16,24 @@ ASM_ALIGN = $(if $(CONFIG_64BIT),3,2)
PROGBITS = $(if $(CONFIG_ARM),%,@)progbits

filechk_fwbin = \
- echo "/* Generated by $(src)/Makefile */" ;\
- echo " .section .rodata" ;\
- echo " .p2align 4" ;\
- echo "_fw_$(FWSTR)_bin:" ;\
- echo " .incbin \"$(fwdir)/$(FWNAME)\"" ;\
- echo "_fw_end:" ;\
- echo " .section .rodata.str,\"aMS\",$(PROGBITS),1" ;\
- echo " .p2align $(ASM_ALIGN)" ;\
- echo "_fw_$(FWSTR)_name:" ;\
- echo " .string \"$(FWNAME)\"" ;\
- echo " .section .builtin_fw,\"a\",$(PROGBITS)" ;\
- echo " .p2align $(ASM_ALIGN)" ;\
- echo " $(ASM_WORD) _fw_$(FWSTR)_name" ;\
- echo " $(ASM_WORD) _fw_$(FWSTR)_bin" ;\
+ if [ ! -s "$(fwdir)/$(FWNAME)" ]; then \
+ echo "error: empty firmware: $(fwdir)/$(FWNAME)" >&2 ;\
+ exit ;\
+ fi ;\
+ echo "/* Generated by $(src)/Makefile */" ;\
+ echo " .section .rodata" ;\
+ echo " .p2align 4" ;\
+ echo "_fw_$(FWSTR)_bin:" ;\
+ echo " .incbin \"$(fwdir)/$(FWNAME)\"" ;\
+ echo "_fw_end:" ;\
+ echo " .section .rodata.str,\"aMS\",$(PROGBITS),1" ;\
+ echo " .p2align $(ASM_ALIGN)" ;\
+ echo "_fw_$(FWSTR)_name:" ;\
+ echo " .string \"$(FWNAME)\"" ;\
+ echo " .section .builtin_fw,\"a\",$(PROGBITS)" ;\
+ echo " .p2align $(ASM_ALIGN)" ;\
+ echo " $(ASM_WORD) _fw_$(FWSTR)_name" ;\
+ echo " $(ASM_WORD) _fw_$(FWSTR)_bin" ;\
echo " $(ASM_WORD) _fw_end - _fw_$(FWSTR)_bin"

$(obj)/%.gen.S: FORCE
--
2.54.0.545.g6539524ca2-goog