标准应用程序工程模块
该模块是其他应用程序工程模块的基础,也是UEFI中常见的一种应用程序工程模块,标准应用程序工程模块,UefiMain就是这个模块的入口函数
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
UINT32 Index;
Index = 0;
//
// Three PCD type (FeatureFlag, UINT32 and String) are used as the sample.
//
if (FeaturePcdGet (PcdHelloWorldPrintEnable)) {
for (Index = 0; Index < PcdGet32 (PcdHelloWorldPrintTimes); Index ++) {
//
// Use UefiLib Print API to print string to UEFI console
//
Print ((CHAR16*)PcdGetPtr (PcdHelloWorldPrintString));
}
}
return EFI_SUCCESS;
}
再来看一下.inf工程文件
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = HelloWorld
MODULE_UNI_FILE = HelloWorld.uni
FILE_GUID = 6987936E-ED34-44db-AE97-1FA5E4ED2116
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = UefiMain
ShellAppMain应用程序工程模块
这种应用程序能在shell中执行命令时输入指定参数,Argc是命令行参数个数,包括应用名字本身,第二个参数Argv是命令参数行列表,也就是说是第几个参数,先看一下主函数:
EFI_STATUS
EFIAPI
ShellAppMain (
IN UINTN Argc,
IN CHAR16 **Argv
)
{
EFI_STATUS Status = EFI_SUCCESS ;
UINTN qUsbProvFileSize;
// UINT8 Embedded_Checksum=0;
UINTN FileSize;//CalSize;
// UINT32 FileCheckum=0xFF;
BYTE i;
CHAR16 *gFileName=0;
int FW_H,FW_L;
int bram_base;
//int err=0;
int FW_v[9];
if(Argc<2) {
clrscr();
vShowUsage();
return EFI_SUCCESS;
}
if(Argc>1) {
clrscr();
//gotoxy(1,10);
for(i=1;i<Argc;i++)
{
if((Argv[i][0]=='/') && (Argv[i][1]=='V')){
FW_flag=1;
if(Argv[i][2]=='B') BRAM_flag=1;
else if(Argv[i][2]=='C') Compal_flag=1;
if(Argv[i][3]=='F')
{
FileVer_flag=1;
gFileName = Argv[i+1];
BIN_Ver_offset=Argv[i+2];
}else{
if((i+1)<Argc) FW_CP=Argv[i+1];
}
break;
}else if((Argv[i][0]!='/')&&(Argv[i-1][1]!='O')&&(Argv[i-1][1]!='R')&&(Argv[i-1][1]!='V')){
hasFile =1; ......
上面的代码为EC更新工具中的一部分,看一下.inf工程文件:
INF_VERSION = 0x00010005
BASE_NAME = GwiEcFlash
FILE_GUID = 05ECD32B-E737-47ee-A504-334A79064997
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = EntryPoint
为啥是EntryPoint呢,因为ShellAppMain函数是再EntryPoint函数中运行的
EFI_STATUS
EFIAPI
EntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_SHELL_PARAMETERS_PROTOCOL *EfiShellParametersProtocol;
EFI_SHELL_INTERFACE *EfiShellInterface;
CHAR16 *Argv[] = {L"GwiEcFlash.efi",
L"ec.bin"};
EFI_STATUS Status;
EfiShellParametersProtocol = NULL;
EfiShellInterface = NULL;
Status = SystemTable->BootServices->OpenProtocol(ImageHandle,
&gEfiShellParametersProtocolGuid,
(VOID **)&EfiShellParametersProtocol,
ImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (!EFI_ERROR(Status)) {
//
// use shell 2.0 interface
//
Status = ShellAppMain (
EfiShellParametersProtocol->Argc,
EfiShellParametersProtocol->Argv
);
} else {
//
// try to get shell 1.0 interface instead.
//
Status = SystemTable->BootServices->OpenProtocol(ImageHandle,
&gEfiShellInterfaceGuid,
(VOID **)&EfiShellInterface,
ImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (!EFI_ERROR(Status)) {
//
// use shell 1.0 interface
//
Status = ShellAppMain (
EfiShellInterface->Argc,
EfiShellInterface->Argv
);
} else {
// Update BIOS with fixed file name
Status = ShellAppMain (2, Argv);
}
}
main应用程序工程模块
这个应用程序工程模块和shellappmain应用程序工程模块类似,不过不包含UefiShellCEntryLib.c
int
EFIAPI
main (
IN int argc,
IN char **argv
)
{
UINTN qUsbProvFileSize;
FILE *fi;
BYTE i;
int FW_H,FW_L;
int bram_base;
......
[Defines]
INF_VERSION = 0x00010006
BASE_NAME = GwiEcFlash
FILE_GUID = 05ECD32B-E737-47ee-A504-334A79064997
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = ShellCEntryLib
符合UEFI驱动模型的驱动
所有符合UEFI驱动模型的驱动,都要遵循EFI_DRIVER_BINDING_PROTOCOL,比如一些GOP的driver
EFI_DRIVER_BINDING_PROTOCOL gSmi768DriverBinding = {
Smi768ControllerDriverSupported,
Smi768ControllerDriverStart,
Smi768ControllerDriverStop,
0x10,
NULL,
NULL
};
DXE驱动模块
DXE环境下运行的驱动,此类驱动不遵循UEFI驱动模型