GPT: Enable partition table to be flashed using fastboot command.

The partition table can be flashed using the command "fastboot flash partition
<name of the file>". Code detects the GPT partition table and flashes it
to the eMMC card.

Change-Id: I93c9a204ba0a7c0328a9cfd30331ea6cbe7d5df4
diff --git a/platform/msm_shared/include/partition_parser.h b/platform/msm_shared/include/partition_parser.h
index 057f4ce..6df3902 100644
--- a/platform/msm_shared/include/partition_parser.h
+++ b/platform/msm_shared/include/partition_parser.h
@@ -43,6 +43,7 @@
 #define PROTECTIVE_MBR_SIZE       BLOCK_SIZE
 #define HEADER_SIZE_OFFSET        12
 #define HEADER_CRC_OFFSET         16
+#define PRIMARY_HEADER_OFFSET     24
 #define BACKUP_HEADER_OFFSET      32
 #define FIRST_USABLE_LBA_OFFSET   40
 #define LAST_USABLE_LBA_OFFSET    48
@@ -51,6 +52,8 @@
 #define PENTRY_SIZE_OFFSET        84
 #define PARTITION_CRC_OFFSET      88
 
+#define MIN_PARTITION_ARRAY_SIZE  0x4000
+
 #define PARTITION_ENTRY_LAST_LBA  40
 
 #define ENTRY_SIZE              0x080
@@ -112,6 +115,25 @@
         ((unsigned long long)*(x+6) << 48) | \
         ((unsigned long long)*(x+7) << 56))
 
+#define GET_LONG(x)    ((uint32_t)*(x) | \
+            ((uint32_t)*(x+1) << 8) | \
+            ((uint32_t)*(x+2) << 16) | \
+            ((uint32_t)*(x+3) << 24))
+
+#define PUT_LONG(x, y)   *(x) = y & 0xff;     \
+    *(x+1) = (y >> 8) & 0xff;     \
+    *(x+2) = (y >> 16) & 0xff;    \
+    *(x+3) = (y >> 24) & 0xff;
+
+#define PUT_LONG_LONG(x,y)    *(x) =(y) & 0xff; \
+     *((x)+1) = (((y) >> 8) & 0xff);    \
+     *((x)+2) = (((y) >> 16) & 0xff);   \
+     *((x)+3) = (((y) >> 24) & 0xff);   \
+     *((x)+4) = (((y) >> 32) & 0xff);   \
+     *((x)+5) = (((y) >> 40) & 0xff);   \
+     *((x)+6) = (((y) >> 48) & 0xff);   \
+     *((x)+7) = (((y) >> 56) & 0xff);
+
 /* Unified mbr and gpt entry types */
 struct partition_entry
 {
@@ -145,5 +167,15 @@
                                         unsigned int * partition_entry_size,
                                         unsigned int * header_size,
                                         unsigned int * max_partition_count);
+
+unsigned int write_mbr(unsigned size, unsigned char *mbrImage,
+                       struct mmc_boot_host *mmc_host,
+                       struct mmc_boot_card *mmc_card);
+unsigned int write_gpt(unsigned size, unsigned char *gptImage,
+                       struct mmc_boot_host *mmc_host,
+                       struct mmc_boot_card *mmc_card);
+unsigned int write_partition(unsigned size, unsigned char* partition);
+
+
 /* For Debugging */
 void partition_dump(void);