29 IN CHAR16 *VariableName,
48 if (!EFI_ERROR (Status) && (Size ==
sizeof (*Value)) && (Buffer !=
NULL)) {
68 IN CHAR16 *VariableName
75 GetFmpVariable (VariableName, &Valid, &Value);
77 Status =
gRT->SetVariable (VariableName, &gEfiCallerIdGuid, 0, 0,
NULL);
78 if (EFI_ERROR (Status)) {
79 DEBUG ((DEBUG_ERROR,
"FmpDxe(%s): Failed to delete variable %s. Status = %r\n",
mImageIdName, VariableName, Status));
81 DEBUG ((DEBUG_INFO,
"FmpDxe(%s): Deleted variable %s\n",
mImageIdName, VariableName));
99GetFmpControllerState (
107 FmpControllerState =
NULL;
110 Private->FmpStateVariableName,
112 (VOID **)&FmpControllerState,
115 if (EFI_ERROR (Status) || (FmpControllerState ==
NULL)) {
116 DEBUG ((DEBUG_ERROR,
"FmpDxe(%s): Failed to get the controller state. Status = %r\n",
mImageIdName, Status));
118 if (Size ==
sizeof (*FmpControllerState)) {
119 return FmpControllerState;
122 DEBUG ((DEBUG_ERROR,
"FmpDxe(%s): Getting controller state returned a size different than expected. Size = 0x%x\n",
mImageIdName, Size));
125 if (FmpControllerState !=
NULL) {
149GenerateFmpVariableName (
150 IN UINT64 HardwareInstance,
151 IN CHAR16 *BaseVariableName
155 CHAR16 *VariableName;
161 Size =
StrSize (BaseVariableName) + 16 *
sizeof (CHAR16);
163 if (VariableName ==
NULL) {
164 DEBUG ((DEBUG_ERROR,
"FmpDxe(%s): Failed to generate variable name %s.\n",
mImageIdName, BaseVariableName));
168 if (HardwareInstance == 0) {
173 &VariableName[
StrLen (BaseVariableName)],
175 PREFIX_ZERO | RADIX_HEX,
215 if (Private->VersionVariableName !=
NULL) {
216 FreePool (Private->VersionVariableName);
219 if (Private->LsvVariableName !=
NULL) {
220 FreePool (Private->LsvVariableName);
223 if (Private->LastAttemptStatusVariableName !=
NULL) {
224 FreePool (Private->LastAttemptStatusVariableName);
227 if (Private->LastAttemptVersionVariableName !=
NULL) {
228 FreePool (Private->LastAttemptVersionVariableName);
231 if (Private->FmpStateVariableName !=
NULL) {
232 FreePool (Private->FmpStateVariableName);
235 Private->VersionVariableName = GenerateFmpVariableName (
236 Private->Descriptor.HardwareInstance,
239 Private->LsvVariableName = GenerateFmpVariableName (
240 Private->Descriptor.HardwareInstance,
243 Private->LastAttemptStatusVariableName = GenerateFmpVariableName (
244 Private->Descriptor.HardwareInstance,
245 VARNAME_LASTATTEMPTSTATUS
247 Private->LastAttemptVersionVariableName = GenerateFmpVariableName (
248 Private->Descriptor.HardwareInstance,
249 VARNAME_LASTATTEMPTVERSION
251 Private->FmpStateVariableName = GenerateFmpVariableName (
252 Private->Descriptor.HardwareInstance,
256 DEBUG ((DEBUG_INFO,
"FmpDxe(%s): Variable %g %s\n",
mImageIdName, &gEfiCallerIdGuid, Private->VersionVariableName));
257 DEBUG ((DEBUG_INFO,
"FmpDxe(%s): Variable %g %s\n",
mImageIdName, &gEfiCallerIdGuid, Private->LsvVariableName));
258 DEBUG ((DEBUG_INFO,
"FmpDxe(%s): Variable %g %s\n",
mImageIdName, &gEfiCallerIdGuid, Private->LastAttemptStatusVariableName));
259 DEBUG ((DEBUG_INFO,
"FmpDxe(%s): Variable %g %s\n",
mImageIdName, &gEfiCallerIdGuid, Private->LastAttemptVersionVariableName));
260 DEBUG ((DEBUG_INFO,
"FmpDxe(%s): Variable %g %s\n",
mImageIdName, &gEfiCallerIdGuid, Private->FmpStateVariableName));
262 Buffer = GetFmpControllerState (Private);
263 if (Buffer !=
NULL) {
269 DeleteFmpVariable (Private->VersionVariableName);
270 DeleteFmpVariable (Private->LsvVariableName);
271 DeleteFmpVariable (Private->LastAttemptStatusVariableName);
272 DeleteFmpVariable (Private->LastAttemptVersionVariableName);
282 Private->VersionVariableName,
283 &FmpControllerState.VersionValid,
284 &FmpControllerState.Version
287 Private->LsvVariableName,
288 &FmpControllerState.LsvValid,
289 &FmpControllerState.Lsv
292 Private->LastAttemptStatusVariableName,
293 &FmpControllerState.LastAttemptStatusValid,
294 &FmpControllerState.LastAttemptStatus
297 Private->LastAttemptVersionVariableName,
298 &FmpControllerState.LastAttemptVersionValid,
299 &FmpControllerState.LastAttemptVersion
301 Status =
gRT->SetVariable (
302 Private->FmpStateVariableName,
305 sizeof (FmpControllerState),
308 if (EFI_ERROR (Status)) {
314 DEBUG ((DEBUG_ERROR,
"FmpDxe(%s): Failed to create controller state. Status = %r\n",
mImageIdName, Status));
316 DeleteFmpVariable (Private->VersionVariableName);
317 DeleteFmpVariable (Private->LsvVariableName);
318 DeleteFmpVariable (Private->LastAttemptStatusVariableName);
319 DeleteFmpVariable (Private->LastAttemptVersionVariableName);
345 FmpControllerState = GetFmpControllerState (Private);
346 if (FmpControllerState !=
NULL) {
347 if (FmpControllerState->VersionValid) {
348 Value = FmpControllerState->Version;
351 "FmpDxe(%s): Get variable %g %s Version %08x\n",
354 Private->FmpStateVariableName,
387 Value = DEFAULT_LOWESTSUPPORTEDVERSION;
388 FmpControllerState = GetFmpControllerState (Private);
389 if (FmpControllerState !=
NULL) {
390 if (FmpControllerState->LsvValid) {
391 Value = FmpControllerState->Lsv;
394 "FmpDxe(%s): Get variable %g %s LowestSupportedVersion %08x\n",
397 Private->FmpStateVariableName,
429 Value = DEFAULT_LASTATTEMPTSTATUS;
430 FmpControllerState = GetFmpControllerState (Private);
431 if (FmpControllerState !=
NULL) {
432 if (FmpControllerState->LastAttemptStatusValid) {
433 Value = FmpControllerState->LastAttemptStatus;
436 "FmpDxe(%s): Get variable %g %s LastAttemptStatus %08x\n",
439 Private->FmpStateVariableName,
471 Value = DEFAULT_LASTATTEMPTVERSION;
472 FmpControllerState = GetFmpControllerState (Private);
473 if (FmpControllerState !=
NULL) {
474 if (FmpControllerState->LastAttemptVersionValid) {
475 Value = FmpControllerState->LastAttemptVersion;
478 "FmpDxe(%s): Get variable %g %s LastAttemptVersion %08x\n",
481 Private->FmpStateVariableName,
511 FmpControllerState = GetFmpControllerState (Private);
512 if (FmpControllerState ==
NULL) {
521 if (!FmpControllerState->VersionValid) {
525 if (FmpControllerState->Version != Version) {
530 DEBUG ((DEBUG_INFO,
"FmpDxe(%s): No need to update controller state. Same value as before.\n",
mImageIdName));
532 FmpControllerState->VersionValid =
TRUE;
533 FmpControllerState->Version = Version;
534 Status =
gRT->SetVariable (
535 Private->FmpStateVariableName,
538 sizeof (*FmpControllerState),
541 if (EFI_ERROR (Status)) {
542 DEBUG ((DEBUG_ERROR,
"FmpDxe(%s): Failed to update controller state. Status = %r\n",
mImageIdName, Status));
546 "FmpDxe(%s): Set variable %g %s Version %08x\n",
549 Private->FmpStateVariableName,
572 IN UINT32 LowestSupportedVersion
579 FmpControllerState = GetFmpControllerState (Private);
580 if (FmpControllerState ==
NULL) {
589 if (!FmpControllerState->LsvValid) {
593 if (FmpControllerState->Lsv < LowestSupportedVersion) {
598 DEBUG ((DEBUG_INFO,
"FmpDxe(%s): No need to update controller state. Same value as before.\n",
mImageIdName));
600 FmpControllerState->LsvValid =
TRUE;
601 FmpControllerState->Lsv = LowestSupportedVersion;
602 Status =
gRT->SetVariable (
603 Private->FmpStateVariableName,
606 sizeof (*FmpControllerState),
609 if (EFI_ERROR (Status)) {
610 DEBUG ((DEBUG_ERROR,
"FmpDxe(%s): Failed to update controller state. Status = %r\n",
mImageIdName, Status));
614 "FmpDxe(%s): Set variable %g %s LowestSupportedVersion %08x\n",
617 Private->FmpStateVariableName,
618 LowestSupportedVersion
640 IN UINT32 LastAttemptStatus
647 FmpControllerState = GetFmpControllerState (Private);
648 if (FmpControllerState ==
NULL) {
657 if (!FmpControllerState->LastAttemptStatusValid) {
661 if (FmpControllerState->LastAttemptStatus != LastAttemptStatus) {
666 DEBUG ((DEBUG_INFO,
"FmpDxe(%s): No need to update controller state. Same value as before.\n",
mImageIdName));
668 FmpControllerState->LastAttemptStatusValid =
TRUE;
669 FmpControllerState->LastAttemptStatus = LastAttemptStatus;
670 Status =
gRT->SetVariable (
671 Private->FmpStateVariableName,
674 sizeof (*FmpControllerState),
677 if (EFI_ERROR (Status)) {
678 DEBUG ((DEBUG_ERROR,
"FmpDxe(%s): Failed to update controller state. Status = %r\n",
mImageIdName, Status));
682 "FmpDxe(%s): Set variable %g %s LastAttemptStatus %08x\n",
685 Private->FmpStateVariableName,
708 IN UINT32 LastAttemptVersion
715 FmpControllerState = GetFmpControllerState (Private);
716 if (FmpControllerState ==
NULL) {
725 if (!FmpControllerState->LastAttemptVersionValid) {
729 if (FmpControllerState->LastAttemptVersion != LastAttemptVersion) {
734 DEBUG ((DEBUG_INFO,
"FmpDxe(%s): No need to update controller state. Same value as before.\n",
mImageIdName));
736 FmpControllerState->LastAttemptVersionValid =
TRUE;
737 FmpControllerState->LastAttemptVersion = LastAttemptVersion;
738 Status =
gRT->SetVariable (
739 Private->FmpStateVariableName,
742 sizeof (*FmpControllerState),
745 if (EFI_ERROR (Status)) {
746 DEBUG ((DEBUG_ERROR,
"FmpDxe(%s): Failed to update controller state. Status = %r\n",
mImageIdName, Status));
750 "FmpDxe(%s): Set variable %g %s LastAttemptVersion %08x\n",
753 Private->FmpStateVariableName,
780 IN CHAR16 *VariableName
786 Status = RegisterBasicVariablePolicy (
790 VARIABLE_POLICY_NO_MIN_SIZE,
791 VARIABLE_POLICY_NO_MAX_SIZE,
792 VARIABLE_POLICY_NO_MUST_ATTR,
793 VARIABLE_POLICY_NO_CANT_ATTR,
794 VARIABLE_POLICY_TYPE_LOCK_NOW
796 if (EFI_ERROR (Status)) {
799 "FmpDxe(%s): Failed to lock variable %g %s. Status = %r\n",
807 if (EFI_ERROR (PreviousStatus)) {
808 return PreviousStatus;
833 Status =
gBS->LocateProtocol (&gEdkiiVariablePolicyProtocolGuid,
NULL, (VOID **)&VariablePolicy);
834 if (EFI_ERROR (Status)) {
835 DEBUG ((DEBUG_ERROR,
"FmpDxe %a - Could not locate VariablePolicy protocol! %r\n", __func__, Status));
840 Status = LockFmpVariable (Status, VariablePolicy, Private->VersionVariableName);
841 Status = LockFmpVariable (Status, VariablePolicy, Private->LsvVariableName);
842 Status = LockFmpVariable (Status, VariablePolicy, Private->LastAttemptStatusVariableName);
843 Status = LockFmpVariable (Status, VariablePolicy, Private->LastAttemptVersionVariableName);
844 Status = LockFmpVariable (Status, VariablePolicy, Private->FmpStateVariableName);
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
RETURN_STATUS EFIAPI UnicodeValueToStringS(IN OUT CHAR16 *Buffer, IN UINTN BufferSize, IN UINTN Flags, IN INT64 Value, IN UINTN Width)
EFI_RUNTIME_SERVICES * gRT
#define DEBUG(Expression)
EFI_STATUS EFIAPI GetVariable2(IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
#define EFI_VARIABLE_NON_VOLATILE
UINT32 GetLastAttemptStatusFromVariable(IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private)
VOID SetVersionInVariable(IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private, IN UINT32 Version)
UINT32 GetLastAttemptVersionFromVariable(IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private)
UINT32 GetLowestSupportedVersionFromVariable(IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private)
VOID SetLowestSupportedVersionInVariable(IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private, IN UINT32 LowestSupportedVersion)
VOID GenerateFmpVariableNames(IN OUT FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private)
UINT32 GetVersionFromVariable(IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private)
VOID SetLastAttemptStatusInVariable(IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private, IN UINT32 LastAttemptStatus)
EFI_STATUS LockAllFmpVariables(FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private)
VOID SetLastAttemptVersionInVariable(IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private, IN UINT32 LastAttemptVersion)