Support "updatable groups".

* BOARD_SUPER_PARTITION_GROUPS defines a list of "updatable groups". Each
updatable group is a group of partitions that share the same pool of free
spaces.

* For each group in BOARD_SUPER_PARTITION_GROUPS, a BOARD_{GROUP}_SIZE and
BOARD_{GROUP}_PARTITION_PARTITION_LIST may be defined.
    - BOARD_{GROUP}_SIZE: The maximum sum of sizes of all
      partitions in the group.
      If empty, no limit is enforced on the sum of sizes for this group.
    - BOARD_{GROUP}_PARTITION_PARTITION_LIST: the list of partitions that
      belongs to this group.
      If empty, no partitions belong to this group, and the sum of sizes is
      effectively 0.

* BOARD_SUPER_PARTITION_PARTITION_LIST should not be defined
by the device. It is now computed from all
BOARD_{GROUP}_PARTITION_PARTITION_LIST.

* Each 'updatable group' has its own pool of space for its
partitions to grow into. Enforce the following:
    * sum(all partitions) <= super partition (/ 2 for A/B)
    * For each group, sum(partitions in group) <= group size
    * sum(all group sizes) <= super partition (/ 2 for A/B)

Test: builds
Bug: 111610495
Change-Id: I072b011714ec31a1d8813cc75edd27da3c6ff39a
Merged-In: I072b011714ec31a1d8813cc75edd27da3c6ff39a
diff --git a/core/config.mk b/core/config.mk
index 676bd64..4c94c42 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -1011,16 +1011,42 @@
 endif # PRODUCT_USE_DYNAMIC_PARTITION_SIZE
 
 ifeq ($(PRODUCT_BUILD_SUPER_PARTITION),true)
-ifdef BOARD_SUPER_PARTITION_PARTITION_LIST
-# BOARD_SUPER_PARTITION_PARTITION_LIST: a list of the following tokens
+
+# BOARD_SUPER_PARTITION_GROUPS defines a list of "updatable groups". Each updatable group is a
+# group of partitions that share the same pool of free spaces.
+# For each group in BOARD_SUPER_PARTITION_GROUPS, a BOARD_{GROUP}_SIZE and
+# BOARD_{GROUP}_PARTITION_PARTITION_LIST may be defined.
+#     - BOARD_{GROUP}_SIZE: The maximum sum of sizes of all partitions in the group.
+#       If empty, no limit is enforced on the sum of sizes for this group.
+#     - BOARD_{GROUP}_PARTITION_PARTITION_LIST: the list of partitions that belongs to this group.
+#       If empty, no partitions belong to this group, and the sum of sizes is effectively 0.
+$(foreach group,$(call to-upper,$(BOARD_SUPER_PARTITION_GROUPS)), \
+    $(eval BOARD_$(group)_SIZE ?=) \
+    $(eval .KATI_READONLY := BOARD_$(group)_SIZE) \
+    $(eval BOARD_$(group)_PARTITION_LIST ?=) \
+    $(eval .KATI_READONLY := BOARD_$(group)_PARTITION_LIST) \
+)
+
+# BOARD_*_PARTITION_LIST: a list of the following tokens
 valid_super_partition_list := system vendor product product_services
-ifneq (,$(filter-out $(valid_super_partition_list),$(BOARD_SUPER_PARTITION_PARTITION_LIST)))
-$(error BOARD_SUPER_PARTITION_PARTITION_LIST contains invalid partition name \
-		($(filter-out $(valid_super_partition_list),$(BOARD_SUPER_PARTITION_PARTITION_LIST))). \
-        Valid names are $(valid_super_partition_list))
-endif
+$(foreach group,$(call to-upper,$(BOARD_SUPER_PARTITION_GROUPS)), \
+    $(if $(filter-out $(valid_super_partition_list),$(BOARD_$(group)_PARTITION_LIST)), \
+        $(error BOARD_$(group)_PARTITION_LIST contains invalid partition name \
+            $(filter-out $(valid_super_partition_list),$(BOARD_$(group)_PARTITION_LIST)). \
+            Valid names are $(valid_super_partition_list))))
 valid_super_partition_list :=
-endif # BOARD_SUPER_PARTITION_PARTITION_LIST
+
+
+# Define BOARD_SUPER_PARTITION_PARTITION_LIST, the sum of all BOARD_*_PARTITION_LIST
+ifdef BOARD_SUPER_PARTITION_PARTITION_LIST
+$(error BOARD_SUPER_PARTITION_PARTITION_LIST should not be defined, but computed from \
+    BOARD_SUPER_PARTITION_GROUPS and BOARD_*_PARTITION_LIST)
+endif
+BOARD_SUPER_PARTITION_PARTITION_LIST := \
+    $(foreach group,$(call to-upper,$(BOARD_SUPER_PARTITION_GROUPS)), \
+        $(BOARD_$(group)_PARTITION_LIST))
+.KATI_READONLY := BOARD_SUPER_PARTITION_PARTITION_LIST
+
 endif # PRODUCT_BUILD_SUPER_PARTITION
 
 # ###############################################################