aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2008-05-23 08:58:12 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2008-07-10 09:30:39 -0400
commit4d2acfbfdf68257e846aaa355edd10fc35ba0feb (patch)
tree6ab49a7d46036fffb0f4588595ede7abca11a51a
parent5658c769443d543728b6c5c673dffc2df8676317 (diff)
firmware: Add CONFIG_EXTRA_FIRMWARE option
This allows arbitrary firmware files to be included in the static kernel where the firmware loader can find them without requiring userspace to be alive. (Updated and CONFIG_EXTRA_FIRMWARE_DIR added with lots of help from Johannes Berg). Signed-off-by: David Woodhouse <dwmw2@infradead.org> Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
-rw-r--r--Makefile2
-rw-r--r--drivers/base/Kconfig39
-rw-r--r--firmware/Makefile88
3 files changed, 128 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 6315424a00b9..f398cffa6c07 100644
--- a/Makefile
+++ b/Makefile
@@ -450,7 +450,7 @@ scripts: scripts_basic include/config/auto.conf
450 450
451# Objects we will link into vmlinux / subdirs we need to visit 451# Objects we will link into vmlinux / subdirs we need to visit
452init-y := init/ 452init-y := init/
453drivers-y := drivers/ sound/ 453drivers-y := drivers/ sound/ firmware/
454net-y := net/ 454net-y := net/
455libs-y := lib/ 455libs-y := lib/
456core-y := usr/ 456core-y := usr/
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index d7da109c24fd..13cfcb435f7d 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -34,6 +34,45 @@ config FW_LOADER
34 require userspace firmware loading support, but a module built outside 34 require userspace firmware loading support, but a module built outside
35 the kernel tree does. 35 the kernel tree does.
36 36
37config EXTRA_FIRMWARE
38 string "External firmware blobs to build into the kernel binary"
39 depends on FW_LOADER
40 help
41 This option allows firmware to be built into the kernel, for the
42 cases where the user either cannot or doesn't want to provide it from
43 userspace at runtime (for example, when the firmware in question is
44 required for accessing the boot device, and the user doesn't want to
45 use an initrd).
46
47 This option is a string, and takes the (space-separated) names of the
48 firmware files -- the same names which appear in MODULE_FIRMWARE()
49 and request_firmware() in the source. These files should exist under
50 the directory specified by the EXTRA_FIRMWARE_DIR option, which is
51 by default the firmware/ subdirectory of the kernel source tree.
52
53 So, for example, you might set CONFIG_EXTRA_FIRMWARE="usb8388.bin",
54 copy the usb8388.bin file into the firmware/ directory, and build the
55 kernel. Then any request_firmware("usb8388.bin") will be
56 satisfied internally without needing to call out to userspace.
57
58 WARNING: If you include additional firmware files into your binary
59 kernel image which are not available under the terms of the GPL,
60 then it may be a violation of the GPL to distribute the resulting
61 image -- since it combines both GPL and non-GPL work. You should
62 consult a lawyer of your own before distributing such an image.
63
64config EXTRA_FIRMWARE_DIR
65 string "Firmware blobs root directory"
66 depends on EXTRA_FIRMWARE != ""
67 default "firmware"
68 help
69 This option controls the directory in which the kernel build system
70 looks for the firmware files listed in the EXTRA_FIRMWARE option.
71 The default is the firmware/ directory in the kernel source tree,
72 but by changing this option you can point it elsewhere, such as
73 the /lib/firmware/ directory or another separate directory
74 containing firmware files.
75
37config DEBUG_DRIVER 76config DEBUG_DRIVER
38 bool "Driver Core verbose debug messages" 77 bool "Driver Core verbose debug messages"
39 depends on DEBUG_KERNEL 78 depends on DEBUG_KERNEL
diff --git a/firmware/Makefile b/firmware/Makefile
new file mode 100644
index 000000000000..e69461f9362b
--- /dev/null
+++ b/firmware/Makefile
@@ -0,0 +1,88 @@
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).
7fwdir := $(subst ",,$(CONFIG_EXTRA_FIRMWARE_DIR))
8fwabs := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir))
9
10fw-external-y := $(subst ",,$(CONFIG_EXTRA_FIRMWARE))
11
12firmware-y := $(fw-external-y) $(fw-shipped-y)
13firmware-dirs := $(sort $(patsubst %,$(objtree)/$(obj)/%/,$(dir $(firmware-y) $(fw-shipped-))))
14
15quiet_cmd_mkdir = MKDIR $(patsubst $(objtree)/%,%,$@)
16 cmd_mkdir = mkdir -p $@
17
18quiet_cmd_ihex = IHEX $@
19 cmd_ihex = $(OBJCOPY) -Iihex -Obinary $< $@
20
21quiet_cmd_fwbin = MK_FW $@
22 cmd_fwbin = FWNAME="$(patsubst firmware/%.gen.S,%,$@)"; \
23 FWSTR="$(subst /,_,$(subst .,_,$(subst -,_,$(patsubst \
24 firmware/%.gen.S,%,$@))))"; \
25 ASM_WORD=$(if $(CONFIG_64BIT),.quad,.long); \
26 ASM_ALIGN=$(if $(CONFIG_64BIT),3,2); \
27 PROGBITS=$(if $(CONFIG_ARM),%,@)progbits; \
28 echo "/* Generated by firmware/Makefile */" > $@;\
29 echo " .section .rodata" >>$@;\
30 echo " .p2align $${ASM_ALIGN}" >>$@;\
31 echo "_fw_$${FWSTR}_bin:" >>$@;\
32 echo " .incbin \"$(2)\"" >>$@;\
33 echo "_fw_end:" >>$@;\
34 echo " .section .rodata.str,\"aMS\",$${PROGBITS},1" >>$@;\
35 echo " .p2align $${ASM_ALIGN}" >>$@;\
36 echo "_fw_$${FWSTR}_name:" >>$@;\
37 echo " .string \"$$FWNAME\"" >>$@;\
38 echo " .section .builtin_fw,\"a\",$${PROGBITS}" >>$@;\
39 echo " .p2align $${ASM_ALIGN}" >>$@;\
40 echo " $${ASM_WORD} _fw_$${FWSTR}_name" >>$@;\
41 echo " $${ASM_WORD} _fw_$${FWSTR}_bin" >>$@;\
42 echo " $${ASM_WORD} _fw_end - _fw_$${FWSTR}_bin" >>$@;
43
44# One of these files will change, or come into existence, whenever
45# the configuration changes between 32-bit and 64-bit. The .S files
46# need to change when that happens.
47wordsize_deps := $(wildcard include/config/64bit.h include/config/32bit.h \
48 include/config/ppc32.h include/config/ppc64.h \
49 include/config/superh32.h include/config/superh64.h \
50 include/config/x86_32.h include/config/x86_64.h)
51
52# Workaround for make < 3.81, where .SECONDEXPANSION doesn't work.
53# It'll end up depending on these targets, so make them a PHONY rule which
54# depends on _all_ the directories in $(firmware-dirs), and it'll work out OK.
55PHONY += $(objtree)/$$(%) $(objtree)/$(obj)/$$(%)
56$(objtree)/$$(%) $(objtree)/$(obj)/$$(%): $(firmware-dirs)
57 @true
58
59# For the $$(dir %) trick, where we need % to be expanded first.
60.SECONDEXPANSION:
61
62$(patsubst %,$(obj)/%.gen.S, $(fw-shipped-y)): %: $(wordsize_deps) \
63 | $(objtree)/$$(dir %)
64 $(call cmd,fwbin,$(patsubst %.gen.S,%,$@))
65$(patsubst %,$(obj)/%.gen.S, $(fw-external-y)): %: $(wordsize_deps) \
66 include/config/builtin/firmware/dir.h | $(objtree)/$$(dir %)
67 $(call cmd,fwbin,$(fwabs)/$(patsubst $(obj)/%.gen.S,%,$@))
68
69# The .o files depend on the binaries directly; the .S files don't.
70$(patsubst %,$(obj)/%.gen.o, $(fw-shipped-y)): %.gen.o: %
71$(patsubst %,$(obj)/%.gen.o, $(fw-external-y)): $(obj)/%.gen.o: $(fwdir)/%
72
73$(obj)/%: $(obj)/%.ihex | $(objtree)/$(obj)/$$(dir %)
74 $(call cmd,ihex)
75
76$(firmware-dirs):
77 $(call cmd,mkdir)
78
79obj-y := $(patsubst %,%.gen.o, $(firmware-y))
80
81# Remove .S files and binaries created from ihex
82# (during 'make clean' .config isn't included so they're all in $(fw-shipped-))
83targets := $(fw-shipped-) $(patsubst $(obj)/%,%, \
84 $(shell find $(obj) -name \*.gen.S 2>/dev/null))
85
86# Without this, built-in.o won't be created when it's empty, and the
87# final vmlinux link will fail.
88obj-n := dummy