37 Transport = UsbMass->Transport;
45 SenseCmd.OpCode = USB_BOOT_REQUEST_SENSE_OPCODE;
46 SenseCmd.
Lun = (UINT8)(USB_BOOT_LUN (UsbMass->Lun));
57 USB_BOOT_GENERAL_CMD_TIMEOUT,
60 if (EFI_ERROR (Status) || (CmdResult != USB_MASS_CMD_SUCCESS)) {
61 DEBUG ((DEBUG_ERROR,
"UsbBootRequestSense: (%r) CmdResult=0x%x\n", Status, CmdResult));
62 if (!EFI_ERROR (Status)) {
63 Status = EFI_DEVICE_ERROR;
73 Media = &UsbMass->BlockIoMedia;
75 switch (USB_BOOT_SENSE_KEY (SenseData.
SenseKey)) {
77 if (SenseData.
Asc == USB_BOOT_ASC_NO_ADDITIONAL_SENSE_INFORMATION) {
83 Status = EFI_NO_RESPONSE;
92 Status = EFI_NOT_READY;
96 Status = EFI_DEVICE_ERROR;
97 if (SenseData.
Asc == USB_BOOT_ASC_NO_MEDIA) {
99 Status = EFI_NO_MEDIA;
100 }
else if (SenseData.
Asc == USB_BOOT_ASC_NOT_READY) {
101 Status = EFI_NOT_READY;
107 Status = EFI_INVALID_PARAMETER;
111 Status = EFI_DEVICE_ERROR;
112 if (SenseData.
Asc == USB_BOOT_ASC_MEDIA_CHANGE) {
116 Status = EFI_MEDIA_CHANGED;
119 }
else if (SenseData.
Asc == USB_BOOT_ASC_NOT_READY) {
120 Status = EFI_NOT_READY;
121 }
else if (SenseData.
Asc == USB_BOOT_ASC_NO_MEDIA) {
122 Status = EFI_NOT_READY;
128 Status = EFI_WRITE_PROTECTED;
133 Status = EFI_DEVICE_ERROR;
139 "UsbBootRequestSense: (%r) with error code (%x) sense key %x/%x/%x\n",
142 USB_BOOT_SENSE_KEY (SenseData.
SenseKey),
184 Transport = UsbMass->Transport;
197 if (Status == EFI_TIMEOUT) {
198 DEBUG ((DEBUG_ERROR,
"UsbBootExecCmd: %r to Exec 0x%x Cmd\n", Status, *(UINT8 *)Cmd));
206 if ((CmdResult == USB_MASS_CMD_SUCCESS) && !EFI_ERROR (Status)) {
213 DEBUG ((DEBUG_ERROR,
"UsbBootExecCmd: %r to Exec 0x%x Cmd (Result = %x)\n", Status, *(UINT8 *)Cmd, CmdResult));
255 Status =
gBS->CreateEvent (
262 if (EFI_ERROR (Status)) {
267 if (EFI_ERROR (Status)) {
274 while (EFI_ERROR (
gBS->CheckEvent (TimeoutEvt))) {
284 if ((Status ==
EFI_SUCCESS) || (Status == EFI_NO_MEDIA)) {
292 if (Status == EFI_NOT_READY) {
299 if (Retry++ >= USB_BOOT_COMMAND_RETRY) {
305 if (TimeoutEvt !=
NULL) {
306 gBS->CloseEvent (TimeoutEvt);
330 TestCmd.OpCode = USB_BOOT_TEST_UNIT_READY_OPCODE;
331 TestCmd.Lun = (UINT8)(USB_BOOT_LUN (UsbMass->Lun));
340 USB_BOOT_GENERAL_CMD_TIMEOUT
363 Media = &(UsbMass->BlockIoMedia);
368 InquiryCmd.OpCode = USB_BOOT_INQUIRY_OPCODE;
369 InquiryCmd.
Lun = (UINT8)(USB_BOOT_LUN (UsbMass->Lun));
377 &UsbMass->InquiryData,
379 USB_BOOT_GENERAL_CMD_TIMEOUT
381 if (EFI_ERROR (Status)) {
389 UsbMass->Pdt = (UINT8)(USB_BOOT_PDT (UsbMass->InquiryData.Pdt));
390 Media->
RemovableMedia = (BOOLEAN)(USB_BOOT_REMOVABLE (UsbMass->InquiryData.Removable));
419 UINT8 CapacityCmd[16];
425 Media = &UsbMass->BlockIoMedia;
431 ZeroMem (CapacityCmd,
sizeof (CapacityCmd));
432 ZeroMem (&CapacityData,
sizeof (CapacityData));
434 CapacityCmd[0] = EFI_SCSI_OP_READ_CAPACITY16;
435 CapacityCmd[1] = 0x10;
439 ZeroMem ((CapacityCmd + 2), 8);
441 CapacityCmd[13] =
sizeof (CapacityData);
446 (UINT8)
sizeof (CapacityCmd),
449 sizeof (CapacityData),
450 USB_BOOT_GENERAL_CMD_TIMEOUT
452 if (EFI_ERROR (Status)) {
466 CapacityData.LowestAlignLogic1;
468 if (BlockSize == 0) {
506 Media = &UsbMass->BlockIoMedia;
511 CapacityCmd.OpCode = USB_BOOT_READ_CAPACITY_OPCODE;
512 CapacityCmd.Lun = (UINT8)(USB_BOOT_LUN (UsbMass->Lun));
521 USB_BOOT_GENERAL_CMD_TIMEOUT
523 if (EFI_ERROR (Status)) {
535 if (BlockSize == 0) {
546 if (!EFI_ERROR (Status)) {
547 UsbMass->Cdb16Byte =
TRUE;
573 Media = &UsbMass->BlockIoMedia;
581 ModeSenseCmd.OpCode = USB_SCSI_MODE_SENSE6_OPCODE;
582 ModeSenseCmd.Lun = (UINT8)USB_BOOT_LUN (UsbMass->Lun);
583 ModeSenseCmd.PageCode = 0x3F;
593 USB_BOOT_GENERAL_CMD_TIMEOUT
601 if (!EFI_ERROR (Status)) {
602 Media->
ReadOnly = (BOOLEAN)((ModeParaHeader.DevicePara & BIT7) != 0);
631 Media = &(UsbMass->BlockIoMedia);
634 if (EFI_ERROR (Status)) {
635 DEBUG ((DEBUG_ERROR,
"UsbBootGetParams: UsbBootInquiry (%r)\n", Status));
648 DEBUG ((DEBUG_ERROR,
"UsbBootGetParams: Found an unsupported peripheral type[%d]\n", UsbMass->Pdt));
649 return EFI_UNSUPPORTED;
660 UsbMass->OpticalStorage =
TRUE;
691 Media = &UsbMass->BlockIoMedia;
698 if (EFI_ERROR (Status)) {
699 DEBUG ((DEBUG_ERROR,
"UsbBootDetectMedia: UsbBootIsUnitReady (%r)\n", Status));
709 if (!EFI_ERROR (Status)) {
722 if (EFI_ERROR (Status)) {
723 DEBUG ((DEBUG_ERROR,
"UsbBootDetectMedia: UsbBootReadCapacity (%r)\n", Status));
727 if (EFI_ERROR (Status) && (Status != EFI_NO_MEDIA)) {
738 return EFI_DEVICE_ERROR;
765 gBS->ReinstallProtocolInterface (
767 &gEfiBlockIoProtocolGuid,
790 Status = Media->
MediaPresent ? EFI_MEDIA_CHANGED : EFI_NO_MEDIA;
826 BlockSize = UsbMass->BlockIoMedia.BlockSize;
827 CountMax = USB_BOOT_MAX_CARRY_SIZE / BlockSize;
830 while (TotalBlock > 0) {
836 Count = (UINT32)
MIN (TotalBlock, CountMax);
837 Count =
MIN (MAX_UINT16, Count);
838 ByteSize = Count * BlockSize;
843 Timeout = (UINT32)USB_BOOT_GENERAL_CMD_TIMEOUT;
850 Cmd.OpCode = Write ? USB_BOOT_WRITE10_OPCODE : USB_BOOT_READ10_OPCODE;
851 Cmd.
Lun = (UINT8)(USB_BOOT_LUN (UsbMass->Lun));
859 Write ? EfiUsbDataOut : EfiUsbDataIn,
864 if (EFI_ERROR (Status)) {
870 "UsbBoot%sBlocks: LBA (0x%lx), Blk (0x%x)\n",
871 Write ? L
"Write" : L
"Read",
912 BlockSize = UsbMass->BlockIoMedia.BlockSize;
913 CountMax = USB_BOOT_MAX_CARRY_SIZE / BlockSize;
916 while (TotalBlock > 0) {
920 Count = (UINT32)
MIN (TotalBlock, CountMax);
921 ByteSize = Count * BlockSize;
926 Timeout = (UINT32)USB_BOOT_GENERAL_CMD_TIMEOUT;
933 Cmd[0] = Write ? EFI_SCSI_OP_WRITE16 : EFI_SCSI_OP_READ16;
934 Cmd[1] = (UINT8)((USB_BOOT_LUN (UsbMass->Lun) & 0xE0));
942 Write ? EfiUsbDataOut : EfiUsbDataIn,
947 if (EFI_ERROR (Status)) {
953 "UsbBoot%sBlocks16: LBA (0x%lx), Blk (0x%x)\n",
954 Write ? L
"Write" : L
"Read",
979 IN UINT8 EndpointAddr
987 Request.RequestType = 0x02;
988 Request.Request = USB_REQ_CLEAR_FEATURE;
989 Request.Value = USB_FEATURE_ENDPOINT_HALT;
990 Request.Index = EndpointAddr;
992 Timeout = USB_BOOT_GENERAL_CMD_TIMEOUT / USB_MASS_1_MILLISECOND;
994 Status = UsbIo->UsbControlTransfer (
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
UINT64 EFIAPI ReadUnaligned64(IN CONST UINT64 *Buffer)
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
UINT32 EFIAPI WriteUnaligned32(OUT UINT32 *Buffer, IN UINT32 Value)
UINT16 EFIAPI WriteUnaligned16(OUT UINT16 *Buffer, IN UINT16 Value)
UINT64 EFIAPI SwapBytes64(IN UINT64 Value)
UINT64 EFIAPI WriteUnaligned64(OUT UINT64 *Buffer, IN UINT64 Value)
UINT32 EFIAPI ReadUnaligned32(IN CONST UINT32 *Buffer)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define DEBUG(Expression)
EFI_TPL EFIAPI EfiGetCurrentTpl(VOID)
#define EFI_TIMER_PERIOD_SECONDS(Seconds)
#define USB_MASS_STORE_SCSI
SCSI transparent command set.
EFI_STATUS UsbBootGetParams(IN USB_MASS_DEVICE *UsbMass)
EFI_STATUS UsbBootInquiry(IN USB_MASS_DEVICE *UsbMass)
EFI_STATUS UsbBootExecCmd(IN USB_MASS_DEVICE *UsbMass, IN VOID *Cmd, IN UINT8 CmdLen, IN EFI_USB_DATA_DIRECTION DataDir, IN VOID *Data, IN UINT32 DataLen, IN UINT32 Timeout)
EFI_STATUS UsbBootIsUnitReady(IN USB_MASS_DEVICE *UsbMass)
EFI_STATUS UsbBootReadCapacity16(IN USB_MASS_DEVICE *UsbMass)
EFI_STATUS UsbBootReadWriteBlocks(IN USB_MASS_DEVICE *UsbMass, IN BOOLEAN Write, IN UINT32 Lba, IN UINTN TotalBlock, IN OUT UINT8 *Buffer)
EFI_STATUS UsbBootReadWriteBlocks16(IN USB_MASS_DEVICE *UsbMass, IN BOOLEAN Write, IN UINT64 Lba, IN UINTN TotalBlock, IN OUT UINT8 *Buffer)
EFI_STATUS UsbBootDetectMedia(IN USB_MASS_DEVICE *UsbMass)
EFI_STATUS UsbBootReadCapacity(IN USB_MASS_DEVICE *UsbMass)
EFI_STATUS UsbClearEndpointStall(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT8 EndpointAddr)
EFI_STATUS UsbScsiModeSense(IN USB_MASS_DEVICE *UsbMass)
EFI_STATUS UsbBootExecCmdWithRetry(IN USB_MASS_DEVICE *UsbMass, IN VOID *Cmd, IN UINT8 CmdLen, IN EFI_USB_DATA_DIRECTION DataDir, IN VOID *Data, IN UINT32 DataLen, IN UINT32 Timeout)
EFI_STATUS UsbBootRequestSense(IN USB_MASS_DEVICE *UsbMass)
#define USB_PDT_DIRECT_ACCESS
Direct access device.
#define USB_BOOT_SENSE_UNIT_ATTENTION
Removable medium may have been changed.
#define USB_BOOT_SENSE_NO_SENSE
No sense key.
#define USB_BOOT_SENSE_NOT_READY
Device not ready.
#define USB_PDT_OPTICAL
Non-CD optical disks.
#define USB_PDT_CDROM
CDROM.
#define USB_BOOT_SENSE_DATA_PROTECT
Write protected.
#define USB_BOOT_SENSE_ILLEGAL_REQUEST
Illegal parameters in the request.
#define USB_BOOT_SENSE_RECOVERED
Last command succeed with recovery actions.
#define USB_PDT_SIMPLE_DIRECT
Simplified direct access device.
USB_MASS_EXEC_COMMAND ExecCommand
Transport command to the device then get result.
UINT32 LogicalBlocksPerPhysicalBlock
UINT8 Lun
Lun (high 3 bits)
UINT8 Lba[4]
Logical block address.
UINT8 Lun
Lun (High 3 bits)
UINT8 TransferLen[2]
Transfer length.
UINT8 AllocLen
Allocation length.
UINT8 Lun
Lun (High 3 bits)
UINT8 Ascq
Additional Sense Code Qualifier.
UINT8 Asc
Additional Sense Code.
UINT8 SenseKey
Sense key (low 4 bits)