Merge ac7a5e200ca5b91def015c719fe86f9bc52a2cee on remote branch

Change-Id: I6957d682d6248c447d9607ed581b302ccdfd0a37
diff --git a/platform/msm_shared/avb/libavb/avb_ops.c b/platform/msm_shared/avb/libavb/avb_ops.c
index 2199d34..8600eb3 100644
--- a/platform/msm_shared/avb/libavb/avb_ops.c
+++ b/platform/msm_shared/avb/libavb/avb_ops.c
@@ -160,14 +160,14 @@
 	AvbIOResult Result = AVB_IO_RESULT_OK;
 	EFI_STATUS Status = EFI_SUCCESS;
 	VOID *Page = NULL;
-	UINTN Offset = 0;
-	UINTN ptn = 0;
-	UINTN part_size = 0;
+	UINT64 Offset = 0;
+	UINT64 ptn = 0;
+	UINT64 part_size = 0;
 	UINT32 PageSize = 0;
-	UINT32 StartBlock = 0;
-	UINT32 LastBlock = 0;
-	UINT32 FullBlock = 0;
-	UINTN StartPageReadSize = 0;
+	UINT64 StartBlock = 0;
+	UINT64 LastBlock = 0;
+	UINT64 FullBlock = 0;
+	UINT64 StartPageReadSize = 0;
 	int index = INVALID_PTN;
 
 	if (Partition == NULL || Buffer == NULL || OutNumRead == NULL || NumBytes <= 0) {
@@ -233,7 +233,7 @@
 
 	if (Offset % PageSize != 0) {
 		/* Offset not aligned to PageSize*/
-		UINT32 StartPageReadOffset = Offset - (StartBlock * PageSize);
+		UINT64 StartPageReadOffset = Offset - (StartBlock * PageSize);
 
 		if (StartBlock == LastBlock) {
 			/* Offset & Offset + NumBytes are in same block */
@@ -244,14 +244,14 @@
 		}
 
 		dprintf(DEBUG,
-		       "StartBlock 0x%x, ReadOffset 0x%x, read_size 0x%llx\n",
-		       StartBlock, StartPageReadOffset, StartPageReadSize);
+		   "StartBlock 0x%llx, ReadOffset 0x%llx, read_size 0x%llx\n",
+		    StartBlock, StartPageReadOffset, StartPageReadSize);
 		if (StartPageReadSize <= 0 || StartPageReadOffset >= PageSize ||
 		    StartPageReadSize > PageSize - StartPageReadOffset ||
 		    StartPageReadSize > NumBytes) {
 			dprintf(CRITICAL,
-			       "StartBlock 0x%x, ReadOffset 0x%x, read_size "
-			       "0x%llx outside range.\n",
+			       "StartBlock 0x%llx, ReadOffset 0x%llx,"
+				"read_size 0x%llx outside range.\n",
 			       StartBlock, StartPageReadOffset, StartPageReadSize);
 			Result = AVB_IO_RESULT_ERROR_RANGE_OUTSIDE_PARTITION;
 			goto out;
@@ -272,18 +272,18 @@
 		/* NumBytes + Offset not aligned to PageSize*/
 		/* Offset for last block is always zero, start at Page boundary
 		 */
-		UINT32 LastPageReadOffset = 0;
-		UINTN ReadOffset2 = (LastBlock * PageSize);
-		UINTN LastPageReadSize = (Offset + NumBytes) - ReadOffset2;
+		UINT64 LastPageReadOffset = 0;
+		UINT64 ReadOffset2 = (LastBlock * PageSize);
+		UINT64 LastPageReadSize = (Offset + NumBytes) - ReadOffset2;
 
 		dprintf(DEBUG,
-		       "LastBlock 0x%x, ReadOffset 0x%x, read_size 0x%llx\n",
+		      "LastBlock 0x%llx, ReadOffset 0x%llx, read_size 0x%llx\n",
 		       LastBlock, LastPageReadOffset, LastPageReadSize);
 
 		if (LastPageReadSize <= 0 || LastPageReadSize >= PageSize ||
 		    LastPageReadSize > (NumBytes - *OutNumRead)) {
 			dprintf(CRITICAL,
-			       "LastBlock 0x%x, ReadOffset 0x%x, read_size "
+			       "LastBlock 0x%llx, ReadOffset 0x%llx, read_size "
 			       "0x%llx outside range.\n",
 			       LastBlock, LastPageReadOffset, LastPageReadSize);
 			Result = AVB_IO_RESULT_ERROR_RANGE_OUTSIDE_PARTITION;
@@ -304,19 +304,19 @@
 
 	if (*OutNumRead < NumBytes) {
 		/* full block reads */
-		UINTN FillPageReadSize = NumBytes - *OutNumRead;
+		UINT64 FillPageReadSize = NumBytes - *OutNumRead;
 
 		if ((FillPageReadSize % PageSize) != 0 ||
 		    (NumBytes - StartPageReadSize) < FillPageReadSize) {
 			dprintf(CRITICAL,
-			       "FullBlock 0x%x, ReadOffset 0x%x, read_size "
+			       "FullBlock 0x%llx, ReadOffset 0x%x, read_size "
 			       "0x%llx outside range.\n",
 			       FullBlock, 0, FillPageReadSize);
 			Result = AVB_IO_RESULT_ERROR_RANGE_OUTSIDE_PARTITION;
 			goto out;
 		}
 			dprintf(SPEW,
-			       "FullBlock 0x%x, ReadOffset 0x%x, read_size "
+			       "FullBlock 0x%llx, ReadOffset 0x%x, read_size "
 			       "0x%llx outside range. StartPageReadSize %#llx PageSize %d ptn %#llx Buffer %p\n",
 			       FullBlock, 0, FillPageReadSize, StartPageReadSize, PageSize, ptn, Buffer);
 		Status = mmc_read(ptn + FullBlock * PageSize, Buffer + StartPageReadSize,
diff --git a/platform/msm_shared/avb/libavb/avb_slot_verify.c b/platform/msm_shared/avb/libavb/avb_slot_verify.c
index c4039d1..40bfbe5 100644
--- a/platform/msm_shared/avb/libavb/avb_slot_verify.c
+++ b/platform/msm_shared/avb/libavb/avb_slot_verify.c
@@ -163,7 +163,7 @@
   }
 
   io_ret = ops->read_from_partition(
-            ops, part_name, 0 /* offset */, image_size, &image_buf, &part_num_read);
+            ops, found, 0 /* offset */, image_size, &image_buf, &part_num_read);
 
   if (image_buf == NULL) {
     ret = AVB_SLOT_VERIFY_RESULT_ERROR_OOM;
@@ -421,6 +421,16 @@
   if (is_vbmeta_partition) {
     vbmeta_offset = 0;
     vbmeta_size = VBMETA_MAX_SIZE;
+    io_ret = ops->read_from_partition(ops,
+                                    partition_name,
+                                    vbmeta_offset,
+                                    vbmeta_size,
+                                    &vbmeta_buf,
+                                    &vbmeta_num_read);
+    if (vbmeta_buf == NULL) {
+      ret = AVB_SLOT_VERIFY_RESULT_ERROR_OOM;
+      goto out;
+    }
   } else {
     uint8_t footer_buf[AVB_FOOTER_SIZE];
     size_t footer_num_read;
@@ -458,17 +468,7 @@
     }
     vbmeta_offset = footer.vbmeta_offset;
     vbmeta_size = footer.vbmeta_size;
-  }
-
-  if (avb_strcmp(full_partition_name, "vbmeta") == 0) {
-    io_ret = ops->read_from_partition(ops,
-                                    full_partition_name,
-                                    vbmeta_offset,
-                                    vbmeta_size,
-                                    &vbmeta_buf,
-                                    &vbmeta_num_read);
-  } else { // for chain partitions
-    vbmeta_buf = avb_malloc(vbmeta_size);
+    vbmeta_buf = avb_malloc(vbmeta_size); // for chain partitions
     if (vbmeta_buf == NULL) {
         ret = AVB_SLOT_VERIFY_RESULT_ERROR_OOM;
         goto out;
@@ -480,10 +480,6 @@
                                     vbmeta_buf,
                                     &vbmeta_num_read);
   }
-  if (vbmeta_buf == NULL) {
-    ret = AVB_SLOT_VERIFY_RESULT_ERROR_OOM;
-    goto out;
-  }
 
   if (io_ret == AVB_IO_RESULT_ERROR_OOM) {
     ret = AVB_SLOT_VERIFY_RESULT_ERROR_OOM;