From: "Yang Jie" <jie.yang@intel.com>
To: devel@edk2.groups.io
Cc: gaoliming@byosoft.com.cn, guomin.jiang@intel.com,
Yang Jie <jie.yang@intel.com>
Subject: [edk2-devel] MdeModulePkg/DxeCapsuleLibFmp: Use new Variable Lock interface
Date: Tue, 26 Oct 2021 14:15:09 +0800 [thread overview]
Message-ID: <20211026061509.2912-1-jie.yang@intel.com> (raw)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3699
The code in MdeModulePkg\Library\DxeCapsuleLibFmp call the deprecated
interface VariableLockRequestToLockc. So I changed the code in
FmpDevicePkg using RegisterBasicVariablePolicy, instead of the
deprecated interface.
Signed-off-by: Yang Jie <jie.yang@intel.com>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
---
.../DxeCapsuleLibFmp/DxeCapsuleLib.inf | 5 +-
.../DxeCapsuleLibFmp/DxeCapsuleReportLib.c | 66 ++++++++++++-------
2 files changed, 47 insertions(+), 24 deletions(-)
diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
index 05de4299fb..9212c81d68 100644
--- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
+++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
@@ -3,7 +3,7 @@
#
# Capsule library instance for DXE_DRIVER module types.
#
-# Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2016 - 2021, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
@@ -51,6 +51,7 @@
DisplayUpdateProgressLib
FileHandleLib
UefiBootManagerLib
+ VariablePolicyHelperLib
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleMax ## CONSUMES
@@ -71,11 +72,11 @@
[Protocols]
gEsrtManagementProtocolGuid ## CONSUMES
gEfiFirmwareManagementProtocolGuid ## CONSUMES
- gEdkiiVariableLockProtocolGuid ## SOMETIMES_CONSUMES
gEdkiiFirmwareManagementProgressProtocolGuid ## SOMETIMES_CONSUMES
gEfiSimpleFileSystemProtocolGuid ## SOMETIMES_CONSUMES
gEfiBlockIoProtocolGuid ## CONSUMES
gEfiDiskIoProtocolGuid ## CONSUMES
+ gEdkiiVariablePolicyProtocolGuid ## CONSUMES
[Guids]
gEfiFmpCapsuleGuid ## SOMETIMES_CONSUMES ## GUID
diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleReportLib.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleReportLib.c
index 0ec5f20676..665b7d06d9 100644
--- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleReportLib.c
+++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleReportLib.c
@@ -1,14 +1,13 @@
/** @file
DXE capsule report related function.
- Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2016 - 2021, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <PiDxe.h>
#include <Protocol/FirmwareManagement.h>
-#include <Protocol/VariableLock.h>
#include <Guid/CapsuleReport.h>
#include <Guid/FmpCapsule.h>
#include <Guid/CapsuleVendor.h>
@@ -26,6 +25,7 @@
#include <Library/ReportStatusCodeLib.h>
#include <Library/DevicePathLib.h>
#include <Library/CapsuleLib.h>
+#include <Library/VariablePolicyHelperLib.h>
#include <IndustryStandard/WindowsUxCapsule.h>
@@ -94,6 +94,44 @@ GetNewCapsuleResultIndex (
return CurrentIndex + 1;
}
+/**
+ Lock Variable by variable policy
+
+ @param[in] VariableGuid The Guid of the variable to be locked
+ @param[in] VariableName The name of the variable to be locked
+**/
+VOID LockVaraible (
+ IN CONST EFI_GUID VariableGuid,
+ IN CHAR16 *VariableName
+ )
+{
+ EFI_STATUS Status;
+ EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy;
+
+ // Locate the VariablePolicy protocol
+ Status = gBS->LocateProtocol (&gEdkiiVariablePolicyProtocolGuid, NULL, (VOID**)&VariablePolicy);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "DxeCapsuleReportLib %a - Could not locate VariablePolicy protocol! %r\n", __FUNCTION__, Status));
+ ASSERT_EFI_ERROR (Status);
+ }
+ // If success, go ahead and set the policies to protect the target variables.
+ Status = RegisterBasicVariablePolicy (VariablePolicy,
+ &VariableGuid,
+ VariableName,
+ VARIABLE_POLICY_NO_MIN_SIZE,
+ VARIABLE_POLICY_NO_MAX_SIZE,
+ VARIABLE_POLICY_NO_MUST_ATTR,
+ VARIABLE_POLICY_NO_CANT_ATTR,
+ VARIABLE_POLICY_TYPE_LOCK_NOW);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "DxeCapsuleLibFmp: Failed to lock variable %g %s. Status = %r\n",
+ &VariableGuid,
+ L"CapsuleLast",
+ Status));
+ ASSERT_EFI_ERROR (Status);
+ }
+}
+
/**
Write a new capsule status variable.
@@ -278,7 +316,7 @@ InitCapsuleMaxVariable (
EFI_STATUS Status;
UINTN Size;
CHAR16 CapsuleMaxStr[sizeof("Capsule####")];
- EDKII_VARIABLE_LOCK_PROTOCOL *VariableLock;
+ //EDKII_VARIABLE_LOCK_PROTOCOL *VariableLock;
UnicodeSPrint(
CapsuleMaxStr,
@@ -297,11 +335,7 @@ InitCapsuleMaxVariable (
);
if (!EFI_ERROR(Status)) {
// Lock it per UEFI spec.
- Status = gBS->LocateProtocol(&gEdkiiVariableLockProtocolGuid, NULL, (VOID **)&VariableLock);
- if (!EFI_ERROR(Status)) {
- Status = VariableLock->RequestToLock(VariableLock, L"CapsuleMax", &gEfiCapsuleReportGuid);
- ASSERT_EFI_ERROR(Status);
- }
+ LockVaraible (gEfiCapsuleReportGuid, L"CapsuleMax");
}
}
@@ -315,7 +349,6 @@ InitCapsuleLastVariable (
{
EFI_STATUS Status;
EFI_BOOT_MODE BootMode;
- EDKII_VARIABLE_LOCK_PROTOCOL *VariableLock;
VOID *CapsuleResult;
UINTN Size;
CHAR16 CapsuleLastStr[sizeof("Capsule####")];
@@ -372,11 +405,7 @@ InitCapsuleLastVariable (
}
// Lock it in normal boot path per UEFI spec.
- Status = gBS->LocateProtocol(&gEdkiiVariableLockProtocolGuid, NULL, (VOID **)&VariableLock);
- if (!EFI_ERROR(Status)) {
- Status = VariableLock->RequestToLock(VariableLock, L"CapsuleLast", &gEfiCapsuleReportGuid);
- ASSERT_EFI_ERROR(Status);
- }
+ LockVaraible (gEfiCapsuleReportGuid, L"CapsuleLast");
}
}
@@ -436,20 +465,13 @@ InitCapsuleRelocationInfo (
VOID
)
{
- EFI_STATUS Status;
- EDKII_VARIABLE_LOCK_PROTOCOL *VariableLock;
-
CoDClearCapsuleRelocationInfo();
//
// Unlock Capsule On Disk relocation Info variable only when Capsule On Disk flag is enabled
//
if (!CoDCheckCapsuleOnDiskFlag()) {
- Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **) &VariableLock);
- if (!EFI_ERROR (Status)) {
- Status = VariableLock->RequestToLock (VariableLock, COD_RELOCATION_INFO_VAR_NAME, &gEfiCapsuleVendorGuid);
- ASSERT_EFI_ERROR (Status);
- }
+ LockVaraible (gEfiCapsuleVendorGuid, COD_RELOCATION_INFO_VAR_NAME);
}
}
--
2.26.2.windows.1
next reply other threads:[~2021-10-26 6:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-26 6:15 Yang Jie [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-10-26 6:10 [edk2-devel] MdeModulePkg/DxeCapsuleLibFmp: Use new Variable Lock interface Yang Jie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211026061509.2912-1-jie.yang@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox