Revert "Move partition size checks to python script"
This reverts commit a4906cd306cd257611b3ff9b6a4717cc8da15143.
Reason for revert: b/143734706
Change-Id: I905bd9c0bfcbd123c8f9e78986bfcb5600a9eca9
diff --git a/core/Makefile b/core/Makefile
index d8f0fef..a86b7b7 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -3428,6 +3428,36 @@
ifeq (true,$(PRODUCT_BUILD_SUPER_PARTITION))
+# (1): list of items like "system", "vendor", "product", "system_ext"
+# return: map each item into a command ( wrapped in $$() ) that reads the size
+define read-size-of-partitions
+$(foreach image,$(call images-for-partitions,$(1)),$$($(SPARSE_IMG) --get_partition_size $(image)))
+endef
+
+# round result to BOARD_SUPER_PARTITION_ALIGNMENT
+#$(1): the calculated size
+ifeq (,$(BOARD_SUPER_PARTITION_ALIGNMENT))
+define round-partition-size
+$(1)
+endef
+else
+define round-partition-size
+$$((($(1)+$(BOARD_SUPER_PARTITION_ALIGNMENT)-1)/$(BOARD_SUPER_PARTITION_ALIGNMENT)*$(BOARD_SUPER_PARTITION_ALIGNMENT)))
+endef
+endif
+
+define super-slot-suffix
+$(if $(filter true,$(AB_OTA_UPDATER)),$(if $(filter true,$(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS)),,_a))
+endef
+
+ifndef BOARD_SUPER_PARTITION_WARN_LIMIT
+BOARD_SUPER_PARTITION_WARN_LIMIT := $$(($(BOARD_SUPER_PARTITION_SIZE) * 95 / 100))
+endif
+
+ifndef BOARD_SUPER_PARTITION_ERROR_LIMIT
+BOARD_SUPER_PARTITION_ERROR_LIMIT := $(BOARD_SUPER_PARTITION_SIZE)
+endif
+
droid_targets: check-all-partition-sizes
.PHONY: check-all-partition-sizes check-all-partition-sizes-nodeps
@@ -3436,28 +3466,103 @@
check-all-partition-sizes: $(check_all_partition_sizes_file)
+# Add image dependencies so that generated_*_image_info.txt are written before checking.
$(check_all_partition_sizes_file): \
- $(CHECK_PARTITION_SIZES) \
+ $(SPARSE_IMG) \
$(call images-for-partitions,$(BOARD_SUPER_PARTITION_PARTITION_LIST))
-# $(1): misc_info.txt
+ifeq ($(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS),true)
+# Check sum(super partition block devices) == super partition
+# Non-retrofit devices already defines BOARD_SUPER_PARTITION_SUPER_DEVICE_SIZE = BOARD_SUPER_PARTITION_SIZE
+define check-super-partition-size
+ size_list="$(foreach device,$(call to-upper,$(BOARD_SUPER_PARTITION_BLOCK_DEVICES)),$(BOARD_SUPER_PARTITION_$(device)_DEVICE_SIZE))"; \
+ sum_sizes_expr=$$(sed -e 's/ /+/g' <<< "$${size_list}"); \
+ max_size_expr="$(BOARD_SUPER_PARTITION_SIZE)"; \
+ if [ $$(( $${sum_sizes_expr} )) -ne $$(( $${max_size_expr} )) ]; then \
+ echo "The sum of super partition block device sizes is not equal to BOARD_SUPER_PARTITION_SIZE:"; \
+ echo $${sum_sizes_expr} '!=' $${max_size_expr}; \
+ exit 1; \
+ else \
+ echo "The sum of super partition block device sizes is equal to BOARD_SUPER_PARTITION_SIZE:"; \
+ echo $${sum_sizes_expr} '==' $${max_size_expr}; \
+ fi
+endef
+endif
+
+# $(1): human-readable max size string
+# $(2): max size expression
+# $(3): list of partition names
+# $(4): human-readable warn size string
+# $(5): warn size expression
+# $(6): human readable error size string
+# $(7): error size expression
+define check-sum-of-partition-sizes
+ partition_size_list="$$(for i in $(call read-size-of-partitions,$(3)); do \
+ echo $(call round-partition-size,$${i}); \
+ done)"; \
+ sum_sizes_expr=$$(tr '\n' '+' <<< "$${partition_size_list}" | sed 's/+$$//'); \
+ if [ $$(( $${sum_sizes_expr} )) -gt $$(( $(2) )) ]; then \
+ echo "The sum of sizes of [$(strip $(3))] is larger than $(strip $(1)):"; \
+ echo $${sum_sizes_expr} '==' $$(( $${sum_sizes_expr} )) '>' "$(2)" '==' $$(( $(2) )); \
+ exit 1; \
+ else \
+ if [[ ! -z "$(7)" ]] && [ $$(( $${sum_sizes_expr} )) -gt $$(( $(7) )) ]; then \
+ echo "!!!! ERROR !!!! The sum of sizes of [$(strip $(3))] is larger than $(strip $(6)):"; \
+ echo $${sum_sizes_expr} '==' $$(( $${sum_sizes_expr} )) '>' "$(7)" '==' $$(( $(7) )); \
+ echo "Super partition is" $$(( $$(( $$(( $${sum_sizes_expr} )) * 100)) / $$(( $(2) )) )) "percent occupied!"; \
+ exit 1; \
+ fi; \
+ if [[ ! -z "$(5)" ]] && [ $$(( $${sum_sizes_expr} )) -gt $$(( $(5) )) ]; then \
+ echo "!!!! WARNING !!!! The sum of sizes of [$(strip $(3))] is larger than $(strip $(4)):"; \
+ echo $${sum_sizes_expr} '==' $$(( $${sum_sizes_expr} )) '>' "$(5)" '==' $$(( $(5) )); \
+ echo "Super partition is" $$(( $$(( $$(( $${sum_sizes_expr} )) * 100)) / $$(( $(2) )) )) "percent occupied!"; \
+ fi; \
+ echo "The sum of sizes of [$(strip $(3))] is within $(strip $(1)):"; \
+ echo $${sum_sizes_expr} '==' $$(( $${sum_sizes_expr} )) '<=' "$(2)" '==' $$(( $(2) )); \
+ fi;
+endef
+
define check-all-partition-sizes-target
- mkdir -p $(dir $(1))
- rm -f $(1)
- $(call dump-super-image-info, $(1))
- $(foreach partition,$(BOARD_SUPER_PARTITION_PARTITION_LIST), \
- echo "$(partition)_image="$(call images-for-partitions,$(partition)) >> $(1);)
- $(CHECK_PARTITION_SIZES) -v $(1)
+ # Check sum(all partitions) <= super partition (/ 2 for A/B devices launched with dynamic partitions)
+ $(if $(BOARD_SUPER_PARTITION_SIZE),$(if $(BOARD_SUPER_PARTITION_PARTITION_LIST), \
+ $(call check-sum-of-partition-sizes,BOARD_SUPER_PARTITION_SIZE$(if $(call super-slot-suffix), / 2), \
+ $(BOARD_SUPER_PARTITION_SIZE)$(if $(call super-slot-suffix), / 2),$(BOARD_SUPER_PARTITION_PARTITION_LIST), \
+ BOARD_SUPER_PARTITION_WARN_LIMIT$(if $(call super-slot-suffix), / 2), \
+ $(BOARD_SUPER_PARTITION_WARN_LIMIT)$(if $(call super-slot-suffix), / 2), \
+ BOARD_SUPER_PARTITION_ERROR_LIMIT$(if $(call super-slot-suffix), / 2), \
+ $(BOARD_SUPER_PARTITION_ERROR_LIMIT)$(if $(call super-slot-suffix), / 2)) \
+ ))
+
+ # For each group, check sum(partitions in group) <= group size
+ $(foreach group,$(call to-upper,$(BOARD_SUPER_PARTITION_GROUPS)), \
+ $(if $(BOARD_$(group)_SIZE),$(if $(BOARD_$(group)_PARTITION_LIST), \
+ $(call check-sum-of-partition-sizes,BOARD_$(group)_SIZE,$(BOARD_$(group)_SIZE),$(BOARD_$(group)_PARTITION_LIST)))))
+
+ # Check sum(all group sizes) <= super partition (/ 2 for A/B devices launched with dynamic partitions)
+ if [[ ! -z $(BOARD_SUPER_PARTITION_SIZE) ]]; then \
+ group_size_list="$(foreach group,$(call to-upper,$(BOARD_SUPER_PARTITION_GROUPS)),$(BOARD_$(group)_SIZE))"; \
+ sum_sizes_expr=$$(sed -e 's/ /+/g' <<< "$${group_size_list}"); \
+ max_size_tail=$(if $(call super-slot-suffix)," / 2"); \
+ max_size_expr="$(BOARD_SUPER_PARTITION_SIZE)$${max_size_tail}"; \
+ if [ $$(( $${sum_sizes_expr} )) -gt $$(( $${max_size_expr} )) ]; then \
+ echo "The sum of sizes of [$(strip $(BOARD_SUPER_PARTITION_GROUPS))] is larger than BOARD_SUPER_PARTITION_SIZE$${max_size_tail}:"; \
+ echo $${sum_sizes_expr} '==' $$(( $${sum_sizes_expr} )) '>' $${max_size_expr} '==' $$(( $${max_size_expr} )); \
+ exit 1; \
+ else \
+ echo "The sum of sizes of [$(strip $(BOARD_SUPER_PARTITION_GROUPS))] is within BOARD_SUPER_PARTITION_SIZE$${max_size_tail}:"; \
+ echo $${sum_sizes_expr} '==' $$(( $${sum_sizes_expr} )) '<=' $${max_size_expr} '==' $$(( $${max_size_expr} )); \
+ fi \
+ fi
endef
$(check_all_partition_sizes_file):
- $(call check-all-partition-sizes-target, \
- $(call intermediates-dir-for,PACKAGING,check-all-partition-sizes)/misc_info.txt)
+ $(call check-all-partition-sizes-target)
+ $(call check-super-partition-size)
touch $@
check-all-partition-sizes-nodeps:
- $(call check-all-partition-sizes-target, \
- $(call intermediates-dir-for,PACKAGING,check-all-partition-sizes-nodeps)/misc_info.txt)
+ $(call check-all-partition-sizes-target)
+ $(call check-super-partition-size)
endif # PRODUCT_BUILD_SUPER_PARTITION
@@ -3871,14 +3976,6 @@
echo "build_non_sparse_super_partition=true" >> $(1))
$(if $(filter true,$(BOARD_SUPER_IMAGE_IN_UPDATE_PACKAGE)), \
echo "super_image_in_update_package=true" >> $(1))
- $(if $(BOARD_SUPER_PARTITION_SIZE), \
- echo "super_partition_size=$(BOARD_SUPER_PARTITION_SIZE)" >> $(1))
- $(if $(BOARD_SUPER_PARTITION_ALIGNMENT), \
- echo "super_partition_alignment=$(BOARD_SUPER_PARTITION_ALIGNMENT)" >> $(1))
- $(if $(BOARD_SUPER_PARTITION_WARN_LIMIT), \
- echo "super_partition_warn_limit=$(BOARD_SUPER_PARTITION_WARN_LIMIT)" >> $(1))
- $(if $(BOARD_SUPER_PARTITION_ERROR_LIMIT), \
- echo "super_partition_error_limit=$(BOARD_SUPER_PARTITION_ERROR_LIMIT)" >> $(1))
endef
# By conditionally including the dependency of the target files package on the
@@ -4444,10 +4541,6 @@
$(call dump-dynamic-partitions-info,$(1))
$(if $(filter true,$(AB_OTA_UPDATER)), \
echo "ab_update=true" >> $(1))
- $(if $(filter true,$(PRODUCT_VIRTUAL_AB_OTA)), \
- echo "virtual_ab=true" >> $(1))
- $(if $(filter true,$(PRODUCT_VIRTUAL_AB_OTA_RETROFIT)), \
- echo "virtual_ab_retrofit=true" >> $(1))
endef
endif # PRODUCT_USE_DYNAMIC_PARTITIONS