[OpenWrt-Devel] [RFC 3/3] build: per-image package set for initramfs

Bjørn Mork bjorn at mork.no
Wed Apr 22 16:58:52 EDT 2020


Move the kernel initramfs build later in the build process
and into image.mk.  This allows using per-target and per-image
rootfs base directories for the initramfs build too.

Proof-of-Concept state.  This needs cleanup and testing, and
someone who knows how to write a Makefilea...

Signed-off-by: Bjørn Mork <bjorn at mork.no>
---
 include/image.mk           | 15 +++++++++++++--
 include/kernel-build.mk    |  1 -
 include/kernel-defaults.mk |  8 ++++----
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/include/image.mk b/include/image.mk
index 69b2bd5445fa..bcddb8e29362 100644
--- a/include/image.mk
+++ b/include/image.mk
@@ -10,6 +10,7 @@ include $(INCLUDE_DIR)/prereq.mk
 include $(INCLUDE_DIR)/kernel.mk
 include $(INCLUDE_DIR)/version.mk
 include $(INCLUDE_DIR)/image-commands.mk
+include $(INCLUDE_DIR)/kernel-defaults.mk
 
 ifndef IB
   ifdef CONFIG_TARGET_PER_DEVICE_ROOTFS
@@ -469,10 +470,17 @@ define set_rootfs_packages
   PACKAGES_$$(ROOTFS_ID/$(1)) := $(2)
 endef
 
+define set_initramfs_packages
+  PKGID := $$(call mkfs_packages_id,$(2))
+  KERNEL_INITRAMFS_NAME := $$(strip $$(KERNEL_INITRAMFS_NAME)+pkg=$$(PKGID))
+  PACKAGES_$$(PKGID) := $(2)
+endef
+
 define Device/Check/Common
   _PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile))))
   DEVICE_PACKAGES += $$(call extra_packages,$$(DEVICE_PACKAGES))
-  $$(eval $$(if $$(_PROFILE_SET),$$(foreach image,$$(IMAGES),$$(if $$(IMAGE_PACKAGES/$$(image)),$$(call set_rootfs_packages,$(1)/$$(image),$$(IMAGE_PACKAGES/$$(image)))))))
+  $$(if $$(_PROFILE_SET),$$(eval $$(foreach image,$$(IMAGES),$$(if $$(IMAGE_PACKAGES/$$(image)),$$(call set_rootfs_packages,$(1)/$$(image),$$(IMAGE_PACKAGES/$$(image)))))))
+  $$(if $$(_PROFILE_SET)$$(KERNEL_INITRAMFS)$$(IMAGE_PACKAGES/initramfs),$$(eval $$(call set_initramfs_packages,$(1),$$(IMAGE_PACKAGES/initramfs))))
   ifdef TARGET_PER_DEVICE_ROOTFS
     $$(if $$(_PROFILE_SET),$$(eval $$(call merge_packages,_PACKAGES,$$(DEVICE_PACKAGES) $$(call DEVICE_EXTRA_PACKAGES,$(1)))))
     $$(if $$(_PROFILE_SET),$$(call set_rootfs_packages,$(1),$$(_PACKAGES)))
@@ -490,10 +498,13 @@ endef
 
 ifndef IB
 define Device/Build/initramfs
+  PKGID := $(param_get,pkg,$(subst +,$(space),$$(KERNEL_INITRAMFS_NAME)))
   $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
   $$(_TARGET): $$(if $$(KERNEL_INITRAMFS),$(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE))
 
-  $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
+  $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: $$(if $$(PKGID),target-dir-$$(PKGID)) image_prepare
+	$$(call Kernel/CompileImage/Initramfs,$(if $$(PKGID),$(KDIR)/target-dir-$$(PKGID),$(TARGET_DIR)))
+
   $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
 	cp $$^ $$@
 
diff --git a/include/kernel-build.mk b/include/kernel-build.mk
index c371e78ab9b0..66f521d7aa7b 100644
--- a/include/kernel-build.mk
+++ b/include/kernel-build.mk
@@ -32,7 +32,6 @@ endef
 
 define Kernel/CompileImage
 	$(call Kernel/CompileImage/Default)
-	$(call Kernel/CompileImage/Initramfs)
 endef
 
 define Kernel/Clean
diff --git a/include/kernel-defaults.mk b/include/kernel-defaults.mk
index f442106ecbcb..934658170f9b 100644
--- a/include/kernel-defaults.mk
+++ b/include/kernel-defaults.mk
@@ -74,11 +74,11 @@ ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
 	$(CP) $(GENERIC_PLATFORM_DIR)/other-files/init $(KERNEL_BUILD_DIR)/initramfs.init
 	$(if $(SOURCE_DATE_EPOCH),touch -hcd "@$(SOURCE_DATE_EPOCH)" $(KERNEL_BUILD_DIR)/initramfs.init)
 	echo "file /init $(KERNEL_BUILD_DIR)/initramfs.init 0755 0 0" >$(KERNEL_BUILD_DIR)/initramfs.txt
-	$(eval INITRAMFS_SOURCES?="$(strip $(KERNEL_BUILD_DIR)/initramfs.txt $(TARGET_DIR) $(INITRAMFS_EXTRA_FILES))")
+	$(eval INITRAMFS_SOURCES=$(KERNEL_BUILD_DIR)/initramfs.txt $(1) $(INITRAMFS_EXTRA_FILES))
     endef
   else
     define Kernel/Configure/Initramfs
-	$(eval INITRAMFS_SOURCES="$(call qstrip,$(CONFIG_EXTERNAL_CPIO))")
+	$(eval INITRAMFS_SOURCES=$(call qstrip,$(CONFIG_EXTERNAL_CPIO)))
     endef
   endif
 else
@@ -115,7 +115,7 @@ endef
 
 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
 define Kernel/CompileImage/Initramfs
-	$(call Kernel/Configure/Initramfs)
+	$(call Kernel/Configure/Initramfs,$(1))
 	+$(KERNEL_MAKE) \
 		CONFIG_BLK_DEV_INITRD=y \
 		CONFIG_INITRAMFS_ROOT_UID=$(shell id -u) \
@@ -126,7 +126,7 @@ define Kernel/CompileImage/Initramfs
 			$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_$(c)),\
 				CONFIG_INITRAMFS_COMPRESSION_$(c)=y CONFIG_RD_$(c)=y,\
 				CONFIG_INITRAMFS_COMPRESSION_$(c)=n CONFIG_RD_$(c)=n))\
-		CONFIG_INITRAMFS_SOURCE=$(INITRAMFS_SOURCES) \
+		CONFIG_INITRAMFS_SOURCE="$(INITRAMFS_SOURCES)" \
 		$(if $(KERNELNAME),$(KERNELNAME),all)
 	$(call Kernel/CopyImage,-initramfs)
 endef
-- 
2.20.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list