From 3e51f4234cc7790a0d8c1fa8fa4cf30a8bc67a2b Mon Sep 17 00:00:00 2001 From: Robin Hsu Date: Wed, 4 Nov 2020 09:29:09 +0800 Subject: [PATCH] Enable system partition compression * Prerequisites: external/f2fs-tools: sload compression support * Must work with corresponding changes in system/extras repository * If Board config does not change, it falls back to old behavior, i.e. no compression for the system partition * Kernel f2fs compression support is a prerequisite if the Board config enables the compression (see below) * Necessary board config change (e.g. device///BoardConfig-common.mk) BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE := f2fs BOARD_SYSTEMIMAGE_PARTITION_RESERVED_SIZE := 200000000 BOARD_SYSTEMIMAGE_FILE_SYSTEM_COMPRESS := true BOARD_SYSTEMIMAGE_F2FS_SLOAD_COMPRESS_FLAGS := Setting BOARD_SYSTEMIMAGE_FILE_SYSTEM_COMPRESS to true enables both the compression support when the initial empty file system be made (mkfs.f2fs) and the compression flag (-c) when the system image files be side-loaded by sload. Sload compress sub-options (i.e. options other than -c) will be provided by BOARD_SYSTEMIMAGE_F2FS_SLOAD_COMPRESS_FLAGS. If it is not given, or is empty, the default sub-options will be used Please refer to the sload.f2fs manual page. Setting BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE to f2fs is trivially necessary. * File system table (fstab), notably the file 'fstab.hardware', should also changed: - The file type must be changed to f2fs - Perhaps also other f2fs-specific options Bug: 170918499 Test: Pixel4a userdebug build (from build id 6918751) Signed-off-by: Robin Hsu Change-Id: Id9d67b5cb35dc806e06ff1320e89114abc996a28 --- core/Makefile | 2 ++ tools/releasetools/build_image.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/Makefile b/core/Makefile index 6656a1999b..6dfb4621bf 100644 --- a/core/Makefile +++ b/core/Makefile @@ -1394,6 +1394,8 @@ $(if $(filter $(2),system),\ $(if $(BOARD_SYSTEMIMAGE_PARTITION_SIZE),$(hide) echo "system_size=$(BOARD_SYSTEMIMAGE_PARTITION_SIZE)" >> $(1)) $(if $(INTERNAL_SYSTEM_OTHER_PARTITION_SIZE),$(hide) echo "system_other_size=$(INTERNAL_SYSTEM_OTHER_PARTITION_SIZE)" >> $(1)) $(if $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "system_fs_type=$(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE)" >> $(1)) + $(if $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_COMPRESS),$(hide) echo "system_fs_compress=$(BOARD_SYSTEMIMAGE_FILE_SYSTEM_COMPRESS)" >> $(1)) + $(if $(BOARD_SYSTEMIMAGE_F2FS_SLOAD_COMPRESS_FLAGS),$(hide) echo "system_f2fs_sldc_flags=$(BOARD_SYSTEMIMAGE_F2FS_SLOAD_COMPRESS_FLAGS)" >> $(1)) $(if $(BOARD_SYSTEMIMAGE_EXTFS_INODE_COUNT),$(hide) echo "system_extfs_inode_count=$(BOARD_SYSTEMIMAGE_EXTFS_INODE_COUNT)" >> $(1)) $(if $(BOARD_SYSTEMIMAGE_EXTFS_RSV_PCT),$(hide) echo "system_extfs_rsv_pct=$(BOARD_SYSTEMIMAGE_EXTFS_RSV_PCT)" >> $(1)) $(if $(BOARD_SYSTEMIMAGE_JOURNAL_SIZE),$(hide) echo "system_journal_size=$(BOARD_SYSTEMIMAGE_JOURNAL_SIZE)" >> $(1)) diff --git a/tools/releasetools/build_image.py b/tools/releasetools/build_image.py index 6487b9b8e2..c03fac104d 100755 --- a/tools/releasetools/build_image.py +++ b/tools/releasetools/build_image.py @@ -350,8 +350,17 @@ def BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config): build_command.append("--prjquota") if (needs_casefold): build_command.append("--casefold") - if (needs_compress): + if (needs_compress or prop_dict.get("system_fs_compress") == "true"): build_command.append("--compression") + if (prop_dict.get("system_fs_compress") == "true"): + build_command.append("--sldc") + if (prop_dict.get("system_f2fs_sldc_flags") == None): + build_command.append(str(0)) + else: + sldc_flags_str = prop_dict.get("system_f2fs_sldc_flags") + sldc_flags = sldc_flags_str.split() + build_command.append(str(len(sldc_flags))) + build_command.extend(sldc_flags) else: raise BuildImageError( "Error: unknown filesystem type: {}".format(fs_type)) @@ -546,6 +555,8 @@ def ImagePropFromGlobalDict(glob_dict, mount_point): "extfs_sparse_flag", "erofs_sparse_flag", "squashfs_sparse_flag", + "system_fs_compress", + "system_f2fs_sldc_flags", "f2fs_sparse_flag", "skip_fsck", "ext_mkuserimg",