Merge "aboot: mdtp: support write back cache"
diff --git a/app/aboot/mdtp.c b/app/aboot/mdtp.c
index 2ecccce..1db57cc 100644
--- a/app/aboot/mdtp.c
+++ b/app/aboot/mdtp.c
@@ -755,6 +755,9 @@
 	ASSERT(dec_dip != NULL);
 	ASSERT(verified != NULL);
 
+	arch_clean_invalidate_cache_range((addr_t)enc_dip, sizeof(DIP_t));
+	arch_invalidate_cache_range((addr_t)dec_dip, sizeof(DIP_t));
+
 	ret = mdtp_cipher_dip_cmd((uint8_t*)enc_dip, sizeof(DIP_t),
 								(uint8_t*)dec_dip, sizeof(DIP_t),
 								DIP_DECRYPT);
@@ -766,6 +769,8 @@
 		return -1;
 	}
 
+	arch_invalidate_cache_range((addr_t)dec_dip, sizeof(DIP_t));
+
 	SHA256_Init(&sha256_ctx);
 	SHA256_Update(&sha256_ctx, dec_dip, sizeof(DIP_t) - HASH_LEN);
 	SHA256_Final(hash, &sha256_ctx);
@@ -796,6 +801,9 @@
 	SHA256_Update(&sha256_ctx, dec_dip, sizeof(DIP_t) - HASH_LEN);
 	SHA256_Final(dec_dip->hash, &sha256_ctx);
 
+	arch_clean_invalidate_cache_range((addr_t)dec_dip, sizeof(DIP_t));
+	arch_invalidate_cache_range((addr_t)enc_dip, sizeof(DIP_t));
+
 	ret = mdtp_cipher_dip_cmd((uint8_t*)dec_dip, sizeof(DIP_t),
 								(uint8_t*)enc_dip, sizeof(DIP_t),
 								DIP_ENCRYPT);
@@ -805,6 +813,8 @@
 		return -1;
 	}
 
+	arch_invalidate_cache_range((addr_t)enc_dip, sizeof(DIP_t));
+
 	return 0;
 }
 
diff --git a/app/aboot/mdtp_fuse.c b/app/aboot/mdtp_fuse.c
index 239d263..81351f4 100644
--- a/app/aboot/mdtp_fuse.c
+++ b/app/aboot/mdtp_fuse.c
@@ -39,8 +39,6 @@
 #define MAX_METADATA_SIZE       (0x1000)
 #define QFPROM_ADDR_SPACE_RAW   (0)
 
-char metadata_block[MAX_METADATA_SIZE] = {0};
-
 /********************************************************************************/
 
 typedef union
@@ -118,6 +116,7 @@
 	uint32_t actual_size;
 	int index = INVALID_PTN;
 	uint32_t block_size = mmc_get_device_blocksize();
+	unsigned char *buf = (unsigned char *)target_get_scratch_address() + MDTP_SCRATCH_OFFSET;
 
 	index = partition_get_index("mdtp");
 	ptn = partition_get_offset(index);
@@ -135,13 +134,13 @@
 		return -1;
 	}
 
-	if(mmc_read(ptn, (void *)metadata_block, actual_size))
+	if(mmc_read(ptn, (void *)buf, actual_size))
 	{
 		dprintf(CRITICAL, "mdtp: read_metadata: ERROR, cannot read mdtp info\n");
 		return -1;
 	}
 
-	memscpy((uint8_t*)metadata, sizeof(metadata_t), (uint8_t*)(&(metadata_block[0])), MAX_METADATA_SIZE);
+	memscpy((uint8_t*)metadata, sizeof(metadata_t), (uint8_t*)(buf), MAX_METADATA_SIZE);
 
 	dprintf(INFO, "mdtp: read_metadata: SUCCESS, read %d bytes\n", actual_size);
 
diff --git a/app/aboot/mdtp_ui.c b/app/aboot/mdtp_ui.c
index 7a94ad6..6200eb5 100644
--- a/app/aboot/mdtp_ui.c
+++ b/app/aboot/mdtp_ui.c
@@ -138,6 +138,7 @@
 				dprintf(CRITICAL, "ERROR: mdtp image read failed\n");
 				return NULL;
 		}
+
 		logo->width = width;
 		logo->height = height;
 	}
@@ -243,6 +244,9 @@
 		display_error_msg(); /* This will never return */
 	}
 
+	/* Flush the contents to memory before giving the data to dma */
+	arch_clean_invalidate_cache_range((addr_t) fb_config->base, (fb_config->height * fb_config->width * bytes_per_bpp));
+
 	fbcon_flush();
 
 #if DISPLAY_MIPI_PANEL_NOVATEK_BLUE