I am a beginner at EDK2 tianocore.
I have EFI Shell and I want to open current USB with EFI Shell as physical disk to read and write blocks. In WinAPI I know CreateFile
function with argument like "\\.\D:", ReadFile
and WriteFile
.
What is the analogue for EDK2? Can you give example and some useful links?
UPD 30.06.2017.
I am trying to use EFI_USB_IO_PROTOCOL to get faster IO operations with USB-flash than EFI_BLOCK_IO_PROTOCOL.
I have such code:
EFI_STATUS
USBXYZDriverBindingSupported (
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH *RemainingDevicePath
)
{
UINT32 *OpenStatus= NULL;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_STATUS Status;
EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
CHAR16 *DevStr = NULL;
DevStr = DevicePathToStr(RemainingDevicePath);
//
// Check if USB_IO protocol is attached on the controller handle.
//
Status = BS->OpenProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
(VOID**)&UsbIo,
gImgHandle,
Controller,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Get the default interface descriptor
//
Status = UsbIo->UsbGetInterfaceDescriptor(
UsbIo,
&InterfaceDescriptor
);
Print(L"%a.%d %r %s\n", __FUNCTION__, __LINE__, Status, DevStr);
UINTN a = 512;
UINTN *byteSize = &a;
char *buf = AllocateZeroPool(512);
Status = UsbIo->UsbBulkTransfer(UsbIo, 0x82, buf, byteSize, 0, OpenStatus);
Print(L"%a.%d %r %d %d\n", __FUNCTION__, __LINE__, Status,OpenStatus, *byteSize);
BS->CloseProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
gImgHandle,
Controller
);
return Status;
}
And I have Success OpenProtocol output only with one device. Than I am trying to read first 512 bytes from USB.
But, function UsbBulkTransfer
fails.
Output:
USBXYZDriverBindingSupported.196 Success PciRoot(0)/Pci(0x14,0x0)/Usb(0x1,0x0) USBXYZDriverBindingSupported.203 Invalid Parametr 0 512
I read that EFI_INVALID_PARAMETER because of:
Data is NULL
- not my option. I am trying to read data.
DataLength is NULL.
- not my option. Length is 512.
If DeviceEndpoint is not valid.
- possible reason. How to know what DeviceEndpoint means? How to get it, compute, use it?
I also tried to OpenProtocol
with EFI_OPEN_PROTOCOL_GET_PROTOCOL
and EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
. Nothing changed.
How to read data with UsbBulkTransfer? What is my mistake?
Thank you.