summaryrefslogtreecommitdiff
path: root/tools/releasetools/build_image.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/releasetools/build_image.py')
-rwxr-xr-xtools/releasetools/build_image.py45
1 files changed, 36 insertions, 9 deletions
diff --git a/tools/releasetools/build_image.py b/tools/releasetools/build_image.py
index ae0dfa0ab0..7f49845860 100755
--- a/tools/releasetools/build_image.py
+++ b/tools/releasetools/build_image.py
@@ -295,6 +295,22 @@ def BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config):
build_command.extend(["--inode_size", "256"])
if "selinux_fc" in prop_dict:
build_command.append(prop_dict["selinux_fc"])
+ elif fs_type.startswith("erofs"):
+ build_command = ["mkerofsimage.sh"]
+ build_command.extend([in_dir, out_file])
+ if "erofs_sparse_flag" in prop_dict:
+ build_command.extend([prop_dict["erofs_sparse_flag"]])
+ build_command.extend(["-m", prop_dict["mount_point"]])
+ if target_out:
+ build_command.extend(["-d", target_out])
+ if fs_config:
+ build_command.extend(["-C", fs_config])
+ if "selinux_fc" in prop_dict:
+ build_command.extend(["-c", prop_dict["selinux_fc"]])
+ if "timestamp" in prop_dict:
+ build_command.extend(["-T", str(prop_dict["timestamp"])])
+ if "uuid" in prop_dict:
+ build_command.extend(["-U", prop_dict["uuid"]])
elif fs_type.startswith("squash"):
build_command = ["mksquashfsimage.sh"]
build_command.extend([in_dir, out_file])
@@ -358,13 +374,14 @@ def BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config):
in_dir, du_str,
int(prop_dict.get("partition_reserved_size", 0)),
int(prop_dict.get("partition_reserved_size", 0)) // BYTES_IN_MB))
- print(
- "The max image size for filesystem files is {} bytes ({} MB), out of a "
- "total partition size of {} bytes ({} MB).".format(
- int(prop_dict["image_size"]),
- int(prop_dict["image_size"]) // BYTES_IN_MB,
- int(prop_dict["partition_size"]),
- int(prop_dict["partition_size"]) // BYTES_IN_MB))
+ if ("image_size" in prop_dict and "partition_size" in prop_dict):
+ print(
+ "The max image size for filesystem files is {} bytes ({} MB), "
+ "out of a total partition size of {} bytes ({} MB).".format(
+ int(prop_dict["image_size"]),
+ int(prop_dict["image_size"]) // BYTES_IN_MB,
+ int(prop_dict["partition_size"]),
+ int(prop_dict["partition_size"]) // BYTES_IN_MB))
raise
if run_e2fsck and prop_dict.get("skip_fsck") != "true":
@@ -402,7 +419,7 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
fs_type = prop_dict.get("fs_type", "")
fs_spans_partition = True
- if fs_type.startswith("squash"):
+ if fs_type.startswith("squash") or fs_type.startswith("erofs"):
fs_spans_partition = False
# Get a builder for creating an image that's to be verified by Verified Boot,
@@ -412,7 +429,16 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
if (prop_dict.get("use_dynamic_partition_size") == "true" and
"partition_size" not in prop_dict):
# If partition_size is not defined, use output of `du' + reserved_size.
- size = GetDiskUsage(in_dir)
+ # For compressed file system, it's better to use the compressed size to avoid wasting space.
+ if fs_type.startswith("erofs"):
+ tmp_dict = prop_dict.copy()
+ if "erofs_sparse_flag" in tmp_dict:
+ tmp_dict.pop("erofs_sparse_flag")
+ BuildImageMkfs(in_dir, tmp_dict, out_file, target_out, fs_config)
+ size = GetDiskUsage(out_file)
+ os.remove(out_file)
+ else:
+ size = GetDiskUsage(in_dir)
logger.info(
"The tree size of %s is %d MB.", in_dir, size // BYTES_IN_MB)
# If not specified, give us 16MB margin for GetDiskUsage error ...
@@ -530,6 +556,7 @@ def ImagePropFromGlobalDict(glob_dict, mount_point):
common_props = (
"extfs_sparse_flag",
+ "erofs_sparse_flag",
"squashfs_sparse_flag",
"f2fs_sparse_flag",
"skip_fsck",