Skip to content

Commit 88ecf81

Browse files
dwmw2David Woodhouse
authored andcommitted
firmware: Add firmware installation to modules_install, add firmware_install
For 'make modules_install', install any firmware required by the modules which are being installed. Also add a 'make firmware_install' target which doesn't depend on the configuration, but installs _all_ available in-kernel-tree firmware into $(INSTALL_FW_PATH), which defaults to /lib/firmware. This is intended for distributors to make arch-independent (and config-independent) packages containing firmware. Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent d172e7f commit 88ecf81

3 files changed

Lines changed: 75 additions & 7 deletions

File tree

‎Makefile‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,16 @@ PHONY += depend dep
994994
depend dep:
995995
@echo '*** Warning: make $@ is unnecessary now.'
996996

997+
# ---------------------------------------------------------------------------
998+
# Firmware install
999+
INSTALL_FW_PATH=$(INSTALL_MOD_PATH)/lib/firmware
1000+
export INSTALL_FW_PATH
1001+
1002+
PHONY += firmware_install
1003+
firmware_install: FORCE
1004+
@mkdir -p $(objtree)/firmware
1005+
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_install
1006+
9971007
# ---------------------------------------------------------------------------
9981008
# Kernel headers
9991009
INSTALL_HDR_PATH=$(objtree)/usr
@@ -1080,6 +1090,7 @@ _modinst_:
10801090
# boot script depmod is the master version.
10811091
PHONY += _modinst_post
10821092
_modinst_post: _modinst_
1093+
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_modinst
10831094
$(call cmd,depmod)
10841095

10851096
else # CONFIG_MODULES
@@ -1197,6 +1208,8 @@ help:
11971208
@echo '* vmlinux - Build the bare kernel'
11981209
@echo '* modules - Build all modules'
11991210
@echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)'
1211+
@echo ' firmware_install- Install all firmware to INSTALL_FW_PATH'
1212+
@echo ' (default: $$(INSTALL_MOD_PATH)/lib/firmware)'
12001213
@echo ' dir/ - Build all files in dir and below'
12011214
@echo ' dir/file.[ois] - Build specified target only'
12021215
@echo ' dir/file.ko - Build module including final link'

‎firmware/Makefile‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@ fwabs := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir))
99

1010
fw-external-y := $(subst ",,$(CONFIG_EXTRA_FIRMWARE))
1111

12-
# If CONFIG_FIRMWARE_IN_KERNEL is not set, then don't include any firmware
13-
ifneq ($(CONFIG_FIRMWARE_IN_KERNEL),y)
14-
fw-shipped-y :=
15-
endif
12+
# There are three cases to care about:
13+
# 1. Building kernel with CONFIG_FIRMWARE_IN_KERNEL=y -- $(fw-shipped-y) should
14+
# include the firmware files to include, according to .config
15+
# 2. 'make modules_install', which will install firmware for modules, and
16+
# _also_ for the in-kernel drivers when CONFIG_FIRMWARE_IN_KERNEL=n
17+
# 3. 'make firmware_install', which installs all firmware, unconditionally.
1618

17-
firmware-y := $(fw-external-y) $(fw-shipped-y)
18-
firmware-dirs := $(sort $(patsubst %,$(objtree)/$(obj)/%/,$(dir $(firmware-y) $(fw-shipped-))))
19+
# For the former two cases we want $(fw-shipped-y) and $(fw-shipped-m) to be
20+
# accurate. In the latter case it doesn't matter -- it'll use $(fw-shipped-all).
21+
# But be aware that the config file might not be included at all.
22+
23+
24+
fw-shipped-all := $(fw-shipped-y) $(fw-shipped-m) $(fw-shipped-)
25+
26+
# Directories which we _might_ need to create, so we have a rule for them.
27+
firmware-dirs := $(sort $(patsubst %,$(objtree)/$(obj)/%/,$(dir $(fw-external-y) $(fw-shipped-all))))
1928

2029
quiet_cmd_mkdir = MKDIR $(patsubst $(objtree)/%,%,$@)
2130
cmd_mkdir = mkdir -p $@
@@ -81,7 +90,8 @@ $(obj)/%: $(obj)/%.ihex | $(objtree)/$(obj)/$$(dir %)
8190
$(firmware-dirs):
8291
$(call cmd,mkdir)
8392

84-
obj-y := $(patsubst %,%.gen.o, $(firmware-y))
93+
obj-y += $(patsubst %,%.gen.o, $(fw-external-y))
94+
obj-$(CONFIG_FIRMWARE_IN_KERNEL) += $(patsubst %,%.gen.o, $(fw-shipped-y))
8595

8696
# Remove .S files and binaries created from ihex
8797
# (during 'make clean' .config isn't included so they're all in $(fw-shipped-))

‎scripts/Makefile.fwinst‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# ==========================================================================
2+
# Installing firmware
3+
#
4+
# We don't include the .config, so all firmware files are in $(fw-shipped-)
5+
# rather than in $(fw-shipped-y) or $(fw-shipped-n).
6+
# ==========================================================================
7+
8+
INSTALL := install
9+
10+
# For modules_install installing firmware, we want to see .config
11+
# But for firmware_install, we don't care, but don't want to require it.
12+
-include $(objtree)/.config
13+
14+
include scripts/Kbuild.include
15+
include $(srctree)/$(obj)/Makefile
16+
17+
include scripts/Makefile.host
18+
19+
mod-fw := $(addprefix $(INSTALL_FW_PATH)/,$(fw-shipped-m))
20+
21+
# If CONFIG_FIRMWARE_IN_KERNEL isn't set, then install the
22+
# firmware for in-kernel drivers too.
23+
ifndef CONFIG_FIRMWARE_IN_KERNEL
24+
mod-fw += $(addprefix $(INSTALL_FW_PATH)/,$(fw-shipped-y))
25+
endif
26+
27+
installed-fw := $(addprefix $(INSTALL_FW_PATH)/,$(fw-shipped-all))
28+
installed-fw-dirs := $(sort $(dir $(installed-fw))) $(INSTALL_FW_PATH)/.
29+
30+
quiet_cmd_install = INSTALL $(subst $(srctree)/,,$@)
31+
cmd_install = $(INSTALL) -m0644 $< $@
32+
33+
$(installed-fw-dirs):
34+
$(call cmd,mkdir)
35+
36+
$(installed-fw): $(INSTALL_FW_PATH)/%: $(obj)/% | $(INSTALL_FW_PATH)/$$(dir %)/
37+
$(call cmd,install)
38+
39+
.PHONY: __fw_install __fw_modinst FORCE
40+
41+
__fw_install: $(installed-fw)
42+
__fw_modinst: $(mod-fw)
43+
44+
45+
FORCE:

0 commit comments

Comments
 (0)