16k: Add 16K variant kernel/ramdisk build targets
This adds two new build variables, BOARD_KERNEL_PATH_16K and
BOARD_KERNEL_MODULES_16K . BOARD_KERNEL_PATH_16K will be copied
to output directory as is.
BOARD_KERNEL_MODULES_16K is a list of modules which will be packed into a
ramdisk and added to output dir. This allows cuttlefish to switch to 16K
kernel at runtime without adding too much overhead, as ramdisk building
takes very little time.
Bug: 253827893
Test: m kernel_16k ramdisk_16k
Change-Id: Ibb36ba4c3399b3f193795aea6597a4aa535f1bec
diff --git a/core/Makefile b/core/Makefile
index ccfa3f2..f7363a1 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -1001,6 +1001,42 @@
BUILT_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk.img
+
+ifneq ($(BOARD_KERNEL_MODULES_16K),)
+
+TARGET_OUT_RAMDISK_16K := $(PRODUCT_OUT)/ramdisk_16k
+BUILT_RAMDISK_16K_TARGET := $(PRODUCT_OUT)/ramdisk_16k.img
+RAMDISK_16K_STAGING_DIR := $(call intermediates-dir-for,PACKAGING,depmod_ramdisk_16k)
+
+$(BUILT_RAMDISK_16K_TARGET): $(DEPMOD) $(MKBOOTFS)
+$(BUILT_RAMDISK_16K_TARGET): $(call copy-many-files,$(foreach file,$(BOARD_KERNEL_MODULES_16K),$(file):$(RAMDISK_16K_STAGING_DIR)/lib/modules/0.0/$(notdir $(file))))
+ $(DEPMOD) -b $(RAMDISK_16K_STAGING_DIR) 0.0
+ for MODULE in $(BOARD_KERNEL_MODULES_16K); do \
+ basename $$MODULE >> $(RAMDISK_16K_STAGING_DIR)/lib/modules/0.0/modules.load ; \
+ done;
+ mkdir -p $(TARGET_OUT_RAMDISK_16K)/lib
+ rm -rf $(TARGET_OUT_RAMDISK_16K)/lib/modules
+ cp -r $(RAMDISK_16K_STAGING_DIR)/lib/modules/0.0 $(TARGET_OUT_RAMDISK_16K)/lib/modules
+ $(MKBOOTFS) $(TARGET_OUT_RAMDISK_16K) > $@
+
+# Builds a ramdisk using modules defined in BOARD_KERNEL_MODULES_16K
+ramdisk_16k: $(BUILT_RAMDISK_16K_TARGET)
+.PHONY: ramdisk_16k
+
+endif
+
+ifneq ($(BOARD_KERNEL_PATH_16K),)
+BUILT_KERNEL_16K_TARGET := $(PRODUCT_OUT)/kernel_16k
+
+$(eval $(call copy-one-file,$(BOARD_KERNEL_PATH_16K),$(BUILT_KERNEL_16K_TARGET)))
+
+# Copies BOARD_KERNEL_PATH_16K to output directory as is
+kernel_16k: $(BUILT_KERNEL_16K_TARGET)
+.PHONY: kernel_16k
+
+endif
+
+
ifeq ($(BOARD_RAMDISK_USE_LZ4),true)
# -l enables the legacy format used by the Linux kernel
COMPRESSION_COMMAND_DEPS := $(LZ4)