bloggerads

2015年6月19日 星期五

UEFI : PEI Phase Code Trace

$ PEI (Pre Efi Initialization)的概述:

● Small, tight startup code
• Startup with transitory memory store for call-stack (I.e., cache)       
• XIP from ROM
● Core locates, validates, and dispatches PEIMs

● Publishes own protocol and call-abstraction with PPI
• Silicon/platform abstractions
● Primary goals
• Discover boot mode       
• Launch modules that initialize main memory       
• Discovery & launch DXE core- Convey platform info into DXE



$ PEI 名詞解釋

● PEI Core
The main PEI executable binary responsible for dispatching PEIM and provide basic services.
● PEIM 
An executable binary that is loaded by the core to do various tasks and initializations.
● PPI 
PEIM to PEIM Interface. An interface that allows a PEIM to invoke another PEIM.
● PEI Dispatcher 
The part of the PEI core that searches for and executes the PEIM.
● PEI Services 
Functions provided by the core visible to all PEIM.

$ PEI Phase Flow

$ PEI提供的Services:

PPI Services
Manages PEIM-to-PEIM Interface (PPIs) to facilitate intermodule calls between PEIMs.
Interfaces are installed and tracked on a database maintained in temporary RAM.
InstallPpi()
ReInstallPpi()
LocatePpi()
NotifyPpi()
Boot Mode Services
Manages the boot mode (S3, S5, normal boot, diagnostics, etc.) of the system.
GetBootMode()
SetBootMode()
HOB Services
Creates data structures called Hand-Off Blocks (HOBs) that are used to pass information to the next phase of the PI Architecture.
GetHobList()
CreateHob()
Firmware Volume Services
Walks the Firmware File Systems (FFS) in firmware volumes to find PEIMs and other firmware files in the flash device.
FfsFindNextVolume()
FfsFindNextFile()
FfsFindSectionData()
PEI Memory Services
Provides a collection of memory management services for use both before and after permanent memory has been discovered.
InstallPeiMemory()
AllocatePages()
AllocatePool()
CopyMem()
SetMem()
Status Code Services
Provides common progress and error code reporting services (for example, port 080h or a serial port for simple text output for debug).
PeiReportStatusCode()
Reset Services
Provides a common means by which to initiate a warm or cold restart of the system.
PeiResetSystem()

$ PEI Code Trace

Pre-Memory經Memory initialized後為Post-Memory

●  PEI 的進入點

VOID
EFIAPI
PeiCore (

/* SecCoreData Points to a data structure containing information about the PEI core's operating environment, such as the size and location of temporary RAM, the stack location and the BFV location. */

  IN CONST EFI_SEC_PEI_HAND_OFF        *SecCoreData,

/* PpiList Points to a list of one or more PPI descriptors to be installed initially by the PEI core. An empty PPI list consists of a single descriptor with the end-tag EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such that both the PEI Foundation and any modules can leverage the associated service calls and/or code in these early PPIs*/

  IN CONST EFI_PEI_PPI_DESCRIPTOR      *PpiList,

/* Data Pointer to old core data that is used to initialize the core's data areas. If NULL, it is first PeiCore entering.*/

  IN VOID                              *Data

  )
{
...
//
// Initialize PEI Core Services
//
InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData);
InitializePpiServices (&PrivateData, OldCoreData);
...
//
// Call PEIM dispatcher
//
PeiDispatcher (SecCoreData, &PrivateData);;
...
//
// Lookup DXE IPL PPI
//
Status = PeiServicesLocatePpi (
             &gEfiDxeIplPpiGuid,
             0,
             NULL,
             (VOID **)&TempPtr.DxeIpl
             );
  ASSERT_EFI_ERROR (Status);

//
// Enter DxeIpl to load Dxe core.
//

Status = TempPtr.DxeIpl->Entry (
                             TempPtr.DxeIpl,
                             &PrivateData.Ps,
                             PrivateData.HobList
                             );

}




PEI dispatch最後一個PEIM (DxeIplPeim),其功用就是將控制權交給DXE phase, 同時也會install EFI_END_OF_PEI_PPI 


VOID
HandOffToDxeCore (
  IN EFI_PHYSICAL_ADDRESS   DxeCoreEntryPoint,
  IN EFI_PEI_HOB_POINTERS   HobList
  )
{
...
  //
  // Transfer the control to the entry point of DxeCore.
  //
  SwitchStack (
    (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
    HobList.Raw,
    NULL,
    TopOfStack

    );
}


●  DXE 的進入點


VOID
EFIAPI
DxeMain (
  IN  VOID *HobStart //Pointer to the beginning of the HOB List from PEI.
  )
{
}


沒有留言:

張貼留言