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