[OpenWrt-Devel] [RFC 1/3] kernel-defaults: refactor initramfs build
Bjørn Mork
bjorn at mork.no
Wed Apr 22 16:58:50 EDT 2020
Simplyfying the code. Avoids temporary modification of kernel
.config and target rootfs.
Signed-off-by: Bjørn Mork <bjorn at mork.no>
---
include/kernel-defaults.mk | 75 ++++++++++++++------------------------
1 file changed, 27 insertions(+), 48 deletions(-)
diff --git a/include/kernel-defaults.mk b/include/kernel-defaults.mk
index db93a53d71e4..f442106ecbcb 100644
--- a/include/kernel-defaults.mk
+++ b/include/kernel-defaults.mk
@@ -49,45 +49,6 @@ else
endef
endif
-ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
- ifeq ($(strip $(CONFIG_EXTERNAL_CPIO)),"")
- define Kernel/SetInitramfs/PreConfigure
- grep -v -e INITRAMFS -e CONFIG_RD_ -e CONFIG_BLK_DEV_INITRD $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
- echo 'CONFIG_BLK_DEV_INITRD=y' >> $(LINUX_DIR)/.config
- echo 'CONFIG_INITRAMFS_SOURCE="$(strip $(TARGET_DIR) $(INITRAMFS_EXTRA_FILES))"' >> $(LINUX_DIR)/.config
- endef
- else
- define Kernel/SetInitramfs/PreConfigure
- grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
- echo 'CONFIG_INITRAMFS_SOURCE="$(call qstrip,$(CONFIG_EXTERNAL_CPIO))"' >> $(LINUX_DIR)/.config
- endef
- endif
-
- define Kernel/SetInitramfs
- rm -f $(LINUX_DIR)/.config.prev
- mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
- $(call Kernel/SetInitramfs/PreConfigure)
- echo 'CONFIG_INITRAMFS_ROOT_UID=$(shell id -u)' >> $(LINUX_DIR)/.config
- echo 'CONFIG_INITRAMFS_ROOT_GID=$(shell id -g)' >> $(LINUX_DIR)/.config
- echo "$(if $(CONFIG_TARGET_INITRAMFS_FORCE),CONFIG_INITRAMFS_FORCE=y,# CONFIG_INITRAMFS_FORCE is not set)" >> $(LINUX_DIR)/.config
- echo "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE),CONFIG_INITRAMFS_COMPRESSION_NONE=y,# CONFIG_INITRAMFS_COMPRESSION_NONE is not set)" >> $(LINUX_DIR)/.config
- echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP),CONFIG_INITRAMFS_COMPRESSION_GZIP=y\nCONFIG_RD_GZIP=y,# CONFIG_INITRAMFS_COMPRESSION_GZIP is not set\n# CONFIG_RD_GZIP is not set)" >> $(LINUX_DIR)/.config
- echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2),CONFIG_INITRAMFS_COMPRESSION_BZIP2=y\nCONFIG_RD_BZIP2=y,# CONFIG_INITRAMFS_COMPRESSION_BZIP2 is not set\n# CONFIG_RD_BZIP2 is not set)" >> $(LINUX_DIR)/.config
- echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA),CONFIG_INITRAMFS_COMPRESSION_LZMA=y\nCONFIG_RD_LZMA=y,# CONFIG_INITRAMFS_COMPRESSION_LZMA is not set\n# CONFIG_RD_LZMA is not set)" >> $(LINUX_DIR)/.config
- echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO),CONFIG_INITRAMFS_COMPRESSION_LZO=y\nCONFIG_RD_LZO=y,# CONFIG_INITRAMFS_COMPRESSION_LZO is not set\n# CONFIG_RD_LZO is not set)" >> $(LINUX_DIR)/.config
- echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ),CONFIG_INITRAMFS_COMPRESSION_XZ=y\nCONFIG_RD_XZ=y,# CONFIG_INITRAMFS_COMPRESSION_XZ is not set\n# CONFIG_RD_XZ is not set)" >> $(LINUX_DIR)/.config
- echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4),CONFIG_INITRAMFS_COMPRESSION_LZ4=y\nCONFIG_RD_LZ4=y,# CONFIG_INITRAMFS_COMPRESSION_LZ4 is not set\n# CONFIG_RD_LZ4 is not set)" >> $(LINUX_DIR)/.config
- endef
-else
-endif
-
-define Kernel/SetNoInitramfs
- mv $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config.old
- grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config.set
- echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config.set
- echo '# CONFIG_INITRAMFS_FORCE is not set' >> $(LINUX_DIR)/.config.set
-endef
-
define Kernel/Configure/Default
rm -f $(LINUX_DIR)/localversion
$(LINUX_CONF_CMD) > $(LINUX_DIR)/.config.target
@@ -98,7 +59,6 @@ define Kernel/Configure/Default
echo "CONFIG_KALLSYMS_UNCOMPRESSED=y" >> $(LINUX_DIR)/.config.target
$(SCRIPT_DIR)/package-metadata.pl kconfig $(TMP_DIR)/.packageinfo $(TOPDIR)/.config $(KERNEL_PATCHVER) > $(LINUX_DIR)/.config.override
$(SCRIPT_DIR)/kconfig.pl 'm+' '+' $(LINUX_DIR)/.config.target /dev/null $(LINUX_DIR)/.config.override > $(LINUX_DIR)/.config.set
- $(call Kernel/SetNoInitramfs)
rm -rf $(KERNEL_BUILD_DIR)/modules
cmp -s $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config.prev || { \
cp $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config; \
@@ -108,9 +68,21 @@ define Kernel/Configure/Default
grep '=[ym]' $(LINUX_DIR)/.config.set | LC_ALL=C sort | mkhash md5 > $(LINUX_DIR)/.vermagic
endef
-define Kernel/Configure/Initramfs
- $(call Kernel/SetInitramfs)
-endef
+ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
+ ifeq ($(strip $(CONFIG_EXTERNAL_CPIO)),"")
+ define Kernel/Configure/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))")
+ endef
+ else
+ define Kernel/Configure/Initramfs
+ $(eval INITRAMFS_SOURCES="$(call qstrip,$(CONFIG_EXTERNAL_CPIO))")
+ endef
+ endif
+else
+endif
define Kernel/CompileModules/Default
rm -f $(LINUX_DIR)/vmlinux $(LINUX_DIR)/System.map
@@ -137,7 +109,6 @@ define Kernel/CopyImage
endef
define Kernel/CompileImage/Default
- rm -f $(TARGET_DIR)/init
+$(KERNEL_MAKE) $(if $(KERNELNAME),$(KERNELNAME),all) modules
$(call Kernel/CopyImage)
endef
@@ -145,10 +116,18 @@ endef
ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
define Kernel/CompileImage/Initramfs
$(call Kernel/Configure/Initramfs)
- $(CP) $(GENERIC_PLATFORM_DIR)/other-files/init $(TARGET_DIR)/init
- $(if $(SOURCE_DATE_EPOCH),touch -hcd "@$(SOURCE_DATE_EPOCH)" $(TARGET_DIR)/init)
- rm -rf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/usr/initramfs_data.cpio*
- +$(KERNEL_MAKE) $(if $(KERNELNAME),$(KERNELNAME),all) modules
+ +$(KERNEL_MAKE) \
+ CONFIG_BLK_DEV_INITRD=y \
+ CONFIG_INITRAMFS_ROOT_UID=$(shell id -u) \
+ CONFIG_INITRAMFS_ROOT_GID=$(shell id -g) \
+ CONFIG_INITRAMFS_FORCE=$(if $(CONFIG_TARGET_INITRAMFS_FORCE),y,n) \
+ CONFIG_INITRAMFS_COMPRESSION_NONE=$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE),y,n)\
+ $(foreach c, GZIP BZIP2 LZMA LZO XZ LZ4,\
+ $(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) \
+ $(if $(KERNELNAME),$(KERNELNAME),all)
$(call Kernel/CopyImage,-initramfs)
endef
else
--
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