Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Tian, Feng <feng.tian@intel.com>
Reviewed-by: Zeng, Star <star.zeng@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15447
6f19259b-4bc3-4df7-8a09-
765794883524
Implementation of the command set of USB Mass Storage Specification\r
for Bootability, Revision 1.0.\r
\r
Implementation of the command set of USB Mass Storage Specification\r
for Bootability, Revision 1.0.\r
\r
-Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
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
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
+ //\r
+ // According to USB Mass Storage Specification for Bootability, only following\r
+ // 4 Peripheral Device Types are in spec.\r
+ //\r
+ if ((UsbMass->Pdt != USB_PDT_DIRECT_ACCESS) &&\r
+ (UsbMass->Pdt != USB_PDT_CDROM) &&\r
+ (UsbMass->Pdt != USB_PDT_OPTICAL) &&\r
+ (UsbMass->Pdt != USB_PDT_SIMPLE_DIRECT)) {\r
+ DEBUG ((EFI_D_ERROR, "UsbBootGetParams: Found an unsupported peripheral type[%d]\n", UsbMass->Pdt));\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
//\r
// Don't use the Removable bit in inquiry data to test whether the media\r
// is removable because many flash disks wrongly set this bit.\r
//\r
// Don't use the Removable bit in inquiry data to test whether the media\r
// is removable because many flash disks wrongly set this bit.\r
/** @file\r
USB Mass Storage Driver that manages USB Mass Storage Device and produces Block I/O Protocol.\r
\r
/** @file\r
USB Mass Storage Driver that manages USB Mass Storage Device and produces Block I/O Protocol.\r
\r
-Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
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
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
@param MaxLun The max LUN number.\r
\r
@retval EFI_SUCCESS At least one LUN is initialized successfully.\r
@param MaxLun The max LUN number.\r
\r
@retval EFI_SUCCESS At least one LUN is initialized successfully.\r
- @retval EFI_OUT_OF_RESOURCES Out of resource while creating device path node.\r
- @retval Other Initialization fails.\r
+ @retval EFI_NOT_FOUND Fail to initialize any of multiple LUNs.\r
DEVICE_LOGICAL_UNIT_DEVICE_PATH LunNode;\r
UINT8 Index;\r
EFI_STATUS Status;\r
DEVICE_LOGICAL_UNIT_DEVICE_PATH LunNode;\r
UINT8 Index;\r
EFI_STATUS Status;\r
+ EFI_STATUS ReturnStatus;\r
\r
ASSERT (MaxLun > 0);\r
\r
ASSERT (MaxLun > 0);\r
+ ReturnStatus = EFI_NOT_FOUND;\r
\r
for (Index = 0; Index <= MaxLun; Index++) { \r
\r
\r
for (Index = 0; Index <= MaxLun; Index++) { \r
\r
// Initialize the media parameter data for EFI_BLOCK_IO_MEDIA of Block I/O Protocol.\r
//\r
Status = UsbMassInitMedia (UsbMass);\r
// Initialize the media parameter data for EFI_BLOCK_IO_MEDIA of Block I/O Protocol.\r
//\r
Status = UsbMassInitMedia (UsbMass);\r
- if (!EFI_ERROR (Status)) {\r
- //\r
- // According to USB Mass Storage Specification for Bootability, only following\r
- // 4 Peripheral Device Types are in spec.\r
- //\r
- if ((UsbMass->Pdt != USB_PDT_DIRECT_ACCESS) && \r
- (UsbMass->Pdt != USB_PDT_CDROM) &&\r
- (UsbMass->Pdt != USB_PDT_OPTICAL) && \r
- (UsbMass->Pdt != USB_PDT_SIMPLE_DIRECT)) {\r
- DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: Found an unsupported peripheral type[%d]\n", UsbMass->Pdt));\r
- goto ON_ERROR;\r
- }\r
- } else if (Status != EFI_NO_MEDIA){\r
+ if ((EFI_ERROR (Status)) && (Status != EFI_NO_MEDIA)) {\r
DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: UsbMassInitMedia (%r)\n", Status));\r
DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: UsbMassInitMedia (%r)\n", Status));\r
+ FreePool (UsbMass);\r
+ continue;\r
\r
if (UsbMass->DevicePath == NULL) {\r
DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: failed to create device logic unit device path\n"));\r
\r
if (UsbMass->DevicePath == NULL) {\r
DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: failed to create device logic unit device path\n"));\r
Status = EFI_OUT_OF_RESOURCES;\r
Status = EFI_OUT_OF_RESOURCES;\r
+ FreePool (UsbMass);\r
+ continue;\r
}\r
\r
InitializeDiskInfo (UsbMass);\r
}\r
\r
InitializeDiskInfo (UsbMass);\r
\r
if (EFI_ERROR (Status)) {\r
DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: InstallMultipleProtocolInterfaces (%r)\n", Status));\r
\r
if (EFI_ERROR (Status)) {\r
DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: InstallMultipleProtocolInterfaces (%r)\n", Status));\r
+ FreePool (UsbMass->DevicePath);\r
+ FreePool (UsbMass);\r
+ continue;\r
&UsbMass->DiskInfo,\r
NULL\r
);\r
&UsbMass->DiskInfo,\r
NULL\r
);\r
+ FreePool (UsbMass->DevicePath);\r
+ FreePool (UsbMass);\r
+ continue;\r
+ ReturnStatus = EFI_SUCCESS;\r
DEBUG ((EFI_D_INFO, "UsbMassInitMultiLun: Success to initialize No.%d logic unit\n", Index));\r
}\r
\r
DEBUG ((EFI_D_INFO, "UsbMassInitMultiLun: Success to initialize No.%d logic unit\n", Index));\r
}\r
\r
- return EFI_SUCCESS;\r
-\r
-ON_ERROR:\r
- if (UsbMass != NULL) {\r
- if (UsbMass->DevicePath != NULL) {\r
- FreePool (UsbMass->DevicePath);\r
- }\r
- FreePool (UsbMass);\r
- }\r
- if (UsbIo != NULL) {\r
- gBS->CloseProtocol (\r
- Controller,\r
- &gEfiUsbIoProtocolGuid,\r
- This->DriverBindingHandle,\r
- UsbMass->Controller\r
- );\r
- }\r
-\r
- //\r
- // Return EFI_SUCCESS if at least one LUN is initialized successfully.\r
- //\r
- if (Index > 0) {\r
- return EFI_SUCCESS; \r
- } else {\r
- return Status;\r
- } \r
// Initialize the media parameter data for EFI_BLOCK_IO_MEDIA of Block I/O Protocol.\r
//\r
Status = UsbMassInitMedia (UsbMass);\r
// Initialize the media parameter data for EFI_BLOCK_IO_MEDIA of Block I/O Protocol.\r
//\r
Status = UsbMassInitMedia (UsbMass);\r
- if (!EFI_ERROR (Status)) {\r
- //\r
- // According to USB Mass Storage Specification for Bootability, only following\r
- // 4 Peripheral Device Types are in spec.\r
- //\r
- if ((UsbMass->Pdt != USB_PDT_DIRECT_ACCESS) && \r
- (UsbMass->Pdt != USB_PDT_CDROM) &&\r
- (UsbMass->Pdt != USB_PDT_OPTICAL) && \r
- (UsbMass->Pdt != USB_PDT_SIMPLE_DIRECT)) {\r
- DEBUG ((EFI_D_ERROR, "UsbMassInitNonLun: Found an unsupported peripheral type[%d]\n", UsbMass->Pdt));\r
- goto ON_ERROR;\r
- }\r
- } else if (Status != EFI_NO_MEDIA){\r
+ if ((EFI_ERROR (Status)) && (Status != EFI_NO_MEDIA)) {\r
DEBUG ((EFI_D_ERROR, "UsbMassInitNonLun: UsbMassInitMedia (%r)\n", Status));\r
goto ON_ERROR;\r
}\r
DEBUG ((EFI_D_ERROR, "UsbMassInitNonLun: UsbMassInitMedia (%r)\n", Status));\r
goto ON_ERROR;\r
}\r
- // Initialize data for device that supports multiple LUNSs.\r
+ // Initialize data for device that supports multiple LUNs.\r
// EFI_SUCCESS is returned if at least 1 LUN is initialized successfully.\r
//\r
Status = UsbMassInitMultiLun (This, Controller, Transport, Context, DevicePath, MaxLun);\r
// EFI_SUCCESS is returned if at least 1 LUN is initialized successfully.\r
//\r
Status = UsbMassInitMultiLun (This, Controller, Transport, Context, DevicePath, MaxLun);\r