[openwrt/openwrt] image: respect TARGET_PER_DEVICE_ROOTFS for initramfs

LEDE Commits lede-commits at lists.infradead.org
Sat Jul 6 07:20:54 PDT 2024


ansuel pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/97fd059e7e6a75766da4b8c9649b105b17e3acb3

commit 97fd059e7e6a75766da4b8c9649b105b17e3acb3
Author: Luiz Angelo Daros de Luca <luizluca at gmail.com>
AuthorDate: Wed Jun 21 20:02:47 2023 -0300

    image: respect TARGET_PER_DEVICE_ROOTFS for initramfs
    
    Initramfs images were using a common rootfs (TARGET_DIR) for all
    devices, ignoring TARGET_PER_DEVICE_ROOTFS. If a single device required
    a package to build a functional initramfs image, it should be included
    by default for all devices or that device should be isolated into a new
    subtarget. Now the initramfs will be built using the target-specific
    
    Implementing Per Device Rootfs for Initramfs is not trivial as the
    rootfs needs to be embedded in the kernel image. The kernel supports an
    option to define the initramfs location and the image generation for the
    kernel can't be run in parallel as other checks are done to config and
    other arch dependent files.
    
    To handle this, we prepare a config for each rootfs and we generate the
    images under lock to prevent problem with parallel execution.
    
    Signed-off-by: Luiz Angelo Daros de Luca <luizluca at gmail.com>
    [ rework implementation for locking support ]
    Link: https://github.com/openwrt/openwrt/pull/12959
    Signed-off-by: Christian Marangi <ansuelsmth at gmail.com>
---
 include/image.mk           | 11 +++++++++--
 include/kernel-defaults.mk | 16 +++++++++++++---
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/include/image.mk b/include/image.mk
index 406f0b8534..be0682c44e 100644
--- a/include/image.mk
+++ b/include/image.mk
@@ -5,6 +5,7 @@
 override TARGET_BUILD=
 include $(INCLUDE_DIR)/prereq.mk
 include $(INCLUDE_DIR)/kernel.mk
+include $(INCLUDE_DIR)/kernel-defaults.mk
 include $(INCLUDE_DIR)/version.mk
 include $(INCLUDE_DIR)/image-commands.mk
 
@@ -533,11 +534,17 @@ define Device/Build/initramfs
 	  $$(if $$(CONFIG_JSON_OVERVIEW_IMAGE_INFO), $(BUILD_DIR)/json_info_files/$$(KERNEL_INITRAMFS_IMAGE).json,))
 
   $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
+  ifdef TARGET_PER_DEVICE_ROOTFS
+    $(KDIR)/$$(KERNEL_INITRAMFS_NAME).$$(ROOTFS_ID/$(1)):: image_prepare target-dir-$$(ROOTFS_ID/$(1))
+	$(call Kernel/CompileImage/Initramfs,$(KDIR)/target-dir-$$(ROOTFS_ID/$(1)),.$$(ROOTFS_ID/$(1)))
+  endif
   $(1)-images: $$(if $$(KERNEL_INITRAMFS),$(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE))
   $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
 	cp $$^ $$@
 
-  $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
+  $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME)$$(strip \
+						$(if $(TARGET_PER_DEVICE_ROOTFS),.$$(ROOTFS_ID/$(1))) \
+					) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
 	@rm -f $$@
 	$$(call concat_cmd,$$(KERNEL_INITRAMFS))
 
@@ -773,7 +780,7 @@ define Device/Build/artifact
 endef
 
 define Device/Build
-  $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
+  $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$$(eval $$(call Device/Build/initramfs,$(1))))
   $(call Device/Build/kernel,$(1))
 
   $$(eval $$(foreach compile,$$(COMPILE), \
diff --git a/include/kernel-defaults.mk b/include/kernel-defaults.mk
index 4ccab2b7b5..fe29430e48 100644
--- a/include/kernel-defaults.mk
+++ b/include/kernel-defaults.mk
@@ -154,13 +154,21 @@ define Kernel/CompileImage/Default
 	$(call Kernel/CopyImage)
 endef
 
+define Kernel/PrepareConfigPerRootfs
+	[ ! -d "$(1)" ] || rm -rf $(1)
+	mkdir $(1)
+
+	$(CP) $(LINUX_DIR)/.config $(1)
+endef
+
 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
 # $1: Custom TARGET_DIR. If omitted TARGET_DIR is used.
+# $2: If defined Generate Per Rootfs Kernel Directory and use it
 define Kernel/CompileImage/Initramfs
+	$(if $(2),$(call Kernel/PrepareConfigPerRootfs,$(LINUX_DIR)$(2)))
 	$(call Kernel/Configure/Initramfs,$(if $(1),$(1),$(TARGET_DIR)),$(LINUX_DIR)$(2))
 	$(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)
-	rm -rf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/usr/initramfs_data.cpio*
 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE),y)
 ifneq ($(call qstrip,$(CONFIG_EXTERNAL_CPIO)),)
 	$(CP) $(CONFIG_EXTERNAL_CPIO) $(KERNEL_BUILD_DIR)/initrd.cpio
@@ -176,8 +184,10 @@ endif
 	$(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.cpio)
 	$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD),$(STAGING_DIR_HOST)/bin/zstd -T0 -f -o $(KERNEL_BUILD_DIR)/initrd.cpio.zstd $(KERNEL_BUILD_DIR)/initrd.cpio)
 endif
-	+$(KERNEL_MAKE) $(KERNEL_MAKEOPTS_IMAGE) $(if $(KERNELNAME),$(KERNELNAME),all)
-	$(call Kernel/CopyImage,-initramfs)
+	+$(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) && \
+		{ $(call Kernel/CopyImage,-initramfs$(2)) },gen-initramfs)
 endef
 else
 define Kernel/CompileImage/Initramfs




More information about the lede-commits mailing list