aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreehugger Robot2019-01-11 11:17:20 -0600
committerGerrit Code Review2019-01-11 11:17:20 -0600
commite093534aba696d54e0fd8a21b08abfd0ad74c019 (patch)
treea96288ff95131fe6cefd7dc953849d4a49bfa779
parentfe714ead449b24dfdfed8ad4546a4432ffa262f6 (diff)
parent6541d0a80e9e5cf7ac6fff19007532f36ef70cbd (diff)
downloadplatform-build-e093534aba696d54e0fd8a21b08abfd0ad74c019.tar.gz
platform-build-e093534aba696d54e0fd8a21b08abfd0ad74c019.tar.xz
platform-build-e093534aba696d54e0fd8a21b08abfd0ad74c019.zip
Merge changes Ic8ef968e,I6665bd6f
* changes: build_image: support non-sparse right-sized images build_image: right-sizing add .2% margin for space and inodes
-rwxr-xr-xtools/releasetools/build_image.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/tools/releasetools/build_image.py b/tools/releasetools/build_image.py
index f5163090f..521b319ed 100755
--- a/tools/releasetools/build_image.py
+++ b/tools/releasetools/build_image.py
@@ -79,22 +79,26 @@ def GetInodeUsage(path):
79 return output.count('\n') * 2 79 return output.count('\n') * 2
80 80
81 81
82def GetFilesystemCharacteristics(sparse_image_path): 82def GetFilesystemCharacteristics(image_path, sparse_image=True):
83 """Returns various filesystem characteristics of "sparse_image_path". 83 """Returns various filesystem characteristics of "image_path".
84 84
85 Args: 85 Args:
86 sparse_image_path: The file to analyze. 86 image_path: The file to analyze.
87 sparse_image: Image is sparse
87 88
88 Returns: 89 Returns:
89 The characteristics dictionary. 90 The characteristics dictionary.
90 """ 91 """
91 unsparse_image_path = UnsparseImage(sparse_image_path, replace=False) 92 unsparse_image_path = image_path
93 if sparse_image:
94 unsparse_image_path = UnsparseImage(image_path, replace=False)
92 95
93 cmd = ["tune2fs", "-l", unsparse_image_path] 96 cmd = ["tune2fs", "-l", unsparse_image_path]
94 try: 97 try:
95 output = common.RunAndCheckOutput(cmd, verbose=False) 98 output = common.RunAndCheckOutput(cmd, verbose=False)
96 finally: 99 finally:
97 os.remove(unsparse_image_path) 100 if sparse_image:
101 os.remove(unsparse_image_path)
98 fs_dict = {} 102 fs_dict = {}
99 for line in output.splitlines(): 103 for line in output.splitlines():
100 fields = line.split(":") 104 fields = line.split(":")
@@ -414,7 +418,10 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
414 "First Pass based on estimates of %d MB and %s inodes.", 418 "First Pass based on estimates of %d MB and %s inodes.",
415 size // BYTES_IN_MB, prop_dict["extfs_inode_count"]) 419 size // BYTES_IN_MB, prop_dict["extfs_inode_count"])
416 BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config) 420 BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config)
417 fs_dict = GetFilesystemCharacteristics(out_file) 421 sparse_image = False
422 if "extfs_sparse_flag" in prop_dict:
423 sparse_image = True
424 fs_dict = GetFilesystemCharacteristics(out_file, sparse_image)
418 os.remove(out_file) 425 os.remove(out_file)
419 block_size = int(fs_dict.get("Block size", "4096")) 426 block_size = int(fs_dict.get("Block size", "4096"))
420 free_size = int(fs_dict.get("Free blocks", "0")) * block_size 427 free_size = int(fs_dict.get("Free blocks", "0")) * block_size
@@ -428,16 +435,21 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
428 else: 435 else:
429 size -= free_size 436 size -= free_size
430 size += reserved_size 437 size += reserved_size
438 if reserved_size == 0:
439 # add .2% margin
440 size = size * 1002 // 1000
441 # Use a minimum size, otherwise we will fail to calculate an AVB footer
442 # or fail to construct an ext4 image.
443 size = max(size, 256 * 1024)
431 if block_size <= 4096: 444 if block_size <= 4096:
432 size = common.RoundUpTo4K(size) 445 size = common.RoundUpTo4K(size)
433 else: 446 else:
434 size = ((size + block_size - 1) // block_size) * block_size 447 size = ((size + block_size - 1) // block_size) * block_size
435 # Use a minimum size, otherwise we will fail to calculate an AVB footer
436 # or fail to construct an ext4 image.
437 size = max(size, 256 * 1024)
438 extfs_inode_count = prop_dict["extfs_inode_count"] 448 extfs_inode_count = prop_dict["extfs_inode_count"]
439 inodes = int(fs_dict.get("Inode count", extfs_inode_count)) 449 inodes = int(fs_dict.get("Inode count", extfs_inode_count))
440 inodes -= int(fs_dict.get("Free inodes", "0")) 450 inodes -= int(fs_dict.get("Free inodes", "0"))
451 # add .2% margin
452 inodes = inodes * 1002 // 1000
441 prop_dict["extfs_inode_count"] = str(inodes) 453 prop_dict["extfs_inode_count"] = str(inodes)
442 prop_dict["partition_size"] = str(size) 454 prop_dict["partition_size"] = str(size)
443 logger.info( 455 logger.info(