From: Andrew Fish <afish@apple.com>
To: Toan Le manh <lemanhtoantb@gmail.com>
Cc: edk2-devel@lists.01.org
Subject: Re: gRT->SetVariable ACCESS DENIED error
Date: Tue, 03 Jul 2018 19:45:36 -0700 [thread overview]
Message-ID: <0FFE09D7-C88E-4044-859F-912F9AC7DB43@apple.com> (raw)
In-Reply-To: <CABH5-svH=_60aXSerP1fYtjhHg=yEZsuB04R7kyzM5vZDXRK0w@mail.gmail.com>
Toan,
gEfiGlobalVariableGuid means it is defined in section 3.3, Globally Defined Variables, in the UEFI Spec:
Identifies the level of hardware error record persistence support implemented by the platform. This variable is only modified by firmware and is read-only to the OS.
As you see it is defined as read only, so it is a special variable. Lets search the UDK2018 for it and look for it being special cased....
/Volumes/Case/UDK2018(vUDK2018)>git grep EFI_HW_ERR_REC_SUPPORT_VARIABLE_NAME -- *.h
MdePkg/Include/Guid/GlobalVariable.h:121:#define EFI_HW_ERR_REC_SUPPORT_VARIABLE_NAME L"HwErrRecSupport"
/Volumes/Case/UDK2018(vUDK2018)>git grep EFI_HW_ERR_REC_SUPPORT_VARIABLE_NAME -- *.c
MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLibNullClass.c:407: EFI_HW_ERR_REC_SUPPORT_VARIABLE_NAME,
MdeModulePkg/Universal/BdsDxe/BdsEntry.c:48: EFI_HW_ERR_REC_SUPPORT_VARIABLE_NAME,
/Volumes/Case/UDK2018(vUDK2018)>git grep 'L"HwErrRecSupport"' -- *.c
IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c:48: L"HwErrRecSupport",
IntelFrameworkModulePkg/Universal/BdsDxe/HwErrRecSupport.c:37: // define same behavior between no value or 0 value for L"HwErrRecSupport".
IntelFrameworkModulePkg/Universal/BdsDxe/HwErrRecSupport.c:40: L"HwErrRecSupport",
MdeModulePkg/Universal/BdsDxe/HwErrRecSupport.c:37: // define same behavior between no value or 0 value for L"HwErrRecSupport".
MdeModulePkg/Universal/BdsDxe/HwErrRecSupport.c:40: L"HwErrRecSupport",
Yep looks like some locking happens in the BDS, so maybe you are writing after the lock event?
https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Universal/BdsDxe/BdsEntry.c#L44
///
/// The read-only variables defined in UEFI Spec.
///
CHAR16 *mReadOnlyVariables[] = {
EFI_PLATFORM_LANG_CODES_VARIABLE_NAME,
EFI_LANG_CODES_VARIABLE_NAME,
EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME,
EFI_HW_ERR_REC_SUPPORT_VARIABLE_NAME,
EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME
};
https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Universal/BdsDxe/BdsEntry.c#L754
//
// Mark the read-only variables if the Variable Lock protocol exists
//
Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **) &VariableLock);
DEBUG ((EFI_D_INFO, "[BdsDxe] Locate Variable Lock protocol - %r\n", Status));
if (!EFI_ERROR (Status)) {
for (Index = 0; Index < ARRAY_SIZE (mReadOnlyVariables); Index++) {
Status = VariableLock->RequestToLock (VariableLock, mReadOnlyVariables[Index], &gEfiGlobalVariableGuid);
ASSERT_EFI_ERROR (Status);
}
}
Maybe you missed it due the mixing of the #define and the architectural name from the UEFI Spec?
Thanks,
Andrew Fish
PS
<Grumpy Old Man>
I really hate when folks take the architecturally defined strings in the gEfiGlobalVariableGuid name space and obfuscate them with #defines. Especially when it is not done in a non-consistent way. The #define solves nothing, and obfuscates reading the code. In general in the edk2 we follow the type system in the UEFI spec, and there is is only the Unicode string for variables, not a #define value.
Lets be real if the UEFI spec ever changed the L"HwErrRecSupport" it would have to be tied to spec version, so all the places that used that variable would need the spec revision check and the #define is still just obfuscation and the code is not constructed with a version check.
</Grumpy Old Man>
> On Jul 3, 2018, at 6:21 PM, Toan Le manh <lemanhtoantb@gmail.com> wrote:
>
> Hi Andrew,
>
> I'm trying to set some variables to NVRAM at the beginning of BDS phase.
> For example, this function returned EFI_ACCESS_DENIED
> Status = gRT->SetVariable (
> L"HwErrRecSupport",
> &gEfiGlobalVariableGuid,
> EFI_VARIABLE_BOOTSERVICE_ACCESS |
> EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
> sizeof (UINT16),
> &HardwareErrorRecordLevel
> );
>
> Thanks & BRs,
> Toan
prev parent reply other threads:[~2018-07-04 2:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-03 9:10 gRT->SetVariable ACCESS DENIED error Toan Le manh
2018-07-03 17:12 ` Andrew Fish
2018-07-04 1:21 ` Toan Le manh
2018-07-04 2:45 ` Andrew Fish [this message]
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=0FFE09D7-C88E-4044-859F-912F9AC7DB43@apple.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