]> git.proxmox.com Git - mirror_edk2.git/commitdiff
FmpDevicePkg FmpDxe: Lock variables in entrypoint instead of callback
authorStar Zeng <star.zeng@intel.com>
Tue, 7 Aug 2018 10:01:12 +0000 (18:01 +0800)
committerStar Zeng <star.zeng@intel.com>
Wed, 8 Aug 2018 11:18:29 +0000 (19:18 +0800)
Current code locks variables in PcdFmpDeviceLockEventGuid callback by
VariableLock protocol whose interface will be closed at EndOfDxe.
So the PcdFmpDeviceLockEventGuid callback needs be executed before
the EndOfDxe callback in Variable driver.
When PcdFmpDeviceLockEventGuid = gEfiEndOfDxeEventGroupGuid, the
callback's execution sequence depends on the callback's TPL and
registration sequence.
When PcdFmpDeviceLockEventGuid = gEfiEventReadyToBootGuid, the
PcdFmpDeviceLockEventGuid callback will be executed after the
EndOfDxe callback in Variable driver, the locking will fail.

The patch moves the variables locking logic to entrypoint.
The patch also moves the IsLockFmpDeviceAtLockEventGuidRequired ()
checking to entrypoint.

The entrypoint's final return status should be better to depend on
the return status of RegisterFmpInstaller/InstallFmpInstance, but not
gBS->CreateEventEx.
So the patch also moves the RegisterFmpInstaller/InstallFmpInstance
calling to the end of entrypoint.

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: Michael D Kinney <michael.d.kinney@intel.com>
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