45 if ((FwClass ==
NULL) || (Entry ==
NULL)) {
46 return EFI_INVALID_PARAMETER;
50 if (EFI_ERROR (Status)) {
65 if (EFI_ERROR (Status)) {
67 if (EFI_ERROR (Status)) {
105 return EFI_INVALID_PARAMETER;
109 if (EFI_ERROR (Status)) {
115 if (!EFI_ERROR (Status)) {
123 if (EFI_ERROR (Status)) {
151 if (FwClass ==
NULL) {
152 return EFI_INVALID_PARAMETER;
156 if (EFI_ERROR (Status)) {
187 return EFI_INVALID_PARAMETER;
191 if (EFI_ERROR (Status)) {
201 if (Status == EFI_NOT_FOUND) {
232 UINTN NumberOfHandles;
233 UINTN *DescriptorSizeBuf;
236 UINT8 *FmpImageInfoCountBuf;
237 UINT32 *FmpImageInfoDescriptorVerBuf;
239 UINT32 PackageVersion;
240 CHAR16 *PackageVersionName;
248 FmpImageInfoBuf =
NULL;
249 FmpImageInfoCountBuf =
NULL;
250 PackageVersionName =
NULL;
251 DescriptorSizeBuf =
NULL;
252 FmpImageInfoDescriptorVerBuf =
NULL;
253 EsrtRepositoryNew =
NULL;
258 Status =
gBS->LocateHandleBuffer (
260 &gEfiFirmwareManagementProtocolGuid,
266 if (Status == EFI_NOT_FOUND) {
268 goto UPDATE_REPOSITORY;
269 }
else if (EFI_ERROR (Status)) {
277 if (EsrtRepositoryNew ==
NULL) {
278 Status = EFI_OUT_OF_RESOURCES;
283 if (FmpBuf ==
NULL) {
284 Status = EFI_OUT_OF_RESOURCES;
289 if (FmpImageInfoBuf ==
NULL) {
290 Status = EFI_OUT_OF_RESOURCES;
295 if (FmpImageInfoCountBuf ==
NULL) {
296 Status = EFI_OUT_OF_RESOURCES;
301 if (DescriptorSizeBuf ==
NULL) {
302 Status = EFI_OUT_OF_RESOURCES;
306 FmpImageInfoDescriptorVerBuf =
AllocateZeroPool (
sizeof (UINT32) * NumberOfHandles);
307 if (FmpImageInfoDescriptorVerBuf ==
NULL) {
308 Status = EFI_OUT_OF_RESOURCES;
315 for (Index1 = 0; Index1 < NumberOfHandles; Index1++) {
316 Status =
gBS->HandleProtocol (
317 HandleBuffer[Index1],
318 &gEfiFirmwareManagementProtocolGuid,
319 (VOID **)&FmpBuf[Index1]
322 if (EFI_ERROR (Status)) {
327 Status = FmpBuf[Index1]->GetImageInfo (
338 if (Status == EFI_BUFFER_TOO_SMALL) {
340 if (FmpImageInfoBuf[Index1] ==
NULL) {
341 Status = EFI_OUT_OF_RESOURCES;
348 PackageVersionName =
NULL;
349 Status = FmpBuf[Index1]->GetImageInfo (
352 FmpImageInfoBuf[Index1],
353 &FmpImageInfoDescriptorVerBuf[Index1],
354 &FmpImageInfoCountBuf[Index1],
355 &DescriptorSizeBuf[Index1],
363 if (EFI_ERROR (Status)) {
364 FmpImageInfoCountBuf[Index1] = 0;
368 if (PackageVersionName !=
NULL) {
376 for (Index2 = 0; Index2 < NumberOfHandles; Index2++) {
377 TempFmpImageInfo = FmpImageInfoBuf[Index2];
378 for (Index3 = 0; Index3 < FmpImageInfoCountBuf[Index2]; Index3++) {
385 for (Index1 = 0; Index1 < EntryNumNew; Index1++) {
387 if (EsrtRepositoryNew[Index1].FwVersion > TempFmpImageInfo->
Version) {
398 if (Index1 == EntryNumNew) {
399 SetEsrtEntryFromFmpInfo (&EsrtRepositoryNew[EntryNumNew], TempFmpImageInfo, FmpImageInfoDescriptorVerBuf[Index2]);
401 if (EntryNumNew >=
PcdGet32 (PcdMaxFmpEsrtCacheNum)) {
417 if (EFI_ERROR (Status)) {
421 Status =
gRT->SetVariable (
422 EFI_ESRT_FMP_VARIABLE_NAME,
432 if (EsrtRepositoryNew !=
NULL) {
436 if (HandleBuffer !=
NULL) {
440 if (FmpBuf !=
NULL) {
444 if (FmpImageInfoCountBuf !=
NULL) {
448 if (DescriptorSizeBuf !=
NULL) {
452 if (FmpImageInfoDescriptorVerBuf !=
NULL) {
453 FreePool (FmpImageInfoDescriptorVerBuf);
456 if (FmpImageInfoBuf !=
NULL) {
457 for (Index1 = 0; Index1 < NumberOfHandles; Index1++) {
458 if (FmpImageInfoBuf[Index1] !=
NULL) {
488 Status =
gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid,
NULL, (VOID **)&VariableLock);
489 if (!EFI_ERROR (Status)) {
490 Status = VariableLock->RequestToLock (VariableLock, EFI_ESRT_FMP_VARIABLE_NAME, &gEfiCallerIdGuid);
491 DEBUG ((DEBUG_INFO,
"EsrtDxe Lock EsrtFmp Variable Status 0x%x", Status));
493 Status = VariableLock->RequestToLock (VariableLock, EFI_ESRT_NONFMP_VARIABLE_NAME, &gEfiCallerIdGuid);
494 DEBUG ((DEBUG_INFO,
"EsrtDxe Lock EsrtNonFmp Variable Status 0x%x", Status));
519 UINTN FmpRepositorySize;
520 UINTN NonFmpRepositorySize;
522 FmpEsrtRepository =
NULL;
523 NonFmpEsrtRepository =
NULL;
524 FmpRepositorySize = 0;
525 NonFmpRepositorySize = 0;
528 if (EFI_ERROR (Status)) {
533 EFI_ESRT_NONFMP_VARIABLE_NAME,
535 (VOID **)&NonFmpEsrtRepository,
536 &NonFmpRepositorySize
539 if (EFI_ERROR (Status)) {
540 NonFmpRepositorySize = 0;
544 DEBUG ((DEBUG_ERROR,
"NonFmp Repository Corrupt. Need to rebuild NonFmp Repository.\n"));
545 NonFmpRepositorySize = 0;
552 EFI_ESRT_FMP_VARIABLE_NAME,
554 (VOID **)&FmpEsrtRepository,
558 if (EFI_ERROR (Status)) {
559 FmpRepositorySize = 0;
563 DEBUG ((DEBUG_ERROR,
"Fmp Repository Corrupt. Need to rebuild Fmp Repository.\n"));
564 FmpRepositorySize = 0;
572 if (NonFmpRepositorySize + FmpRepositorySize == 0) {
577 if (EsrtTable ==
NULL) {
578 DEBUG ((DEBUG_ERROR,
"Esrt table memory allocation failure\n"));
586 if ((NonFmpRepositorySize != 0) && (NonFmpEsrtRepository !=
NULL)) {
587 CopyMem (EsrtTable + 1, NonFmpEsrtRepository, NonFmpRepositorySize);
590 if ((FmpRepositorySize != 0) && (FmpEsrtRepository !=
NULL)) {
591 CopyMem ((UINT8 *)(EsrtTable + 1) + NonFmpRepositorySize, FmpEsrtRepository, FmpRepositorySize);
597 Status =
gBS->InstallConfigurationTable (&gEfiSystemResourceTableGuid, EsrtTable);
602 gBS->CloseEvent (Event);
606 if (FmpEsrtRepository !=
NULL) {
610 if (NonFmpEsrtRepository !=
NULL) {
641 Status =
gBS->InstallMultipleProtocolInterfaces (
643 &gEsrtManagementProtocolGuid,
644 &mEsrtManagementProtocolTemplate,
652 Status =
gBS->CreateEventEx (
657 &gEfiEventReadyToBootGuid,
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI EsrtDxeLockEsrtRepository(VOID)
EFI_STATUS EFIAPI EsrtDxeEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI EsrtDxeUpdateEsrtEntry(IN EFI_SYSTEM_RESOURCE_ENTRY *Entry)
VOID EFIAPI EsrtReadyToBootEventNotify(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI EsrtDxeSyncFmp(VOID)
EFI_STATUS EFIAPI EsrtDxeRegisterEsrtEntry(IN EFI_SYSTEM_RESOURCE_ENTRY *Entry)
EFI_STATUS EFIAPI EsrtDxeUnRegisterEsrtEntry(IN EFI_GUID *FwClass)
EFI_STATUS EFIAPI EsrtDxeGetEsrtEntry(IN EFI_GUID *FwClass, IN OUT EFI_SYSTEM_RESOURCE_ENTRY *Entry)
VOID SetEsrtEntryFromFmpInfo(IN OUT EFI_SYSTEM_RESOURCE_ENTRY *EsrtEntry, IN EFI_FIRMWARE_IMAGE_DESCRIPTOR *FmpImageInfo, IN UINT32 DescriptorVersion)
EFI_STATUS DeleteEsrtEntry(IN EFI_GUID *FwClass, IN UINTN Attribute)
EFI_STATUS GetEsrtEntry(IN EFI_GUID *FwClass, IN UINTN Attribute, OUT EFI_SYSTEM_RESOURCE_ENTRY *Entry)
EFI_STATUS UpdateEsrtEntry(IN EFI_SYSTEM_RESOURCE_ENTRY *Entry, UINTN Attribute)
EFI_STATUS InsertEsrtEntry(IN EFI_SYSTEM_RESOURCE_ENTRY *Entry, UINTN Attribute)
#define IMAGE_ATTRIBUTE_IN_USE
EFI_RUNTIME_SERVICES * gRT
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define PcdGet32(TokenName)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
#define EFI_SYSTEM_RESOURCE_TABLE_FIRMWARE_RESOURCE_VERSION
VOID EFIAPI EfiReleaseLock(IN EFI_LOCK *Lock)
EFI_STATUS EFIAPI EfiAcquireLockOrFail(IN EFI_LOCK *Lock)
EFI_STATUS EFIAPI GetVariable2(IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
EFI_LOCK *EFIAPI EfiInitializeLock(IN OUT EFI_LOCK *Lock, IN EFI_TPL Priority)
#define EFI_VARIABLE_NON_VOLATILE
UINT64 AttributesSupported
UINT32 FwResourceCountMax