OpenProtocol返回2当我使用OpenProtocol打开LocateHandleBuffer返回的句柄时。
主要代码如下所示:
//Entry Point for this application
EFI_STATUS UefiMain (IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE *SystemTable)//ImageHandle and system table
{
//Define and initialize all the variables.
EFI_STATUS Status=EFI_SUCCESS;//zero
UINTN HandleIndex=0,HandleCount=0;//the index for handle buffer and the num of handle elem
EFI_HANDLE* DiskControllerHandles=NULL;//NULL
EFI_DISK_IO_PROTOCOL* DiskIOProtocol=NULL;//NULL
EFI_DEVICE_PATH_PROTOCOL* DiskDevicePathProtocol=NULL;//NULL
//the return result
Status=gBS->LocateHandleBuffer(ByProtocol,&gEfiDiskIoProtocolGuid,NULL,&HandleCount,&DiskControllerHandles);//Get all handles which support EFI_DISK_IO_PROTOCOL into the buffer.
if(EFI_ERROR(Status))//LocateHandleBuffer failed.
{
Print(L"UefiMain:gBS->LocateHandleBuffer failed,error=%d.\r\n",Status);
return EFI_SUCCESS;//failed
}
//Open the handle which supports EFI_DEVICE_PATH_TO_TEXT_PROTOCOL and was returned by LocateHandleBuffer previously.
//Loop
for(HandleIndex=0;HandleIndex<HandleCount;HandleIndex++)
{
DiskIOProtocol=NULL;
DiskDevicePathProtocol=NULL;
//Open each handle which supports EFI_DEVICE_PATH_PROTOCOL.
Status=gBS->OpenProtocol(DiskControllerHandles[HandleIndex],&gEfiDevicePathProtocolGuid,(VOID**)DiskDevicePathProtocol,
ImageHandle,NULL,EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);//EFI_OPEN_PROTOCOL_GET_PROTOCOL);//Here 2 was returned. I haven't known why 2 was returned here after looking up Unified Extensible Firmware Interface 2.6
}
return EFI_SUCCESS;//return
}
答案 0 :(得分:0)
第三个参数不正确,所以正确的代码如下:
Status=gBS->OpenProtocol(DiskControllerHandles[HandleIndex],&gEfiDevicePathProtocolGuid,(VOID**)&DiskDevicePathProtocol,
ImageHandle,NULL,EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);