26#include <Protocol/VariablePolicy.h>
28#define VAR_POLICY_FLAG_STATS_STR L"-s"
29#define VAR_POLICY_FLAG_POLICY_STR L"-p"
30#define VAR_POLICY_FLAG_VERBOSE_STR L"-v"
32#define VAR_POLICY_CMD_MIN_ATTR_STR_LEN 64
37 { VAR_POLICY_FLAG_POLICY_STR,
TypeFlag },
38 { VAR_POLICY_FLAG_STATS_STR,
TypeFlag },
39 { VAR_POLICY_FLAG_VERBOSE_STR,
TypeFlag },
45 VariableVendorCapsule,
46 &gEfiCapsuleVendorGuid,
50 VariableVendorCapsuleReport,
51 &gEfiCapsuleReportGuid,
56 &gEfiGlobalVariableGuid,
60 VariableVendorMemoryTypeInfo,
61 &gEfiMemoryTypeInformationGuid,
62 L
"Memory Type Information"
65 VariableVendorMonotonicCounter,
70 VariableVendorMorControl,
71 &gEfiMemoryOverwriteRequestControlLockGuid,
72 L
"Memory Overwrite Request (MOR) Control Lock"
102 IN UINT32 Attributes,
104 OUT CHAR16 *AttributesStr
107 if ((AttributesStr ==
NULL) || (AttributesStrSize < VAR_POLICY_CMD_MIN_ATTR_STR_LEN)) {
108 return EFI_INVALID_PARAMETER;
111 AttributesStr[0] = L
'0';
112 AttributesStr[1] = L
'x';
113 AttributesStr[2] = L
'\0';
115 UnicodeValueToStringS (AttributesStr + 2, AttributesStrSize - 2, (RADIX_HEX), (INT64)Attributes, 30);
117 if (Attributes == 0) {
118 StrCatS (AttributesStr, AttributesStrSize, L
" No Attributes");
121 StrCatS (AttributesStr, AttributesStrSize, L
" NV");
125 if ((Attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS) == EFI_VARIABLE_BOOTSERVICE_ACCESS) {
126 StrCatS (AttributesStr, AttributesStrSize, L
" BS");
127 Attributes ^= EFI_VARIABLE_BOOTSERVICE_ACCESS;
130 if ((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == EFI_VARIABLE_RUNTIME_ACCESS) {
131 StrCatS (AttributesStr, AttributesStrSize, L
" RT");
132 Attributes ^= EFI_VARIABLE_RUNTIME_ACCESS;
136 StrCatS (AttributesStr, AttributesStrSize, L
" HW-Error");
141 StrCatS (AttributesStr, AttributesStrSize, L
" Auth-WA");
146 StrCatS (AttributesStr, AttributesStrSize, L
" Auth-TIME-WA");
150 if ((Attributes & EFI_VARIABLE_APPEND_WRITE) == EFI_VARIABLE_APPEND_WRITE) {
151 StrCatS (AttributesStr, AttributesStrSize, L
" APPEND-W");
152 Attributes ^= EFI_VARIABLE_APPEND_WRITE;
155 if (Attributes != 0) {
156 StrCatS (AttributesStr, AttributesStrSize, L
" <Unknown Attribute>");
200 if (VariableGuid ==
NULL) {
201 ASSERT (VariableGuid !=
NULL);
205 for (Index = 0; Index <
ARRAY_SIZE (mVarNamespaces); Index++) {
206 if (
CompareGuid (mVarNamespaces[Index].VendorGuid, VariableGuid)) {
207 return &mVarNamespaces[Index];
229 IN CHAR16 *VariableName,
232 IN UINT32 VariableAttributes
236 CHAR16 *AttributesStr;
237 CHAR16 *DescriptionStr;
240 AttributesStr =
NULL;
241 DescriptionStr =
NULL;
243 if ((VariableName ==
NULL) || (VariableGuid ==
NULL)) {
244 return EFI_INVALID_PARAMETER;
249 if (CmdVarNamespace ==
NULL) {
251 if (DescriptionStr ==
NULL) {
252 Status = EFI_OUT_OF_RESOURCES;
259 DescriptionStr = CmdVarNamespace->Description;
267 if (AttributesStr ==
NULL) {
268 Status = EFI_OUT_OF_RESOURCES;
280 mVarPolicyShellCommandHiiHandle,
288 if (AttributesStr !=
NULL) {
292 if ((CmdVarNamespace ==
NULL) && (DescriptionStr !=
NULL)) {
315 if ((DataSize == 0) || (Data ==
NULL)) {
316 return EFI_INVALID_PARAMETER;
337 IN CHAR16 *VariableName,
344 UINTN VariablePolicyVariableNameBufferSize;
345 UINTN ReturnedVariableNameSize;
346 BOOLEAN PolicyHeaderPresent;
347 CHAR16 *VariablePolicyVariableName;
348 CHAR16 *VariableAttributesStr;
351 PolicyHeaderPresent =
FALSE;
352 VariableAttributesStr =
NULL;
353 VariablePolicyVariableName =
NULL;
355 if ((VariableName ==
NULL) || (VendorGuid ==
NULL)) {
356 ASSERT ((VariableName !=
NULL) && (VendorGuid !=
NULL));
361 Status =
gBS->LocateProtocol (&gEdkiiVariablePolicyProtocolGuid,
NULL, (VOID **)&VariablePolicy);
362 if (EFI_ERROR (Status)) {
369 if (VariablePolicyVariableName ==
NULL) {
370 Status = EFI_OUT_OF_RESOURCES;
375 ZeroMem (VariablePolicyVariableName, VariablePolicyVariableNameBufferSize);
376 ReturnedVariableNameSize = VariablePolicyVariableNameBufferSize;
377 Status = VariablePolicy->GetVariablePolicyInfo (
380 &ReturnedVariableNameSize,
381 &VariablePolicyEntry,
382 VariablePolicyVariableName
384 if (Status == EFI_NOT_READY) {
386 }
else if (Status == EFI_NOT_FOUND) {
388 }
else if (EFI_ERROR (Status)) {
392 PolicyHeaderPresent =
TRUE;
398 if ((ReturnedVariableNameSize > 0) && (VariablePolicyVariableName[0] != CHAR_NULL)) {
408 switch (VariablePolicyEntry.LockPolicyType) {
409 case VARIABLE_POLICY_TYPE_NO_LOCK:
412 case VARIABLE_POLICY_TYPE_LOCK_NOW:
415 case VARIABLE_POLICY_TYPE_LOCK_ON_CREATE:
418 case VARIABLE_POLICY_TYPE_LOCK_ON_VAR_STATE:
421 ZeroMem (VariablePolicyVariableName, VariablePolicyVariableNameBufferSize);
422 ReturnedVariableNameSize = VariablePolicyVariableNameBufferSize;
423 Status = VariablePolicy->GetLockOnVariableStateVariablePolicyInfo (
426 &ReturnedVariableNameSize,
427 &LockOnVarStatePolicy,
428 VariablePolicyVariableName
430 if (EFI_ERROR (Status)) {
436 if ((ReturnedVariableNameSize > 0) && (VariablePolicyVariableName[0] != CHAR_NULL)) {
450 if (VariableAttributesStr ==
NULL) {
451 Status = EFI_OUT_OF_RESOURCES;
464 mVarPolicyShellCommandHiiHandle
471 mVarPolicyShellCommandHiiHandle,
472 VariableAttributesStr
484 mVarPolicyShellCommandHiiHandle
491 mVarPolicyShellCommandHiiHandle,
492 VariableAttributesStr
498 if (PolicyHeaderPresent) {
502 if (VariableAttributesStr !=
NULL) {
506 if (VariablePolicyVariableName !=
NULL) {
507 FreePages (VariablePolicyVariableName, 1);
545 IN OUT CHAR16 **VariableName,
550 UINTN NextVariableNameBufferSize;
552 if ((VariableNameBufferSize ==
NULL) || (VariableName ==
NULL) || (VariableGuid ==
NULL)) {
553 return EFI_INVALID_PARAMETER;
556 if (*VariableNameBufferSize == 0) {
557 if (*VariableName !=
NULL) {
558 return EFI_INVALID_PARAMETER;
566 *VariableNameBufferSize =
sizeof (CHAR16) * 256;
568 if (*VariableName ==
NULL) {
569 return EFI_OUT_OF_RESOURCES;
575 NextVariableNameBufferSize = *VariableNameBufferSize;
576 Status =
gRT->GetNextVariableName (
577 &NextVariableNameBufferSize,
581 if (Status == EFI_BUFFER_TOO_SMALL) {
583 *VariableNameBufferSize,
584 NextVariableNameBufferSize,
587 if (*VariableName ==
NULL) {
588 return EFI_OUT_OF_RESOURCES;
591 *VariableNameBufferSize = NextVariableNameBufferSize;
593 Status =
gRT->GetNextVariableName (
594 &NextVariableNameBufferSize,
598 ASSERT (Status != EFI_BUFFER_TOO_SMALL);
624 IN BOOLEAN PolicyCheck
630 UINTN CurrentVariableDataBufferSize;
633 UINTN TotalVariables;
634 UINTN TotalVariablesWithPolicy;
635 UINTN VariableNameBufferSize;
637 CHAR16 *VariableName;
643 CurrentVariableDataBufferSize = 0;
646 TotalVariablesWithPolicy = 0;
647 VariableNameBufferSize = 0;
651 &VariableNameBufferSize,
656 if (!EFI_ERROR (GetNextVariableStatus)) {
658 Status =
gRT->GetVariable (
665 if (Status != EFI_BUFFER_TOO_SMALL) {
667 Status = EFI_DEVICE_ERROR;
668 goto DeallocateAndExit;
671 TotalDataSize += DataSize;
674 if (!Stats || Verbose) {
676 if (!EFI_ERROR (Status)) {
681 if (PolicyCheck || Verbose) {
683 TotalVariablesWithPolicy++;
688 if (CurrentVariableDataBufferSize < DataSize) {
695 Status = EFI_OUT_OF_RESOURCES;
696 goto DeallocateAndExit;
699 CurrentVariableDataBufferSize = DataSize;
702 Status =
gRT->GetVariable (
709 if (EFI_ERROR (Status)) {
710 Status = EFI_DEVICE_ERROR;
711 goto DeallocateAndExit;
715 if (EFI_ERROR (Status)) {
716 Status = EFI_DEVICE_ERROR;
717 goto DeallocateAndExit;
721 }
while (!EFI_ERROR (GetNextVariableStatus));
723 if (TotalVariables == 0) {
726 if (Verbose || Stats) {
730 if (Verbose || PolicyCheck) {
731 ASSERT (TotalVariablesWithPolicy <= TotalVariables);
734 if (TotalVariablesWithPolicy == TotalVariables) {
740 mVarPolicyShellCommandHiiHandle,
741 TotalVariablesWithPolicy,
750 mVarPolicyShellCommandHiiHandle,
751 TotalVariablesWithPolicy,
763 if (VariableName !=
NULL) {
801 CHAR16 *ProblemParam;
811 if (EFI_ERROR (Status)) {
817 if (EFI_ERROR (Status)) {
818 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam !=
NULL)) {
837 Status =
DumpVars (VerboseDump, StatsDump, PolicyCheck);
842 if (Package !=
NULL) {
869 Status =
gBS->OpenProtocol (
871 &gEfiHiiPackageListProtocolGuid,
872 (VOID **)&PackageList,
875 EFI_OPEN_PROTOCOL_GET_PROTOCOL
878 if (EFI_ERROR (Status)) {
892 if (EFI_ERROR (Status)) {
RETURN_STATUS EFIAPI StrCatS(IN OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePages(IN VOID *Buffer, IN UINTN Pages)
VOID *EFIAPI ReallocatePool(IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
RETURN_STATUS EFIAPI UnicodeValueToStringS(IN OUT CHAR16 *Buffer, IN UINTN BufferSize, IN UINTN Flags, IN INT64 Value, IN UINTN Width)
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
EFI_RUNTIME_SERVICES * gRT
#define ARRAY_SIZE(Array)
#define ASSERT_EFI_ERROR(StatusParameter)
@ SHELL_INVALID_PARAMETER
VOID *EFIAPI AllocatePages(IN UINTN Pages)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellCommandLineGetFlag(IN CONST LIST_ENTRY *CONST CheckPackage, IN CONST CHAR16 *CONST KeyString)
@ TypeFlag
A flag that is present or not present only (IE "-a").
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
UINTN EFIAPI ShellCommandLineGetCount(IN CONST LIST_ENTRY *CheckPackage)
#define VAR_POLICY_CMD_SHELL_DUMP_HEX(Offset, Data, DataSize)
VOID EFIAPI Exit(IN EFI_STATUS Status)
#define EFI_PAGES_TO_SIZE(Pages)
#define EFI_SIZE_TO_PAGES(Size)
EFI_HII_DATABASE_PROTOCOL * gHiiDatabase
#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
#define EFI_VARIABLE_HARDWARE_ERROR_RECORD
#define EFI_VARIABLE_NON_VOLATILE
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
SHELL_STATUS EFIAPI RunVarPolicy(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS DumpVars(IN BOOLEAN Verbose, IN BOOLEAN Stats, IN BOOLEAN PolicyCheck)
EFI_STATUS PrintNonVerboseVarInfo(IN CHAR16 *VariableName, IN EFI_GUID *VariableGuid, IN UINTN VariableSize, IN UINT32 VariableAttributes)
EFI_STATUS GetNextVariableNameWithDynamicReallocation(IN OUT UINTN *VariableNameBufferSize, IN OUT CHAR16 **VariableName, IN OUT EFI_GUID *VariableGuid)
EFI_STATUS GetAttributesString(IN UINT32 Attributes, IN UINTN AttributesStrSize, OUT CHAR16 *AttributesStr)
EFI_HII_HANDLE InitializeHiiPackage(IN EFI_HANDLE ImageHandle)
EFI_STATUS PrintVerboseVarInfo(IN VOID *Data, IN UINTN DataSize)
VOID PrintStats(IN UINTN TotalVariables, IN UINTN TotalVariablesSize)
CONST VAR_POLICY_CMD_VAR_NAMESPACE * GetNameSpaceInfo(IN EFI_GUID *VariableGuid)
BOOLEAN PrintVariablePolicyInfo(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid)