25BOOLEAN mNvRamUpdated =
FALSE;
65 IN VOID *SystemFirmwareImage,
66 IN UINTN SystemFirmwareImageSize,
68 OUT UINT32 *LastAttemptVersion,
69 OUT UINT32 *LastAttemptStatus,
77 DEBUG ((DEBUG_INFO,
"PlatformUpdate:"));
78 DEBUG ((DEBUG_INFO,
" BaseAddress - 0x%lx,", ConfigData->BaseAddress));
79 DEBUG ((DEBUG_INFO,
" ImageOffset - 0x%x,", ConfigData->ImageOffset));
80 DEBUG ((DEBUG_INFO,
" Legnth - 0x%x\n", ConfigData->Length));
81 if (Progress !=
NULL) {
82 Progress (StartPercentage);
86 ConfigData->FirmwareType,
87 ConfigData->BaseAddress,
88 ConfigData->AddressType,
89 (VOID *)((
UINTN)SystemFirmwareImage + (
UINTN)ConfigData->ImageOffset),
95 if (Progress !=
NULL) {
96 Progress (EndPercentage);
99 if (!EFI_ERROR (Status)) {
101 if (ConfigData->FirmwareType == PlatformFirmwareTypeNvRam) {
102 mNvRamUpdated =
TRUE;
105 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
127 IN VOID *SystemFirmwareImage,
128 IN UINTN SystemFirmwareImageSize,
129 IN VOID *ConfigImage,
131 OUT UINT32 *LastAttemptVersion,
132 OUT UINT32 *LastAttemptStatus,
143 UINTN StartPercentage;
146 if (ConfigImage ==
NULL) {
147 DEBUG ((DEBUG_INFO,
"PlatformUpdate (NoConfig):"));
148 DEBUG ((DEBUG_INFO,
" BaseAddress - 0x%x,", 0));
149 DEBUG ((DEBUG_INFO,
" Length - 0x%x\n", SystemFirmwareImageSize));
153 if (Progress !=
NULL) {
154 Progress (StartPercentage);
158 PlatformFirmwareTypeNvRam,
160 FlashAddressTypeRelativeAddress,
162 SystemFirmwareImageSize,
167 if (Progress !=
NULL) {
168 Progress (EndPercentage);
171 if (!EFI_ERROR (Status)) {
173 mNvRamUpdated =
TRUE;
175 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
181 DEBUG ((DEBUG_INFO,
"PlatformUpdate (With Config):\n"));
183 ZeroMem (&ConfigHeader,
sizeof (ConfigHeader));
190 DEBUG ((DEBUG_INFO,
"ParseUpdateDataFile - %r\n", Status));
191 if (EFI_ERROR (Status)) {
192 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
193 return EFI_INVALID_PARAMETER;
196 DEBUG ((DEBUG_INFO,
"ConfigHeader.NumOfUpdates - 0x%x\n", ConfigHeader.NumOfUpdates));
197 DEBUG ((DEBUG_INFO,
"PcdEdkiiSystemFirmwareFileGuid - %g\n",
PcdGetPtr (PcdEdkiiSystemFirmwareFileGuid)));
200 for (Index = 0; Index < ConfigHeader.NumOfUpdates; Index++) {
202 TotalSize = TotalSize + ConfigData[Index].Length;
208 UpdateConfigData = ConfigData;
209 while (Index < ConfigHeader.NumOfUpdates) {
211 DEBUG ((DEBUG_INFO,
"FileGuid - %g (processing)\n", &UpdateConfigData->FileGuid));
212 StartPercentage = (BytesWritten * 100) / TotalSize;
213 EndPercentage = ((BytesWritten + UpdateConfigData->Length) * 100) / TotalSize;
216 SystemFirmwareImageSize,
228 if (EFI_ERROR (Status)) {
232 DEBUG ((DEBUG_INFO,
"FileGuid - %g (ignored)\n", &UpdateConfigData->FileGuid));
235 BytesWritten += UpdateConfigData->Length;
263 OUT UINT32 *LastAttemptVersion,
264 OUT UINT32 *LastAttemptStatus,
269 VOID *SystemFirmwareImage;
270 UINTN SystemFirmwareImageSize;
272 UINTN ConfigImageSize;
273 VOID *AuthenticatedImage;
274 UINTN AuthenticatedImageSize;
276 AuthenticatedImage =
NULL;
277 AuthenticatedImageSize = 0;
279 DEBUG ((DEBUG_INFO,
"SystemFirmwareAuthenticatedUpdate...\n"));
282 if (EFI_ERROR (Status)) {
283 DEBUG ((DEBUG_INFO,
"SystemFirmwareAuthenticateImage - %r\n", Status));
287 DEBUG ((DEBUG_INFO,
"ExtractSystemFirmwareImage ...\n"));
289 DEBUG ((DEBUG_INFO,
"ExtractConfigImage ...\n"));
290 ExtractConfigImage (AuthenticatedImage, AuthenticatedImageSize, &ConfigImage, &ConfigImageSize);
292 DEBUG ((DEBUG_INFO,
"UpdateImage ...\n"));
293 Status =
UpdateImage (SystemFirmwareImage, SystemFirmwareImageSize, ConfigImage, ConfigImageSize, LastAttemptVersion, LastAttemptStatus, Progress);
294 if (EFI_ERROR (Status)) {
295 DEBUG ((DEBUG_INFO,
"UpdateImage - %r\n", Status));
299 DEBUG ((DEBUG_INFO,
"SystemFirmwareAuthenticatedUpdate Done\n"));
324 IN CHAR16 *VariableName,
326 OUT UINT32 *Attributes OPTIONAL,
331 DEBUG ((DEBUG_INFO,
"GetVariableHook - %S, %g\n", VariableName, VendorGuid));
353 IN OUT CHAR16 *VariableName,
357 DEBUG ((DEBUG_INFO,
"GetNextVariableNameHook - %S, %g\n", VariableName, VendorGuid));
382 IN CHAR16 *VariableName,
384 IN UINT32 Attributes,
389 DEBUG ((DEBUG_INFO,
"SetVariableHook - %S, %g, 0x%x (0x%x)\n", VariableName, VendorGuid, Attributes, DataSize));
412 IN UINT32 Attributes,
413 OUT UINT64 *MaximumVariableStorageSize,
414 OUT UINT64 *RemainingVariableStorageSize,
415 OUT UINT64 *MaximumVariableSize
418 DEBUG ((DEBUG_INFO,
"QueryVariableInfoHook - 0x%x\n", Attributes));
477 OUT CHAR16 **AbortReason
484 if ((Image ==
NULL) || (ImageSize == 0) || (AbortReason ==
NULL)) {
485 return EFI_INVALID_PARAMETER;
491 if ((ImageIndex == 0) || (ImageIndex > SystemFmpPrivate->DescriptorCount)) {
492 return EFI_INVALID_PARAMETER;
495 Status =
SystemFirmwareAuthenticatedUpdate ((VOID *)Image, ImageSize, &SystemFmpPrivate->LastAttempt.LastAttemptVersion, &SystemFmpPrivate->LastAttempt.LastAttemptStatus, Progress);
496 DEBUG ((DEBUG_INFO,
"SetImage - LastAttempt Version - 0x%x, State - 0x%x\n", SystemFmpPrivate->LastAttempt.LastAttemptVersion, SystemFmpPrivate->LastAttempt.LastAttemptStatus));
503 DEBUG ((DEBUG_INFO,
"NvRamUpdated, Update Variable Services\n"));
510 gBS->CalculateCrc32 (
517 VarStatus =
gRT->SetVariable (
518 SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME,
519 &gSystemFmpLastAttemptVariableGuid,
521 sizeof (SystemFmpPrivate->LastAttempt),
522 &SystemFmpPrivate->LastAttempt
524 DEBUG ((DEBUG_INFO,
"SetLastAttempt - %r\n", VarStatus));
550 OUT UINT8 *FmpImageInfoCount,
558 UINT32 FmpImageInfoDescriptorVer;
559 UINT32 PackageVersion;
560 CHAR16 *PackageVersionName;
562 *FmpImageInfoCount = 0;
565 Status =
gBS->HandleProtocol (
570 if (EFI_ERROR (Status)) {
578 Status = Fmp->GetImageInfo (
582 &FmpImageInfoDescriptorVer,
588 if (Status != EFI_BUFFER_TOO_SMALL) {
589 DEBUG ((DEBUG_ERROR,
"SystemFirmwareUpdateDxe: Unexpected Failure. Status = %r\n", Status));
596 FmpImageInfoBuf =
NULL;
598 if (FmpImageInfoBuf ==
NULL) {
599 DEBUG ((DEBUG_ERROR,
"SystemFirmwareUpdateDxe: Failed to allocate memory for descriptors.\n"));
606 PackageVersionName =
NULL;
607 Status = Fmp->GetImageInfo (
611 &FmpImageInfoDescriptorVer,
621 if (PackageVersionName !=
NULL) {
623 PackageVersionName =
NULL;
626 if (EFI_ERROR (Status)) {
627 DEBUG ((DEBUG_ERROR,
"SystemFirmwareUpdateDxe: Failure in GetImageInfo. Status = %r\n", Status));
628 if (FmpImageInfoBuf !=
NULL) {
635 return FmpImageInfoBuf;
656 UINTN TempHandleCount;
663 UINT8 FmpImageInfoCount;
664 UINTN DescriptorSize;
670 Status =
gBS->LocateHandleBuffer (
677 if (EFI_ERROR (Status)) {
681 for (Index = 0; Index < TempHandleCount; Index++) {
693 if (OriginalFmpImageInfoBuf !=
NULL) {
694 FmpImageInfoBuf = OriginalFmpImageInfoBuf;
696 for (Index2 = 0; Index2 < FmpImageInfoCount; Index2++) {
697 for (Index3 = 0; Index3 < mSystemFmpPrivate->DescriptorCount; Index3++) {
700 &mSystemFmpPrivate->ImageDescriptor[Index3].ImageTypeId
718 HandleBuffer[*HandleCount] = HandleBuffer[Index];
726 if ((*HandleCount) == 0) {
761 &gSystemFmpProtocolGuid,
764 DEBUG ((DEBUG_INFO,
"SystemFirmwareUpdateDxe: Found %d matching System FMP instances\n", HandleCount));
766 for (Index = 0; Index < HandleCount; Index++) {
767 Status =
gBS->HandleProtocol (
769 &gSystemFmpProtocolGuid,
772 if (EFI_ERROR (Status)) {
776 DEBUG ((DEBUG_INFO,
"SystemFirmwareUpdateDxe: Uninstall SystemFmp produced by another capsule\n"));
777 Status =
gBS->UninstallProtocolInterface (
779 &gSystemFmpProtocolGuid,
782 if (EFI_ERROR (Status)) {
783 DEBUG ((DEBUG_ERROR,
"SystemFirmwareUpdateDxe: Failed to uninstall SystemFmp %r. Exiting.\n", Status));
789 if (HandleBuffer !=
NULL) {
824 if (mSystemFmpPrivate ==
NULL) {
825 return EFI_OUT_OF_RESOURCES;
829 if (EFI_ERROR (Status)) {
831 mSystemFmpPrivate =
NULL;
840 if (EFI_ERROR (Status)) {
842 mSystemFmpPrivate =
NULL;
851 &gEfiFirmwareManagementProtocolGuid,
854 DEBUG ((DEBUG_INFO,
"SystemFirmwareUpdateDxe: Found %d matching FMP instances\n", HandleCount));
856 switch (HandleCount) {
861 DEBUG ((DEBUG_INFO,
"SystemFirmwareUpdateDxe: Install FMP onto a new handle\n"));
862 Status =
gBS->InstallMultipleProtocolInterfaces (
863 &mSystemFmpPrivate->Handle,
864 &gEfiFirmwareManagementProtocolGuid,
865 &mSystemFmpPrivate->Fmp,
873 DEBUG ((DEBUG_INFO,
"SystemFirmwareUpdateDxe: Install System FMP onto matching FMP handle\n"));
874 mSystemFmpPrivate->Handle = HandleBuffer[0];
875 Status =
gBS->InstallMultipleProtocolInterfaces (
877 &gSystemFmpProtocolGuid,
878 &mSystemFmpPrivate->Fmp,
886 DEBUG ((DEBUG_ERROR,
"SystemFirmwareUpdateDxe: More than one matching FMP handle. Unload driver.\n"));
887 Status = EFI_DEVICE_ERROR;
891 if (HandleBuffer !=
NULL) {
895 if (EFI_ERROR (Status)) {
897 mSystemFmpPrivate =
NULL;
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
BOOLEAN EFIAPI ExtractSystemFirmwareImage(IN VOID *AuthenticatedImage, IN UINTN AuthenticatedImageSize, OUT VOID **SystemFirmwareImage, OUT UINTN *SystemFirmwareImageSize)
EFI_STATUS EFIAPI CapsuleAuthenticateSystemFirmware(IN VOID *Image, IN UINTN ImageSize, IN BOOLEAN ForceVersionMatch, OUT UINT32 *LastAttemptVersion, OUT UINT32 *LastAttemptStatus, OUT VOID **AuthenticatedImage, OUT UINTN *AuthenticatedImageSize)
BOOLEAN EFIAPI ExtractConfigImage(IN VOID *AuthenticatedImage, IN UINTN AuthenticatedImageSize, OUT VOID **ConfigImage, OUT UINTN *ConfigImageSize)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS(EFIAPI * EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS)(IN UINTN Completion)
EFI_RUNTIME_SERVICES * gRT
#define DEBUG(Expression)
#define PcdGetPtr(TokenName)
#define EFI_NOT_AVAILABLE_YET
EFI_STATUS InitializePrivateData(IN SYSTEM_FMP_PRIVATE_DATA *SystemFmpPrivate)
#define SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(a)
EFI_STATUS PerformUpdate(IN VOID *SystemFirmwareImage, IN UINTN SystemFirmwareImageSize, IN UPDATE_CONFIG_DATA *ConfigData, OUT UINT32 *LastAttemptVersion, OUT UINT32 *LastAttemptStatus, IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress, IN UINTN StartPercentage, IN UINTN EndPercentage)
EFI_HANDLE * FindMatchingFmpHandles(IN EFI_GUID *ProtocolGuid, OUT UINTN *HandleCount)
EFI_STATUS EFIAPI SetVariableHook(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
EFI_STATUS UninstallMatchingSystemFmpProtocols(VOID)
EFI_STATUS EFIAPI QueryVariableInfoHook(IN UINT32 Attributes, OUT UINT64 *MaximumVariableStorageSize, OUT UINT64 *RemainingVariableStorageSize, OUT UINT64 *MaximumVariableSize)
EFI_STATUS ParseUpdateDataFile(IN UINT8 *DataBuffer, IN UINTN BufferSize, IN OUT CONFIG_HEADER *ConfigHeader, IN OUT UPDATE_CONFIG_DATA **UpdateArray)
EFI_STATUS EFIAPI GetVariableHook(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT UINT32 *Attributes OPTIONAL, IN OUT UINTN *DataSize, OUT VOID *Data)
EFI_STATUS EFIAPI GetNextVariableNameHook(IN OUT UINTN *VariableNameSize, IN OUT CHAR16 *VariableName, IN OUT EFI_GUID *VendorGuid)
EFI_STATUS SystemFirmwareAuthenticatedUpdate(IN VOID *Image, IN UINTN ImageSize, OUT UINT32 *LastAttemptVersion, OUT UINT32 *LastAttemptStatus, IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress)
EFI_STATUS EFIAPI SystemFirmwareUpdateMainDxe(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_FIRMWARE_IMAGE_DESCRIPTOR * GetFmpImageDescriptors(IN EFI_HANDLE Handle, IN EFI_GUID *ProtocolGuid, OUT UINT8 *FmpImageInfoCount, OUT UINTN *DescriptorSize)
EFI_STATUS UpdateImage(IN VOID *SystemFirmwareImage, IN UINTN SystemFirmwareImageSize, IN VOID *ConfigImage, IN UINTN ConfigImageSize, OUT UINT32 *LastAttemptVersion, OUT UINT32 *LastAttemptStatus, IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress)
EFI_STATUS EFIAPI FmpSetImage(IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This, IN UINT8 ImageIndex, IN CONST VOID *Image, IN UINTN ImageSize, IN CONST VOID *VendorCode, IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress, OUT CHAR16 **AbortReason)
#define LAST_ATTEMPT_STATUS_SUCCESS
#define EFI_VARIABLE_NON_VOLATILE