diff --git a/tools/releasetools/check_partition_sizes.py b/tools/releasetools/check_partition_sizes.py index 745c136e90..3047ddb7cc 100644 --- a/tools/releasetools/check_partition_sizes.py +++ b/tools/releasetools/check_partition_sizes.py @@ -40,6 +40,7 @@ if sys.hexversion < 0x02070000: logger = logging.getLogger(__name__) + class Expression(object): def __init__(self, desc, expr, value=None): # Human-readable description @@ -62,6 +63,20 @@ class Expression(object): else: logger.log(level, msg) + def CheckLt(self, other, level=logging.ERROR): + format_args = (self.desc, other.desc, self.expr, self.value, + other.expr, other.value) + if self.value < other.value: + logger.info("%s is less than %s:\n%s == %d < %s == %d", + *format_args) + else: + msg = "{} is greater than or equal to {}:\n{} == {} >= {} == {}".format( + *format_args) + if level == logging.ERROR: + raise RuntimeError(msg) + else: + logger.log(level, msg) + def CheckEq(self, other): format_args = (self.desc, other.desc, self.expr, self.value, other.expr, other.value) @@ -116,7 +131,6 @@ class DynamicPartitionSizeChecker(object): int(info_dict["super_partition_size"]) self.info_dict = info_dict - def _ReadSizeOfPartition(self, name): # Tests uses *_image_size instead (to avoid creating empty sparse images # on disk) @@ -124,7 +138,6 @@ class DynamicPartitionSizeChecker(object): return int(self.info_dict[name + "_image_size"]) return sparse_img.GetImagePartitionSize(self.info_dict[name + "_image"]) - # Round result to BOARD_SUPER_PARTITION_ALIGNMENT def _RoundPartitionSize(self, size): alignment = self.info_dict.get("super_partition_alignment") @@ -132,7 +145,6 @@ class DynamicPartitionSizeChecker(object): return size return (size + alignment - 1) // alignment * alignment - def _CheckSuperPartitionSize(self): info_dict = self.info_dict super_block_devices = \ @@ -239,7 +251,20 @@ class DynamicPartitionSizeChecker(object): max_size = Expression( "BOARD_SUPER_PARTITION_SIZE{}".format(size_limit_suffix), int(info_dict["super_partition_size"]) // num_slots) - sum_size.CheckLe(max_size) + # Retrofit DAP will build metadata as part of super image. + if Dap.Get(info_dict) == Dap.RDAP: + sum_size.CheckLe(max_size) + return + + sum_size.CheckLt(max_size) + # Display a warning if group size + 1M >= super size + minimal_metadata_size = 1024 * 1024 # 1MiB + sum_size_plus_metadata = Expression( + "sum of sizes of {} plus 1M metadata".format(groups), + "+".join(str(size) for size in + group_size_list + [minimal_metadata_size]), + sum(group_size_list) + minimal_metadata_size) + sum_size_plus_metadata.CheckLe(max_size, level=logging.WARNING) def Run(self): self._CheckAllPartitionSizes() diff --git a/tools/releasetools/test_check_partition_sizes.py b/tools/releasetools/test_check_partition_sizes.py index ed20873acb..073d2290eb 100644 --- a/tools/releasetools/test_check_partition_sizes.py +++ b/tools/releasetools/test_check_partition_sizes.py @@ -27,8 +27,8 @@ class CheckPartitionSizesTest(test_utils.ReleaseToolsTestCase): dynamic_partition_list=system vendor product super_partition_groups=group super_group_partition_list=system vendor product - super_partition_size=200 - super_super_device_size=200 + super_partition_size=202 + super_super_device_size=202 super_group_group_size=100 system_image_size=50 vendor_image_size=20 @@ -41,8 +41,8 @@ class CheckPartitionSizesTest(test_utils.ReleaseToolsTestCase): def test_non_ab(self): self.info_dict.update(common.LoadDictionaryFromLines(""" ab_update=false - super_partition_size=100 - super_super_device_size=100 + super_partition_size=101 + super_super_device_size=101 """.split("\n"))) CheckPartitionSizes(self.info_dict) @@ -112,8 +112,8 @@ class CheckPartitionSizesTest(test_utils.ReleaseToolsTestCase): def test_vab(self): self.info_dict.update(common.LoadDictionaryFromLines(""" virtual_ab=true - super_partition_size=100 - super_super_device_size=100 + super_partition_size=101 + super_super_device_size=101 """.split("\n"))) CheckPartitionSizes(self.info_dict)