28#include <Library/VariablePolicyHelperLib.h>
56 CHAR16 CapsuleLastStr[
sizeof (
"Capsule####")];
60 Size =
sizeof (L
"Capsule####") -
sizeof (CHAR16);
61 Status =
gRT->GetVariable (
63 &gEfiCapsuleReportGuid,
68 if (EFI_ERROR (Status)) {
72 CurrentIndex = (UINT16)
StrHexToUintn (&CapsuleLastStr[
sizeof (
"Capsule") - 1]);
90 if (CurrentIndex >=
PcdGet16 (PcdCapsuleMax)) {
91 DEBUG ((DEBUG_INFO,
" CapsuleResult variable Rolling Over!\n"));
95 return CurrentIndex + 1;
108 IN CHAR16 *VariableName,
115 Status = RegisterBasicVariablePolicy (
119 VARIABLE_POLICY_NO_MIN_SIZE,
120 VARIABLE_POLICY_NO_MAX_SIZE,
121 VARIABLE_POLICY_NO_MUST_ATTR,
122 VARIABLE_POLICY_NO_CANT_ATTR,
123 VARIABLE_POLICY_TYPE_LOCK_NOW
125 if (EFI_ERROR (Status)) {
128 "DxeCapsuleLibFmp: Failed to lock variable %g %s. Status = %r\n",
148 IN VOID *CapsuleResult,
152 INTN CapsuleResultIndex;
153 CHAR16 CapsuleResultStr[
sizeof (
"Capsule####")];
158 DEBUG ((DEBUG_INFO,
"New CapsuleResultIndex - 0x%x\n", CapsuleResultIndex));
162 sizeof (CapsuleResultStr),
167 Status =
gRT->SetVariable (
169 &gEfiCapsuleReportGuid,
174 if (!EFI_ERROR (Status)) {
175 Size =
sizeof (L
"Capsule####") -
sizeof (CHAR16);
176 DEBUG ((DEBUG_INFO,
"Set CapsuleLast - %s\n", CapsuleResultStr));
177 Status =
gRT->SetVariable (
179 &gEfiCapsuleReportGuid,
215 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {
242 IN CHAR16 *CapFileName OPTIONAL
248 UINT8 *CapsuleResultVariable;
249 UINTN CapsuleResultVariableSize;
250 CHAR16 *DevicePathStr;
251 UINTN DevicePathStrSize;
252 UINTN CapFileNameSize;
254 DevicePathStr =
NULL;
255 CapFileNameSize =
sizeof (CHAR16);
257 if (FmpDevicePath !=
NULL) {
261 if (DevicePathStr !=
NULL) {
262 DevicePathStrSize =
StrSize (DevicePathStr);
264 DevicePathStrSize =
sizeof (CHAR16);
267 if (CapFileName !=
NULL) {
268 CapFileNameSize =
StrSize (CapFileName);
277 if (CapsuleResultVariable ==
NULL) {
278 return EFI_OUT_OF_RESOURCES;
281 CapsuleResultVariableHeader = (VOID *)CapsuleResultVariable;
282 CapsuleResultVariableHeader->
VariableTotalSize = (UINT32)CapsuleResultVariableSize;
283 CapsuleResultVariableHeader->
Reserved = 0;
290 CapsuleResultVariableFmp->
Version = 0x1;
291 CapsuleResultVariableFmp->
PayloadIndex = (UINT8)PayloadIndex;
295 if (CapFileName !=
NULL) {
299 if (DevicePathStr !=
NULL) {
302 DevicePathStr =
NULL;
306 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {
326 CHAR16 CapsuleMaxStr[
sizeof (
"Capsule####")];
330 sizeof (CapsuleMaxStr),
335 Size =
sizeof (L
"Capsule####") -
sizeof (CHAR16);
336 Status =
gRT->SetVariable (
338 &gEfiCapsuleReportGuid,
339 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
343 if (!EFI_ERROR (Status)) {
345 LockVariable (gEfiCapsuleReportGuid, L
"CapsuleMax", VariablePolicy);
363 CHAR16 CapsuleLastStr[
sizeof (
"Capsule####")];
366 if (BootMode == BOOT_ON_FLASH_UPDATE) {
367 Status =
gRT->SetVariable (
369 &gEfiCapsuleReportGuid,
379 ZeroMem (CapsuleLastStr,
sizeof (CapsuleLastStr));
380 Size =
sizeof (L
"Capsule####") -
sizeof (CHAR16);
381 Status =
gRT->GetVariable (
383 &gEfiCapsuleReportGuid,
388 if (!EFI_ERROR (Status)) {
394 &gEfiCapsuleReportGuid,
395 (VOID **)&CapsuleResult,
398 if (EFI_ERROR (Status)) {
402 Status =
gRT->SetVariable (
404 &gEfiCapsuleReportGuid,
410 if (CapsuleResult !=
NULL) {
417 LockVariable (gEfiCapsuleReportGuid, L
"CapsuleLast", VariablePolicy);
431 CHAR16 CapsuleVarName[30];
440 TempVarName = CapsuleVarName +
StrLen (CapsuleVarName);
446 sizeof (CapsuleVarName) - ((
UINTN)TempVarName - (
UINTN)CapsuleVarName),
453 Status =
gRT->SetVariable (
455 &gEfiCapsuleVendorGuid,
460 if (EFI_ERROR (Status)) {
487 LockVariable (gEfiCapsuleVendorGuid, COD_RELOCATION_INFO_VAR_NAME, VariablePolicy);
503 Status =
gBS->LocateProtocol (&gEdkiiVariablePolicyProtocolGuid,
NULL, (VOID **)&VariablePolicy);
504 if (EFI_ERROR (Status)) {
505 DEBUG ((DEBUG_ERROR,
"DxeCapsuleReportLib %a - Could not locate VariablePolicy protocol! %r\n", __func__, Status));
EFI_BOOT_MODE EFIAPI GetBootModeHob(VOID)
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
UINTN EFIAPI StrHexToUintn(IN CONST CHAR16 *String)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
BOOLEAN EFIAPI CoDCheckCapsuleOnDiskFlag(VOID)
#define EFI_CAPSULE_VARIABLE_NAME
CHAR16 *EFIAPI ConvertDevicePathToText(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN DisplayOnly, IN BOOLEAN AllowShortcuts)
INTN GetCurrentCapsuleLastIndex(VOID)
VOID InitCapsuleUpdateVariable(VOID)
INTN GetNewCapsuleResultIndex(VOID)
EFI_STATUS RecordCapsuleStatusVariable(IN EFI_CAPSULE_HEADER *CapsuleHeader, IN EFI_STATUS CapsuleStatus)
VOID LockVariable(IN CONST EFI_GUID VariableGuid, IN CHAR16 *VariableName, IN EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy)
EFI_STATUS CoDClearCapsuleRelocationInfo(VOID)
VOID InitCapsuleLastVariable(EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy)
EFI_STATUS WriteNewCapsuleResultVariable(IN VOID *CapsuleResult, IN UINTN CapsuleResultSize)
VOID InitCapsuleRelocationInfo(EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy)
EFI_STATUS RecordFmpCapsuleStatusVariable(IN EFI_CAPSULE_HEADER *CapsuleHeader, IN EFI_STATUS CapsuleStatus, IN UINTN PayloadIndex, IN EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *ImageHeader, IN EFI_DEVICE_PATH_PROTOCOL *FmpDevicePath OPTIONAL, IN CHAR16 *CapFileName OPTIONAL)
VOID InitCapsuleMaxVariable(EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy)
VOID InitCapsuleVariable(VOID)
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 ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define PcdGet16(TokenName)
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
EFI_GUID UpdateImageTypeId
EFI_TIME CapsuleProcessed