bloggerads

2016年5月12日 星期四

UEFI : Coding after S3 BootScript

做這個實驗的動機是工作上必須在S3 BootScript完成後加patch code, 當時趕時間就把程式直接加在AMI 的 code裡。趁現在有空,就研究看有沒有辦法把她加在公司package code裡。

想想,應該可以註冊個Notify CallBack function在Pei phase結束之前自動呼叫她,實驗結果是可以的。以下是我的作法,在S3 Pei init 的路徑上加上  


(*PeiServices)->NotifyPpi(PeiServices, mTest);


然後將對應的CallBack function寫好 (如下),就可以在PEI 結束前自動呼叫到我寫的MartinFunc()了。
EFI_STATUS 
MartinFunc(
   IN EFI_PEI_SERVICES** PeiServices,
   IN EFI_PEI_NOTIFY_DESCRIPTOR* NotifyDescriptor,
   IN VOID* Ppi)
 {
     PEI_DEBUG ((PeiServices, EFI_D_INFO, "Martin S3 is called \n"));
     return EFI_SUCCESS;
 }

EFI_GUID gEfiPeiEndOfPeiPhasePpiGuid = EFI_PEI_END_OF_PEI_PHASE_PPI_GUID;

/*  EFI_PEI_NOTIFY_DESCRIPTOR: 
The data structure in a given PEIM that tells the PEI Foundation where to invoke the notification service.
*/
 EFI_PEI_NOTIFY_DESCRIPTOR mTest [ ] = {
    ( 
      EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK   |
      EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
    ), 
    &gEfiPeiEndOfPeiPhasePpiGuid,
    MartinFunc
 };

以下是我設定的Flag:
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST

Prototype

#define EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST 0x80000000

Description

This flag is set to 1 in the last structure entry in the list of PEI PPI descriptors. This flag is used by the PEI Foundation Services to know that there are no additional interfaces to install.

EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK

Prototype

#define EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK 0x00000020

Description

When set to 1, this flag designates that the service registered in the descriptor is to be invoked at callback. This means that if the PPI is installed for which the listener registers a notification, then the callback routine will be immediately invoked. The danger herein is that the callback will inherit whatever depth had been traversed up to and including this call.


沒有留言:

張貼留言