Makefile.modinst 3.9 KB

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