Skip to content

Commit df85b2d

Browse files
Markus Trippelsdorftorvalds
Markus Trippelsdorf
authored andcommitted
firmware: Restore support for built-in firmware
Commit 5620a0d ("firmware: delete in-kernel firmware") removed the entire firmware directory. Unfortunately it thereby also removed the support for built-in firmware. This restores the ability to build firmware directly into the kernel by pruning the original Makefile to the necessary minimum. The default for EXTRA_FIRMWARE_DIR is now the standard directory /lib/firmware/. Fixes: 5620a0d ("firmware: delete in-kernel firmware") Signed-off-by: Markus Trippelsdorf <[email protected]> Acked-by: Greg K-H <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7318413 commit df85b2d

File tree

4 files changed

+71
-5
lines changed

4 files changed

+71
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ scripts: scripts_basic include/config/auto.conf include/config/tristate.conf \
562562

563563
# Objects we will link into vmlinux / subdirs we need to visit
564564
init-y := init/
565-
drivers-y := drivers/ sound/
565+
drivers-y := drivers/ sound/ firmware/
566566
net-y := net/
567567
libs-y := lib/
568568
core-y := usr/

drivers/base/Kconfig

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,10 @@ config EXTRA_FIRMWARE
140140
config EXTRA_FIRMWARE_DIR
141141
string "Firmware blobs root directory"
142142
depends on EXTRA_FIRMWARE != ""
143-
default "firmware"
143+
default "/lib/firmware"
144144
help
145145
This option controls the directory in which the kernel build system
146146
looks for the firmware files listed in the EXTRA_FIRMWARE option.
147-
The default is firmware/ in the kernel source tree, but by changing
148-
this option you can point it elsewhere, such as /lib/firmware/ or
149-
some other directory containing the firmware files.
150147

151148
config FW_LOADER_USER_HELPER
152149
bool

firmware/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.gen.S
2+
*.fw
3+
*.bin
4+
*.csp
5+
*.dsp
6+
ihex2fw

firmware/Makefile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#
2+
# kbuild file for firmware/
3+
#
4+
5+
# Create $(fwabs) from $(CONFIG_EXTRA_FIRMWARE_DIR) -- if it doesn't have a
6+
# leading /, it's relative to $(srctree).
7+
fwdir := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE_DIR))
8+
fwabs := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir))
9+
10+
fw-external-y := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE))
11+
12+
quiet_cmd_fwbin = MK_FW $@
13+
cmd_fwbin = FWNAME="$(patsubst firmware/%.gen.S,%,$@)"; \
14+
FWSTR="$(subst /,_,$(subst .,_,$(subst -,_,$(patsubst \
15+
firmware/%.gen.S,%,$@))))"; \
16+
ASM_WORD=$(if $(CONFIG_64BIT),.quad,.long); \
17+
ASM_ALIGN=$(if $(CONFIG_64BIT),3,2); \
18+
PROGBITS=$(if $(CONFIG_ARM),%,@)progbits; \
19+
echo "/* Generated by firmware/Makefile */" > $@;\
20+
echo " .section .rodata" >>$@;\
21+
echo " .p2align $${ASM_ALIGN}" >>$@;\
22+
echo "_fw_$${FWSTR}_bin:" >>$@;\
23+
echo " .incbin \"$(2)\"" >>$@;\
24+
echo "_fw_end:" >>$@;\
25+
echo " .section .rodata.str,\"aMS\",$${PROGBITS},1" >>$@;\
26+
echo " .p2align $${ASM_ALIGN}" >>$@;\
27+
echo "_fw_$${FWSTR}_name:" >>$@;\
28+
echo " .string \"$$FWNAME\"" >>$@;\
29+
echo " .section .builtin_fw,\"a\",$${PROGBITS}" >>$@;\
30+
echo " .p2align $${ASM_ALIGN}" >>$@;\
31+
echo " $${ASM_WORD} _fw_$${FWSTR}_name" >>$@;\
32+
echo " $${ASM_WORD} _fw_$${FWSTR}_bin" >>$@;\
33+
echo " $${ASM_WORD} _fw_end - _fw_$${FWSTR}_bin" >>$@;
34+
35+
# One of these files will change, or come into existence, whenever
36+
# the configuration changes between 32-bit and 64-bit. The .S files
37+
# need to change when that happens.
38+
wordsize_deps := $(wildcard include/config/64bit.h include/config/32bit.h \
39+
include/config/ppc32.h include/config/ppc64.h \
40+
include/config/superh32.h include/config/superh64.h \
41+
include/config/x86_32.h include/config/x86_64.h \
42+
firmware/Makefile)
43+
44+
$(patsubst %,$(obj)/%.gen.S, $(fw-external-y)): %: $(wordsize_deps) \
45+
include/config/extra/firmware/dir.h
46+
$(call cmd,fwbin,$(fwabs)/$(patsubst $(obj)/%.gen.S,%,$@))
47+
48+
# The .o files depend on the binaries directly; the .S files don't.
49+
$(patsubst %,$(obj)/%.gen.o, $(fw-external-y)): $(obj)/%.gen.o: $(fwdir)/%
50+
51+
obj-y += $(patsubst %,%.gen.o, $(fw-external-y))
52+
53+
ifeq ($(KBUILD_SRC),)
54+
# Makefile.build only creates subdirectories for O= builds, but external
55+
# firmware might live outside the kernel source tree
56+
_dummy := $(foreach d,$(addprefix $(obj)/,$(dir $(fw-external-y))), $(shell [ -d $(d) ] || mkdir -p $(d)))
57+
endif
58+
59+
targets := $(patsubst $(obj)/%,%, \
60+
$(shell find $(obj) -name \*.gen.S 2>/dev/null))
61+
# Without this, built-in.o won't be created when it's empty, and the
62+
# final vmlinux link will fail.
63+
obj- := dummy

0 commit comments

Comments
 (0)