]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleReportLib.c
MdeModulePkg: Add Capsule On Disk APIs into CapsuleLib.
[mirror_edk2.git] / MdeModulePkg / Library / DxeCapsuleLibFmp / DxeCapsuleReportLib.c
index 6ad766d65a48d6f6374595d106b4fef4193e1ee8..0ec5f20676c82ba2e03723bc36bbfea282d5858a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   DXE capsule report related function.\r
 \r
-  Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include <IndustryStandard/WindowsUxCapsule.h>\r
 \r
+/**\r
+  This routine is called to clear CapsuleOnDisk Relocation Info variable.\r
+  Total Capsule On Disk length is recorded in this variable\r
+\r
+  @retval EFI_SUCCESS   Capsule On Disk flags are cleared\r
+\r
+**/\r
+EFI_STATUS\r
+CoDClearCapsuleRelocationInfo(\r
+  VOID\r
+  );\r
+\r
 /**\r
   Get current capsule last variable index.\r
 \r
@@ -174,6 +186,7 @@ RecordCapsuleStatusVariable (
   @param[in] PayloadIndex   FMP payload index\r
   @param[in] ImageHeader    FMP image header\r
   @param[in] FmpDevicePath  DevicePath associated with the FMP producer\r
+  @param[in] CapFileName    Capsule file name\r
 \r
   @retval EFI_SUCCESS          The capsule status variable is recorded.\r
   @retval EFI_OUT_OF_RESOURCES No resource to record the capsule status variable.\r
@@ -184,7 +197,8 @@ RecordFmpCapsuleStatusVariable (
   IN EFI_STATUS                                    CapsuleStatus,\r
   IN UINTN                                         PayloadIndex,\r
   IN EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER  *ImageHeader,\r
-  IN EFI_DEVICE_PATH_PROTOCOL                      *FmpDevicePath OPTIONAL\r
+  IN EFI_DEVICE_PATH_PROTOCOL                      *FmpDevicePath, OPTIONAL\r
+  IN CHAR16                                        *CapFileName    OPTIONAL\r
   )\r
 {\r
   EFI_CAPSULE_RESULT_VARIABLE_HEADER  *CapsuleResultVariableHeader;\r
@@ -194,8 +208,11 @@ RecordFmpCapsuleStatusVariable (
   UINTN                               CapsuleResultVariableSize;\r
   CHAR16                              *DevicePathStr;\r
   UINTN                               DevicePathStrSize;\r
+  UINTN                               CapFileNameSize;\r
+\r
+  DevicePathStr   = NULL;\r
+  CapFileNameSize = sizeof(CHAR16);\r
 \r
-  DevicePathStr = NULL;\r
   if (FmpDevicePath != NULL) {\r
     DevicePathStr = ConvertDevicePathToText (FmpDevicePath, FALSE, FALSE);\r
   }\r
@@ -204,10 +221,16 @@ RecordFmpCapsuleStatusVariable (
   } else {\r
     DevicePathStrSize = sizeof(CHAR16);\r
   }\r
+\r
+  if (CapFileName != NULL) {\r
+    CapFileNameSize = StrSize(CapFileName);\r
+  }\r
+\r
   //\r
-  // Allocate zero CHAR16 for CapsuleFileName.\r
+  // Allocate room for CapsuleFileName.\r
   //\r
-  CapsuleResultVariableSize = sizeof(EFI_CAPSULE_RESULT_VARIABLE_HEADER) + sizeof(EFI_CAPSULE_RESULT_VARIABLE_FMP) + sizeof(CHAR16) + DevicePathStrSize;\r
+  CapsuleResultVariableSize = sizeof(EFI_CAPSULE_RESULT_VARIABLE_HEADER) + sizeof(EFI_CAPSULE_RESULT_VARIABLE_FMP) + CapFileNameSize + DevicePathStrSize;\r
+\r
   CapsuleResultVariable     = AllocateZeroPool (CapsuleResultVariableSize);\r
   if (CapsuleResultVariable == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -225,8 +248,13 @@ RecordFmpCapsuleStatusVariable (
   CapsuleResultVariableFmp->PayloadIndex = (UINT8)PayloadIndex;\r
   CapsuleResultVariableFmp->UpdateImageIndex = ImageHeader->UpdateImageIndex;\r
   CopyGuid (&CapsuleResultVariableFmp->UpdateImageTypeId, &ImageHeader->UpdateImageTypeId);\r
+\r
+  if (CapFileName != NULL) {\r
+    CopyMem((UINT8 *)CapsuleResultVariableFmp + sizeof(EFI_CAPSULE_RESULT_VARIABLE_FMP), CapFileName, CapFileNameSize);\r
+  }\r
+\r
   if (DevicePathStr != NULL) {\r
-    CopyMem ((UINT8 *)CapsuleResultVariableFmp + sizeof(EFI_CAPSULE_RESULT_VARIABLE_FMP) + sizeof(CHAR16), DevicePathStr, DevicePathStrSize);\r
+    CopyMem ((UINT8 *)CapsuleResultVariableFmp + sizeof(EFI_CAPSULE_RESULT_VARIABLE_FMP) + CapFileNameSize, DevicePathStr, DevicePathStrSize);\r
     FreePool (DevicePathStr);\r
     DevicePathStr = NULL;\r
   }\r
@@ -400,6 +428,31 @@ InitCapsuleUpdateVariable (
   }\r
 }\r
 \r
+/**\r
+  Initialize capsule relocation info variable.\r
+**/\r
+VOID\r
+InitCapsuleRelocationInfo (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                   Status;\r
+  EDKII_VARIABLE_LOCK_PROTOCOL *VariableLock;\r
+\r
+  CoDClearCapsuleRelocationInfo();\r
+\r
+  //\r
+  // Unlock Capsule On Disk relocation Info variable only when Capsule On Disk flag is enabled\r
+  //\r
+  if (!CoDCheckCapsuleOnDiskFlag()) {\r
+    Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **) &VariableLock);\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = VariableLock->RequestToLock (VariableLock, COD_RELOCATION_INFO_VAR_NAME, &gEfiCapsuleVendorGuid);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+  }\r
+}\r
+\r
 /**\r
   Initialize capsule related variables.\r
 **/\r
@@ -411,6 +464,8 @@ InitCapsuleVariable (
   InitCapsuleUpdateVariable();\r
   InitCapsuleMaxVariable();\r
   InitCapsuleLastVariable();\r
+  InitCapsuleRelocationInfo();\r
+\r
   //\r
   // No need to clear L"Capsule####", because OS/APP should refer L"CapsuleLast"\r
   // to check status and delete them.\r