OpenProtocol 返回 2 当我使用 OpenProtocol 打开句柄时
OpenProtocol returned 2 When I used OpenProtocol to open a handle
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
}
第三个参数不正确,正确的代码应该是这样:
Status=gBS->OpenProtocol(DiskControllerHandles[HandleIndex],&gEfiDevicePathProtocolGuid,(VOID**)&DiskDevicePathProtocol,
ImageHandle,NULL,EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
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
}
第三个参数不正确,正确的代码应该是这样:
Status=gBS->OpenProtocol(DiskControllerHandles[HandleIndex],&gEfiDevicePathProtocolGuid,(VOID**)&DiskDevicePathProtocol,
ImageHandle,NULL,EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);