EFI_STATUS DxeInitializeDriverLib ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Intialize Driver Lib if it has not yet been initialized. Arguments: ImageHandle - Standard EFI Image entry parameter SystemTable - Standard EFI Image entry parameter Returns: EFI_STATUS always returns EFI_SUCCESS --*/ { EFI_STATUS Status; Status = EfiInitializeDriverLib (ImageHandle, SystemTable); if (!EFI_ERROR (Status)) { Status = EfiLibGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS); } return Status; }
EFI_STATUS GetPeiProtocol ( IN EFI_GUID *ProtocolGuid, IN VOID **Interface ) /*++ Routine Description: Searches for a Protocol Interface passed from PEI through a HOB Arguments: ProtocolGuid - The Protocol GUID to search for in the HOB List Interface - A pointer to the interface for the Protocol GUID Returns: EFI_SUCCESS - The Protocol GUID was found and its interface is returned in Interface EFI_NOT_FOUND - The Protocol GUID was not found in the HOB List --*/ { EFI_STATUS Status; EFI_PEI_HOB_POINTERS GuidHob; // // Get Hob list // Status = EfiLibGetSystemConfigurationTable (&gEfiHobListGuid, (VOID **) &GuidHob.Raw); if (EFI_ERROR (Status)) { return Status; } for (Status = EFI_NOT_FOUND; EFI_ERROR (Status);) { if (END_OF_HOB_LIST (GuidHob)) { Status = EFI_NOT_FOUND; break; } if (GET_HOB_TYPE (GuidHob) == EFI_HOB_TYPE_GUID_EXTENSION) { if (EfiCompareGuid (ProtocolGuid, &GuidHob.Guid->Name)) { Status = EFI_SUCCESS; *Interface = (VOID *) *(UINTN *) ((UINT8 *) (&GuidHob.Guid->Name) + sizeof (EFI_GUID)); } } GuidHob.Raw = GET_NEXT_HOB (GuidHob); } return Status; }
EFI_STATUS EfiInitializeWinNtDriverLib ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Intialize gWinNt and initialize debug console. Arguments: (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT) Returns: None --*/ // TODO: ImageHandle - add argument and description to function comment // TODO: SystemTable - add argument and description to function comment // TODO: EFI_NOT_FOUND - add return value to function comment // TODO: EFI_NOT_FOUND - add return value to function comment // TODO: EFI_SUCCESS - add return value to function comment { EFI_STATUS Status; VOID *HobList; VOID *Pointer; Status = EfiLibGetSystemConfigurationTable (&mEfiHobListGuid, &HobList); if (EFI_ERROR (Status)) { return EFI_NOT_FOUND; } ASSERT (NULL != HobList); Status = GetNextGuidHob (&HobList, &gEfiWinNtThunkProtocolGuid, &Pointer, NULL); if (EFI_ERROR (Status)) { return EFI_NOT_FOUND; } gWinNt = (VOID *) (*(UINTN *) (Pointer)); return EFI_SUCCESS; }
VOID BdsLockNonUpdatableFlash ( VOID ) { EFI_FLASH_MAP_ENTRY_DATA *FlashMapEntryData; VOID *HobList; VOID *Buffer; EFI_STATUS Status; EFI_CPU_IO_PROTOCOL *CpuIo; Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, &CpuIo); ASSERT_EFI_ERROR (Status); Status = EfiLibGetSystemConfigurationTable (&gEfiHobListGuid, &HobList); ASSERT_EFI_ERROR (Status); for (;;) { Status = GetNextGuidHob (&HobList, &gEfiFlashMapHobGuid, &Buffer, NULL); if (EFI_ERROR (Status)) { break; } FlashMapEntryData = (EFI_FLASH_MAP_ENTRY_DATA *) Buffer; // // Get the variable store area // if ((FlashMapEntryData->AreaType == EFI_FLASH_AREA_RECOVERY_BIOS) || (FlashMapEntryData->AreaType == EFI_FLASH_AREA_MAIN_BIOS) ) { BdsLockFv (CpuIo, &(FlashMapEntryData->Entries[0])); } } return ; }
EFI_STATUS GetPeiPerformance ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable, IN UINT64 Ticker ) /*++ Routine Description: Transfer PEI performance data to gauge data node. Arguments: ImageHandle - Standard entry point parameter SystemTable - Standard entry point parameter Ticker - Start tick Returns: EFI_OUT_OF_RESOURCES - No enough resource to create data node. EFI_SUCCESS - Transfer done successfully. --*/ { EFI_STATUS Status; VOID *HobList; EFI_HOB_GUID_DATA_PERFORMANCE_LOG *LogHob; PEI_PERFORMANCE_MEASURE_LOG_ENTRY *LogEntry; UINT32 Index; EFI_PERF_DATA_LIST *Node; UINT64 TimerValue; Node = CreateDataNode (0, PEI_TOK, NULL); if (!Node) { return EFI_OUT_OF_RESOURCES; } if (Ticker != 0) { TimerValue = Ticker; } else { GetTimerValue (&TimerValue); } (Node->GaugeData).EndTick = TimerValue; InsertTailList (&mPerfDataHead, &(Node->Link)); EfiLibGetSystemConfigurationTable (&gEfiHobListGuid, &HobList); do { Status = GetNextGuidHob (&HobList, &gEfiPeiPerformanceHobGuid, (VOID **) &LogHob, NULL); if (EFI_ERROR (Status)) { break; } for (Index = 0; Index < LogHob->NumberOfEntries; Index++) { LogEntry = &(LogHob->Log[Index]); Node = CreateDataNode (0, LogEntry->DescriptionString, NULL); if (!Node) { return EFI_OUT_OF_RESOURCES; } (Node->GaugeData).StartTick = LogEntry->StartTimeCount; EfiCopyMem (&(Node->GaugeData.GuidName), &LogEntry->Name, sizeof (EFI_GUID)); InsertTailList (&mPerfDataHead, &(Node->Link)); (Node->GaugeData).EndTick = LogEntry->StopTimeCount; } } while (!EFI_ERROR (Status)); return EFI_SUCCESS; }
EFI_STATUS EfiInitializeRuntimeDriverLib ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable, IN EFI_EVENT_NOTIFY GoVirtualChildEvent ) /*++ Routine Description: Intialize runtime Driver Lib if it has not yet been initialized. Arguments: ImageHandle - The firmware allocated handle for the EFI image. SystemTable - A pointer to the EFI System Table. GoVirtualChildEvent - Caller can register a virtual notification event. Returns: EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started. --*/ { EFI_STATUS Status; EFI_PLABEL *Plabel; if (mRuntimeLibInitialized) { return EFI_ALREADY_STARTED; } mRuntimeLibInitialized = TRUE; gST = SystemTable; gBS = SystemTable->BootServices; mRT = SystemTable->RuntimeServices; Status = EfiLibGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS); ASSERT_EFI_ERROR (Status); // // The protocol contains a function pointer, which is an indirect procedure call. // An indirect procedure call goes through a plabel, and pointer to a function is // a pointer to a plabel. To implement indirect procedure calls that can work in // both physical and virtual mode, two plabels are required (one physical and one // virtual). So lets grap the physical PLABEL for the EsalEntryPoint and store it // away. We cache it in a module global, so we can register the vitrual version. // Status = gBS->LocateProtocol (&gEfiExtendedSalBootServiceProtocolGuid, NULL, (VOID **) &mEsalBootService); ASSERT_EFI_ERROR (Status); Plabel = (EFI_PLABEL *) (UINTN) mEsalBootService->ExtendedSalProc; mPlabel.EntryPoint = Plabel->EntryPoint; mPlabel.GP = Plabel->GP; SetEsalPhysicalEntryPoint (mPlabel.EntryPoint, mPlabel.GP); // // Create a Virtual address change notification event. Pass in the callers // GoVirtualChildEvent so it's get passed to the event as contex. // Status = gBS->CreateEvent ( EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE, EFI_TPL_NOTIFY, EfiRuntimeLibVirtualNotifyEvent, (VOID *) GoVirtualChildEvent, &mEfiVirtualNotifyEvent ); ASSERT_EFI_ERROR (Status); return EFI_SUCCESS; }
EFI_STATUS RebuildHeap ( IN OUT HEAP_MANAGER **HeapManagerPtr ) { EFI_STATUS Status; AGESA_STATUS AgesaStatus; UINTN BufferSize; UINTN AlignTo16ByteInDxeMem; UINTN TotalAlignTo16ByteInHob; EFI_PEI_HOB_POINTERS Hob; VOID *HobList; VOID *HeapBufferInHob; HEAP_MANAGER *HeapManagerInHob; BUFFER_NODE *HeapHeaderNodeInHob; BUFFER_NODE *HeapCurrentNodeInHob; BUFFER_NODE *HeapPreNodeInHob; HEAP_MANAGER *HeapManagerInDxeMem; BUFFER_NODE *HeapHeaderNodeInDxeMem; BUFFER_NODE *HeapCurrentNodeInDxeMem; BUFFER_NODE *HeapPreNodeInDxeMem; UINT32 OffsetOfHeapCurrentNodeInDxeMem; AGESA_BUFFER_PARAMS AllocParams; Status = EfiLibGetSystemConfigurationTable (&gEfiHobListGuid, &HobList); ASSERT_EFI_ERROR (Status); Hob.Raw = HobList; HeapBufferInHob = NULL; while (!END_OF_HOB_LIST (Hob)) { Status = GetNextGuidHob ( &HobList, &gAmdHeapHobGuid, &HeapBufferInHob, &BufferSize ); if (Status == EFI_SUCCESS ) { HeapManagerInHob = (HEAP_MANAGER *) HeapBufferInHob; HeapHeaderNodeInHob = (BUFFER_NODE *) ((UINT8 *) HeapManagerInHob + HeapManagerInHob->FirstActiveBufferOffset); HeapCurrentNodeInHob = HeapHeaderNodeInHob; // // 1. Analyse heap buffer from HOB data to calculate the final size for recreating the heap buffers // Reserve maximum pad size for each heap node. // 2. Allocate memory for heap buffers // 3. Copying heap manager data from HOB include extracing 1-byte alignment to 16-byte alignment // // // 1. Analyse heap buffer from HOB data to calculate the final size for recreating the heap buffers. // Reserve maximum pad size for each heap node. // TotalAlignTo16ByteInHob = 0; do { HeapPreNodeInHob = HeapCurrentNodeInHob; TotalAlignTo16ByteInHob += 0xF; HeapCurrentNodeInHob = (BUFFER_NODE *) ((UINT8 *) HeapBufferInHob + HeapCurrentNodeInHob->OffsetOfNextNode); } while (HeapPreNodeInHob->OffsetOfNextNode != AMD_HEAP_INVALID_HEAP_OFFSET); // // 2. Allocate memory for heap buffers // AllocParams.BufferLength = (UINT32) (HeapManagerInHob->UsedSize + TotalAlignTo16ByteInHob + 0x0F); AllocParams.BufferHandle = AMD_HEAP_IN_MAIN_MEMORY_HANDLE; if ((AgesaStatus = AgesaAllocateBuffer (0, &AllocParams)) != AGESA_SUCCESS) { if (AGESA_ERROR > AgesaStatus) { return EFI_OUT_OF_RESOURCES; } } EfiZeroMem (AllocParams.BufferPointer, AllocParams.BufferLength); *HeapManagerPtr = AllocParams.BufferPointer; // // 3. Copying heap manager data from HOB include extracing 1-byte alignment to 16-byte alignment // HeapManagerInDxeMem = *HeapManagerPtr; HeapManagerInDxeMem->FirstActiveBufferOffset = sizeof (HEAP_MANAGER); HeapManagerInDxeMem->UsedSize = sizeof (HEAP_MANAGER); HeapHeaderNodeInDxeMem = (BUFFER_NODE *) ((UINT8 *) HeapManagerInDxeMem + HeapManagerInDxeMem->FirstActiveBufferOffset); OffsetOfHeapCurrentNodeInDxeMem = HeapManagerInDxeMem->FirstActiveBufferOffset; HeapCurrentNodeInDxeMem = HeapHeaderNodeInDxeMem; HeapCurrentNodeInHob = HeapHeaderNodeInHob; HeapPreNodeInHob = NULL; do { // Create BUFFER_NODE with 16-byte alignment padding considered. // The beginning of data buffer is on 16-byte boundary address. // The structure of a heap buffer would be looked like below. // // +---------------------------------------------------------------------------------+ // | BUFFER_NODE | Pad | IDS SENTINEL ("Head") | Data buffer | IDS SENTINEL ("Tail") | // +---------------------------------------------------------------------------------+ // AlignTo16ByteInDxeMem = ((0x10 - (((UINTN) (VOID *) HeapCurrentNodeInDxeMem + sizeof (BUFFER_NODE) + SIZE_OF_SENTINEL) & 0xF)) & 0xF); HeapCurrentNodeInDxeMem->BufferHandle = HeapCurrentNodeInHob->BufferHandle; HeapCurrentNodeInDxeMem->BufferSize = (UINT32) (HeapCurrentNodeInHob->BufferSize + AlignTo16ByteInDxeMem); HeapCurrentNodeInDxeMem->Persist = HeapCurrentNodeInHob->Persist; HeapCurrentNodeInDxeMem->PadSize = (UINT8) AlignTo16ByteInDxeMem; HeapCurrentNodeInDxeMem->OffsetOfNextNode = OffsetOfHeapCurrentNodeInDxeMem + sizeof (BUFFER_NODE) + HeapCurrentNodeInDxeMem->BufferSize; // Copy buffer data gBS->CopyMem ( (UINT8 *) ((UINT8 *) HeapCurrentNodeInDxeMem + sizeof (BUFFER_NODE) + AlignTo16ByteInDxeMem), (UINT8 *) ((UINT8 *) HeapCurrentNodeInHob + sizeof (BUFFER_NODE)), HeapCurrentNodeInHob->BufferSize ); // Point to the next heap node HeapPreNodeInHob = HeapCurrentNodeInHob; HeapPreNodeInDxeMem = HeapCurrentNodeInDxeMem; HeapCurrentNodeInHob = (BUFFER_NODE *) ((UINT8 *) HeapBufferInHob + HeapCurrentNodeInHob->OffsetOfNextNode); HeapCurrentNodeInDxeMem = (BUFFER_NODE *) ((UINT8 *) HeapManagerInDxeMem + HeapCurrentNodeInDxeMem->OffsetOfNextNode); OffsetOfHeapCurrentNodeInDxeMem = (UINT32) ((UINTN) HeapCurrentNodeInDxeMem - (UINTN) HeapManagerInDxeMem); } while (HeapPreNodeInHob->OffsetOfNextNode != AMD_HEAP_INVALID_HEAP_OFFSET); // // Finalize the last heap node // HeapManagerInDxeMem->UsedSize = (UINT32) HeapPreNodeInDxeMem->OffsetOfNextNode; HeapPreNodeInDxeMem->OffsetOfNextNode = AMD_HEAP_INVALID_HEAP_OFFSET; // // Finalize Heap Manager pointer // No free buffer node is provide after heap recreation. // *HeapManagerPtr = HeapManagerInDxeMem; HeapManagerInDxeMem->FirstActiveBufferOffset = (UINT32) ((UINT8 *) HeapHeaderNodeInDxeMem - (UINT8 *) HeapManagerInDxeMem); HeapManagerInDxeMem->FirstFreeSpaceOffset = AMD_HEAP_INVALID_HEAP_OFFSET; HeapManagerInDxeMem->Signature = HeapManagerInHob->Signature; return EFI_SUCCESS; } } return EFI_NOT_FOUND; }
EFI_STATUS EfiInitializeRuntimeDriverLib ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable, IN EFI_EVENT_NOTIFY GoVirtualChildEvent ) /*++ Routine Description: Intialize runtime Driver Lib if it has not yet been initialized. Arguments: ImageHandle - The firmware allocated handle for the EFI image. SystemTable - A pointer to the EFI System Table. GoVirtualChildEvent - Caller can register a virtual notification event. Returns: EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started. --*/ { EFI_STATUS Status; #if (EFI_SPECIFICATION_VERSION >= 0x00020000) VOID *Registration; #endif if (mRuntimeLibInitialized) { return EFI_ALREADY_STARTED; } mRuntimeLibInitialized = TRUE; gST = SystemTable; ASSERT (gST != NULL); gBS = SystemTable->BootServices; ASSERT (gBS != NULL); mRT = SystemTable->RuntimeServices; ASSERT (mRT != NULL); Status = EfiLibGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS); ASSERT_EFI_ERROR (Status); #if (EFI_SPECIFICATION_VERSION >= 0x00020000) // // Register EFI_STATUS_CODE_PROTOCOL notify function // Status = gBS->CreateEvent ( EFI_EVENT_NOTIFY_SIGNAL, EFI_TPL_CALLBACK, OnStatusCodeInstall, NULL, &gEfiStatusCodeNotifyEvent ); ASSERT_EFI_ERROR (Status); Status = gBS->RegisterProtocolNotify ( &gEfiStatusCodeRuntimeProtocolGuid, gEfiStatusCodeNotifyEvent, &Registration ); ASSERT_EFI_ERROR (Status); gBS->SignalEvent (gEfiStatusCodeNotifyEvent); #endif Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, (VOID **) &gCpuIo); if (EFI_ERROR (Status)) { gCpuIo = NULL; } // // Register our ExitBootServices () notify function // Status = gBS->CreateEvent ( EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES, EFI_TPL_NOTIFY, RuntimeDriverExitBootServices, NULL, &mRuntimeNotifyEvent ); ASSERT_EFI_ERROR (Status); // // Register SetVirtualAddressMap () notify function // Status = gBS->CreateEvent ( EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE, EFI_TPL_NOTIFY, EfiRuntimeLibVirtualNotifyEvent, (VOID *) (UINTN) GoVirtualChildEvent, &mEfiVirtualNotifyEvent ); ASSERT_EFI_ERROR (Status); return EFI_SUCCESS; }
EFI_STATUS ProcessCapsules ( EFI_BOOT_MODE BootMode ) /*++ Routine Description: This routine is called to see if there are any capsules we need to process. If the boot mode is not UPDATE, then we do nothing. Otherwise find the capsule HOBS and produce firmware volumes for them via the DXE service. Then call the dispatcher to dispatch drivers from them. Finally, check the status of the updates. Arguments: BootMode - the current boot mode Returns: EFI_INVALID_PARAMETER - boot mode is not correct for an update Note: This function should be called by BDS in case we need to do some sort of processing even if there is no capsule to process. We need to do this if an earlier update went awry and we need to clear the capsule variable so on the next reset PEI does not see it and think there is a capsule available. --*/ { EFI_STATUS Status; EFI_HOB_HANDOFF_INFO_TABLE *HobList; EFI_PHYSICAL_ADDRESS BaseAddress; UINT64 Length; EFI_STATUS HobStatus; EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; EFI_HANDLE FvProtocolHandle; #if (EFI_SPECIFICATION_VERSION >= 0x00020000) EFI_CAPSULE_HEADER *CapsuleHeader; EFI_PHYSICAL_ADDRESS BodyBaseAddress; UINT32 Size; UINT8 CapsuleNumber; UINT8 CapsuleTotalNumber; EFI_CAPSULE_TABLE *CapsuleTable; VOID *AddDataPtr; UINT32 *DataPtr; UINT32 *BeginPtr; UINT32 Index; UINT32 PopulateIndex; UINT32 CacheIndex; UINT32 CacheNumber; BOOLEAN CachedFlag; VOID *CapsulePtr[MAX_SUPPORT_CAPSULE_NUM]; EFI_GUID CapsuleGuidCache[MAX_SUPPORT_CAPSULE_NUM]; PopulateIndex = 0; CapsuleNumber = 0; CapsuleTotalNumber = 0; AddDataPtr = NULL; DataPtr = NULL; BeginPtr = NULL; CacheIndex = 0; CacheNumber = 0; gBS->SetMem(CapsuleGuidCache, sizeof(EFI_GUID)* MAX_SUPPORT_CAPSULE_NUM, 0); #endif // // We don't do anything else if the boot mode is not flash-update // if (BootMode != BOOT_ON_FLASH_UPDATE) { return EFI_INVALID_PARAMETER; } // // Get the HOB list so we can determine the boot mode, and (if update mode) // look for capsule hobs. // Status = EfiLibGetSystemConfigurationTable (&gEfiHobListGuid, (VOID *) &HobList); if (EFI_ERROR (Status)) { return Status; } Status = EFI_SUCCESS; // // If flash update mode, then walk the hobs to find capsules and produce // FVB protocols for them. // if ((HobList->Header.HobType == EFI_HOB_TYPE_HANDOFF) && (HobList->BootMode == BOOT_ON_FLASH_UPDATE)) { // // Only one capsule HOB allowed. // HobStatus = GetNextCapsuleVolumeHob (&HobList, &BaseAddress, &Length); if (EFI_ERROR (HobStatus)) { // // We didn't find a hob, so had no errors. // BdsLockNonUpdatableFlash (); return EFI_SUCCESS; } // // Now walk the capsule and call the core to process each // firmware volume in it. // #if (EFI_SPECIFICATION_VERSION >= 0x00020000) AddDataPtr = (VOID *)((UINTN)BaseAddress + (UINTN)Length); AddDataPtr = (UINT8 *) (((UINTN) AddDataPtr + sizeof(UINT32) - 1) &~ (UINTN) (sizeof (UINT32) - 1)); DataPtr = (UINT32*)AddDataPtr; CapsuleTotalNumber = (UINT8)*DataPtr++; BeginPtr = DataPtr; // // Record the memory address where capsules' offset variable reside. // DataPtr = BeginPtr; // // Capsules who have CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE always are used for operating // System to have information persist across a system reset. EFI System Table must // point to an array of capsules that contains the same CapsuleGuid value. And agents // searching for this type capsule will look in EFI System Table and search for the // capsule's Guid and associated pointer to retrieve the data. Two steps below describes // how to sorting the capsules by the unique guid and install the array to EFI System Table. // Firstly, Loop for all coalesced capsules, record unique CapsuleGuids and cache them in an // array for later sorting capsules by CapsuleGuid. // for (Index = 0; Index < CapsuleTotalNumber; Index++) { CachedFlag = FALSE; CapsuleHeader = (EFI_CAPSULE_HEADER*)((UINTN)BaseAddress + (UINT32)(UINTN)*DataPtr++); if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) { // // For each capsule, we compare it with known CapsuleGuid in the CacheArray. // If already has the Guid, skip it. Whereas, record it in the CacheArray as // an additional one. // CacheIndex= 0; while (CacheIndex < CacheNumber) { if (EfiCompareGuid(&CapsuleGuidCache[CacheIndex],&CapsuleHeader->CapsuleGuid)) { CachedFlag = TRUE; break; } CacheIndex++; } if (!CachedFlag) { gBS->CopyMem(&CapsuleGuidCache[CacheNumber++],&CapsuleHeader->CapsuleGuid,sizeof(EFI_GUID)); } } } // // Secondly, for each unique CapsuleGuid in CacheArray, gather all coalesced capsules // whose guid is the same as it, and malloc memory for an array which preceding // with UINT32. The array fills with entry point of capsules that have the same // CapsuleGuid, and UINT32 represents the size of the array of capsules. Then install // this array into EFI System Table, so that agents searching for this type capsule // will look in EFI System Table and search for the capsule's Guid and associated // pointer to retrieve the data. // DataPtr = BeginPtr; CacheIndex = 0; while (CacheIndex < CacheNumber) { CapsuleNumber = 0; DataPtr = BeginPtr; for (Index = 0; Index < CapsuleTotalNumber; Index++) { CapsuleHeader = (EFI_CAPSULE_HEADER*)((UINTN)BaseAddress + (UINT32)(UINTN)*DataPtr++); if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) { if (EfiCompareGuid(&CapsuleGuidCache[CacheIndex],&CapsuleHeader->CapsuleGuid)) { // // Cache Caspuleheader to the array, this array is uniqued with certain CapsuleGuid. // CapsulePtr[CapsuleNumber++]= (VOID*)CapsuleHeader; } } } if (CapsuleNumber != 0) { Size = sizeof(EFI_CAPSULE_TABLE) + (CapsuleNumber - 1) * sizeof(VOID*); Status = gBS->AllocatePool (EfiRuntimeServicesData, Size, (VOID **) &CapsuleTable); if (EFI_ERROR (Status)) { return Status; } CapsuleTable->CapsuleArrayNumber = CapsuleNumber; gBS->CopyMem(&CapsuleTable->CapsulePtr[0],CapsulePtr, CapsuleNumber * sizeof(VOID*)); Status = gBS->InstallConfigurationTable (&CapsuleGuidCache[CacheIndex], (VOID*)CapsuleTable); ASSERT_EFI_ERROR (Status); } CacheIndex++; } // // Besides ones with CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag, all capsules left are // recognized by platform with CapsuleGuid. For general platform driver, UpdateFlash // type is commonly supported, so here only deal with encapsuled FVs capsule. Additional // type capsule transaction could be extended. It depends on platform policy. // DataPtr = BeginPtr; for (Index = 0; Index < CapsuleTotalNumber; Index++) { CapsuleHeader = (EFI_CAPSULE_HEADER*)((UINTN)BaseAddress + (UINT32)(UINTN)*DataPtr++); if (((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) \ && (EfiCompareGuid (&CapsuleHeader->CapsuleGuid, &mUpdateFlashCapsuleGuid))) { // // Skip the capsule header, move to the Firware Volume // BodyBaseAddress = (EFI_PHYSICAL_ADDRESS)CapsuleHeader + CapsuleHeader->HeaderSize; Length = CapsuleHeader->CapsuleImageSize - CapsuleHeader->HeaderSize; while (Length != 0) { // // Point to the next firmware volume header, and then // call the DXE service to process it. // FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BodyBaseAddress; if (FwVolHeader->FvLength > Length) { // // Notes: need to stuff this status somewhere so that the // error can be detected at OS runtime // Status = EFI_VOLUME_CORRUPTED; break; } Status = gDS->ProcessFirmwareVolume ( (VOID *) (UINTN) BodyBaseAddress, (UINTN) FwVolHeader->FvLength, &FvProtocolHandle ); if (EFI_ERROR (Status)) { break; } // // Call the dispatcher to dispatch any drivers from the produced firmware volume // gDS->Dispatch (); // // On to the next FV in the capsule // Length -= FwVolHeader->FvLength; BodyBaseAddress = (EFI_PHYSICAL_ADDRESS) ((UINTN) BodyBaseAddress + FwVolHeader->FvLength); // // Notes: when capsule spec is finalized, if the requirement is made to // have each FV in a capsule aligned, then we will need to align the // BaseAddress and Length here. // } } } #else while (Length != 0) { // // Point to the next firmware volume header, and then // call the DXE service to process it. // FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress; if (FwVolHeader->FvLength > Length) { // // Notes: need to stuff this status somewhere so that the // error can be detected at OS runtime // Status = EFI_VOLUME_CORRUPTED; break; } Status = gDS->ProcessFirmwareVolume ( (VOID *) (UINTN) BaseAddress, (UINTN) FwVolHeader->FvLength, &FvProtocolHandle ); if (EFI_ERROR (Status)) { break; } // // Call the dispatcher to dispatch any drivers from the produced firmware volume // gDS->Dispatch (); // // On to the next FV in the capsule // Length -= FwVolHeader->FvLength; BaseAddress = (EFI_PHYSICAL_ADDRESS) ((UINTN) BaseAddress + FwVolHeader->FvLength); // // Notes: when capsule spec is finalized, if the requirement is made to // have each FV in a capsule aligned, then we will need to align the // BaseAddress and Length here. // } #endif } BdsLockNonUpdatableFlash (); return Status; }