app: aboot: Add support for CHUNK_FILL type for sparse image

ext4 utils add CHUNK_TYPE_FILL chunk for the sparse images, handle
these chunk types when flashing the sparse image.

FPIIM-2067

CRs-Fixed: 540173
Change-Id: Icc031b5c0a6a66ddf91a0887363928d98dfdd769
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index 1c8b989..66ee012 100755
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -1904,12 +1904,16 @@
 {
 	unsigned int chunk;
 	unsigned int chunk_data_sz;
+	uint32_t *fill_buf = NULL;
+	uint32_t fill_val;
+	uint32_t chunk_blk_cnt = 0;
 	sparse_header_t *sparse_header;
 	chunk_header_t *chunk_header;
 	uint32_t total_blocks = 0;
 	unsigned long long ptn = 0;
 	unsigned long long size = 0;
 	int index = INVALID_PTN;
+	int i;
 	/*End of the sparse image address*/
 	uint32_t data_end = (uint32_t)data + sz;
 
@@ -2034,6 +2038,47 @@
 			data += chunk_data_sz;
 			break;
 
+			case CHUNK_TYPE_FILL:
+			if(chunk_header->total_sz != (sparse_header->chunk_hdr_sz +
+											sizeof(uint32_t)))
+			{
+				fastboot_fail("Bogus chunk size for chunk type FILL");
+				return;
+			}
+
+			fill_buf = (uint32_t *)memalign(CACHE_LINE, ROUNDUP(sparse_header->blk_sz, CACHE_LINE));
+			if (!fill_buf)
+			{
+				fastboot_fail("Malloc failed for: CHUNK_TYPE_FILL");
+				return;
+			}
+
+			fill_val = *(uint32_t *)data;
+			data = (char *) data + sizeof(uint32_t);
+			chunk_blk_cnt = chunk_data_sz / sparse_header->blk_sz;
+
+			for (i = 0; i < (sparse_header->blk_sz / sizeof(fill_val)); i++)
+			{
+				fill_buf[i] = fill_val;
+			}
+
+			for (i = 0; i < chunk_blk_cnt; i++)
+			{
+				if(mmc_write(ptn + ((uint64_t)total_blocks*sparse_header->blk_sz),
+							sparse_header->blk_sz,
+							fill_buf))
+				{
+					fastboot_fail("flash write failure");
+					free(fill_buf);
+					return;
+				}
+
+				total_blocks++;
+			}
+
+			free(fill_buf);
+			break;
+
 			case CHUNK_TYPE_DONT_CARE:
 			if(total_blocks > (UINT_MAX - chunk_header->chunk_sz)) {
 				fastboot_fail("bogus size for chunk DONT CARE type");
@@ -2065,6 +2110,7 @@
 			break;
 
 			default:
+			dprintf(CRITICAL, "Unkown chunk type: %x\n",chunk_header->chunk_type);
 			fastboot_fail("Unknown chunk type");
 			return;
 		}