主要分为两部分,一部分install ppi,一部分locate ppi。 需要用到前面写的Lib
Install
c文件
PATH:
edk2/EmulatorPkg/TestByMy/PeiTest/MyFirstPeiLib/MyFirstPeiLib.c
代码部分:
/*++ @file
Copyright (c) 2019
a peim
**/
#include <Uefi/UefiBaseType.h>
#include <Pi/PiPeiCis.h>
#include <Ppi/MyFirstPeiLib.h>
#include <Library/PeimEntryPoint.h>
#include <Library/DebugLib.h>
#include <Library/BaseLib.h>
#include <Library/PeiServicesLib.h>
extern EFI_GUID gMyFirstPpiGuid;
EFI_STATUS
EFIAPI
NotifiMyDriverCallBack (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
IN VOID *Ppi
)
{
UINTN Temp;
for(Temp = 0; Temp <= 5; Temp++) {
DEBUG ((DEBUG_INFO, "\n"));
}
DEBUG ((DEBUG_INFO, "Ppi Peim A is install!..\n"));
return EFI_SUCCESS;
}
EFI_MYPPI_STR InstallMy = {
PrintHelloMesg
};
EFI_PEI_NOTIFY_DESCRIPTOR PpiMySetNotif = {
(EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gMyFirstPpiGuid,
&NotifiMyDriverCallBack
};
EFI_PEI_PPI_DESCRIPTOR PpiMySet = {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gMyFirstPpiGuid,
&InstallMy
};
/**
Arguments:
FfsHeader - General purpose data available to every PEIM
PeiServices - General purpose services available to every PEIM.
Returns:
None
**/
EFI_STATUS
EFIAPI
MyPpiPeimAEntry(
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
EFI_STATUS Status;
UINTN Temp;
for(Temp = 0; Temp <= 5; Temp++) {
DEBUG ((DEBUG_INFO, "\n"));
}
DEBUG ((DEBUG_INFO, "MyPpiPeimA is Start..\n"));
Status = PeiServicesNotifyPpi (&PpiMySetNotif);
ASSERT_EFI_ERROR (Status);
Status = PeiServicesInstallPpi (&PpiMySet);
ASSERT_EFI_ERROR (Status);
DEBUG ((DEBUG_INFO, "MyPpiPeimA is End..\n"));
return Status;
}
inf文件
PATH:
edk2/EmulatorPkg/TestByMy/PeiTest/MyPpiPeimA/MyPpiPeimA.inf
代码部分:
## @file
# a driver write by used in pei
#
# This module for
# Copyright (c) 2019 - 2020, All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
#
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MyPpiPeimA
FILE_GUID = 2D6F6BC2-9681-8E11-8579-B57DCD006011
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
ENTRY_POINT = MyPpiPeimAEntry
[Sources]
MyPpiPeimA.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
PeimEntryPoint
DebugLib
BaseLib
MyFirstPeiLib
PeiServicesLib
[Ppis]
gMyFirstPpiGuid
[Depex]
TRUE
dec文件
对绑定GUID进行全局声明:
[Ppis]
gMyFirstPpiGuid = { 0xE113F897, 0x75CF, 0xF630, { 0x81, 0x7F, 0xC8, 0x5A, 0x79, 0xE8, 0xAE, 0x66 } }
dsc文件
把对应工程文件加入编译:
##
# PEI Phase modules
##
EmulatorPkg/TestByMy/PeiTest/MyPpiPeimA/MyPpiPeimA.inf
##
# DXE Phase modules
##
fdf文件
将编译生成工程文件对应的二进制加入到fd中运行:
#
# PEI Phase modules
#
INF EmulatorPkg/TestByMy/PeiTest/MyPpiPeimA/MyPpiPeimA.inf
#
# DXE Phase modules
#
Locate
c文件
PATH:
edk2/EmulatorPkg/TestByMy/PeiTest/MyPpiPeimB/MyPpiPeimB.c
代码:
/*++ @file
Copyright (c) 2019
a peim
**/
#include <Uefi/UefiBaseType.h>
#include <Pi/PiPeiCis.h>
#include <Ppi/MyFirstPeiLib.h>
#include <Library/PeimEntryPoint.h>
#include <Library/DebugLib.h>
#include <Library/BaseLib.h>
#include <Library/PeiServicesLib.h>
extern EFI_GUID gMyFirstPpiGuid;
/**
Arguments:
FfsHeader - General purpose data available to every PEIM
PeiServices - General purpose services available to every PEIM.
Returns:
None
**/
EFI_STATUS
EFIAPI
MyPpiPeimBEntry(
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
EFI_STATUS Status;
UINTN Temp;
EFI_MYPPI_STR *LocatePpiMy;
for(Temp = 0; Temp <= 5; Temp++) {
DEBUG ((DEBUG_INFO, "\n"));
}
DEBUG ((DEBUG_INFO, "MyPpiPeimB is Start..\n"));
Status = PeiServicesLocatePpi (
&gMyFirstPpiGuid,
0,
NULL,
(VOID **)&LocatePpiMy
);
ASSERT_EFI_ERROR (Status);
LocatePpiMy->PrintMesg(L"My Locate PPI to printf Hello World in MyPpiPeimB ...\n");
DEBUG ((DEBUG_INFO, "MyPpiPeimB is End..\n"));
return Status;
}
inf文件
PATH:
edk2/EmulatorPkg/TestByMy/PeiTest/MyPpiPeimB/MyPpiPeimB.inf
代码:
## @file
# a driver write by used in pei
#
# This module for
# Copyright (c) 2019 - 2020, All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
#
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MyPpiPeimB
FILE_GUID = 2D6F6232-9622-8E11-8579-B57DCD006011
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
ENTRY_POINT = MyPpiPeimBEntry
[Sources]
MyPpiPeimB.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
PeimEntryPoint
DebugLib
BaseLib
MyFirstPeiLib
PeiServicesLib
[Ppis]
gMyFirstPpiGuid
[Depex]
gMyFirstPpiGuid
dsc
把对应工程文件加入编译:
##
# PEI Phase modules
##
EmulatorPkg/TestByMy/PeiTest/MyPpiPeimA/MyPpiPeimA.inf
EmulatorPkg/TestByMy/PeiTest/MyPpiPeimB/MyPpiPeimB.inf
##
# DXE Phase modules
##
fdf文件
将编译生成工程文件对应的二进制加入到fd中运行:
#
# PEI Phase modules
#
INF EmulatorPkg/TestByMy/PeiTest/MyPpiPeimB/MyPpiPeimB.inf
INF EmulatorPkg/TestByMy/PeiTest/MyPpiPeimA/MyPpiPeimA.inf
#
# DXE Phase modules
#
在fdf中把peiA放在B后面,但是运行的时候还是A在前面运行,应为在B的inf文件中加了
[Depex]
gMyFirstPpiGuid