Newer
Older
AMI-Aptio-BIOS-Reversed / EsrtDxe / EsrtDxe.md
@Ajax Dong Ajax Dong 2 days ago 7 KB Init

EsrtDxe

Function Table

Address Name Description
FreePool
ReadUnaligned64
CompareGuid
GetDebugOutputProtocol
DebugPrint
DebugAssert
EfiInitializeLock
EfiAcquireLock
EfiReleaseLock
EfiGetSystemConfigurationTable
HobLibConstructor
GetEfiVariable
EsrtDxeFindAndCopyEntry
EsrtDxeAppendNonFmpEntry
EsrtDxeDeleteNonFmpEntry
EsrtDxeUpdateRepositoryEntry
EsrtDxeUpdateEntry
EsrtDxeDeleteEntry
EsrtDxeRemoveEntry
EsrtDxeAddEntry
EsrtDxeCopyCollectedEntry
EsrtDxeCollectFmpEntries
EsrtDxeLockVariables
EsrtDxeNotifyInstallEsrtTable
EsrtDxeEntryInit
EsrtDxeRegisterCallbacks
UefiMain
Module Global Variables
GUID definitions (module-local)
EFI_GUID gEfiEsrtTableProtocolGuid = ESRT_TABLE_PROTOCOL_GUID;
Internal Memory Helpers (Minimal implementations)
Dst8 += Length - 1;
UINTN Count = Length >> 3;
Count = Length - 1;
Library Function Wrappers (from EDK2 libraries)
Allocation Helpers
GUID Comparison
Debug Output Support
Check debug enable via CMOS register 0x4B.
__outbyte **(0x70, __inbyte (0x70) & 0x80 0x4B);**
Determine debug level
if (CmosByte == 0) {
Map decoded level to standard DEBUG masks.
Call the protocol's Print routine.
Lock Management (from UefiLib)
TPL_NOTIFY Lock->OwnerTpl = 4; // Default saved TPL
EfiLockReleased }
EfiLockAcquired return 0;
EfiLockReleased gBS->RestoreTPL (OldTpl);
Configuration Table Access (from UefiLib)
HOB List Initialization
Variable Access (from UefiLib)
First query: get size.
Status = gRT->GetVariable (
EFI_BUFFER_TOO_SMALL Buffer = AllocatePool (BufferSize);
ESRT Repository: Find, Copy, Update, Append, Delete Operations
1280 bytes = 32 entries
EsrtDxeFindAndCopyEntry // ---------------------------------------------------------------------------
Validate repository alignment.
EntryCount = RepoSize / ESRT_ENTRY_SIZE;
Scan for matching GUID.
Status = (UINTN)0x800000000000000EuLL; // EFI_NOT_FOUND
EFI_SUCCESS break;
EFI_NOT_FOUND //
Create a new variable with single entry.
return gRT->SetVariable (
Validate repository.
Delete corrupt variable, then create new with this entry.
Repository is full (1280 bytes / 40 = 32 entries).
if (Repository != NULL) {
Allocate larger buffer, copy existing, append new entry.
NewRepo = AllocatePool (RepoSize + ESRT_ENTRY_SIZE);
Find the entry to delete.
for (Index = 0; Index < EntryCount; Index++) {
Shift entries after gap.
if (Index < EntryCount - 1) {
Write updated (smaller) repository.
Status = gRT->SetVariable (
CopyMem (&Repository[Index], FwClass, ESRT_ENTRY_SIZE);
Not found: append if space available.
if (RepoSize < ESRT_REPO_MAX) {
Allocate larger buffer, append entry.
VOID *NewRepo = AllocatePool (RepoSize + ESRT_ENTRY_SIZE);
ESRT Protocol Entry Points
Not in Non-FMP; try FMP.
EfiReleaseLock (&mNonFmpLock);
Not in FMP; try Non-FMP.
Status = EfiAcquireLock (&mNonFmpLock);
EFI_NOT_FOUND Status = EsrtDxeAppendNonFmpEntry (Entry);
FMP Entry Collection
Initialize collected entry fields.
System firmware type
Copy GUID (from src offset 4).
CopyMem (&Dest->FwClass, (UINT8 *)Src + 4, sizeof (EFI_GUID));
Optional fields based on descriptor attributes.
if (Attributes >= 2) {
Working buffers per handle.
UINTN *FmpImageInfoSizes;
HandleBuffer = NULL;
Locate all FMP protocol handles.
Status = gBS->LocateHandleBuffer (
EFI_NOT_FOUND goto WRITE_REPOSITORY;
Allocate workspace arrays.
FmpImageInfoSizes = AllocateZeroPool (HandleCount * sizeof (UINTN));
EFI_OUT_OF_RESOURCES goto CLEANUP;
Phase 1: Query all FMP protocol instances for image info.
for (BufferIndex = 0; BufferIndex < HandleCount; BufferIndex++) {
Query size.
ImageInfoSize = 0;
EFI_BUFFER_TOO_SMALL ESRT_ENTRY *InfoBuffer;
Phase 2: Collect entries, deduplicating by firmware class GUID.
Walk descriptors for this handle.
Check descriptor validity flags.
if (((UINT8 )((UINT8 *)&ImageInfo[DescIndex] + 64) & 8) != 0 &&
Look for existing entry with same FwClass GUID.
EntryIndex = NumCollected;
if (Collected[CollectedIndex].LastAttemptVersion <=
force skip append
Phase 3: Write collected entries to EsrtFmp variable.
if (NumCollected > 0) {
Copy collected entries.
for (Index = 0; Index < NumCollected; Index++) {
Write under lock.
Status = EfiAcquireLock (&mFmpLock);
NV + BS + RT
Free all allocated buffers.
if (HandleBuffer != NULL) {
Variable Lock (ReadyToBoot / VirtualAddressChange callback)
Locate the Variable Lock protocol.
Status = gBS->LocateProtocol (
ReadyToBoot Notification: Build & Install ESRT Configuration Table
Step 1: Read Non-FMP repository (under lock).
Step 2: Read FMP repository (under lock).
Step 3: Build and install combined ESRT table.
TotalEntries = NonFmpEntryCount + FmpEntryCount;
TableBuffer = AllocateZeroPool (TotalEntries * ESRT_ENTRY_SIZE + 16);
ESRT header fields:
if (NonFmpSize > 0 && NonFmpRepository != NULL) {
Install configuration table.
Signal the context event (may be a notification registration).
Driver Initialization
Store globals.
Initialize HOB list.
HobLibConstructor ();
Locate DxeServicesTable.
Status = EfiGetSystemConfigurationTable (
Initialize locks.
EfiInitializeLock (&mFmpLock);
Register ReadyToBoot event -> build ESRT table.
Status = gBS->CreateEventEx (
Register VirtualAddressChange event -> lock variables.
Install protocol interfaces and FMP protocol notify.
Status = gBS->InstallProtocolInterface (
from the decompiled output; it is stored in an init data
array (off_2470).
_ModuleEntryPoint (UefiMain)

Generated by HR650X BIOS Decompilation Project