From: Christian Marangi Date: Wed, 18 Sep 2024 23:01:27 +0000 (+0200) Subject: kernel: rework Initramfs compile cpio handling X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=bfb2e099e41172d4cf8884a97058ff6d495b9976;p=openwrt%2Fstaging%2Fansuel.git kernel: rework Initramfs compile cpio handling Now that we copy and then delete the Per-Device rootfs linux directory, it's not valid anymore placing the generated cpio there as artifacts or subsequent commands need the generated cpio. To handle this, rework Initramfs compile cpio handling by placing them in the KERNEL_BUILD_DIR but add to the name the rootfs HASH ID. To also prevent race condition, generate and access these file under a lock to prevent fit command to reference a cpio while a parallel execution is genereting it. Fixes: 52cc9d82f113 ("kernel: rework Initramfs locking logic") Signed-off-by: Christian Marangi --- diff --git a/include/image-commands.mk b/include/image-commands.mk index cb899a2f30..d2974f4e01 100644 --- a/include/image-commands.mk +++ b/include/image-commands.mk @@ -373,7 +373,7 @@ define Build/initrd_compression endef define Build/fit - $(TOPDIR)/scripts/mkits.sh \ + $(call locked,$(TOPDIR)/scripts/mkits.sh \ -D $(DEVICE_NAME) -o $@.its -k $@ \ -C $(word 1,$(1)) \ $(if $(word 2,$(1)),\ @@ -383,14 +383,14 @@ define Build/fit $(if $(findstring with-rootfs,$(word 3,$(1))),-r $(IMAGE_ROOTFS)) \ $(if $(findstring with-initrd,$(word 3,$(1))), \ $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE), \ - -i $(if $(TARGET_PER_DEVICE_ROOTFS),$(LINUX_DIR).$(ROOTFS_ID/$(DEVICE_NAME)),$(KERNEL_BUILD_DIR))/initrd.cpio$(strip $(call Build/initrd_compression)))) \ + -i $(KERNEL_BUILD_DIR)/initrd$(if $(TARGET_PER_DEVICE_ROOTFS),.$(ROOTFS_ID/$(DEVICE_NAME))).cpio$(strip $(call Build/initrd_compression)))) \ -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \ $(if $(DEVICE_FDT_NUM),-n $(DEVICE_FDT_NUM)) \ $(if $(DEVICE_DTS_DELIMITER),-l $(DEVICE_DTS_DELIMITER)) \ $(if $(DEVICE_DTS_LOADADDR),-s $(DEVICE_DTS_LOADADDR)) \ $(if $(DEVICE_DTS_OVERLAY),$(foreach dtso,$(DEVICE_DTS_OVERLAY), -O $(dtso):$(KERNEL_BUILD_DIR)/image-$(dtso).dtbo)) \ -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config-1") \ - -A $(LINUX_KARCH) -v $(LINUX_VERSION) + -A $(LINUX_KARCH) -v $(LINUX_VERSION), gen-cpio$(if $(TARGET_PER_DEVICE_ROOTFS),.$(ROOTFS_ID/$(DEVICE_NAME)))) PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage $(if $(findstring external,$(word 3,$(1))),\ -E -B 0x1000 $(if $(findstring static,$(word 3,$(1))),-p 0x1000)) -f $@.its $@.new @mv $@.new $@ diff --git a/include/kernel-defaults.mk b/include/kernel-defaults.mk index 64b8a3775e..f94ed33230 100644 --- a/include/kernel-defaults.mk +++ b/include/kernel-defaults.mk @@ -191,25 +191,27 @@ define Kernel/CompileImage/Initramfs $(CP) $(GENERIC_PLATFORM_DIR)/other-files/init $(if $(1),$(1),$(TARGET_DIR))/init; \ $(if $(SOURCE_DATE_EPOCH),touch -hcd "@$(SOURCE_DATE_EPOCH)" $(if $(1),$(1),$(TARGET_DIR)) $(if $(1),$(1),$(TARGET_DIR))/init;) \ $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE), \ - $(if $(call qstrip,$(CONFIG_EXTERNAL_CPIO)), \ - $(CP) $(CONFIG_EXTERNAL_CPIO) $(KERNEL_BUILD_DIR)/initrd.cpio;,\ - ( cd $(if $(1),$(1),$(TARGET_DIR)); find . | LC_ALL=C sort | $(STAGING_DIR_HOST)/bin/cpio --reproducible -o -H newc -R 0:0 > $(if $(2),$(LINUX_DIR)$(2),$(KERNEL_BUILD_DIR))/initrd.cpio );) \ - $(if $(SOURCE_DATE_EPOCH), \ - touch -hcd "@$(SOURCE_DATE_EPOCH)" $(if $(2),$(LINUX_DIR)$(2),$(KERNEL_BUILD_DIR))/initrd.cpio;) \ - $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2), \ - $(STAGING_DIR_HOST)/bin/bzip2 -9 -c < $(if $(2),$(LINUX_DIR)$(2),$(KERNEL_BUILD_DIR))/initrd.cpio > $(if $(2),$(LINUX_DIR)$(2),$(KERNEL_BUILD_DIR))/initrd.cpio.bzip2;) \ - $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP), \ - $(STAGING_DIR_HOST)/bin/libdeflate-gzip -n -f -S .gzip -12 $(if $(2),$(LINUX_DIR)$(2),$(KERNEL_BUILD_DIR))/initrd.cpio;) \ - $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4), \ - $(STAGING_DIR_HOST)/bin/lz4c -l -c1 -fz --favor-decSpeed $(if $(2),$(LINUX_DIR)$(2),$(KERNEL_BUILD_DIR))/initrd.cpio;) \ - $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA), \ - $(STAGING_DIR_HOST)/bin/lzma e -lc1 -lp2 -pb2 $(if $(2),$(LINUX_DIR)$(2),$(KERNEL_BUILD_DIR))/initrd.cpio $(if $(2),$(LINUX_DIR)$(2),$(KERNEL_BUILD_DIR))/initrd.cpio.lzma;) \ - $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO), \ - $(STAGING_DIR_HOST)/bin/lzop -9 -f $(if $(2),$(LINUX_DIR)$(2),$(KERNEL_BUILD_DIR))/initrd.cpio;) \ - $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ), \ - $(STAGING_DIR_HOST)/bin/xz -T$(if $(filter 1,$(NPROC)),2,0) -9 -fz --check=crc32 $(if $(2),$(LINUX_DIR)$(2),$(KERNEL_BUILD_DIR))/initrd.cpio;) \ - $(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;) \ + $(call locked,{ \ + $(if $(call qstrip,$(CONFIG_EXTERNAL_CPIO)), \ + $(CP) $(CONFIG_EXTERNAL_CPIO) $(KERNEL_BUILD_DIR)/initrd$(2).cpio;,\ + ( cd $(if $(1),$(1),$(TARGET_DIR)); find . | LC_ALL=C sort | $(STAGING_DIR_HOST)/bin/cpio --reproducible -o -H newc -R 0:0 > $(KERNEL_BUILD_DIR)/initrd$(2).cpio );) \ + $(if $(SOURCE_DATE_EPOCH), \ + touch -hcd "@$(SOURCE_DATE_EPOCH)" $(KERNEL_BUILD_DIR)/initrd$(2).cpio;) \ + $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2), \ + $(STAGING_DIR_HOST)/bin/bzip2 -9 -c < $(KERNEL_BUILD_DIR)/initrd$(2).cpio > $(KERNEL_BUILD_DIR)/initrd$(2).cpio.bzip2;) \ + $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP), \ + $(STAGING_DIR_HOST)/bin/libdeflate-gzip -n -f -S .gzip -12 $(KERNEL_BUILD_DIR)/initrd$(2).cpio;) \ + $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4), \ + $(STAGING_DIR_HOST)/bin/lz4c -l -c1 -fz --favor-decSpeed $(KERNEL_BUILD_DIR)/initrd$(2).cpio;) \ + $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA), \ + $(STAGING_DIR_HOST)/bin/lzma e -lc1 -lp2 -pb2 $(KERNEL_BUILD_DIR)/initrd$(2).cpio $(KERNEL_BUILD_DIR)/initrd$(2).cpio.lzma;) \ + $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO), \ + $(STAGING_DIR_HOST)/bin/lzop -9 -f $(KERNEL_BUILD_DIR)/initrd$(2).cpio;) \ + $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ), \ + $(STAGING_DIR_HOST)/bin/xz -T$(if $(filter 1,$(NPROC)),2,0) -9 -fz --check=crc32 $(KERNEL_BUILD_DIR)/initrd$(2).cpio;) \ + $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD), \ + $(STAGING_DIR_HOST)/bin/zstd -T0 -f -o $(KERNEL_BUILD_DIR)/initrd$(2).cpio.zstd $(KERNEL_BUILD_DIR)/initrd$(2).cpio;) \ + }, gen-cpio$(2)); \ $(if $(2),,$(KERNEL_MAKE) $(KERNEL_MAKEOPTS_IMAGE) $(if $(KERNELNAME),$(KERNELNAME),all);),\ $(KERNEL_MAKE) $(if $(2),-C $(LINUX_DIR)$(2)) $(KERNEL_MAKEOPTS_IMAGE) $(if $(KERNELNAME),$(KERNELNAME),all);) \ $(call Kernel/CopyImage,-initramfs,$(2)); \