QcomModulePkg : fix flash result of sparse images of size < MAX_DOWNLOAD_SIZE

Currently, while flashing sparse images if it encounters flash error,
it shows flash result as error in the next upcoming flash command, which
is misleading for sparse images size less than < MAX_DOWNLOAD_SIZE.

Change-Id: Iac9287efb9ec0943bf2f9eb3e3adc1b7a38530fa
diff --git a/QcomModulePkg/Library/FastbootLib/FastbootCmds.c b/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
index 299c69b..2f04b29 100644
--- a/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
+++ b/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
@@ -1527,6 +1527,7 @@
   BOOLEAN HasSlot = FALSE;
   CHAR16 SlotSuffix[MAX_SLOT_SUFFIX_SZ];
   CHAR8 FlashResultStr[MAX_RSP_SIZE] = "";
+  UINT64 PartitionSize = 0;
 
   ExchangeFlashAndUsbDataBuf ();
   if (mFlashDataBuffer == NULL) {
@@ -1634,15 +1635,18 @@
     }
 
     IsFlashComplete = FALSE;
+    PartitionSize = (BlockIo->Media->LastBlock + 1)
+                        * (BlockIo->Media->BlockSize);
 
-    Status = HandleUsbEventsInTimer ();
-    if (EFI_ERROR (Status)) {
-      DEBUG ((EFI_D_ERROR, "Failed to handle usb event: %r\n", Status));
-
-      IsFlashComplete = TRUE;
-      StopUsbTimer ();
-    } else {
-      FastbootOkay ("");
+    if (PartitionSize > MAX_DOWNLOAD_SIZE) {
+      Status = HandleUsbEventsInTimer ();
+      if (EFI_ERROR (Status)) {
+        DEBUG ((EFI_D_ERROR, "Failed to handle usb event: %r\n", Status));
+        IsFlashComplete = TRUE;
+        StopUsbTimer ();
+      } else {
+        FastbootOkay ("");
+      }
     }
 
     FlashResult = HandleSparseImgFlash (PartitionName, sizeof (PartitionName),
@@ -1650,7 +1654,6 @@
 
     IsFlashComplete = TRUE;
     StopUsbTimer ();
-
   } else if (!AsciiStrnCmp (UbiHeader->HdrMagic, UBI_HEADER_MAGIC, 4)) {
     FlashResult = HandleUbiImgFlash (PartitionName,
                                      sizeof (PartitionName),
@@ -1672,7 +1675,9 @@
    * sparse images.
    */
   if ((sparse_header->magic != SPARSE_HEADER_MAGIC) ||
-      (Status != EFI_SUCCESS)) {
+        (PartitionSize < MAX_DOWNLOAD_SIZE) ||
+        ((PartitionSize > MAX_DOWNLOAD_SIZE) &&
+        (Status != EFI_SUCCESS))) {
     if (EFI_ERROR (FlashResult)) {
       if (FlashResult == EFI_NOT_FOUND) {
         AsciiSPrint (FlashResultStr, MAX_RSP_SIZE, "(%s) No such partition",