[openwrt/openwrt] image: add support for EROFS rootfs image generation

LEDE Commits lede-commits at lists.infradead.org
Sat Jul 5 06:25:11 PDT 2025


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

commit f7fa414d3b4d967a7e40b162977f48e1be430c1c
Author: Gao Xiang <hsiangkao at linux.alibaba.com>
AuthorDate: Thu Jun 26 01:45:22 2025 +0800

    image: add support for EROFS rootfs image generation
    
    Add support for generating EROFS rootfs images.
    
    The EROFS filesystem can offer competitive I/O performance while
    minimizing final image size when using the MicroLZMA compressor.
    
    Target platform: linux-x86_generic (target-i386_pentium4_musl)
    
    Filesystem     Image Size
    =============  ==========
    root.erofs     4882432
    root.ext4      109051904
    root.squashfs  4903302
    
    Co-Developed-by: Gao Xiang <hsiangkao at linux.alibaba.com>
    Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
    Link: https://github.com/openwrt/openwrt/pull/19244
    Signed-off-by: Christian Marangi <ansuelsmth at gmail.com>
---
 config/Config-build.in           |  1 +
 config/Config-images.in          | 17 +++++++++++++++++
 config/Config-kernel.in          | 27 +++++++++++++++++++++++++++
 include/image.mk                 | 17 +++++++++++++++++
 scripts/target-metadata.pl       |  1 +
 target/Config.in                 |  3 +++
 target/linux/generic/config-6.12 | 11 +++++++++++
 target/linux/generic/config-6.6  |  9 +++++++++
 8 files changed, 86 insertions(+)

diff --git a/config/Config-build.in b/config/Config-build.in
index 822073d61c..42b353ecf7 100644
--- a/config/Config-build.in
+++ b/config/Config-build.in
@@ -384,6 +384,7 @@ menu "Global build settings"
 	config TARGET_ROOTFS_SECURITY_LABELS
 		bool
 		select KERNEL_SQUASHFS_XATTR
+		select KERNEL_EROFS_FS_SECURITY
 		select KERNEL_EXT4_FS_SECURITY
 		select KERNEL_F2FS_FS_SECURITY
 		select KERNEL_UBIFS_FS_SECURITY
diff --git a/config/Config-images.in b/config/Config-images.in
index 21ce0b8d28..05476dac77 100644
--- a/config/Config-images.in
+++ b/config/Config-images.in
@@ -87,6 +87,23 @@ menu "Target Images"
 
 	comment "Root filesystem images"
 
+	menuconfig TARGET_ROOTFS_EROFS
+		bool "erofs"
+		default y if USES_EROFS
+		select KERNEL_EROFS_FS
+		help
+		  Build a EROFS root filesystem.
+
+		config TARGET_EROFS_PCLUSTER_SIZE
+			int "physical cluster size (in KiB)"
+			depends on TARGET_ROOTFS_EROFS
+			default 64 if LOW_MEMORY_FOOTPRINT
+			default 1024 if (SMALL_FLASH && !LOW_MEMORY_FOOTPRINT)
+			default 256
+			help
+			  Specify the EROFS physical cluster size (must be equal
+			  to or a multiple of the filesystem block size).
+
 	menuconfig TARGET_ROOTFS_EXT4FS
 		bool "ext4"
 		default y if USES_EXT4
diff --git a/config/Config-kernel.in b/config/Config-kernel.in
index 57d693ce49..86a7804f96 100644
--- a/config/Config-kernel.in
+++ b/config/Config-kernel.in
@@ -1278,6 +1278,23 @@ config KERNEL_BTRFS_FS
 	  Say Y here if you want to make the kernel to be able to boot off a
 	  BTRFS partition.
 
+config KERNEL_EROFS_FS
+	bool "Compile the kernel with built-in EROFS support"
+	help
+	  Say Y here if you want to make the kernel to be able to boot off a
+	  EROFS partition.
+
+config KERNEL_EROFS_FS_XATTR
+	bool "EROFS XATTR support"
+
+config KERNEL_EROFS_FS_ZIP
+	bool
+	default y if KERNEL_EROFS_FS
+
+config KERNEL_EROFS_FS_ZIP_LZMA
+	bool
+	default y if KERNEL_EROFS_FS
+
 menu "Filesystem ACL and attr support options"
 	config USE_FS_ACL_ATTR
 		bool "Use filesystem ACL and attr support by default"
@@ -1298,6 +1315,11 @@ menu "Filesystem ACL and attr support options"
 		select KERNEL_FS_POSIX_ACL
 		default y if USE_FS_ACL_ATTR
 
+	config KERNEL_EROFS_FS_POSIX_ACL
+		bool "Enable POSIX ACL for EROFS Filesystems"
+		select KERNEL_FS_POSIX_ACL
+		default y if USE_FS_ACL_ATTR
+
 	config KERNEL_EXT4_FS_POSIX_ACL
 		bool "Enable POSIX ACL for Ext4 Filesystems"
 		select KERNEL_FS_POSIX_ACL
@@ -1440,6 +1462,11 @@ config KERNEL_LSM
 	default "lockdown,yama,loadpin,safesetid,integrity,selinux"
 	depends on KERNEL_SECURITY_SELINUX
 
+config KERNEL_EROFS_FS_SECURITY
+	bool "EROFS Security Labels"
+	default y if !SMALL_FLASH
+	select KERNEL_EROFS_FS_XATTR
+
 config KERNEL_EXT4_FS_SECURITY
 	bool "Ext4 Security Labels"
 	default y if !SMALL_FLASH
diff --git a/include/image.mk b/include/image.mk
index 2eca62a664..262edd79d4 100644
--- a/include/image.mk
+++ b/include/image.mk
@@ -99,11 +99,22 @@ endif
 
 JFFS2_BLOCKSIZE ?= 64k 128k
 
+EROFS_PCLUSTERSIZE := $(shell echo $$(($(CONFIG_TARGET_EROFS_PCLUSTER_SIZE)*1024)))
+EROFSOPT := -C$(EROFS_PCLUSTERSIZE)
+EROFSOPT += -Efragments,dedupe,ztailpacking -Uclear --all-root
+EROFSOPT += $(if $(SOURCE_DATE_EPOCH),-T$(SOURCE_DATE_EPOCH) --ignore-mtime)
+EROFSOPT += $(if $(CONFIG_SELINUX),,-x-1)
+EROFSCOMP := lz4hc,12
+ifeq ($(CONFIG_EROFS_FS_ZIP_LZMA),y)
+EROFSCOMP := lzma,109
+endif
+
 fs-types-$(CONFIG_TARGET_ROOTFS_SQUASHFS) += squashfs
 fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addprefix jffs2-,$(JFFS2_BLOCKSIZE))
 fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2_NAND) += $(addprefix jffs2-nand-,$(NAND_BLOCKSIZE))
 fs-types-$(CONFIG_TARGET_ROOTFS_EXT4FS) += ext4
 fs-types-$(CONFIG_TARGET_ROOTFS_UBIFS) += ubifs
+fs-types-$(CONFIG_TARGET_ROOTFS_EROFS) += erofs
 fs-subtypes-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addsuffix -raw,$(addprefix jffs2-,$(JFFS2_BLOCKSIZE)))
 
 TARGET_FILESYSTEMS := $(fs-types-y)
@@ -309,6 +320,12 @@ define Image/mkfs/ext4
 		$@ $(call mkfs_target_dir,$(1))/
 endef
 
+# Don't use the mkfs.erofs builtin $SOURCE_DATE_EPOCH behavior
+define Image/mkfs/erofs
+	env -u SOURCE_DATE_EPOCH $(STAGING_DIR_HOST)/bin/mkfs.erofs -z$(EROFSCOMP) $(EROFSOPT) \
+		$@ $(call mkfs_target_dir,$(1))
+endef
+
 define Image/Manifest
 	$(if $(CONFIG_USE_APK), \
 		$(call apk,$(TARGET_DIR_ORIG)) list --quiet --manifest --no-network \
diff --git a/scripts/target-metadata.pl b/scripts/target-metadata.pl
index da42f04a24..299dee92a7 100755
--- a/scripts/target-metadata.pl
+++ b/scripts/target-metadata.pl
@@ -18,6 +18,7 @@ sub target_config_features(@) {
 		/^dt$/ and $ret .= "\tselect USES_DEVICETREE\n";
 		/^dt-overlay$/ and $ret .= "\tselect HAS_DT_OVERLAY_SUPPORT\n";
 		/^emmc$/ and $ret .= "\tselect EMMC_SUPPORT\n";
+		/^erofs$/ and $ret .= "\tselect USES_EROFS\n";
 		/^ext4$/ and $ret .= "\tselect USES_EXT4\n";
 		/^fpu$/ and $ret .= "\tselect HAS_FPU\n";
 		/^gpio$/ and $ret .= "\tselect GPIO_SUPPORT\n";
diff --git a/target/Config.in b/target/Config.in
index c2395923d4..c0f3237ca9 100644
--- a/target/Config.in
+++ b/target/Config.in
@@ -69,6 +69,9 @@ config USES_JFFS2_NAND
 config USES_EXT4
 	bool
 
+config USES_EROFS
+	bool
+
 config USES_TARGZ
 	bool
 
diff --git a/target/linux/generic/config-6.12 b/target/linux/generic/config-6.12
index ec526e8e1d..4e2e5ae36e 100644
--- a/target/linux/generic/config-6.12
+++ b/target/linux/generic/config-6.12
@@ -1901,6 +1901,17 @@ CONFIG_ELFCORE=y
 CONFIG_EPOLL=y
 # CONFIG_EQUALIZER is not set
 # CONFIG_EROFS_FS is not set
+# CONFIG_EROFS_FS_DEBUG is not set
+# CONFIG_EROFS_FS_XATTR is not set
+# CONFIG_EROFS_FS_POSIX_ACL is not set
+# CONFIG_EROFS_FS_SECURITY is not set
+# CONFIG_EROFS_FS_BACKED_BY_FILE is not set
+# CONFIG_EROFS_FS_ZIP is not set
+# CONFIG_EROFS_FS_ZIP_DEFLATE is not set
+# CONFIG_EROFS_FS_ZIP_ZSTD is not set
+# CONFIG_EROFS_FS_ONDEMAND is not set
+CONFIG_EROFS_FS_PCPU_KTHREAD=y
+CONFIG_EROFS_FS_PCPU_KTHREAD_HIPRI=y
 # CONFIG_ET131X is not set
 CONFIG_ETHERNET=y
 # CONFIG_ETHOC is not set
diff --git a/target/linux/generic/config-6.6 b/target/linux/generic/config-6.6
index a8b5cabf88..7bf434ef0a 100644
--- a/target/linux/generic/config-6.6
+++ b/target/linux/generic/config-6.6
@@ -1840,6 +1840,15 @@ CONFIG_ELFCORE=y
 CONFIG_EPOLL=y
 # CONFIG_EQUALIZER is not set
 # CONFIG_EROFS_FS is not set
+# CONFIG_EROFS_FS_DEBUG is not set
+# CONFIG_EROFS_FS_XATTR is not set
+# CONFIG_EROFS_FS_POSIX_ACL is not set
+# CONFIG_EROFS_FS_SECURITY is not set
+# CONFIG_EROFS_FS_ZIP is not set
+# CONFIG_EROFS_FS_ZIP_DEFLATE is not set
+# CONFIG_EROFS_FS_ONDEMAND is not set
+CONFIG_EROFS_FS_PCPU_KTHREAD=y
+CONFIG_EROFS_FS_PCPU_KTHREAD_HIPRI=y
 # CONFIG_ET131X is not set
 CONFIG_ETHERNET=y
 # CONFIG_ETHOC is not set




More information about the lede-commits mailing list