kernel: Add kernel modules to partition file list

This is required to ensure that kernel modules end up on the final
partition images when `BUILD_BROKEN_INCORRECT_PARTITION_IMAGES`
environment variable or board config variable is not set.

See 152cdfab7c
for more information.

Co-authored-by: Bruno Martins <bgcngm@gmail.com>
Change-Id: I8b6040e03589bde2af4e161c891ded237a9bb335
This commit is contained in:
Aaron Kling 2024-07-07 16:29:49 -05:00 committed by Bartłomiej Rudecki
parent fe0af9d2f6
commit ad4d8af7e8
Signed by: przekichane
GPG key ID: 751F23C6F014EF76

View file

@ -357,6 +357,7 @@ endef
# $(4): staging dir
# $(5): module load list
# $(6): suffix for output dir, needed for GKI modules usecase, empty otherwise
# $(7): partition image intermediates file list
# Depmod requires a well-formed kernel version so 0.0 is used as a placeholder.
define build-image-kernel-modules-tequila
mkdir -p $(2)/lib/modules$(6)
@ -377,6 +378,16 @@ define build-image-kernel-modules-tequila
echo "ERROR: $$NAME.ko was not found in the kernel modules intermediates dir, module load list must be corrected" 1>&2 && exit 1; \
fi; \
done
if [ ! -z "$(7)" ]; then \
echo lib/modules$(6)/modules.alias >> "$(7)"; \
echo lib/modules$(6)/modules.dep >> "$(7)"; \
if [ ! -z "$(5)" ]; then echo lib/modules$(6)/modules.load >> "$(7)"; fi; \
echo lib/modules$(6)/modules.softdep >> "$(7)"; \
for MODULE in $(1); do \
BASENAME=$$(basename $$MODULE); \
echo lib/modules$(6)/"$$BASENAME" >> "$(7)"; \
done \
fi;
endef
endif # FULL_RECOVERY_KERNEL_BUILD or FULL_KERNEL_BUILD
@ -401,17 +412,20 @@ else ifeq ($(BOARD_USES_VENDOR_DLKMIMAGE),true)
KERNEL_MODULES_OUT := $(TARGET_OUT_VENDOR_DLKM)
KERNEL_DEPMOD_STAGING_DIR := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,depmod_vendor)
KERNEL_MODULE_MOUNTPOINT := vendor_dlkm
KERNEL_MODULES_PARTITION_FILE_LIST := $(vendor_dlkmimage_intermediates)/file_list.txt
$(INSTALLED_VENDOR_DLKMIMAGE_TARGET): $(TARGET_PREBUILT_INT_KERNEL)
else
KERNEL_MODULES_OUT := $(TARGET_OUT_VENDOR)
KERNEL_DEPMOD_STAGING_DIR := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,depmod_vendor)
KERNEL_MODULE_MOUNTPOINT := vendor
KERNEL_MODULES_PARTITION_FILE_LIST := $(vendorimage_intermediates)/file_list.txt
$(INSTALLED_VENDORIMAGE_TARGET): $(TARGET_PREBUILT_INT_KERNEL)
endif
ifeq ($(BOARD_USES_SYSTEM_DLKMIMAGE),true)
SYSTEM_KERNEL_MODULES_OUT := $(TARGET_OUT_SYSTEM_DLKM)
SYSTEM_KERNEL_DEPMOD_STAGING_DIR := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,depmod_system_dlkm)
SYSTEM_KERNEL_MODULE_MOUNTPOINT := system_dlkm
SYSTEM_KERNEL_MODULES_PARTITION_FILE_LIST := $(system_dlkmimage_intermediates)/file_list.txt
$(INSTALLED_SYSTEM_DLKMIMAGE_TARGET): $(TARGET_PREBUILT_INT_KERNEL)
endif
MODULES_INTERMEDIATES := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,kernel_modules)
@ -453,7 +467,7 @@ $(KERNEL_CONFIG): $(KERNEL_OUT) $(ALL_KERNEL_DEFCONFIG_SRCS)
@echo "Building Kernel Config"
$(call make-kernel-config,$(KERNEL_OUT),$(KERNEL_DEFCONFIG))
$(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_CONFIG) $(DEPMOD) $(DTC)
$(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_CONFIG) $(DEPMOD) $(DTC) $(KERNEL_MODULES_PARTITION_FILE_LIST) $(SYSTEM_KERNEL_MODULES_PARTITION_FILE_LIST)
@echo "Building Kernel Image ($(BOARD_KERNEL_IMAGE_NAME))"
$(call make-kernel-target,$(BOARD_KERNEL_IMAGE_NAME))
$(hide) if grep -q '^CONFIG_OF=y' $(KERNEL_CONFIG); then \
@ -493,14 +507,14 @@ $(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_CONFIG) $(DEPMOD) $(DTC)
if [ -n "$$p" ]; then echo $$p; else echo "ERROR: $$m from SYSTEM_KERNEL_MODULES was not found" 1>&2 && exit 1; fi; \
done); \
[ $$? -ne 0 ] && exit 1; \
($(call build-image-kernel-modules-tequila,$$gki_modules,$(SYSTEM_KERNEL_MODULES_OUT),$(SYSTEM_KERNEL_MODULE_MOUNTPOINT)/,$(SYSTEM_KERNEL_DEPMOD_STAGING_DIR),$(BOARD_SYSTEM_KERNEL_MODULES_LOAD),/$(GKI_SUFFIX))) || exit "$$?"; \
($(call build-image-kernel-modules-tequila,$$gki_modules,$(SYSTEM_KERNEL_MODULES_OUT),$(SYSTEM_KERNEL_MODULE_MOUNTPOINT)/,$(SYSTEM_KERNEL_DEPMOD_STAGING_DIR),$(BOARD_SYSTEM_KERNEL_MODULES_LOAD),/$(GKI_SUFFIX),$(SYSTEM_KERNEL_MODULES_PARTITION_FILE_LIST))) || exit "$$?"; \
filtered_modules=$$(for n in $$all_modules; do \
module_name=$$(basename $$n); \
if [[ ! "$(SYSTEM_KERNEL_MODULES)" =~ "$$module_name" ]]; then echo $$n; fi; \
done); \
($(call build-image-kernel-modules-tequila,$$filtered_modules,$(KERNEL_MODULES_OUT),$(KERNEL_MODULE_MOUNTPOINT)/,$(KERNEL_DEPMOD_STAGING_DIR),$(BOARD_VENDOR_KERNEL_MODULES_LOAD),/)) || exit "$$?"; \
($(call build-image-kernel-modules-tequila,$$filtered_modules,$(KERNEL_MODULES_OUT),$(KERNEL_MODULE_MOUNTPOINT)/,$(KERNEL_DEPMOD_STAGING_DIR),$(BOARD_VENDOR_KERNEL_MODULES_LOAD),,$(KERNEL_MODULES_PARTITION_FILE_LIST))) || exit "$$?"; \
,\
($(call build-image-kernel-modules-tequila,$$all_modules,$(KERNEL_MODULES_OUT),$(KERNEL_MODULE_MOUNTPOINT)/,$(KERNEL_DEPMOD_STAGING_DIR),$(BOARD_VENDOR_KERNEL_MODULES_LOAD),/)) || exit "$$?"; \
($(call build-image-kernel-modules-tequila,$$all_modules,$(KERNEL_MODULES_OUT),$(KERNEL_MODULE_MOUNTPOINT)/,$(KERNEL_DEPMOD_STAGING_DIR),$(BOARD_VENDOR_KERNEL_MODULES_LOAD),,$(KERNEL_MODULES_PARTITION_FILE_LIST))) || exit "$$?"; \
) \
$(if $(BOOT_KERNEL_MODULES),\
vendor_boot_modules=$$(for m in $(BOOT_KERNEL_MODULES); do \
@ -508,7 +522,7 @@ $(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_CONFIG) $(DEPMOD) $(DTC)
if [ -n "$$p" ]; then echo $$p; else echo "ERROR: $$m from BOOT_KERNEL_MODULES was not found" 1>&2 && exit 1; fi; \
done); \
[ $$? -ne 0 ] && exit 1; \
($(call build-image-kernel-modules-tequila,$$vendor_boot_modules,$(KERNEL_VENDOR_RAMDISK_MODULES_OUT),/,$(KERNEL_VENDOR_RAMDISK_DEPMOD_STAGING_DIR),$(KERNEL_VENDOR_RAMDISK_KERNEL_MODULES_LOAD),/)) || exit "$$?"; \
($(call build-image-kernel-modules-tequila,$$vendor_boot_modules,$(KERNEL_VENDOR_RAMDISK_MODULES_OUT),,$(KERNEL_VENDOR_RAMDISK_DEPMOD_STAGING_DIR),$(KERNEL_VENDOR_RAMDISK_KERNEL_MODULES_LOAD),,)) || exit "$$?"; \
) \
$(if $(RECOVERY_KERNEL_MODULES),\
recovery_modules=$$(for m in $(RECOVERY_KERNEL_MODULES); do \
@ -516,7 +530,7 @@ $(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_CONFIG) $(DEPMOD) $(DTC)
if [ -n "$$p" ]; then echo $$p; else echo "ERROR: $$m from RECOVERY_KERNEL_MODULES was not found" 1>&2 && exit 1; fi; \
done); \
[ $$? -ne 0 ] && exit 1; \
($(call build-image-kernel-modules-tequila,$$recovery_modules,$(KERNEL_RECOVERY_MODULES_OUT),/,$(KERNEL_RECOVERY_DEPMOD_STAGING_DIR),$(BOARD_RECOVERY_RAMDISK_KERNEL_MODULES_LOAD),/)) || exit "$$?"; \
($(call build-image-kernel-modules-tequila,$$recovery_modules,$(KERNEL_RECOVERY_MODULES_OUT),,$(KERNEL_RECOVERY_DEPMOD_STAGING_DIR),$(BOARD_RECOVERY_RAMDISK_KERNEL_MODULES_LOAD),,)) || exit "$$?"; \
) \
fi