poplar: Add LOAD_IMAGE_V2 support

Signed-off-by: Victor Chong <victor.chong@linaro.org>
Tested-by: Shawn Guo <shawn.guo@linaro.org>
diff --git a/plat/hisilicon/poplar/bl31_plat_setup.c b/plat/hisilicon/poplar/bl31_plat_setup.c
index e3a5c50..ec72acd 100644
--- a/plat/hisilicon/poplar/bl31_plat_setup.c
+++ b/plat/hisilicon/poplar/bl31_plat_setup.c
@@ -59,14 +59,64 @@
 		return NULL;
 }
 
+/*******************************************************************************
+ * Perform any BL31 early platform setup common to ARM standard platforms.
+ * Here is an opportunity to copy parameters passed by the calling EL (S-EL1
+ * in BL2 & S-EL3 in BL1) before they are lost (potentially). This needs to be
+ * done before the MMU is initialized so that the memory layout can be used
+ * while creating page tables. BL2 has flushed this information to memory, so
+ * we are guaranteed to pick up good data.
+ ******************************************************************************/
+#if LOAD_IMAGE_V2
+void bl31_early_platform_setup(void *from_bl2,
+			       void *plat_params_from_bl2)
+#else
 void bl31_early_platform_setup(bl31_params_t *from_bl2,
 			       void *plat_params_from_bl2)
+#endif
 {
 	console_init(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ, PL011_BAUDRATE);
 
 	/* Init console for crash report */
 	plat_crash_console_init();
 
+#if LOAD_IMAGE_V2
+		/*
+		 * Check params passed from BL2 should not be NULL,
+		 */
+		bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
+
+		assert(params_from_bl2 != NULL);
+		assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
+		assert(params_from_bl2->h.version >= VERSION_2);
+
+		bl_params_node_t *bl_params = params_from_bl2->head;
+
+		/*
+		 * Copy BL33 and BL32 (if present), entry point information.
+		 * They are stored in Secure RAM, in BL2's address space.
+		 */
+		while (bl_params) {
+			if (bl_params->image_id == BL32_IMAGE_ID)
+				bl32_image_ep_info = *bl_params->ep_info;
+
+			if (bl_params->image_id == BL33_IMAGE_ID)
+				bl33_image_ep_info = *bl_params->ep_info;
+
+			bl_params = bl_params->next_params_info;
+		}
+
+		if (bl33_image_ep_info.pc == 0)
+			panic();
+
+#else /* LOAD_IMAGE_V2 */
+
+	/*
+	 * Check params passed from BL2 should not be NULL,
+	 */
+	assert(params_from_bl2 != NULL);
+	assert(params_from_bl2->h.type == PARAM_BL31);
+	assert(params_from_bl2->h.version >= VERSION_1);
 
 	/*
 	 * Copy BL32 (if populated by BL2) and BL33 entry point information.
@@ -75,6 +125,7 @@
 	if (from_bl2->bl32_ep_info)
 		bl32_image_ep_info = *from_bl2->bl32_ep_info;
 	bl33_image_ep_info = *from_bl2->bl33_ep_info;
+#endif /* LOAD_IMAGE_V2 */
 }
 
 void bl31_platform_setup(void)
@@ -97,8 +148,8 @@
 
 void bl31_plat_arch_setup(void)
 {
-	plat_configure_mmu_el3(BL31_RO_BASE,
-			       (BL31_COHERENT_RAM_LIMIT - BL31_RO_BASE),
+	plat_configure_mmu_el3(BL31_BASE,
+			       (BL31_LIMIT - BL31_BASE),
 			       BL31_RO_BASE,
 			       BL31_RO_LIMIT,
 			       BL31_COHERENT_RAM_BASE,