/** @file\r
\r
-Copyright (c) 2007, Intel Corporation\r
+ This file implement the command set of "USB Mass Storage Specification\r
+ for Bootability".\r
+\r
+Copyright (c) 2007 - 2008, Intel Corporation\r
All rights reserved. This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
\r
-Module Name:\r
+**/\r
\r
- UsbMassBoot.c\r
+#include "UsbMassImpl.h"\r
\r
-Abstract:\r
\r
- This file implement the command set of "USB Mass Storage Specification\r
- for Bootability".\r
-\r
-Revision History\r
+/**\r
+ Return the current TPL.\r
\r
+ @return Current TPL.\r
\r
**/\r
-\r
-#include "UsbMassImpl.h"\r
-\r
-\r
EFI_TPL\r
UsbGetCurrentTpl (\r
VOID\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- return the current TPL, copied from the EDKII glue lib.\r
-\r
-Arguments:\r
-\r
- VOID\r
-\r
-Returns:\r
-\r
- Current TPL\r
-\r
---*/\r
{\r
EFI_TPL Tpl;\r
\r
/**\r
Read an UINT32 from the buffer to avoid byte alignment problems, then\r
convert that to the little endia. The USB mass storage bootability spec\r
- use big endia\r
+ use big endia.\r
\r
@param Buf The buffer contains the first byte of the UINT32\r
in big endia.\r
@return The UINT32 value read from the buffer in little endia.\r
\r
**/\r
-STATIC\r
UINT32\r
UsbBootGetUint32 (\r
IN UINT8 *Buf\r
Put an UINT32 in little endia to the buffer. The data is converted to\r
big endia before writing.\r
\r
- @param Buf The buffer to write data to\r
+ @param Buf The buffer to write data to.\r
@param Data32 The data to write.\r
\r
- @return None\r
+ @return None.\r
\r
**/\r
-STATIC\r
VOID\r
UsbBootPutUint32 (\r
IN UINT8 *Buf,\r
CopyMem (Buf, &Data32, sizeof (UINT32));\r
}\r
\r
-\r
/**\r
Put an UINT16 in little endia to the buffer. The data is converted to\r
big endia before writing.\r
\r
- @param Buf The buffer to write data to\r
- @param Data16 The data to write\r
+ @param Buf The buffer to write data to.\r
+ @param Data16 The data to write.\r
\r
- @return None\r
+ @return None.\r
\r
**/\r
-STATIC\r
VOID\r
UsbBootPutUint16 (\r
IN UINT8 *Buf,\r
CopyMem (Buf, &Data16, sizeof (UINT16));\r
}\r
\r
-\r
/**\r
Request sense information via sending Request Sense\r
Packet Command.\r
\r
- @param UsbMass The device to be requested sense data\r
+ @param UsbMass The device to be requested sense data.\r
\r
- @retval EFI_DEVICE_ERROR Hardware error\r
- @retval EFI_SUCCESS Success\r
+ @retval EFI_SUCCESS The command is excuted OK.\r
+ @retval EFI_DEVICE_ERROR Failed to request sense.\r
+ @retval EFI_NO_RESPONSE The device media doesn't response this request.\r
+ @retval EFI_INVALID_PARAMETER The command has some invalid parameters.\r
+ @retval EFI_WRITE_PROTECTED The device is write protected.\r
+ @retval EFI_MEDIA_CHANGED The device media has been changed.\r
\r
**/\r
EFI_STATUS\r
EfiUsbDataIn,\r
&SenseData,\r
sizeof (USB_BOOT_REQUEST_SENSE_DATA),\r
+ UsbMass->Lun,\r
USB_BOOT_GENERAL_CMD_TIMEOUT,\r
&CmdResult\r
);\r
if (EFI_ERROR (Status) || CmdResult != USB_MASS_CMD_SUCCESS) {\r
- DEBUG ((mUsbMscError, "UsbBootRequestSense: (%r) CmdResult=0x%x\n", Status, CmdResult));\r
+ DEBUG ((EFI_D_ERROR, "UsbBootRequestSense: (%r) CmdResult=0x%x\n", Status, CmdResult));\r
return Status;\r
}\r
\r
break;\r
}\r
\r
- DEBUG ((mUsbMscInfo, "UsbBootRequestSense: (%r) with sense key %x/%x/%x\n",\r
+ DEBUG ((EFI_D_INFO, "UsbBootRequestSense: (%r) with sense key %x/%x/%x\n",\r
Status,\r
USB_BOOT_SENSE_KEY (SenseData.SenseKey),\r
SenseData.ASC,\r
@retval EFI_MEDIA_CHANGED The device media has been changed\r
\r
**/\r
-STATIC\r
EFI_STATUS\r
UsbBootExecCmd (\r
IN USB_MASS_DEVICE *UsbMass,\r
DataDir,\r
Data,\r
DataLen,\r
+ UsbMass->Lun,\r
Timeout,\r
&CmdResult\r
);\r
return EFI_SUCCESS;\r
}\r
\r
- DEBUG ((mUsbMscInfo, "UsbBootExecCmd: Fail to Exec 0x%x Cmd /w %r\n",\r
+ DEBUG ((EFI_D_INFO, "UsbBootExecCmd: Fail to Exec 0x%x Cmd /w %r\n",\r
*(UINT8 *)Cmd ,Status));\r
\r
return UsbBootRequestSense (UsbMass);\r
@param DataDir The direction of data transfer\r
@param Data The buffer to hold the data\r
@param DataLen The length of expected data\r
+ @param Timeout The timeout used to transfer\r
\r
@retval EFI_SUCCESS The command is excuted OK\r
@retval EFI_DEVICE_ERROR Failed to request sense\r
@retval EFI_MEDIA_CHANGED The device media has been changed\r
\r
**/\r
-STATIC\r
EFI_STATUS\r
UsbBootExecCmdWithRetry (\r
IN USB_MASS_DEVICE *UsbMass,\r
DataDir,\r
Data,\r
DataLen,\r
- Timeout * (Index + 1)\r
+ Timeout\r
);\r
if (Status == EFI_SUCCESS ||\r
Status == EFI_MEDIA_CHANGED) {\r
}\r
\r
\r
-\r
/**\r
Use the TEST UNIT READY command to check whether it is ready.\r
If it is ready, update the parameters.\r
\r
@retval EFI_SUCCESS The disk gemotric is successfully retrieved.\r
@retval EFI_DEVICE_ERROR Something is inconsistent with the disk gemotric.\r
-\r
+ @retval Other Read capacity request fails.\r
+ \r
**/\r
EFI_STATUS\r
UsbBootReadCapacity (\r
return EFI_NOT_READY;\r
}\r
\r
- DEBUG ((mUsbMscInfo, "UsbBootReadCapacity Success LBA=%ld BlockSize=%d\n",\r
+ DEBUG ((EFI_D_INFO, "UsbBootReadCapacity Success LBA=%ld BlockSize=%d\n",\r
Media->LastBlock, Media->BlockSize));\r
\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
Retrieves mode sense information via sending Mode Sense\r
Packet Command.\r
\r
@param UsbMass The USB_FLOPPY_DEV instance.\r
\r
- @retval EFI_DEVICE_ERROR Hardware error\r
@retval EFI_SUCCESS Success\r
+ @retval Other Execute Request command fails.\r
\r
**/\r
EFI_STATUS\r
IN USB_MASS_DEVICE *UsbMass\r
)\r
{\r
- EFI_STATUS Status;\r
+ EFI_STATUS Status;\r
USB_SCSI_MODE_SENSE6_CMD ModeSenseCmd;\r
USB_SCSI_MODE_SENSE6_PARA_HEADER ModeParaHeader;\r
EFI_BLOCK_IO_MEDIA *Media;\r
\r
- CopyMem (\r
- &Media,\r
- &(UsbMass->BlockIoMedia),\r
- sizeof (EFI_BLOCK_IO_MEDIA)\r
- );\r
+ Media = &UsbMass->BlockIoMedia;\r
\r
ZeroMem (&ModeSenseCmd, sizeof (USB_SCSI_MODE_SENSE6_CMD));\r
ZeroMem (&ModeParaHeader, sizeof (USB_SCSI_MODE_SENSE6_PARA_HEADER));\r
// devices support this command, so have a try here.\r
//\r
if (!EFI_ERROR (Status)) {\r
- Media->ReadOnly = (BOOLEAN) ((ModeParaHeader.DevicePara & 0x80) ? TRUE : FALSE);\r
+ Media->ReadOnly = (BOOLEAN) (((ModeParaHeader.DevicePara & 0x80) != 0) ? TRUE : FALSE);\r
}\r
\r
return Status;\r
@param UsbMass The device to retireve disk gemotric.\r
\r
@retval EFI_SUCCESS The disk gemotric is successfully retrieved.\r
- @retval EFI_DEVICE_ERROR Something is inconsistent with the disk gemotric.\r
+ @retval Other Get the parameters failed.\r
\r
**/\r
EFI_STATUS\r
EFI_STATUS Status;\r
UINT8 CmdSet;\r
\r
- CopyMem (\r
- &Media,\r
- &(UsbMass->BlockIoMedia),\r
- sizeof (EFI_BLOCK_IO_MEDIA)\r
- );\r
-\r
+ Media = &(UsbMass->BlockIoMedia);\r
CmdSet = ((EFI_USB_INTERFACE_DESCRIPTOR *) (UsbMass->Context))->InterfaceSubClass;\r
\r
Status = UsbBootInquiry (UsbMass);\r
if (EFI_ERROR (Status)) {\r
- DEBUG ((mUsbMscError, "UsbBootGetParams: UsbBootInquiry (%r)\n", Status));\r
+ DEBUG ((EFI_D_ERROR, "UsbBootGetParams: UsbBootInquiry (%r)\n", Status));\r
return Status;\r
}\r
\r
@param UsbMass The device to retireve disk gemotric.\r
\r
@retval EFI_SUCCESS The disk gemotric is successfully retrieved.\r
- @retval EFI_DEVICE_ERROR Something is inconsistent with the disk gemotric.\r
+ @retval Other Decect media fails.\r
\r
**/\r
EFI_STATUS\r
\r
Status = UsbBootIsUnitReady (UsbMass);\r
if (EFI_ERROR (Status)) {\r
- DEBUG ((mUsbMscError, "UsbBootDetectMedia: UsbBootIsUnitReady (%r)\n", Status));\r
+ DEBUG ((EFI_D_ERROR, "UsbBootDetectMedia: UsbBootIsUnitReady (%r)\n", Status));\r
goto ON_ERROR;\r
}\r
\r
\r
Status = UsbBootReadCapacity (UsbMass);\r
if (EFI_ERROR (Status)) {\r
- DEBUG ((mUsbMscError, "UsbBootDetectMedia: UsbBootReadCapacity (%r)\n", Status));\r
+ DEBUG ((EFI_D_ERROR, "UsbBootDetectMedia: UsbBootReadCapacity (%r)\n", Status));\r
goto ON_ERROR;\r
}\r
\r
(Media->LastBlock != OldMedia.LastBlock)) {\r
\r
OldTpl = UsbGetCurrentTpl ();\r
- DEBUG ((mUsbMscError, "UsbBootDetectMedia: TPL before reinstall BlockIoProtocol is %d\n", OldTpl));\r
+ DEBUG ((EFI_D_ERROR, "UsbBootDetectMedia: TPL before reinstall BlockIoProtocol is %d\n", (UINT32)OldTpl));\r
\r
gBS->RestoreTPL (TPL_CALLBACK);\r
\r
&UsbMass->BlockIo\r
);\r
\r
- DEBUG ((mUsbMscError, "UsbBootDetectMedia: TPL after reinstall is %d\n", UsbGetCurrentTpl()));\r
+ DEBUG ((EFI_D_ERROR, "UsbBootDetectMedia: TPL after reinstall is %d\n", (UINT32)UsbGetCurrentTpl()));\r
ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK);\r
\r
gBS->RaiseTPL (OldTpl);\r