1# SPDX-License-Identifier: GPL-2.0 2# ========================================================================== 3# Installing modules 4# ========================================================================== 5 6PHONY := __modinst 7__modinst: 8 9include $(objtree)/include/config/auto.conf 10include $(srctree)/scripts/Kbuild.include 11 12install-y := 13 14ifeq ($(KBUILD_EXTMOD)$(sign-only),) 15 16# remove the old directory and symlink 17$(shell rm -fr $(MODLIB)/kernel $(MODLIB)/build) 18 19install-$(CONFIG_MODULES) += $(addprefix $(MODLIB)/, build modules.order) 20 21$(MODLIB)/build: FORCE 22 $(call cmd,symlink) 23 24quiet_cmd_symlink = SYMLINK $@ 25 cmd_symlink = ln -s $(CURDIR) $@ 26 27$(MODLIB)/modules.order: modules.order FORCE 28 $(call cmd,install_modorder) 29 30quiet_cmd_install_modorder = INSTALL $@ 31 cmd_install_modorder = sed 's:^\(.*\)\.o$$:kernel/\1.ko:' $< > $@ 32 33# Install modules.builtin(.modinfo,.ranges) even when CONFIG_MODULES is disabled. 34install-y += $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo) 35 36install-$(CONFIG_BUILTIN_MODULE_RANGES) += $(MODLIB)/modules.builtin.ranges 37 38$(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo modules.builtin.ranges): $(MODLIB)/%: $(mixed-build-prefix)% FORCE 39 $(call cmd,install) 40 41endif 42 43modules := $(call read-file, $(MODORDER)) 44 45ifeq ($(KBUILD_EXTMOD),) 46dst := $(MODLIB)/kernel 47else 48INSTALL_MOD_DIR ?= updates 49dst := $(MODLIB)/$(INSTALL_MOD_DIR) 50endif 51 52$(foreach x, % :, $(if $(findstring $x, $(dst)), \ 53 $(error module installation path cannot contain '$x'))) 54 55suffix-y := 56ifdef CONFIG_MODULE_COMPRESS_ALL 57suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz 58suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz 59suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst 60endif 61 62modules := $(patsubst $(extmod_prefix)%.o, $(dst)/%.ko$(suffix-y), $(modules)) 63ifneq ($(KBUILD_EXTMOD),) 64extmod_suffix := $(shell echo "${KBUILD_EXTMOD}" | md5sum | cut -d " " -f 1) 65modules += $(dst)/modules.order.$(extmod_suffix) 66endif 67install-$(CONFIG_MODULES) += $(modules) 68 69__modinst: $(install-y) 70 @: 71 72# 73# Installation 74# 75quiet_cmd_install = INSTALL $@ 76 cmd_install = cp $< $@ 77 78# Strip 79# 80# INSTALL_MOD_STRIP, if defined, will cause modules to be stripped after they 81# are installed. If INSTALL_MOD_STRIP is '1', then the default option 82# --strip-debug will be used. Otherwise, INSTALL_MOD_STRIP value will be used 83# as the options to the strip command. 84ifdef INSTALL_MOD_STRIP 85 86ifeq ($(INSTALL_MOD_STRIP),1) 87strip-option := --strip-debug 88else 89strip-option := $(INSTALL_MOD_STRIP) 90endif 91 92quiet_cmd_strip = STRIP $@ 93 cmd_strip = $(STRIP) $(strip-option) $@ 94 95else 96 97quiet_cmd_strip = 98 cmd_strip = : 99 100endif 101 102# 103# Signing 104# Don't stop modules_install even if we can't sign external modules. 105# 106ifeq ($(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY)),) 107sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY) 108else 109sig-key := $(CONFIG_MODULE_SIG_KEY) 110endif 111quiet_cmd_sign = SIGN $@ 112 cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) "$(sig-key)" certs/signing_key.x509 $@ \ 113 $(if $(KBUILD_EXTMOD),|| true) 114 115ifeq ($(sign-only),) 116 117# During modules_install, modules are signed only when CONFIG_MODULE_SIG_ALL=y. 118ifndef CONFIG_MODULE_SIG_ALL 119quiet_cmd_sign := 120 cmd_sign := : 121endif 122 123# Create necessary directories 124$(foreach dir, $(sort $(dir $(install-y))), $(shell mkdir -p $(dir))) 125 126$(dst)/%.ko: $(extmod_prefix)%.ko FORCE 127 $(call cmd,install) 128 $(call cmd,strip) 129 $(call cmd,sign) 130 131ifneq ($(KBUILD_EXTMOD),) 132$(dst)/modules.order.$(extmod_suffix): $(MODORDER) FORCE 133 $(call cmd,install) 134 @sed -e "s:^$(KBUILD_EXTMOD):$(INSTALL_MOD_DIR):g" \ 135 -e 's:^\(.*\)\.o$$:\1.ko:' \ 136 -i $@ 137endif 138 139ifdef CONFIG_MODULES 140__modinst: depmod 141 142PHONY += depmod 143depmod: $(install-y) 144 $(call cmd,depmod) 145 146quiet_cmd_depmod = DEPMOD $(MODLIB) 147 cmd_depmod = $(srctree)/scripts/depmod.sh $(KERNELRELEASE) $(mixed-build-prefix) 148endif 149 150else 151 152$(dst)/%.ko: FORCE 153 $(call cmd,sign) 154 155endif 156 157# 158# Compression 159# 160quiet_cmd_gzip = GZIP $@ 161 cmd_gzip = $(KGZIP) -n -f $< 162quiet_cmd_xz = XZ $@ 163 cmd_xz = $(XZ) --check=crc32 --lzma2=dict=1MiB -f $< 164quiet_cmd_zstd = ZSTD $@ 165 cmd_zstd = $(ZSTD) --rm -f -q $< 166 167$(dst)/%.ko.gz: $(dst)/%.ko FORCE 168 $(call cmd,gzip) 169 170$(dst)/%.ko.xz: $(dst)/%.ko FORCE 171 $(call cmd,xz) 172 173$(dst)/%.ko.zst: $(dst)/%.ko FORCE 174 $(call cmd,zstd) 175 176PHONY += FORCE 177FORCE: 178 179.PHONY: $(PHONY) 180