Merge "QcomModulePkg: Fix fail to bootup issue after pushing some file"
diff --git a/QcomModulePkg/Library/BootLib/ShutdownServices.c b/QcomModulePkg/Library/BootLib/ShutdownServices.c
old mode 100644
new mode 100755
index f863226..d9c6e50
--- a/QcomModulePkg/Library/BootLib/ShutdownServices.c
+++ b/QcomModulePkg/Library/BootLib/ShutdownServices.c
@@ -17,6 +17,7 @@
 
 #include "ShutdownServices.h"
 
+#include <FastbootLib/FastbootCmds.h>
 #include <Guid/ArmMpCoreInfo.h>
 #include <Guid/FileInfo.h>
 #include <Guid/GlobalVariable.h>
@@ -40,6 +41,8 @@
   UINT32 DescriptorVersion;
   UINTN Pages;
 
+  WaitForFlashFinished ();
+
   MemoryMap = NULL;
   MemoryMapSize = 0;
   Pages = 0;
@@ -102,6 +105,8 @@
   ResetDataType ResetData;
   EFI_STATUS Status = EFI_INVALID_PARAMETER;
 
+  WaitForFlashFinished ();
+
   StrnCpyS (ResetData.DataBuffer, ARRAY_SIZE (ResetData.DataBuffer),
             (CONST CHAR16 *)STR_RESET_PARAM, ARRAY_SIZE (STR_RESET_PARAM) - 1);
   ResetData.Bdata = RebootReason;
@@ -120,6 +125,9 @@
 VOID ShutdownDevice (VOID)
 {
   EFI_STATUS Status = EFI_INVALID_PARAMETER;
+
+  WaitForFlashFinished ();
+
   gRT->ResetSystem (EfiResetShutdown, Status, 0, NULL);
 
   /* Flow never comes here and is fatal if it comes here.*/
diff --git a/QcomModulePkg/Library/FastbootLib/FastbootCmds.c b/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
index b057b21..94d0228 100755
--- a/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
+++ b/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
@@ -1318,16 +1318,6 @@
   return Status;
 }
 
-//Shoud block command until flash finished
-VOID WaitForFlashFinished (VOID)
-{
-  if (!IsFlashComplete &&
-    IsUseMThreadParallel ()) {
-    KernIntf->Lock->AcquireLock (LockFlash);
-    KernIntf->Lock->ReleaseLock (LockFlash);
-  }
-}
-
 INT32 __attribute__ ( (no_sanitize ("safe-stack")))
 SparseImgFlashThread (VOID* Arg)
 {
@@ -2405,6 +2395,16 @@
   return;
 }
 
+//Shoud block command until flash finished
+VOID WaitForFlashFinished (VOID)
+{
+  if (!IsFlashComplete &&
+    IsUseMThreadParallel ()) {
+    KernIntf->Lock->AcquireLock (LockFlash);
+    KernIntf->Lock->ReleaseLock (LockFlash);
+  }
+}
+
 VOID ThreadSleep (TimeDuration Delay)
 {
   KernIntf->Thread->ThreadSleep (Delay);
diff --git a/QcomModulePkg/Library/FastbootLib/FastbootCmds.h b/QcomModulePkg/Library/FastbootLib/FastbootCmds.h
index b8b4c35..7fb91c1 100755
--- a/QcomModulePkg/Library/FastbootLib/FastbootCmds.h
+++ b/QcomModulePkg/Library/FastbootLib/FastbootCmds.h
@@ -179,4 +179,5 @@
 BOOLEAN IsDisableParallelDownloadFlash (VOID);
 BOOLEAN IsUseMThreadParallel (VOID);
 VOID ThreadSleep (TimeDuration Delay);
+VOID WaitForFlashFinished (VOID);
 #endif
diff --git a/QcomModulePkg/Library/avb/VerifiedBoot.c b/QcomModulePkg/Library/avb/VerifiedBoot.c
old mode 100644
new mode 100755
index e1536ce..d276294
--- a/QcomModulePkg/Library/avb/VerifiedBoot.c
+++ b/QcomModulePkg/Library/avb/VerifiedBoot.c
@@ -31,6 +31,7 @@
 #include "BootImage.h"
 #include "KeymasterClient.h"
 #include "libavb/libavb.h"
+#include <FastbootLib/FastbootCmds.h>
 #include <Library/MenuKeysDetection.h>
 #include <Library/VerifiedBootMenu.h>
 #include <Library/LEOEMCertificate.h>
@@ -1581,6 +1582,8 @@
   QCOM_MDTP_PROTOCOL *MdtpProtocol;
   UINT32 AVBVersion = NO_AVB;
 
+  WaitForFlashFinished ();
+
   if (Info == NULL) {
     DEBUG ((EFI_D_ERROR, "Invalid parameter Info\n"));
     return EFI_INVALID_PARAMETER;