From c12dd84d01e7e31e79aeb9083718142134060a64 Mon Sep 17 00:00:00 2001 From: Yi-Yo Chiang Date: Thu, 4 Feb 2021 23:20:15 +0800 Subject: [PATCH] Kernel modules: add modules.blocklist build support BOARD__KERNEL_MODULES_BLOCKLIST_FILE checks the syntax of and installs a prebuilt modules.blocklist file. Example usage: ``` BOARD_VENDOR_KERNEL_MODULES_BLOCKLIST_FILE := \ $(wildcard ) ``` Then the modules blocklist would be install to (vendor|vendor_dlkm)/lib/modules/modules.blocklist. Bug: 175165656 Test: Create a blocklist with incorrect syntax, verify build fails Test: Verify the new macro indeed installs the blocklist file Change-Id: Icb75aae1bdb45546792f28f4c4e8d06d9439391a --- core/Makefile | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/core/Makefile b/core/Makefile index 79255caec..f64caa9a6 100644 --- a/core/Makefile +++ b/core/Makefile @@ -230,7 +230,7 @@ endef # $(7): module archive # $(8): staging dir for stripped modules # $(9): module directory name -# Returns the a list of src:dest pairs to install the modules using copy-many-files. +# Returns a list of src:dest pairs to install the modules using copy-many-files. define build-image-kernel-modules $(if $(9), \ $(eval _dir := $(9)/), \ @@ -315,6 +315,26 @@ $(1)/$(DEPMOD_STAGING_SUBDIR)/$(4): $(2) @echo '$$(strip $$(notdir $$(PRIVATE_LOAD_MODULES)))' | tr ' ' '\n' > $$(@) endef +# $(1): source blocklist file +# $(2): destination pathname +# Returns a build rule that checks the syntax of and installs a kernel modules +# blocklist file. Strip and squeeze any extra space in the blocklist. +# For use via $(eval). +define build-image-kernel-modules-blocklist-file +$(2): $(1) + @echo "modprobe blocklist $$(@)" + $(hide) mkdir -p "$$(dir $$@)" + $(hide) rm -f "$$@" + $(hide) awk <"$$<" >"$$@" \ + '/^#/ { print; next } \ + NF == 0 { next } \ + NF != 2 || $$$$1 != "blocklist" \ + { print "Invalid blocklist line " FNR ": " $$$$0 >"/dev/stderr"; \ + exit_status = 1; next } \ + { $$$$1 = $$$$1; print } \ + END { exit exit_status }' +endef + # $(1): image name # $(2): build output directory (TARGET_OUT_VENDOR, TARGET_RECOVERY_ROOT_OUT, etc) # $(3): mount point @@ -331,7 +351,12 @@ $(if $(5),\ $(if $(strip $(BOARD_$(1)_KERNEL_MODULES$(_sep)$(_kver))$(BOARD_$(1)_KERNEL_MODULES_ARCHIVE$(_sep)$(_kver))),\ $(if $(BOARD_$(1)_KERNEL_MODULES_LOAD$(_sep)$(_kver)),,\ $(eval BOARD_$(1)_KERNEL_MODULES_LOAD$(_sep)$(_kver) := $(BOARD_$(1)_KERNEL_MODULES$(_sep)$(_kver)))) \ - $(call copy-many-files,$(call build-image-kernel-modules,$(BOARD_$(1)_KERNEL_MODULES$(_sep)$(_kver)),$(2),$(3),$(call intermediates-dir-for,PACKAGING,depmod_$(1)$(_sep)$(_kver)),$(BOARD_$(1)_KERNEL_MODULES_LOAD$(_sep)$(_kver)),$(4),$(BOARD_$(1)_KERNEL_MODULES_ARCHIVE$(_sep)$(_kver)),$(_stripped_staging_dir),$(_kver)))) + $(call copy-many-files,$(call build-image-kernel-modules,$(BOARD_$(1)_KERNEL_MODULES$(_sep)$(_kver)),$(2),$(3),$(call intermediates-dir-for,PACKAGING,depmod_$(1)$(_sep)$(_kver)),$(BOARD_$(1)_KERNEL_MODULES_LOAD$(_sep)$(_kver)),$(4),$(BOARD_$(1)_KERNEL_MODULES_ARCHIVE$(_sep)$(_kver)),$(_stripped_staging_dir),$(_kver)))) \ +$(if $(BOARD_$(1)_KERNEL_MODULES_BLOCKLIST_FILE$(_sep)$(_kver)), \ + $(eval $(call build-image-kernel-modules-blocklist-file, \ + $(BOARD_$(1)_KERNEL_MODULES_BLOCKLIST_FILE$(_sep)$(_kver)), \ + $(2)/lib/modules/modules.blocklist)) \ + $(2)/lib/modules/modules.blocklist) endef # $(1): kernel module directory name (top is an out of band value for no directory)