FVP: Add dummy configs for BL31, BL32 and BL33

This patch adds soc_fw_config, tos_fw_config and nt_fw_config to the FVP.
The config files are placeholders and do not have any useful bindings
defined. The tos_fw_config is packaged in FIP and loaded by BL2 only
if SPD=tspd. The load address of these configs are specified in tb_fw_config
via new bindings defined for these configs. Currently, in FVP, the
soc_fw_config and tos_fw_config is loaded in the page between BL2_BASE
and ARM_SHARED_RAM. This memory was typically used for BL32 when
ARM_TSP_RAM_LOCATION=tsram but since we cannot fit BL32 in that
space anymore, it should be safe to use this memory for these configs.
There is also a runtime check in arm_bl2_dyn_cfg_init() which ensures
that this overlap doesn't happen.

The previous arm_dyn_get_hwconfig_info() is modified to accept configs
other than hw_config and hence renamed to arm_dyn_get_config_load_info().
The patch also corrects the definition of ARM_TB_FW_CONFIG_LIMIT to be
BL2_BASE.

Change-Id: I03a137d9fa1f92c862c254be808b8330cfd17a5a
Signed-off-by: Soby Mathew <soby.mathew@arm.com>
diff --git a/plat/arm/common/arm_dyn_cfg.c b/plat/arm/common/arm_dyn_cfg.c
index 33dc08b..3f0a9b4 100644
--- a/plat/arm/common/arm_dyn_cfg.c
+++ b/plat/arm/common/arm_dyn_cfg.c
@@ -85,14 +85,25 @@
 
 /*
  * BL2 utility function to initialize dynamic configuration specified by
- * TB_FW_CONFIG. Return early if TB_FW_CONFIG is not found or HW_CONFIG is
- * not specified in TB_FW_CONFIG.
+ * TB_FW_CONFIG. Populate the bl_mem_params_node_t of other FW_CONFIGs if
+ * specified in TB_FW_CONFIG.
  */
 void arm_bl2_dyn_cfg_init(void)
 {
-	int err = 0;
-	int tb_fw_node;
-	bl_mem_params_node_t *hw_cfg_mem_params = NULL;
+	int err = 0, tb_fw_node;
+	unsigned int i;
+	bl_mem_params_node_t *cfg_mem_params = NULL;
+	uint64_t image_base;
+	uint32_t image_size;
+	const unsigned int config_ids[] = {
+			HW_CONFIG_ID,
+			SOC_FW_CONFIG_ID,
+			NT_FW_CONFIG_ID,
+#ifdef SPD_tspd
+			/* Currently tos_fw_config is only present for TSP */
+			TOS_FW_CONFIG_ID
+#endif
+	};
 
 	if (tb_fw_cfg_dtb == NULL) {
 		VERBOSE("No TB_FW_CONFIG specified\n");
@@ -105,23 +116,57 @@
 		panic();
 	}
 
-	/* Get the hw_config load address and size from TB_FW_CONFIG */
-	hw_cfg_mem_params = get_bl_mem_params_node(HW_CONFIG_ID);
-	if (hw_cfg_mem_params == NULL) {
-		VERBOSE("Couldn't find HW_CONFIG in bl_mem_params_node\n");
-		return;
-	}
+	/* Iterate through all the fw config IDs */
+	for (i = 0; i < ARRAY_SIZE(config_ids); i++) {
+		/* Get the config load address and size from TB_FW_CONFIG */
+		cfg_mem_params = get_bl_mem_params_node(config_ids[i]);
+		if (cfg_mem_params == NULL) {
+			VERBOSE("Couldn't find HW_CONFIG in bl_mem_params_node\n");
+			continue;
+		}
 
-	err = arm_dyn_get_hwconfig_info((void *)tb_fw_cfg_dtb, tb_fw_node,
-		(uint64_t *) &hw_cfg_mem_params->image_info.image_base,
-		&hw_cfg_mem_params->image_info.image_max_size);
-	if (err < 0) {
-		VERBOSE("Couldn't find HW_CONFIG load info in TB_FW_CONFIG\n");
-		return;
-	}
+		err = arm_dyn_get_config_load_info((void *)tb_fw_cfg_dtb, tb_fw_node,
+				config_ids[i], &image_base, &image_size);
+		if (err < 0) {
+			VERBOSE("Couldn't find config_id %d load info in TB_FW_CONFIG\n",
+					config_ids[i]);
+			continue;
+		}
 
-	/* Remove the IMAGE_ATTRIB_SKIP_LOADING attribute from HW_CONFIG node */
-	hw_cfg_mem_params->image_info.h.attr &= ~IMAGE_ATTRIB_SKIP_LOADING;
+		/*
+		 * Do some runtime checks on the load addresses of soc_fw_config,
+		 * tos_fw_config, nt_fw_config. This is not a comprehensive check
+		 * of all invalid addresses but to prevent trivial porting errors.
+		 */
+		if (config_ids[i] != HW_CONFIG_ID) {
+
+			if (check_uptr_overflow(image_base, image_size) != 0)
+				continue;
+
+			/* Ensure the configs don't overlap with BL2 */
+			if ((image_base > BL2_BASE) || ((image_base + image_size) > BL2_BASE))
+				continue;
+
+			/* Ensure the configs are loaded in a valid address */
+			if (image_base < ARM_BL_RAM_BASE)
+				continue;
+#ifdef BL32_BASE
+			/*
+			 * If BL32 is present, ensure that the configs don't
+			 * overlap with it.
+			 */
+			if (image_base >= BL32_BASE && image_base <= BL32_LIMIT)
+				continue;
+#endif
+		}
+
+
+		cfg_mem_params->image_info.image_base = (uintptr_t)image_base;
+		cfg_mem_params->image_info.image_max_size = image_size;
+
+		/* Remove the IMAGE_ATTRIB_SKIP_LOADING attribute from HW_CONFIG node */
+		cfg_mem_params->image_info.h.attr &= ~IMAGE_ATTRIB_SKIP_LOADING;
+	}
 
 #if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH)
 	uint32_t disable_auth = 0;