• 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
21$(foreach x, % :, $(if $(findstring $x, $(dst)), \
22	$(error module installation path cannot contain '$x')))
23
24suffix-y				:=
25suffix-$(CONFIG_MODULE_COMPRESS_GZIP)	:= .gz
26suffix-$(CONFIG_MODULE_COMPRESS_XZ)	:= .xz
27suffix-$(CONFIG_MODULE_COMPRESS_ZSTD)	:= .zst
28
29modules := $(patsubst $(extmod_prefix)%, $(dst)/%$(suffix-y), $(modules))
30ifneq ($(KBUILD_EXTMOD),)
31extmod_suffix := $(shell echo "${KBUILD_EXTMOD}" | md5sum | cut -d " " -f 1)
32modules += $(dst)/modules.order.$(extmod_suffix)
33endif
34
35__modinst: $(modules)
36	@:
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)
73ifeq ($(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY)),)
74sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY)
75else
76sig-key := $(CONFIG_MODULE_SIG_KEY)
77endif
78quiet_cmd_sign = SIGN    $@
79      cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) "$(sig-key)" certs/signing_key.x509 $@ \
80                 $(if $(KBUILD_EXTMOD),|| true)
81else
82quiet_cmd_sign :=
83      cmd_sign := :
84endif
85
86ifeq ($(modules_sign_only),)
87
88$(dst)/%.ko: $(extmod_prefix)%.ko FORCE
89	$(call cmd,install)
90	$(call cmd,strip)
91	$(call cmd,sign)
92
93ifneq ($(KBUILD_EXTMOD),)
94$(dst)/modules.order.$(extmod_suffix): $(MODORDER) FORCE
95	$(call cmd,install)
96	@sed -i "s:^$(KBUILD_EXTMOD):$(INSTALL_MOD_DIR):g" $@
97endif
98
99else
100
101$(dst)/%.ko: FORCE
102	$(call cmd,sign)
103
104endif
105
106#
107# Compression
108#
109quiet_cmd_gzip = GZIP    $@
110      cmd_gzip = $(KGZIP) -n -f $<
111quiet_cmd_xz = XZ      $@
112      cmd_xz = $(XZ) --lzma2=dict=2MiB -f $<
113quiet_cmd_zstd = ZSTD    $@
114      cmd_zstd = $(ZSTD) -T0 --rm -f -q $<
115
116$(dst)/%.ko.gz: $(dst)/%.ko FORCE
117	$(call cmd,gzip)
118
119$(dst)/%.ko.xz: $(dst)/%.ko FORCE
120	$(call cmd,xz)
121
122$(dst)/%.ko.zst: $(dst)/%.ko FORCE
123	$(call cmd,zstd)
124
125PHONY += FORCE
126FORCE:
127
128.PHONY: $(PHONY)
129