• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPDX-License-Identifier: GPL-2.0
2# ==========================================================================
3# Installing modules
4# ==========================================================================
5
6PHONY := __modinst
7__modinst:
8
9include include/config/auto.conf
10include $(srctree)/scripts/Kbuild.include
11
12modules := $(sort $(shell cat $(MODORDER)))
13
14ifeq ($(KBUILD_EXTMOD),)
15dst := $(MODLIB)/kernel
16else
17INSTALL_MOD_DIR ?= extra
18dst := $(MODLIB)/$(INSTALL_MOD_DIR)
19endif
20
21suffix-y				:=
22suffix-$(CONFIG_MODULE_COMPRESS_GZIP)	:= .gz
23suffix-$(CONFIG_MODULE_COMPRESS_XZ)	:= .xz
24suffix-$(CONFIG_MODULE_COMPRESS_ZSTD)	:= .zst
25
26modules := $(patsubst $(extmod_prefix)%, $(dst)/%$(suffix-y), $(modules))
27ifneq ($(KBUILD_EXTMOD),)
28extmod_suffix := $(shell echo "${KBUILD_EXTMOD}" | md5sum | cut -d " " -f 1)
29modules += $(dst)/modules.order.$(extmod_suffix)
30endif
31
32__modinst: $(modules)
33	@:
34
35quiet_cmd_none =
36      cmd_none = :
37
38#
39# Installation
40#
41quiet_cmd_install = INSTALL $@
42      cmd_install = mkdir -p $(dir $@); cp $< $@
43
44# Strip
45#
46# INSTALL_MOD_STRIP, if defined, will cause modules to be stripped after they
47# are installed. If INSTALL_MOD_STRIP is '1', then the default option
48# --strip-debug will be used. Otherwise, INSTALL_MOD_STRIP value will be used
49# as the options to the strip command.
50ifdef INSTALL_MOD_STRIP
51
52ifeq ($(INSTALL_MOD_STRIP),1)
53strip-option := --strip-debug
54else
55strip-option := $(INSTALL_MOD_STRIP)
56endif
57
58quiet_cmd_strip = STRIP   $@
59      cmd_strip = $(STRIP) $(strip-option) $@
60
61else
62
63quiet_cmd_strip =
64      cmd_strip = :
65
66endif
67
68#
69# Signing
70# Don't stop modules_install even if we can't sign external modules.
71#
72ifeq ($(CONFIG_MODULE_SIG_ALL),y)
73quiet_cmd_sign = SIGN    $@
74$(eval $(call config_filename,MODULE_SIG_KEY))
75      cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY) certs/signing_key.x509 $@ \
76                 $(if $(KBUILD_EXTMOD),|| true)
77else
78quiet_cmd_sign :=
79      cmd_sign := :
80endif
81
82ifeq ($(modules_sign_only),)
83
84$(dst)/%.ko: $(extmod_prefix)%.ko FORCE
85	$(call cmd,install)
86	$(call cmd,strip)
87	$(call cmd,sign)
88
89ifneq ($(KBUILD_EXTMOD),)
90$(dst)/modules.order.$(extmod_suffix): $(MODORDER) FORCE
91	$(call cmd,install)
92	@sed -i "s:^$(KBUILD_EXTMOD):$(INSTALL_MOD_DIR):g" $@
93endif
94
95else
96
97$(dst)/%.ko: FORCE
98	$(call cmd,sign)
99
100endif
101
102#
103# Compression
104#
105quiet_cmd_gzip = GZIP    $@
106      cmd_gzip = $(KGZIP) -n -f $<
107quiet_cmd_xz = XZ      $@
108      cmd_xz = $(XZ) --lzma2=dict=2MiB -f $<
109quiet_cmd_zstd = ZSTD    $@
110      cmd_zstd = $(ZSTD) -T0 --rm -f -q $<
111
112$(dst)/%.ko.gz: $(dst)/%.ko FORCE
113	$(call cmd,gzip)
114
115$(dst)/%.ko.xz: $(dst)/%.ko FORCE
116	$(call cmd,xz)
117
118$(dst)/%.ko.zst: $(dst)/%.ko FORCE
119	$(call cmd,zstd)
120
121PHONY += FORCE
122FORCE:
123
124.PHONY: $(PHONY)
125