kernel: copy kernel build dir on Per-Device Initramfs compilation
authorChristian Marangi <ansuelsmth@gmail.com>
Mon, 16 Sep 2024 16:38:16 +0000 (18:38 +0200)
committerChristian Marangi <ansuelsmth@gmail.com>
Tue, 17 Sep 2024 10:12:38 +0000 (12:12 +0200)
To speedup compilation of Per-Device Initramfs, copy the kernel build
directory for each rootfs ID.

This permits concurrent execution of kernel build without conflicting
with each other at the expense of additional disk space usage.

To limit disk space usage, the copied kernel directory is deleted after
the Per-Device Initramfs image is generated and saved.

Link: https://github.com/openwrt/openwrt/pull/16404
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
include/kernel-defaults.mk

index fc1262aad37aa4dd317f3cc9abd3f9a68be8abca..e9e36d72b6924e540ecc45978104a55eb6d9eafb 100644 (file)
@@ -153,13 +153,13 @@ endif
 # $1: image suffix
 # $2: Per Device Rootfs ID
 define Kernel/CopyImage
-       cmp -s $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).debug$(2) || { \
-               $(KERNEL_CROSS)objcopy -O binary $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)$(1)$(2); \
-               $(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).elf$(2); \
-               $(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).debug$(2); \
+       cmp -s $(LINUX_DIR)$(2)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).debug$(2) || { \
+               $(KERNEL_CROSS)objcopy -O binary $(OBJCOPY_STRIP) -S $(LINUX_DIR)$(2)/vmlinux $(LINUX_KERNEL)$(1)$(2); \
+               $(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) -S $(LINUX_DIR)$(2)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).elf$(2); \
+               $(CP) $(LINUX_DIR)$(2)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).debug$(2); \
                $(foreach k, \
                        $(if $(KERNEL_IMAGES),$(KERNEL_IMAGES),$(filter-out vmlinux dtbs,$(KERNELNAME))), \
-                       $(CP) $(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/$(IMAGES_DIR)/$(k) $(KERNEL_BUILD_DIR)/$(k)$(1)$(2); \
+                       $(CP) $(LINUX_DIR)$(2)/arch/$(LINUX_KARCH)/boot/$(IMAGES_DIR)/$(k) $(KERNEL_BUILD_DIR)/$(k)$(1)$(2); \
                ) \
        }
 endef
@@ -173,7 +173,9 @@ endef
 define Kernel/PrepareConfigPerRootfs
        { \
                [ ! -d "$(1)" ] || rm -rf $(1); \
-               mkdir $(1) && $(CP) $(LINUX_DIR)/.config $(1); \
+               mkdir $(1) && $(CP) -T $(LINUX_DIR) $(1); \
+               touch $(1)/.config; \
+               rm -rf $(1)/usr/initramfs_data.cpio*; \
        }
 endef
 
@@ -209,10 +211,9 @@ define Kernel/CompileImage/Initramfs
                        $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD), \
                                $(STAGING_DIR_HOST)/bin/zstd -T0 -f -o $(if $(2),$(LINUX_DIR)$(2),$(KERNEL_BUILD_DIR))/initrd.cpio.zstd $(if $(2),$(LINUX_DIR)$(2),$(KERNEL_BUILD_DIR))/initrd.cpio;) \
                        $(if $(2),,$(KERNEL_MAKE) $(KERNEL_MAKEOPTS_IMAGE) $(if $(KERNELNAME),$(KERNELNAME),all);),\
-                       $(call locked,$(if $(2),$(CP) $(LINUX_DIR)$(2)/.config* $(LINUX_DIR) && touch $(LINUX_DIR)/.config && ) \
-                               rm -rf $(LINUX_DIR)/usr/initramfs_data.cpio* $(LINUX_DIR)/.config.prev && \
-                               $(KERNEL_MAKE) $(KERNEL_MAKEOPTS_IMAGE) $(if $(KERNELNAME),$(KERNELNAME),all), compile-initramfs);) \
+                       $(KERNEL_MAKE) $(if $(2),-C $(LINUX_DIR)$(2)) $(KERNEL_MAKEOPTS_IMAGE) $(if $(KERNELNAME),$(KERNELNAME),all);) \
                $(call Kernel/CopyImage,-initramfs,$(2)); \
+               $(if $(2),rm -rf $(LINUX_DIR)$(2);) \
        }, gen-initramfs$(if $(2),-$(2)));
 endef
 else