Merge "target: msm8952: add support for truly 1080p panel for SDM439/SDM429"
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index 168b872..10cae72 100644
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -321,8 +321,8 @@
 char display_panel_buf[MAX_PANEL_BUF_SIZE];
 char panel_display_mode[MAX_RSP_SIZE];
 char soc_version_str[MAX_RSP_SIZE];
-#if PRODUCT_IOT
 char block_size_string[MAX_RSP_SIZE];
+#if PRODUCT_IOT
 
 /* For IOT we are using custom version */
 #define PRODUCT_IOT_VERSION "IOT001"
@@ -4700,17 +4700,24 @@
 			device.display_panel);
 	fastboot_publish("display-panel",
 			(const char *) panel_display_mode);
+
+        if (target_is_emmc_boot())
+        {
+		mmc_blocksize = mmc_get_device_blocksize();
+        }
+        else
+        {
+		mmc_blocksize = flash_block_size();
+        }
+	snprintf(block_size_string, MAX_RSP_SIZE, "0x%x", mmc_blocksize);
+	fastboot_publish("erase-block-size", (const char *) block_size_string);
+	fastboot_publish("logical-block-size", (const char *) block_size_string);
 #if PRODUCT_IOT
 	get_bootloader_version_iot(&bootloader_version_string);
 	fastboot_publish("version-bootloader", (const char *) bootloader_version_string);
 
 	/* Version baseband is n/a for apq iot devices */
 	fastboot_publish("version-baseband", "N/A");
-
-	/* IOT targets support only mmc target */
-	snprintf(block_size_string, MAX_RSP_SIZE, "0x%x", mmc_get_device_blocksize());
-	fastboot_publish("erase-block-size", (const char *) block_size_string);
-	fastboot_publish("logical-block-size", (const char *) block_size_string);
 #else
 	fastboot_publish("version-bootloader", (const char *) device.bootloader_version);
 	fastboot_publish("version-baseband", (const char *) device.radio_version);
diff --git a/dev/gcdb/display/include/panel_auo_400p_cmd.h b/dev/gcdb/display/include/panel_auo_400p_cmd.h
index f772f2d..400d156 100644
--- a/dev/gcdb/display/include/panel_auo_400p_cmd.h
+++ b/dev/gcdb/display/include/panel_auo_400p_cmd.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -38,7 +38,7 @@
 /*---------------------------------------------------------------------------*/
 static struct panel_config auo_400p_cmd_panel_data = {
 	"qcom,mdss_dsi_auo_400p_cmd", "dsi:0:", "qcom,mdss-dsi-panel",
-	10, 1, "DISPLAY_1", 0, 0, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ""
+	10, 1, "DISPLAY_1", 0, 0, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
 };
 
 /*---------------------------------------------------------------------------*/
diff --git a/dev/gcdb/display/include/panel_auo_cx_qvga_cmd.h b/dev/gcdb/display/include/panel_auo_cx_qvga_cmd.h
index b0ac9c3..caaf084 100644
--- a/dev/gcdb/display/include/panel_auo_cx_qvga_cmd.h
+++ b/dev/gcdb/display/include/panel_auo_cx_qvga_cmd.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2015, 2017, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2015, 2018, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -39,7 +39,7 @@
 /*---------------------------------------------------------------------------*/
 static struct panel_config auo_cx_qvga_cmd_panel_data = {
 	"qcom,mdss_dsi_auo_cx_qvga_cmd", "dsi:0:", "qcom,mdss-dsi-panel",
-	10, 1, "DISPLAY_1", 0, 0, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ""
+	10, 1, "DISPLAY_1", 0, 0, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
 };
 
 /*---------------------------------------------------------------------------*/
diff --git a/dev/gcdb/display/include/panel_hx8399c_hd_plus_video.h b/dev/gcdb/display/include/panel_hx8399c_hd_plus_video.h
index 1adbc49..4a32b0f 100644
--- a/dev/gcdb/display/include/panel_hx8399c_hd_plus_video.h
+++ b/dev/gcdb/display/include/panel_hx8399c_hd_plus_video.h
@@ -47,7 +47,7 @@
 /* Panel resolution                                                          */
 /*---------------------------------------------------------------------------*/
 static struct panel_resolution hx8399c_hd_plus_video_panel_res = {
-	720, 1440, 24, 24, 16, 0, 36, 40, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0
+	720, 1440, 48, 48, 16, 0, 36, 40, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };
 
 /*---------------------------------------------------------------------------*/
@@ -304,19 +304,19 @@
 /* Panel timing                                                              */
 /*---------------------------------------------------------------------------*/
 static const uint32_t hx8399c_hd_plus_video_timings[] = {
-	0x7E, 0x48, 0x3C, 0x00, 0x64, 0x59, 0x3B, 0x4A, 0x2E, 0x03, 0x04, 0x00
+	0x90, 0x1C, 0x12, 0x00, 0x42, 0x44, 0x18, 0x20, 0x16, 0x03, 0x04, 0x00
 };
 
 static const uint32_t hx8399c_hd_plus_video_12nm_timings[] = {
-	0x08, 0x06, 0x0A, 0x02, 0x00, 0x04, 0x02, 0x08
+	0x09, 0x06, 0x0A, 0x02, 0x00, 0x05, 0x02, 0x08
 };
 
 static const uint32_t hx8399c_hd_plus_14nm_video_timings[] = {
-	0x24, 0x1f, 0x08, 0x09, 0x05, 0x03, 0x04, 0xa0,
-	0x24, 0x1f, 0x08, 0x09, 0x05, 0x03, 0x04, 0xa0,
-	0x24, 0x1f, 0x08, 0x09, 0x05, 0x03, 0x04, 0xa0,
-	0x24, 0x1f, 0x08, 0x09, 0x05, 0x03, 0x04, 0xa0,
-	0x24, 0x1c, 0x08, 0x09, 0x05, 0x03, 0x04, 0xa0,
+	0x1e, 0x1c, 0x04, 0x06, 0x02, 0x03, 0x04, 0xa0,
+	0x1e, 0x1c, 0x04, 0x06, 0x02, 0x03, 0x04, 0xa0,
+	0x1e, 0x1c, 0x04, 0x06, 0x02, 0x03, 0x04, 0xa0,
+	0x1e, 0x1c, 0x04, 0x06, 0x02, 0x03, 0x04, 0xa0,
+	0x1e, 0x0e, 0x04, 0x05, 0x02, 0x03, 0x04, 0xa0,
 };
 static struct panel_timing hx8399c_hd_plus_video_timing_info = {
 	0, 4, 0x0e, 0x31
diff --git a/platform/msm_shared/avb/libavb/avb_ops.c b/platform/msm_shared/avb/libavb/avb_ops.c
index 8c56f71..ebb84c7 100644
--- a/platform/msm_shared/avb/libavb/avb_ops.c
+++ b/platform/msm_shared/avb/libavb/avb_ops.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017-2018 The Android Open Source Project
+ * Copyright (C) 2017 The Android Open Source Project
  *
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
diff --git a/platform/msm_shared/boot_verifier.c b/platform/msm_shared/boot_verifier.c
index 2f5e2ff..ced0fac 100644
--- a/platform/msm_shared/boot_verifier.c
+++ b/platform/msm_shared/boot_verifier.c
@@ -586,12 +586,12 @@
 			}
 			ret = set_tamper_fuse_cmd(HLOS_TAMPER_NOTIFY_FUSE);
 			if (ret) {
-				dprintf(CRITICAL, "QCOM_VB_SendROT: set_tamper_fuse_cmd (TZ_HLOS_TAMPER_NOTIFY_FUSE) fails!\n");
+				dprintf(CRITICAL, "send_rot_command: set_tamper_fuse_cmd (TZ_HLOS_TAMPER_NOTIFY_FUSE) fails!\n");
 				ret = false;
 				goto err;
 			}
 		} else {
-			dprintf(CRITICAL, "QCOM_VB_SendROT: TZ didn't support this feature! Version: major = %d, minor = %d, patch = %d\n", (version >> 22) & 0x3FF, (version >> 12) & 0x3FF, version & 0x3FF);
+			dprintf(CRITICAL, "send_rot_command: TZ didn't support this feature! Version: major = %d, minor = %d, patch = %d\n", (version >> 22) & 0x3FF, (version >> 12) & 0x3FF, version & 0x3FF);
 		ret = false;
 		goto err;
 		}
diff --git a/platform/msm_shared/partition_parser.c b/platform/msm_shared/partition_parser.c
old mode 100644
new mode 100755
index 3752ba8..7874adb
--- a/platform/msm_shared/partition_parser.c
+++ b/platform/msm_shared/partition_parser.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -83,6 +83,8 @@
 struct partition_entry *partition_entries;
 static unsigned gpt_partitions_exist = 0;
 static unsigned partition_count;
+/* this is a pointer to ptn_entries_buffer */
+static unsigned char *new_buffer = NULL;
 
 unsigned partition_get_partition_count()
 {
@@ -273,10 +275,12 @@
 	unsigned int n = 0;	/* Counter for UTF-16 -> 8 conversion */
 	unsigned char UTF16_name[MAX_GPT_NAME_SIZE];
 	/* LBA of first partition -- 1 Block after Protected MBR + 1 for PT */
-	unsigned long long partition_0;
 	uint64_t device_density;
 	uint8_t *data = NULL;
+	uint8_t *data_org_ptr = NULL;
 	uint32_t part_entry_cnt = block_size / ENTRY_SIZE;
+	uint32_t blocks_for_entries =
+			(NUM_PARTITIONS * PARTITION_ENTRY_SIZE)/block_size;
 
 	/* Get the density of the mmc device */
 
@@ -289,6 +293,7 @@
 		ret = -1;
 		goto end;
 	}
+	data_org_ptr = data;
 
 	/* Print out the GPT first */
 	ret = mmc_read(block_size, (unsigned int *)data, block_size);
@@ -330,19 +335,11 @@
 		}
 		parse_secondary_gpt = 0;
 	}
-	partition_0 = GET_LLWORD_FROM_BYTE(&data[PARTITION_ENTRIES_OFFSET]);
 	/* Read GPT Entries */
 	for (i = 0; i < (ROUNDUP(max_partition_count, part_entry_cnt)) / part_entry_cnt; i++) {
 		ASSERT(partition_count < NUM_PARTITIONS);
-		ret = mmc_read((partition_0 * block_size) + (i * block_size),
-						(uint32_t *) data, block_size);
-
-		if (ret) {
-			dprintf(CRITICAL,
-				"GPT: mmc read card failed reading partition entries.\n");
-			goto end;
-		}
-
+		
+		data = (new_buffer + (i * block_size));
 		for (j = 0; j < part_entry_cnt; j++) {
 			memcpy(&(partition_entries[partition_count].type_guid),
 			       &data[(j * partition_entry_size)],
@@ -368,13 +365,28 @@
 			    GET_LLWORD_FROM_BYTE(&data
 						 [(j * partition_entry_size) +
 						  LAST_LBA_OFFSET]);
+
+			/* If partition entry LBA is not valid, skip this entry
+				and parse next entry */
+			if (partition_entries[partition_count].first_lba < first_usable_lba
+				|| partition_entries[partition_count].last_lba >
+						(device_density/block_size -
+						(blocks_for_entries + GPT_HEADER_BLOCKS + 1))
+				|| partition_entries[partition_count].first_lba >
+					partition_entries[partition_count].last_lba)
+			{
+				dprintf(CRITICAL, "Partition entry(%d), lba not valid\n", j);
+				partition_count++;
+				continue;
+			}
+
 			partition_entries[partition_count].size =
 			    partition_entries[partition_count].last_lba -
 			    partition_entries[partition_count].first_lba + 1;
 			partition_entries[partition_count].attribute_flag =
 			    GET_LLWORD_FROM_BYTE(&data
 						 [(j * partition_entry_size) +
-						  ATTRIBUTE_FLAG_OFFSET]);
+				 		  ATTRIBUTE_FLAG_OFFSET]);
 
 			memset(&UTF16_name, 0x00, MAX_GPT_NAME_SIZE);
 			memcpy(UTF16_name, &data[(j * partition_entry_size) +
@@ -394,8 +406,10 @@
 		}
 	}
 end:
-	if (data)
-		free(data);
+	if (data_org_ptr)
+		free(data_org_ptr);
+	if (new_buffer)
+		free(new_buffer);
 
 	return ret;
 }
@@ -589,6 +603,8 @@
 	unsigned int partition_entry_array_start;
 	unsigned char *primary_gpt_header;
 	unsigned char *secondary_gpt_header;
+	//define as 64 bit unsigned int
+	unsigned long long *last_partition_entry;
 	unsigned int offset;
 	unsigned long long card_size_sec;
 	int total_part = 0;
@@ -624,9 +640,14 @@
 					(ptn_entries_blocks + GPT_HEADER_BLOCKS))));
 
 	/* Find last partition */
-	while (*(primary_gpt_header + block_size + total_part * ENTRY_SIZE) !=
-	       0) {
+	last_partition_entry = (unsigned long long *)
+		(primary_gpt_header + block_size + total_part * ENTRY_SIZE);
+	//need check 128 bit for GUID
+	while (*last_partition_entry != 0 ||
+		*(last_partition_entry + 1) != 0 ) {
 		total_part++;
+		last_partition_entry = (unsigned long long *)
+			(primary_gpt_header + block_size + total_part * ENTRY_SIZE);
 	}
 
 	/* Patching last partition */
@@ -1163,11 +1184,12 @@
 	uint32_t ret = 0;
 	uint32_t partitions_for_block = 0;
 	uint32_t blocks_to_read = 0;
-	unsigned char *new_buffer = NULL;
 	unsigned long long last_usable_lba = 0;
 	unsigned long long partition_0 = 0;
 	unsigned long long current_lba = 0;
 	uint32_t block_size = mmc_get_device_blocksize();
+	uint32_t blocks_for_entries =
+			(NUM_PARTITIONS * PARTITION_ENTRY_SIZE)/ block_size;
 	/* Get the density of the mmc device */
 	uint64_t device_density = mmc_get_device_capacity();
 
@@ -1215,10 +1237,19 @@
 	/*current lba and GPT lba should be same*/
 	if (!parse_secondary_gpt) {
 		if (current_lba != GPT_LBA) {
-			dprintf(CRITICAL,"GPT first usable LBA mismatch\n");
+			dprintf(CRITICAL,"Primary GPT first usable LBA mismatch\n");
 			return 1;
 		}
 	}
+	else
+	{
+		if (current_lba != ((device_density/block_size) - 1))
+		{
+			dprintf(CRITICAL,"Secondary GPT first usable LBA mismatch\n");
+			return 1;
+		}
+	}
+
 	/*check for first lba should be with in the valid range*/
 	if (*first_usable_lba > (device_density/block_size)) {
 		dprintf(CRITICAL,"Invalid first_usable_lba\n");
@@ -1258,11 +1289,24 @@
 	if (!flashing_gpt) {
 		partition_0 = GET_LLWORD_FROM_BYTE(&buffer[PARTITION_ENTRIES_OFFSET]);
 		/*start LBA should always be 2 in primary GPT*/
-		if(partition_0 != 0x2 && !parse_secondary_gpt) {
-			dprintf(CRITICAL, "Starting LBA mismatch\n");
-			ret = 1;
-			goto fail;
-
+		if (!parse_secondary_gpt)
+		{
+			if (partition_0 != 0x2)
+			{
+				dprintf(CRITICAL, "PrimaryGPT starting LBA mismatch\n");
+				ret = 1;
+				goto fail;
+			}
+		}
+		else
+		{
+			if (partition_0 != ((device_density/block_size) -
+						(blocks_for_entries + GPT_HEADER_BLOCKS)))
+			{
+				dprintf(CRITICAL, "BackupGPT starting LBA mismatch\n");
+				ret = 1;
+				goto fail;
+			}
 		}
 		/*read the partition entries to new_buffer*/
 		ret = mmc_read((partition_0) * (block_size), (unsigned int *)new_buffer, (blocks_to_read * block_size));
@@ -1278,6 +1322,7 @@
 			dprintf(CRITICAL,"Partition entires crc mismatch crc_val= %u with crc_val_org= %u\n",crc_val,crc_val_org);
 			ret = 1;
 		}
+		return ret;
 	}
 fail:
 	free(new_buffer);
diff --git a/platform/msm_shared/secapp_loader.c b/platform/msm_shared/secapp_loader.c
index c8e3de4..2c282f2 100644
--- a/platform/msm_shared/secapp_loader.c
+++ b/platform/msm_shared/secapp_loader.c
@@ -93,13 +93,12 @@
 	}
 	version = qseecom_get_version();
 	if(allow_set_fuse(version)) {
-		dprintf(CRITICAL, "HLOS_BL_MILESTONE_FUSE ");
                ret = set_tamper_fuse_cmd(HLOS_BL_MILESTONE_FUSE);
                if (ret) {
-                       dprintf(CRITICAL, "QCOM_VB_Send_Milestone: set_tamper_fuse_cmd (HLOS_BL_MILESTONE_FUSE) fails!\n");
+                       dprintf(CRITICAL, "send_milestone_call_to_tz: set_tamper_fuse_cmd (HLOS_BL_MILESTONE_FUSE) fails!\n");
 		}
 	} else {
-               dprintf(CRITICAL, "QCOM_VB_Send_Milestone: TZ didn't support this feature! Version: major = %d, minor = %d, patch = %d\n",
+               dprintf(CRITICAL, "send_milestone_call_to_tz: TZ didn't support this feature! Version: major = %d, minor = %d, patch = %d\n",
 			(version >> 22) & 0x3FF, (version >> 12) & 0x3FF, version & 0x3FF);
                return ret;
 	}
diff --git a/target/msm8909/init.c b/target/msm8909/init.c
index 7ebf174..2558067 100644
--- a/target/msm8909/init.c
+++ b/target/msm8909/init.c
@@ -870,7 +870,8 @@
 uint32_t target_get_pmic()
 {
 	if ((board_hardware_subtype() == HW_PLATFORM_SUBTYPE_8909_PM660) ||
-		(board_hardware_subtype() == HW_PLATFORM_SUBTYPE_8909_PM660_V1))
+		(board_hardware_subtype() == HW_PLATFORM_SUBTYPE_8909_PM660_V1) ||
+		(board_hardware_subtype() == HW_PLATFORM_SUBTYPE_8909_COMPAL_ALPHA))
 		return PMIC_IS_PM660;
 	else
 		return PMIC_IS_PM8909;
diff --git a/target/msm8952/oem_panel.c b/target/msm8952/oem_panel.c
index 6b5482b..b0a1536 100644
--- a/target/msm8952/oem_panel.c
+++ b/target/msm8952/oem_panel.c
@@ -607,7 +607,9 @@
 		memcpy(phy_db->timing,
 						hx8394f_720p_video_timings, TIMING_SIZE);
 		pinfo->mipi.signature = HX8394F_720P_VIDEO_SIGNATURE;
-		pinfo->disable_wled_labibb = true;
+		if ((board_platform_id() == SDM429) || (board_platform_id() == SDM439) ||
+				(board_platform_id() == SDA429) || (board_platform_id() == SDA439))
+			pinfo->disable_wled_labibb = true;
 		break;
 	case BYD_1200P_VIDEO_PANEL:
 		panelstruct->paneldata    = &byd_1200p_video_panel_data;
diff --git a/target/msm8953/oem_panel.c b/target/msm8953/oem_panel.c
index 8bb0c47..e20f8d9 100644
--- a/target/msm8953/oem_panel.c
+++ b/target/msm8953/oem_panel.c
@@ -254,6 +254,12 @@
 	case HX8399C_FHD_PLUSE_VIDEO_PANEL:
 		panelstruct->paneldata    = &hx8399c_fhd_pluse_video_panel_data;
 		panelstruct->panelres     = &hx8399c_fhd_pluse_video_panel_res;
+		panelstruct->panelres->hfront_porch = 52;
+		panelstruct->panelres->hback_porch = 48;
+		panelstruct->panelres->hpulse_width = 8;
+		panelstruct->panelres->vfront_porch = 8;
+		panelstruct->panelres->vback_porch = 8;
+		panelstruct->panelres->vpulse_width = 4;
 		panelstruct->color        = &hx8399c_fhd_pluse_video_color;
 		panelstruct->videopanel   =
 				&hx8399c_fhd_pluse_video_video_panel;