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,.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)/%: % 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 := 56suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz 57suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz 58suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst 59 60modules := $(patsubst $(extmod_prefix)%.o, $(dst)/%.ko$(suffix-y), $(modules)) 61install-$(CONFIG_MODULES) += $(modules) 62 63__modinst: $(install-y) 64 @: 65 66# 67# Installation 68# 69quiet_cmd_install = INSTALL $@ 70 cmd_install = cp $< $@ 71 72# Strip 73# 74# INSTALL_MOD_STRIP, if defined, will cause modules to be stripped after they 75# are installed. If INSTALL_MOD_STRIP is '1', then the default option 76# --strip-debug will be used. Otherwise, INSTALL_MOD_STRIP value will be used 77# as the options to the strip command. 78ifdef INSTALL_MOD_STRIP 79 80ifeq ($(INSTALL_MOD_STRIP),1) 81strip-option := --strip-debug 82else 83strip-option := $(INSTALL_MOD_STRIP) 84endif 85 86quiet_cmd_strip = STRIP $@ 87 cmd_strip = $(STRIP) $(strip-option) $@ 88 89else 90 91quiet_cmd_strip = 92 cmd_strip = : 93 94endif 95 96# 97# Signing 98# Don't stop modules_install even if we can't sign external modules. 99# 100ifeq ($(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY)),) 101sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY) 102else 103sig-key := $(CONFIG_MODULE_SIG_KEY) 104endif 105quiet_cmd_sign = SIGN $@ 106 cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) "$(sig-key)" certs/signing_key.x509 $@ \ 107 $(if $(KBUILD_EXTMOD),|| true) 108 109ifeq ($(sign-only),) 110 111# During modules_install, modules are signed only when CONFIG_MODULE_SIG_ALL=y. 112ifndef CONFIG_MODULE_SIG_ALL 113quiet_cmd_sign := 114 cmd_sign := : 115endif 116 117# Create necessary directories 118$(foreach dir, $(sort $(dir $(install-y))), $(shell mkdir -p $(dir))) 119 120$(dst)/%.ko: $(extmod_prefix)%.ko FORCE 121 $(call cmd,install) 122 $(call cmd,strip) 123 $(call cmd,sign) 124 125ifdef CONFIG_MODULES 126__modinst: depmod 127 128PHONY += depmod 129depmod: $(install-y) 130 $(call cmd,depmod) 131 132quiet_cmd_depmod = DEPMOD $(MODLIB) 133 cmd_depmod = $(srctree)/scripts/depmod.sh $(KERNELRELEASE) 134endif 135 136else 137 138$(dst)/%.ko: FORCE 139 $(call cmd,sign) 140 141endif 142 143# 144# Compression 145# 146quiet_cmd_gzip = GZIP $@ 147 cmd_gzip = $(KGZIP) -n -f $< 148quiet_cmd_xz = XZ $@ 149 cmd_xz = $(XZ) --check=crc32 --lzma2=dict=1MiB -f $< 150quiet_cmd_zstd = ZSTD $@ 151 cmd_zstd = $(ZSTD) --rm -f -q $< 152 153$(dst)/%.ko.gz: $(dst)/%.ko FORCE 154 $(call cmd,gzip) 155 156$(dst)/%.ko.xz: $(dst)/%.ko FORCE 157 $(call cmd,xz) 158 159$(dst)/%.ko.zst: $(dst)/%.ko FORCE 160 $(call cmd,zstd) 161 162PHONY += FORCE 163FORCE: 164 165.PHONY: $(PHONY) 166