MdeModulePkg DxeCapsuleLib: Use Attr to know whether reset is required
authorStar Zeng <star.zeng@intel.com>
Thu, 26 Jul 2018 05:38:34 +0000 (13:38 +0800)
committerStar Zeng <star.zeng@intel.com>
Wed, 1 Aug 2018 02:15:15 +0000 (10:15 +0800)
Current DxeCapsuleLibFmp always do reset for FMP capsule.
Actually, the code should use Attributes from FMP descriptor to know
whether reset is required or not.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLib.c

index 3c283e2..d4026dd 100644 (file)
@@ -618,11 +618,14 @@ DumpAllFmpInfo (
 \r
   @param[in]     UpdateImageTypeId       Used to identify device firmware targeted by this update.\r
   @param[in]     UpdateHardwareInstance  The HardwareInstance to target with this update.\r
-  @param[in,out] NoHandles               The number of handles returned in Buffer.\r
-  @param[out]    Buffer[out]             A pointer to the buffer to return the requested array of handles.\r
-\r
-  @retval EFI_SUCCESS            The array of handles was returned in Buffer, and the number of\r
-                                 handles in Buffer was returned in NoHandles.\r
+  @param[out]    NoHandles               The number of handles returned in HandleBuf.\r
+  @param[out]    HandleBuf               A pointer to the buffer to return the requested array of handles.\r
+  @param[out]    ResetRequiredBuf        A pointer to the buffer to return reset required flag for\r
+                                         the requested array of handles.\r
+\r
+  @retval EFI_SUCCESS            The array of handles and their reset required flag were returned in\r
+                                 HandleBuf and ResetRequiredBuf, and the number of handles in HandleBuf\r
+                                 was returned in NoHandles.\r
   @retval EFI_NOT_FOUND          No handles match the search.\r
   @retval EFI_OUT_OF_RESOURCES   There is not enough pool memory to store the matching results.\r
 **/\r
@@ -630,14 +633,16 @@ EFI_STATUS
 GetFmpHandleBufferByType (\r
   IN     EFI_GUID                     *UpdateImageTypeId,\r
   IN     UINT64                       UpdateHardwareInstance,\r
-  IN OUT UINTN                        *NoHandles,\r
-  OUT    EFI_HANDLE                   **Buffer\r
+  OUT    UINTN                        *NoHandles, OPTIONAL\r
+  OUT    EFI_HANDLE                   **HandleBuf, OPTIONAL\r
+  OUT    BOOLEAN                      **ResetRequiredBuf OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                                    Status;\r
   EFI_HANDLE                                    *HandleBuffer;\r
   UINTN                                         NumberOfHandles;\r
   EFI_HANDLE                                    *MatchedHandleBuffer;\r
+  BOOLEAN                                       *MatchedResetRequiredBuffer;\r
   UINTN                                         MatchedNumberOfHandles;\r
   EFI_FIRMWARE_MANAGEMENT_PROTOCOL              *Fmp;\r
   UINTN                                         Index;\r
@@ -651,8 +656,15 @@ GetFmpHandleBufferByType (
   UINTN                                         Index2;\r
   EFI_FIRMWARE_IMAGE_DESCRIPTOR                 *TempFmpImageInfo;\r
 \r
-  *NoHandles = 0;\r
-  *Buffer = NULL;\r
+  if (NoHandles != NULL) {\r
+    *NoHandles = 0;\r
+  }\r
+  if (HandleBuf != NULL) {\r
+    *HandleBuf = NULL;\r
+  }\r
+  if (ResetRequiredBuf != NULL) {\r
+    *ResetRequiredBuf = NULL;\r
+  }\r
 \r
   Status = gBS->LocateHandleBuffer (\r
                   ByProtocol,\r
@@ -666,10 +678,26 @@ GetFmpHandleBufferByType (
   }\r
 \r
   MatchedNumberOfHandles = 0;\r
-  MatchedHandleBuffer = AllocateZeroPool (sizeof(EFI_HANDLE) * NumberOfHandles);\r
-  if (MatchedHandleBuffer == NULL) {\r
-    FreePool (HandleBuffer);\r
-    return EFI_OUT_OF_RESOURCES;\r
+\r
+  MatchedHandleBuffer = NULL;\r
+  if (HandleBuf != NULL) {\r
+    MatchedHandleBuffer = AllocateZeroPool (sizeof(EFI_HANDLE) * NumberOfHandles);\r
+    if (MatchedHandleBuffer == NULL) {\r
+      FreePool (HandleBuffer);\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  }\r
+\r
+  MatchedResetRequiredBuffer = NULL;\r
+  if (ResetRequiredBuf != NULL) {\r
+    MatchedResetRequiredBuffer = AllocateZeroPool (sizeof(BOOLEAN) * NumberOfHandles);\r
+    if (MatchedResetRequiredBuffer == NULL) {\r
+      if (MatchedHandleBuffer != NULL) {\r
+        FreePool (MatchedHandleBuffer);\r
+      }\r
+      FreePool (HandleBuffer);\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
   }\r
 \r
   for (Index = 0; Index < NumberOfHandles; Index++) {\r
@@ -731,7 +759,15 @@ GetFmpHandleBufferByType (
         if ((UpdateHardwareInstance == 0) ||\r
             ((FmpImageInfoDescriptorVer >= EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION) &&\r
              (UpdateHardwareInstance == TempFmpImageInfo->HardwareInstance))) {\r
-          MatchedHandleBuffer[MatchedNumberOfHandles] = HandleBuffer[Index];\r
+          if (MatchedHandleBuffer != NULL) {\r
+            MatchedHandleBuffer[MatchedNumberOfHandles] = HandleBuffer[Index];\r
+          }\r
+          if (MatchedResetRequiredBuffer != NULL) {\r
+            MatchedResetRequiredBuffer[MatchedNumberOfHandles] = (((TempFmpImageInfo->AttributesSupported & \r
+                                                                 IMAGE_ATTRIBUTE_RESET_REQUIRED) != 0) &&\r
+                                                                 ((TempFmpImageInfo->AttributesSetting &\r
+                                                                 IMAGE_ATTRIBUTE_RESET_REQUIRED) != 0));\r
+          }\r
           MatchedNumberOfHandles++;\r
           break;\r
         }\r
@@ -745,8 +781,15 @@ GetFmpHandleBufferByType (
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  *NoHandles = MatchedNumberOfHandles;\r
-  *Buffer = MatchedHandleBuffer;\r
+  if (NoHandles != NULL) {\r
+    *NoHandles = MatchedNumberOfHandles;\r
+  }\r
+  if (HandleBuf != NULL) {\r
+    *HandleBuf = MatchedHandleBuffer;\r
+  }\r
+  if (ResetRequiredBuf != NULL) {\r
+    *ResetRequiredBuf = MatchedResetRequiredBuffer;\r
+  }\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -1074,7 +1117,8 @@ RecordFmpCapsuleStatus (
 \r
   This function need support nested FMP capsule.\r
 \r
-  @param[in]   CapsuleHeader         Points to a capsule header.\r
+  @param[in]  CapsuleHeader         Points to a capsule header.\r
+  @param[out] ResetRequired         Indicates whether reset is required or not.\r
 \r
   @retval EFI_SUCESS            Process Capsule Image successfully.\r
   @retval EFI_UNSUPPORTED       Capsule image is not supported by the firmware.\r
@@ -1084,7 +1128,8 @@ RecordFmpCapsuleStatus (
 **/\r
 EFI_STATUS\r
 ProcessFmpCapsuleImage (\r
-  IN EFI_CAPSULE_HEADER  *CapsuleHeader\r
+  IN EFI_CAPSULE_HEADER  *CapsuleHeader,\r
+  OUT BOOLEAN            *ResetRequired OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                                    Status;\r
@@ -1094,6 +1139,7 @@ ProcessFmpCapsuleImage (
   UINT32                                        ItemNum;\r
   UINTN                                         Index;\r
   EFI_HANDLE                                    *HandleBuffer;\r
+  BOOLEAN                                       *ResetRequiredBuffer;\r
   UINTN                                         NumberOfHandles;\r
   UINTN                                         DriverLen;\r
   UINT64                                        UpdateHardwareInstance;\r
@@ -1102,7 +1148,7 @@ ProcessFmpCapsuleImage (
   BOOLEAN                                       Abort;\r
 \r
   if (!IsFmpCapsuleGuid(&CapsuleHeader->CapsuleGuid)) {\r
-    return ProcessFmpCapsuleImage ((EFI_CAPSULE_HEADER *)((UINTN)CapsuleHeader + CapsuleHeader->HeaderSize));\r
+    return ProcessFmpCapsuleImage ((EFI_CAPSULE_HEADER *)((UINTN)CapsuleHeader + CapsuleHeader->HeaderSize), ResetRequired);\r
   }\r
 \r
   NotReady = FALSE;\r
@@ -1172,7 +1218,8 @@ ProcessFmpCapsuleImage (
                &ImageHeader->UpdateImageTypeId,\r
                UpdateHardwareInstance,\r
                &NumberOfHandles,\r
-               &HandleBuffer\r
+               &HandleBuffer,\r
+               &ResetRequiredBuffer\r
                );\r
     if (EFI_ERROR(Status)) {\r
       NotReady = TRUE;\r
@@ -1205,6 +1252,10 @@ ProcessFmpCapsuleImage (
                  );\r
       if (Status != EFI_SUCCESS) {\r
         Abort = TRUE;\r
+      } else {\r
+        if (ResetRequired != NULL) {\r
+          *ResetRequired |= ResetRequiredBuffer[Index2];\r
+        }\r
       }\r
 \r
       RecordFmpCapsuleStatus (\r
@@ -1218,6 +1269,9 @@ ProcessFmpCapsuleImage (
     if (HandleBuffer != NULL) {\r
       FreePool(HandleBuffer);\r
     }\r
+    if (ResetRequiredBuffer != NULL) {\r
+      FreePool(ResetRequiredBuffer);\r
+    }\r
   }\r
 \r
   if (NotReady) {\r
@@ -1252,8 +1306,6 @@ IsNestedFmpCapsule (
   UINTN                      NestedCapsuleSize;\r
   ESRT_MANAGEMENT_PROTOCOL   *EsrtProtocol;\r
   EFI_SYSTEM_RESOURCE_ENTRY  Entry;\r
-  EFI_HANDLE                 *HandleBuffer;\r
-  UINTN                      NumberOfHandles;\r
 \r
   EsrtGuidFound = FALSE;\r
   if (mIsVirtualAddrConverted) {\r
@@ -1282,19 +1334,16 @@ IsNestedFmpCapsule (
     // Check Firmware Management Protocols\r
     //\r
     if (!EsrtGuidFound) {\r
-      HandleBuffer = NULL;\r
       Status = GetFmpHandleBufferByType (\r
                  &CapsuleHeader->CapsuleGuid,\r
                  0,\r
-                 &NumberOfHandles,\r
-                 &HandleBuffer\r
+                 NULL,\r
+                 NULL,\r
+                 NULL\r
                  );\r
       if (!EFI_ERROR(Status)) {\r
         EsrtGuidFound = TRUE;\r
       }\r
-      if (HandleBuffer != NULL) {\r
-        FreePool (HandleBuffer);\r
-      }\r
     }\r
   }\r
   if (!EsrtGuidFound) {\r
@@ -1382,6 +1431,7 @@ SupportCapsuleImage (
   Caution: This function may receive untrusted input.\r
 \r
   @param[in]  CapsuleHeader         Points to a capsule header.\r
+  @param[out] ResetRequired         Indicates whether reset is required or not.\r
 \r
   @retval EFI_SUCESS            Process Capsule Image successfully.\r
   @retval EFI_UNSUPPORTED       Capsule image is not supported by the firmware.\r
@@ -1390,8 +1440,9 @@ SupportCapsuleImage (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ProcessCapsuleImage (\r
-  IN EFI_CAPSULE_HEADER  *CapsuleHeader\r
+ProcessThisCapsuleImage (\r
+  IN EFI_CAPSULE_HEADER  *CapsuleHeader,\r
+  OUT BOOLEAN            *ResetRequired OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                   Status;\r
@@ -1428,7 +1479,7 @@ ProcessCapsuleImage (
     // Process EFI FMP Capsule\r
     //\r
     DEBUG((DEBUG_INFO, "ProcessFmpCapsuleImage ...\n"));\r
-    Status = ProcessFmpCapsuleImage(CapsuleHeader);\r
+    Status = ProcessFmpCapsuleImage(CapsuleHeader, ResetRequired);\r
     DEBUG((DEBUG_INFO, "ProcessFmpCapsuleImage - %r\n", Status));\r
 \r
     return Status;\r
@@ -1437,6 +1488,27 @@ ProcessCapsuleImage (
   return EFI_UNSUPPORTED;\r
 }\r
 \r
+/**\r
+  The firmware implements to process the capsule image.\r
+\r
+  Caution: This function may receive untrusted input.\r
+\r
+  @param[in]  CapsuleHeader         Points to a capsule header.\r
+\r
+  @retval EFI_SUCESS            Process Capsule Image successfully.\r
+  @retval EFI_UNSUPPORTED       Capsule image is not supported by the firmware.\r
+  @retval EFI_VOLUME_CORRUPTED  FV volume in the capsule is corrupted.\r
+  @retval EFI_OUT_OF_RESOURCES  Not enough memory.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ProcessCapsuleImage (\r
+  IN EFI_CAPSULE_HEADER  *CapsuleHeader\r
+  )\r
+{\r
+  return ProcessThisCapsuleImage (CapsuleHeader, NULL);\r
+}\r
+\r
 /**\r
   Callback function executed when the EndOfDxe event group is signaled.\r
 \r
index 26ca4e2..176dea1 100644 (file)
@@ -99,12 +99,32 @@ IsValidCapsuleHeader (
   );\r
 \r
 extern BOOLEAN                   mDxeCapsuleLibEndOfDxe;\r
-BOOLEAN                          mNeedReset;\r
+BOOLEAN                          mNeedReset = FALSE;\r
 \r
 VOID                        **mCapsulePtr;\r
 EFI_STATUS                  *mCapsuleStatusArray;\r
 UINT32                      mCapsuleTotalNumber;\r
 \r
+/**\r
+  The firmware implements to process the capsule image.\r
+\r
+  Caution: This function may receive untrusted input.\r
+\r
+  @param[in]  CapsuleHeader         Points to a capsule header.\r
+  @param[out] ResetRequired         Indicates whether reset is required or not.\r
+\r
+  @retval EFI_SUCESS            Process Capsule Image successfully.\r
+  @retval EFI_UNSUPPORTED       Capsule image is not supported by the firmware.\r
+  @retval EFI_VOLUME_CORRUPTED  FV volume in the capsule is corrupted.\r
+  @retval EFI_OUT_OF_RESOURCES  Not enough memory.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ProcessThisCapsuleImage (\r
+  IN EFI_CAPSULE_HEADER  *CapsuleHeader,\r
+  OUT BOOLEAN            *ResetRequired OPTIONAL\r
+  );\r
+\r
 /**\r
   Function indicate the current completion progress of the firmware\r
   update. Platform may override with own specific progress function.\r
@@ -381,6 +401,7 @@ ProcessTheseCapsules (
   UINT32                      Index;\r
   ESRT_MANAGEMENT_PROTOCOL    *EsrtManagement;\r
   UINT16                      EmbeddedDriverCount;\r
+  BOOLEAN                     ResetRequired;\r
 \r
   REPORT_STATUS_CODE(EFI_PROGRESS_CODE, (EFI_SOFTWARE | PcdGet32(PcdStatusCodeSubClassCapsule) | PcdGet32(PcdCapsuleStatusCodeProcessCapsulesBegin)));\r
 \r
@@ -416,11 +437,11 @@ ProcessTheseCapsules (
   for (Index = 0; Index < mCapsuleTotalNumber; Index++) {\r
     CapsuleHeader = (EFI_CAPSULE_HEADER*) mCapsulePtr [Index];\r
     if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gWindowsUxCapsuleGuid)) {\r
-      DEBUG ((DEBUG_INFO, "ProcessCapsuleImage (Ux) - 0x%x\n", CapsuleHeader));\r
+      DEBUG ((DEBUG_INFO, "ProcessThisCapsuleImage (Ux) - 0x%x\n", CapsuleHeader));\r
       DEBUG ((DEBUG_INFO, "Display logo capsule is found.\n"));\r
-      Status = ProcessCapsuleImage (CapsuleHeader);\r
+      Status = ProcessThisCapsuleImage (CapsuleHeader, NULL);\r
       mCapsuleStatusArray [Index] = EFI_SUCCESS;\r
-      DEBUG((DEBUG_INFO, "ProcessCapsuleImage (Ux) - %r\n", Status));\r
+      DEBUG((DEBUG_INFO, "ProcessThisCapsuleImage (Ux) - %r\n", Status));\r
       break;\r
     }\r
   }\r
@@ -454,10 +475,11 @@ ProcessTheseCapsules (
       }\r
 \r
       if ((!FirstRound) || (EmbeddedDriverCount == 0)) {\r
-        DEBUG((DEBUG_INFO, "ProcessCapsuleImage - 0x%x\n", CapsuleHeader));\r
-        Status = ProcessCapsuleImage (CapsuleHeader);\r
+        DEBUG((DEBUG_INFO, "ProcessThisCapsuleImage - 0x%x\n", CapsuleHeader));\r
+        ResetRequired = FALSE;\r
+        Status = ProcessThisCapsuleImage (CapsuleHeader, &ResetRequired);\r
         mCapsuleStatusArray [Index] = Status;\r
-        DEBUG((DEBUG_INFO, "ProcessCapsuleImage - %r\n", Status));\r
+        DEBUG((DEBUG_INFO, "ProcessThisCapsuleImage - %r\n", Status));\r
 \r
         if (Status != EFI_NOT_READY) {\r
           if (EFI_ERROR(Status)) {\r
@@ -467,8 +489,8 @@ ProcessTheseCapsules (
             REPORT_STATUS_CODE(EFI_PROGRESS_CODE, (EFI_SOFTWARE | PcdGet32(PcdStatusCodeSubClassCapsule) | PcdGet32(PcdCapsuleStatusCodeUpdateFirmwareSuccess)));\r
           }\r
 \r
-          if ((CapsuleHeader->Flags & PcdGet16(PcdSystemRebootAfterCapsuleProcessFlag)) != 0 ||\r
-              IsFmpCapsule(CapsuleHeader)) {\r
+          mNeedReset |= ResetRequired;\r
+          if ((CapsuleHeader->Flags & PcdGet16(PcdSystemRebootAfterCapsuleProcessFlag)) != 0) {\r
             mNeedReset = TRUE;\r
           }\r
         }\r