refactor(stm32mp1): update PLAT_PARTITION_MAX_ENTRIES

Fix the maximum partition number to a default value. It must
also take care of the extra partition when FWU feature is enabled.

Change-Id: Ib64b1f19f1f0514f7e89d35fc367facd6df54bed
Signed-off-by: Lionel Debieve <lionel.debieve@foss.st.com>
Signed-off-by: Yann Gautier <yann.gautier@st.com>
diff --git a/plat/st/stm32mp1/platform.mk b/plat/st/stm32mp1/platform.mk
index a903a16..b425fa5 100644
--- a/plat/st/stm32mp1/platform.mk
+++ b/plat/st/stm32mp1/platform.mk
@@ -86,34 +86,28 @@
 WORKAROUND_CVE_2017_5715:=	0
 WORKAROUND_CVE_2022_23960:=	0
 
+# Number of TF-A copies in the device
+STM32_TF_A_COPIES		:=	2
+
+# PLAT_PARTITION_MAX_ENTRIES must take care of STM32_TF-A_COPIES and other partitions
+# such as metadata (2) to find all the FIP partitions (default is 2).
+PLAT_PARTITION_MAX_ENTRIES	:=	$(shell echo $$(($(STM32_TF_A_COPIES) + 4)))
+
 ifeq (${PSA_FWU_SUPPORT},1)
 ifneq (${STM32MP_USE_STM32IMAGE},1)
 # Number of banks of updatable firmware
 NR_OF_FW_BANKS			:=	2
 NR_OF_IMAGES_IN_FW_BANK		:=	1
 
-# Number of TF-A copies in the device
-STM32_TF_A_COPIES		:=	2
-STM32_BL33_PARTS_NUM		:=	2
-STM32_RUNTIME_PARTS_NUM		:=	4
-else
-$(error FWU Feature enabled only with FIP images)
+FWU_MAX_PART = $(shell echo $$(($(STM32_TF_A_COPIES) + 2 + $(NR_OF_FW_BANKS))))
+ifeq ($(shell test $(FWU_MAX_PART) -gt $(PLAT_PARTITION_MAX_ENTRIES); echo $$?),0)
+$(error "Required partition number is $(FWU_MAX_PART) where PLAT_PARTITION_MAX_ENTRIES is only \
+$(PLAT_PARTITION_MAX_ENTRIES)")
 endif
 else
-# Number of TF-A copies in the device
-STM32_TF_A_COPIES		:=	2
-STM32_BL33_PARTS_NUM		:=	1
-ifeq ($(AARCH32_SP),optee)
-STM32_RUNTIME_PARTS_NUM		:=	3
-else ifeq ($(STM32MP_USE_STM32IMAGE),1)
-STM32_RUNTIME_PARTS_NUM		:=	0
-else
-STM32_RUNTIME_PARTS_NUM		:=	1
+$(error FWU Feature enabled only with FIP images)
 endif
 endif
-PLAT_PARTITION_MAX_ENTRIES	:=	$(shell echo $$(($(STM32_TF_A_COPIES) + \
-							 $(STM32_BL33_PARTS_NUM) + \
-							 $(STM32_RUNTIME_PARTS_NUM))))
 
 # Boot devices
 STM32MP_EMMC		?=	0