]> git.proxmox.com Git - mirror_edk2.git/blobdiff - FmpDevicePkg/FmpDxe/FmpDxe.c
FmpDevicePkg/FmpDxe: Different variable for each FMP Descriptor
[mirror_edk2.git] / FmpDevicePkg / FmpDxe / FmpDxe.c
index dab3310834c113a05cdcc5d15c2eda91f7d6aaf3..17c3378fa2bded286f621bff1eee6410d8d1ef48 100644 (file)
@@ -11,6 +11,7 @@
 **/\r
 \r
 #include "FmpDxe.h"\r
+#include "VariableSupport.h"\r
 \r
 ///\r
 /// FILE_GUID from FmpDxe.inf.  When FmpDxe.inf is used in a platform, the\r
@@ -73,7 +74,13 @@ const FIRMWARE_MANAGEMENT_PRIVATE_DATA  mFirmwareManagementPrivateDataTemplate =
   NULL,                                        // VersionName\r
   TRUE,                                        // RuntimeVersionSupported\r
   NULL,                                        // FmpDeviceLockEvent\r
-  FALSE                                        // FmpDeviceLocked\r
+  FALSE,                                       // FmpDeviceLocked\r
+  NULL,                                        // FmpDeviceContext\r
+  NULL,                                        // VersionVariableName\r
+  NULL,                                        // LsvVariableName\r
+  NULL,                                        // LastAttemptStatusVariableName\r
+  NULL,                                        // LastAttemptVersionVariableName\r
+  NULL                                         // FmpStateVariableName\r
 };\r
 \r
 ///\r
@@ -142,7 +149,7 @@ FmpDxeProgress (
   the GUID value from the FmpDeviceLib. If the FmpDeviceLib does not provide\r
   a GUID value, then gEfiCallerIdGuid is returned.\r
 \r
-  @return  The ImageTypeId GUID\r
+  @retval  The ImageTypeId GUID\r
 \r
 **/\r
 EFI_GUID *\r
@@ -171,7 +178,7 @@ GetImageTypeIdGuid (
 /**\r
   Returns a pointer to the Null-terminated Unicode ImageIdName string.\r
 \r
-  @return  Null-terminated Unicode ImageIdName string.\r
+  @retval  Null-terminated Unicode ImageIdName string.\r
 \r
 **/\r
 CHAR16 *\r
@@ -188,12 +195,15 @@ GetImageTypeNameString (
   2. Check if we have a variable for lowest supported version (this will be updated with each capsule applied)\r
   3. Check Fixed at build PCD\r
 \r
-  @return  The largest value\r
+  @param[in] Private  Pointer to the private context structure for the\r
+                      Firmware Management Protocol instance.\r
+\r
+  @retval  The largest value\r
 \r
 **/\r
 UINT32\r
 GetLowestSupportedVersion (\r
-  VOID\r
+  FIRMWARE_MANAGEMENT_PRIVATE_DATA  *Private\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -230,7 +240,7 @@ GetLowestSupportedVersion (
   //\r
   // Check the lowest supported version UEFI variable for this device\r
   //\r
-  VariableLowestSupportedVersion = GetLowestSupportedVersionFromVariable();\r
+  VariableLowestSupportedVersion = GetLowestSupportedVersionFromVariable (Private);\r
   if (VariableLowestSupportedVersion > ReturnLsv) {\r
     ReturnLsv = VariableLowestSupportedVersion;\r
   }\r
@@ -265,6 +275,20 @@ PopulateDescriptor (
   Private->Descriptor.ImageId     = Private->Descriptor.ImageIndex;\r
   Private->Descriptor.ImageIdName = GetImageTypeNameString();\r
 \r
+  //\r
+  // Get the hardware instance from FmpDeviceLib\r
+  //\r
+  Status = FmpDeviceGetHardwareInstance (&Private->Descriptor.HardwareInstance);\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    Private->Descriptor.HardwareInstance = 0;\r
+  }\r
+\r
+  //\r
+  // Generate UEFI Variable names used to store status information for this\r
+  // FMP instance.\r
+  //\r
+  GenerateFmpVariableNames (Private);\r
+\r
   //\r
   // Get the version.  Some devices don't support getting the firmware version\r
   // at runtime.  If FmpDeviceLib does not support returning a version, then\r
@@ -273,7 +297,7 @@ PopulateDescriptor (
   Status = FmpDeviceGetVersion (&Private->Descriptor.Version);\r
   if (Status == EFI_UNSUPPORTED) {\r
     Private->RuntimeVersionSupported = FALSE;\r
-    Private->Descriptor.Version = GetVersionFromVariable();\r
+    Private->Descriptor.Version = GetVersionFromVariable (Private);\r
   } else if (EFI_ERROR (Status)) {\r
     //\r
     // Unexpected error.   Use default version.\r
@@ -309,7 +333,7 @@ PopulateDescriptor (
                                         );\r
   }\r
 \r
-  Private->Descriptor.LowestSupportedImageVersion = GetLowestSupportedVersion();\r
+  Private->Descriptor.LowestSupportedImageVersion = GetLowestSupportedVersion (Private);\r
 \r
   //\r
   // Get attributes from the FmpDeviceLib\r
@@ -341,16 +365,8 @@ PopulateDescriptor (
     Private->Descriptor.Size = 0;\r
   }\r
 \r
-  Private->Descriptor.LastAttemptVersion = GetLastAttemptVersionFromVariable ();\r
-  Private->Descriptor.LastAttemptStatus  = GetLastAttemptStatusFromVariable ();\r
-\r
-  //\r
-  // Get the hardware instance from FmpDeviceLib\r
-  //\r
-  Status = FmpDeviceGetHardwareInstance (&Private->Descriptor.HardwareInstance);\r
-  if (Status == EFI_UNSUPPORTED) {\r
-    Private->Descriptor.HardwareInstance = 0;\r
-  }\r
+  Private->Descriptor.LastAttemptVersion = GetLastAttemptVersionFromVariable (Private);\r
+  Private->Descriptor.LastAttemptStatus  = GetLastAttemptStatusFromVariable (Private);\r
 \r
   Private->DescriptorPopulated = TRUE;\r
 }\r
@@ -453,7 +469,7 @@ GetTheImageInfo (
   *ImageInfoSize = sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR);\r
 \r
   //\r
-  // make sure the descriptor has already been loaded\r
+  // Make sure the descriptor has already been loaded or refreshed\r
   //\r
   PopulateDescriptor (Private);\r
 \r
@@ -696,7 +712,7 @@ CheckTheImage (
   FmpDeviceSetContext (Private->Handle, &Private->FmpDeviceContext);\r
 \r
   //\r
-  // make sure the descriptor has already been loaded\r
+  // Make sure the descriptor has already been loaded or refreshed\r
   //\r
   PopulateDescriptor (Private);\r
 \r
@@ -949,7 +965,15 @@ SetTheImage (
   Private = FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS (This);\r
   FmpDeviceSetContext (Private->Handle, &Private->FmpDeviceContext);\r
 \r
-  SetLastAttemptVersionInVariable (IncommingFwVersion); //set to 0 to clear any previous results.\r
+  //\r
+  // Make sure the descriptor has already been loaded or refreshed\r
+  //\r
+  PopulateDescriptor (Private);\r
+\r
+  //\r
+  // Set to 0 to clear any previous results.\r
+  //\r
+  SetLastAttemptVersionInVariable (Private, IncommingFwVersion);\r
 \r
   //\r
   // if we have locked the device, then skip the set operation.\r
@@ -988,7 +1012,7 @@ SetTheImage (
     //\r
     // Set to actual value\r
     //\r
-    SetLastAttemptVersionInVariable (IncommingFwVersion);\r
+    SetLastAttemptVersionInVariable (Private, IncommingFwVersion);\r
   }\r
 \r
 \r
@@ -1080,7 +1104,7 @@ SetTheImage (
   // Save LastAttemptStatus as error so that if SetImage never returns the error\r
   // state is recorded.\r
   //\r
-  SetLastAttemptStatusInVariable (LastAttemptStatus);\r
+  SetLastAttemptStatusInVariable (Private, LastAttemptStatus);\r
 \r
   //\r
   // Strip off all the headers so the device can process its firmware\r
@@ -1132,23 +1156,21 @@ SetTheImage (
   if (!Private->RuntimeVersionSupported) {\r
     Version = DEFAULT_VERSION;\r
     GetFmpPayloadHeaderVersion (FmpHeader, FmpPayloadSize, &Version);\r
-    SetVersionInVariable (Version);\r
+    SetVersionInVariable (Private, Version);\r
   }\r
 \r
   //\r
   // Update lowest supported variable\r
   //\r
-  {\r
-    LowestSupportedVersion = DEFAULT_LOWESTSUPPORTEDVERSION;\r
-    GetFmpPayloadHeaderLowestSupportedVersion (FmpHeader, FmpPayloadSize, &LowestSupportedVersion);\r
-    SetLowestSupportedVersionInVariable (LowestSupportedVersion);\r
-  }\r
+  LowestSupportedVersion = DEFAULT_LOWESTSUPPORTEDVERSION;\r
+  GetFmpPayloadHeaderLowestSupportedVersion (FmpHeader, FmpPayloadSize, &LowestSupportedVersion);\r
+  SetLowestSupportedVersionInVariable (Private, LowestSupportedVersion);\r
 \r
   LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;\r
 \r
 cleanup:\r
   mProgressFunc = NULL;\r
-  SetLastAttemptStatusInVariable (LastAttemptStatus);\r
+  SetLastAttemptStatusInVariable (Private, LastAttemptStatus);\r
 \r
   if (Progress != NULL) {\r
     //\r
@@ -1359,13 +1381,18 @@ InstallFmpInstance (
     goto cleanup;\r
   }\r
 \r
+  //\r
+  // Make sure the descriptor has already been loaded or refreshed\r
+  //\r
+  PopulateDescriptor (Private);\r
+\r
   DEBUG ((DEBUG_ERROR, "InstallFmpInstance: Lock events\n"));\r
 \r
   if (IsLockFmpDeviceAtLockEventGuidRequired ()) {\r
     //\r
     // Lock all UEFI Variables used by this module.\r
     //\r
-    Status = LockAllFmpVariables ();\r
+    Status = LockAllFmpVariables (Private);\r
     if (EFI_ERROR (Status)) {\r
       DEBUG ((DEBUG_ERROR, "FmpDxe: Failed to lock variables.  Status = %r.\n", Status));\r
     } else {\r
@@ -1417,6 +1444,27 @@ cleanup:
       if (Private->FmpDeviceLockEvent != NULL) {\r
         gBS->CloseEvent (Private->FmpDeviceLockEvent);\r
       }\r
+      if (Private->Descriptor.VersionName != NULL) {\r
+        FreePool (Private->Descriptor.VersionName);\r
+      }\r
+      if (Private->FmpDeviceContext != NULL) {\r
+        FmpDeviceSetContext (NULL, &Private->FmpDeviceContext);\r
+      }\r
+      if (Private->VersionVariableName != NULL) {\r
+        FreePool (Private->VersionVariableName);\r
+      }\r
+      if (Private->LsvVariableName != NULL) {\r
+        FreePool (Private->LsvVariableName);\r
+      }\r
+      if (Private->LastAttemptStatusVariableName != NULL) {\r
+        FreePool (Private->LastAttemptStatusVariableName);\r
+      }\r
+      if (Private->LastAttemptVersionVariableName != NULL) {\r
+        FreePool (Private->LastAttemptVersionVariableName);\r
+      }\r
+      if (Private->FmpStateVariableName != NULL) {\r
+        FreePool (Private->FmpStateVariableName);\r
+      }\r
       FreePool (Private);\r
     }\r
   }\r
@@ -1473,8 +1521,27 @@ UninstallFmpInstance (
     return Status;\r
   }\r
 \r
-  FmpDeviceSetContext (NULL, &Private->FmpDeviceContext);\r
-\r
+  if (Private->Descriptor.VersionName != NULL) {\r
+    FreePool (Private->Descriptor.VersionName);\r
+  }\r
+  if (Private->FmpDeviceContext != NULL) {\r
+    FmpDeviceSetContext (NULL, &Private->FmpDeviceContext);\r
+  }\r
+  if (Private->VersionVariableName != NULL) {\r
+    FreePool (Private->VersionVariableName);\r
+  }\r
+  if (Private->LsvVariableName != NULL) {\r
+    FreePool (Private->LsvVariableName);\r
+  }\r
+  if (Private->LastAttemptStatusVariableName != NULL) {\r
+    FreePool (Private->LastAttemptStatusVariableName);\r
+  }\r
+  if (Private->LastAttemptVersionVariableName != NULL) {\r
+    FreePool (Private->LastAttemptVersionVariableName);\r
+  }\r
+  if (Private->FmpStateVariableName != NULL) {\r
+    FreePool (Private->FmpStateVariableName);\r
+  }\r
   FreePool (Private);\r
 \r
   return EFI_SUCCESS;\r