28 IN CONST CHAR8 *AsciiVariableGuid,
29 OUT GUID *VariableGuid,
30 IN OC_NVRAM_LEGACY_MAP *Schema OPTIONAL,
31 OUT OC_NVRAM_LEGACY_ENTRY **SchemaEntry OPTIONAL
37 Status = AsciiStrToGuid (AsciiVariableGuid, VariableGuid);
38 if (EFI_ERROR (Status)) {
39 DEBUG ((DEBUG_WARN,
"OCVAR: Failed to convert NVRAM GUID %a - %r\n", AsciiVariableGuid, Status));
42 if (!EFI_ERROR (Status) && (Schema != NULL)) {
43 for (GuidIndex = 0; GuidIndex < Schema->Count; ++GuidIndex) {
44 if (AsciiStrCmp (AsciiVariableGuid,
OC_BLOB_GET (Schema->Keys[GuidIndex])) == 0) {
45 *SchemaEntry = Schema->Values[GuidIndex];
50 DEBUG ((DEBUG_INFO,
"OCVAR: Ignoring NVRAM GUID %a\n", AsciiVariableGuid));
51 Status = EFI_SECURITY_VIOLATION;
59 IN OC_NVRAM_LEGACY_ENTRY *SchemaEntry,
60 IN EFI_GUID *VariableGuid OPTIONAL,
61 IN CONST VOID *VariableName,
68 if (SchemaEntry == NULL) {
77 for (VariableIndex = 0; VariableIndex < SchemaEntry->Count; ++VariableIndex) {
78 if ((VariableIndex == 0) && (AsciiStrCmp (
"*",
OC_BLOB_GET (SchemaEntry->Values[VariableIndex])) == 0)) {
84 && (AsciiStrCmp ((CONST CHAR8 *)VariableName,
OC_BLOB_GET (SchemaEntry->Values[VariableIndex])) == 0))
99 DEBUG ((DEBUG_INFO,
"OCVAR: NVRAM %g:%s is not permitted\n", VariableGuid, VariableName));
107 IN CONST CHAR8 *AsciiVariableName,
108 IN EFI_GUID *VariableGuid,
109 IN UINT32 Attributes,
110 IN UINT32 VariableSize,
111 IN VOID *VariableData,
112 IN OC_NVRAM_LEGACY_ENTRY *SchemaEntry OPTIONAL,
117 UINTN OriginalVariableSize;
118 CHAR16 *UnicodeVariableName;
121 UINT32 OrgAttributes;
129 if (UnicodeVariableName == NULL) {
130 DEBUG ((DEBUG_WARN,
"OCVAR: Failed to convert NVRAM variable name %a\n", AsciiVariableName));
134 OriginalVariableSize = 0;
135 Status =
gRT->GetVariable (
139 &OriginalVariableSize,
143 if ((Status == EFI_BUFFER_TOO_SMALL) && Overwrite) {
144 Status = GetVariable3 (UnicodeVariableName, VariableGuid, &OrgValue, &OrgSize, &OrgAttributes);
145 if (!EFI_ERROR (Status)) {
150 if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS))
151 == (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS))
153 Status =
gRT->SetVariable (UnicodeVariableName, VariableGuid, 0, 0, 0);
155 if (EFI_ERROR (Status)) {
158 "OCVAR: Failed to delete overwritten variable %g:%a - %r\n",
163 Status = EFI_BUFFER_TOO_SMALL;
168 "OCVAR: Overwritten variable %g:%a has invalid attrs - %X\n",
173 Status = EFI_BUFFER_TOO_SMALL;
180 "OCVAR: Overwritten variable %g:%a has unknown attrs - %r\n",
185 Status = EFI_BUFFER_TOO_SMALL;
189 if (Status != EFI_BUFFER_TOO_SMALL) {
190 Status =
gRT->SetVariable (
198 EFI_ERROR (Status) && VariableSize > 0 ? DEBUG_WARN : DEBUG_INFO,
199 "OCVAR: Setting NVRAM %g:%a - %r\n",
207 "OCVAR: Setting NVRAM %g:%a - ignored, exists\n",
214 FreePool (UnicodeVariableName);
VOID OcSetNvramVariable(IN CONST CHAR8 *AsciiVariableName, IN EFI_GUID *VariableGuid, IN UINT32 Attributes, IN UINT32 VariableSize, IN VOID *VariableData, IN OC_NVRAM_LEGACY_ENTRY *SchemaEntry OPTIONAL, IN BOOLEAN Overwrite)