]> git.proxmox.com Git - mirror_edk2.git/blobdiff - FmpDevicePkg/FmpDxe/FmpDxe.c
FmpDevicePkg FmpDxe: Lock variables in entrypoint instead of callback
[mirror_edk2.git] / FmpDevicePkg / FmpDxe / FmpDxe.c
index 3794ac5008f95ecc51cb881540e745e62fa3782e..57eac5ac147fc925b2c4ac98c4a3ba42d57627d0 100644 (file)
@@ -1248,32 +1248,18 @@ FmpDxeLockEventNotify (
   EFI_STATUS  Status;\r
 \r
   if (!mFmpDeviceLocked) {\r
-    if (IsLockFmpDeviceAtLockEventGuidRequired ()) {\r
-      //\r
-      // Lock all UEFI Variables used by this module.\r
-      //\r
-      Status = LockAllFmpVariables ();\r
-      if (EFI_ERROR (Status)) {\r
-        DEBUG ((DEBUG_ERROR, "FmpDxe: Failed to lock variables.  Status = %r.\n"));\r
+    //\r
+    // Lock the firmware device\r
+    //\r
+    Status = FmpDeviceLock();\r
+    if (EFI_ERROR (Status)) {\r
+      if (Status != EFI_UNSUPPORTED) {\r
+        DEBUG ((DEBUG_ERROR, "FmpDxe: FmpDeviceLock() returned error.  Status = %r\n", Status));\r
       } else {\r
-        DEBUG ((DEBUG_INFO, "FmpDxe: All variables locked\n"));\r
-      }\r
-\r
-      //\r
-      // Lock the firmware device\r
-      //\r
-      Status = FmpDeviceLock();\r
-      if (EFI_ERROR (Status)) {\r
-        if (Status != EFI_UNSUPPORTED) {\r
-          DEBUG ((DEBUG_ERROR, "FmpDxe: FmpDeviceLock() returned error.  Status = %r\n", Status));\r
-        } else {\r
-          DEBUG ((DEBUG_WARN, "FmpDxe: FmpDeviceLock() returned error.  Status = %r\n", Status));\r
-        }\r
+        DEBUG ((DEBUG_WARN, "FmpDxe: FmpDeviceLock() returned error.  Status = %r\n", Status));\r
       }\r
-      mFmpDeviceLocked = TRUE;\r
-    } else {\r
-      DEBUG ((DEBUG_VERBOSE, "FmpDxe: Not calling FmpDeviceLock() because mfg mode\n"));\r
     }\r
+    mFmpDeviceLocked = TRUE;\r
   }\r
 }\r
 \r
@@ -1417,6 +1403,45 @@ FmpDxeEntryPoint (
   //\r
   DetectTestKey ();\r
 \r
+  if (IsLockFmpDeviceAtLockEventGuidRequired ()) {\r
+    //\r
+    // Lock all UEFI Variables used by this module.\r
+    //\r
+    Status = LockAllFmpVariables ();\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((DEBUG_ERROR, "FmpDxe: Failed to lock variables.  Status = %r.\n", Status));\r
+    } else {\r
+      DEBUG ((DEBUG_INFO, "FmpDxe: All variables locked\n"));\r
+    }\r
+\r
+    //\r
+    // Register notify function to lock the FMP device.\r
+    // The lock event GUID is retrieved from PcdFmpDeviceLockEventGuid.\r
+    // If PcdFmpDeviceLockEventGuid is not the size of an EFI_GUID, then\r
+    // gEfiEndOfDxeEventGroupGuid is used.\r
+    //\r
+    LockGuid = &gEfiEndOfDxeEventGroupGuid;\r
+    if (PcdGetSize (PcdFmpDeviceLockEventGuid) == sizeof (EFI_GUID)) {\r
+      LockGuid = (EFI_GUID *)PcdGetPtr (PcdFmpDeviceLockEventGuid);\r
+    }\r
+    DEBUG ((DEBUG_INFO, "FmpDxe: Lock GUID: %g\n", LockGuid));\r
+\r
+    Status = gBS->CreateEventEx (\r
+                    EVT_NOTIFY_SIGNAL,\r
+                    TPL_CALLBACK,\r
+                    FmpDxeLockEventNotify,\r
+                    NULL,\r
+                    LockGuid,\r
+                    &mFmpDeviceLockEvent\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((DEBUG_ERROR, "FmpDxe: Failed to register notification.  Status = %r\n", Status));\r
+    }\r
+    ASSERT_EFI_ERROR (Status);\r
+  } else {\r
+    DEBUG ((DEBUG_VERBOSE, "FmpDxe: Not registering notification to call FmpDeviceLock() because mfg mode\n"));\r
+  }\r
+\r
   //\r
   // Register with library the install function so if the library uses\r
   // UEFI driver model/driver binding protocol it can install FMP on its device handle\r
@@ -1436,30 +1461,5 @@ FmpDxeEntryPoint (
       ));\r
   }\r
 \r
-  //\r
-  // Register notify function to lock the FMP device.\r
-  // The lock event GUID is retrieved from PcdFmpDeviceLockEventGuid.\r
-  // If PcdFmpDeviceLockEventGuid is not the size of an EFI_GUID, then\r
-  // gEfiEndOfDxeEventGroupGuid is used.\r
-  //\r
-  LockGuid = &gEfiEndOfDxeEventGroupGuid;\r
-  if (PcdGetSize (PcdFmpDeviceLockEventGuid) == sizeof (EFI_GUID)) {\r
-    LockGuid = (EFI_GUID *)PcdGetPtr (PcdFmpDeviceLockEventGuid);\r
-  }\r
-  DEBUG ((DEBUG_INFO, "FmpDxe: Lock GUID: %g\n", LockGuid));\r
-\r
-  Status = gBS->CreateEventEx (\r
-                  EVT_NOTIFY_SIGNAL,\r
-                  TPL_CALLBACK,\r
-                  FmpDxeLockEventNotify,\r
-                  NULL,\r
-                  LockGuid,\r
-                  &mFmpDeviceLockEvent\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG ((DEBUG_ERROR, "FmpDxe: Failed to register for ready to boot.  Status = %r\n", Status));\r
-  }\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   return Status;\r
 }\r