SPM: Load image and RD from SP package

Load SP and RD from package instead of relying on RD being already
loaded in memory and the SP being loaded as a BL32 image.

Change-Id: I18d4fbf4597656c6a7e878e1d7c01a8a324f3f8a
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
diff --git a/services/std_svc/spm/spm_main.c b/services/std_svc/spm/spm_main.c
index ad1262c..6de4858 100644
--- a/services/std_svc/spm/spm_main.c
+++ b/services/std_svc/spm/spm_main.c
@@ -157,7 +157,10 @@
  ******************************************************************************/
 int32_t spm_setup(void)
 {
+	int rc;
 	sp_context_t *ctx;
+	void *sp_base, *rd_base;
+	size_t sp_size, rd_size;
 
 	/* Disable MMU at EL1 (initialized by BL2) */
 	disable_mmu_icache_el1();
@@ -167,9 +170,26 @@
 
 	ctx = &sp_ctx;
 
+	rc = plat_spm_sp_get_next_address(&sp_base, &sp_size,
+					  &rd_base, &rd_size);
+	if (rc != 0) {
+		ERROR("No Secure Partition found.\n");
+		panic();
+	}
+
 	/* Assign translation tables context. */
 	ctx->xlat_ctx_handle = spm_get_sp_xlat_context();
 
+	/* Save location of the image in physical memory */
+	ctx->image_base = (uintptr_t)sp_base;
+	ctx->image_size = sp_size;
+
+	rc = plat_spm_sp_rd_load(&ctx->rd, rd_base, rd_size);
+	if (rc < 0) {
+		ERROR("Error while loading RD blob.\n");
+		panic();
+	}
+
 	spm_sp_setup(ctx);
 
 	/* Register init function for deferred init.  */