ShellPkg: Add extended USB decoding for consistent device names

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: jaben carsey <jaben.carsey@intel.com>
Reviewed-by: Joe Peterson <joe.peterson@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hp.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16423 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jaben carsey 2014-11-24 14:58:33 +00:00 committed by jcarsey
parent 431dac9441
commit 0db3fade2c
3 changed files with 92 additions and 36 deletions

View File

@ -15,6 +15,7 @@
#include <Library/DevicePathLib.h> #include <Library/DevicePathLib.h>
#include <Library/SortLib.h> #include <Library/SortLib.h>
#include <Library/UefiLib.h> #include <Library/UefiLib.h>
#include <Protocol/UsbIo.h>
typedef enum { typedef enum {
MTDTypeUnknown, MTDTypeUnknown,
@ -41,10 +42,12 @@ typedef struct {
CHAR16 *Name; CHAR16 *Name;
} MTD_NAME; } MTD_NAME;
typedef VOID (EFIAPI *SerialDecodeFucntion) (EFI_DEVICE_PATH_PROTOCOL *DevPath, DEVICE_CONSIST_MAPPING_INFO *MapInfo,EFI_DEVICE_PATH_PROTOCOL *);
typedef struct { typedef struct {
UINT8 Type; UINT8 Type;
UINT8 SubType; UINT8 SubType;
VOID (EFIAPI *SerialFun) (EFI_DEVICE_PATH_PROTOCOL *DevPath, DEVICE_CONSIST_MAPPING_INFO *MapInfo); SerialDecodeFucntion SerialFun;
INTN (EFIAPI *CompareFun) (EFI_DEVICE_PATH_PROTOCOL *DevPath, EFI_DEVICE_PATH_PROTOCOL *DevPath2); INTN (EFIAPI *CompareFun) (EFI_DEVICE_PATH_PROTOCOL *DevPath, EFI_DEVICE_PATH_PROTOCOL *DevPath2);
} DEV_PATH_CONSIST_MAPPING_TABLE; } DEV_PATH_CONSIST_MAPPING_TABLE;
@ -428,7 +431,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialHardDrive ( DevPathSerialHardDrive (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
HARDDRIVE_DEVICE_PATH *Hd; HARDDRIVE_DEVICE_PATH *Hd;
@ -454,7 +458,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialAtapi ( DevPathSerialAtapi (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
ATAPI_DEVICE_PATH *Atapi; ATAPI_DEVICE_PATH *Atapi;
@ -476,7 +481,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialCdRom ( DevPathSerialCdRom (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
CDROM_DEVICE_PATH *Cd; CDROM_DEVICE_PATH *Cd;
@ -499,7 +505,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialFibre ( DevPathSerialFibre (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
FIBRECHANNEL_DEVICE_PATH *Fibre; FIBRECHANNEL_DEVICE_PATH *Fibre;
@ -522,7 +529,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialUart ( DevPathSerialUart (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
UART_DEVICE_PATH *Uart; UART_DEVICE_PATH *Uart;
@ -547,10 +555,16 @@ VOID
EFIAPI EFIAPI
DevPathSerialUsb ( DevPathSerialUsb (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
USB_DEVICE_PATH *Usb; USB_DEVICE_PATH *Usb;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_HANDLE TempHandle;
EFI_STATUS Status;
USB_INTERFACE_DESCRIPTOR InterfaceDesc;
ASSERT(DevicePathNode != NULL); ASSERT(DevicePathNode != NULL);
ASSERT(MappingItem != NULL); ASSERT(MappingItem != NULL);
@ -558,6 +572,35 @@ DevPathSerialUsb (
Usb = (USB_DEVICE_PATH *) DevicePathNode; Usb = (USB_DEVICE_PATH *) DevicePathNode;
AppendCSDNum (MappingItem, Usb->ParentPortNumber); AppendCSDNum (MappingItem, Usb->ParentPortNumber);
AppendCSDNum (MappingItem, Usb->InterfaceNumber); AppendCSDNum (MappingItem, Usb->InterfaceNumber);
if (PcdGetBool(PcdUsbExtendedDecode)) {
Status = gBS->LocateDevicePath( &gEfiUsbIoProtocolGuid, &DevicePath, &TempHandle );
UsbIo = NULL;
if (!EFI_ERROR(Status)) {
Status = gBS->OpenProtocol(TempHandle, &gEfiUsbIoProtocolGuid, (VOID**)&UsbIo, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
}
if (!EFI_ERROR(Status)) {
ASSERT(UsbIo != NULL);
Status = UsbIo->UsbGetInterfaceDescriptor(UsbIo, &InterfaceDesc);
if (!EFI_ERROR(Status)) {
if (InterfaceDesc.InterfaceClass == USB_MASS_STORE_CLASS && MappingItem->Mtd == MTDTypeUnknown) {
switch (InterfaceDesc.InterfaceSubClass){
case USB_MASS_STORE_SCSI:
MappingItem->Mtd = MTDTypeHardDisk;
break;
case USB_MASS_STORE_8070I:
case USB_MASS_STORE_UFI:
MappingItem->Mtd = MTDTypeFloppy;
break;
case USB_MASS_STORE_8020I:
MappingItem->Mtd = MTDTypeCDRom;
break;
}
}
}
}
}
} }
/** /**
@ -571,7 +614,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialVendor ( DevPathSerialVendor (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
VENDOR_DEVICE_PATH *Vendor; VENDOR_DEVICE_PATH *Vendor;
@ -603,14 +647,14 @@ DevPathSerialVendor (
ASSERT(Buffer != NULL); ASSERT(Buffer != NULL);
if (Buffer == NULL) { if (Buffer == NULL) {
return; return;
} }
// //
// Build the string data // Build the string data
// //
for (Index = 0; Index < TargetNameLength; Index++) { for (Index = 0; Index < TargetNameLength; Index++) {
Buffer = CatSPrint (Buffer, L"%02x", *((UINT8*)Vendor + sizeof (VENDOR_DEVICE_PATH) + Index)); Buffer = CatSPrint (Buffer, L"%02x", *((UINT8*)Vendor + sizeof (VENDOR_DEVICE_PATH) + Index));
} }
// //
// Append the new data block // Append the new data block
@ -632,7 +676,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialLun ( DevPathSerialLun (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
DEVICE_LOGICAL_UNIT_DEVICE_PATH *Lun; DEVICE_LOGICAL_UNIT_DEVICE_PATH *Lun;
@ -654,7 +699,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialSata ( DevPathSerialSata (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
SATA_DEVICE_PATH *Sata; SATA_DEVICE_PATH *Sata;
@ -678,7 +724,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialIScsi ( DevPathSerialIScsi (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
ISCSI_DEVICE_PATH *IScsi; ISCSI_DEVICE_PATH *IScsi;
@ -721,7 +768,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialI2O ( DevPathSerialI2O (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
I2O_DEVICE_PATH *DevicePath_I20; I2O_DEVICE_PATH *DevicePath_I20;
@ -743,7 +791,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialMacAddr ( DevPathSerialMacAddr (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
MAC_ADDR_DEVICE_PATH *Mac; MAC_ADDR_DEVICE_PATH *Mac;
@ -779,7 +828,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialInfiniBand ( DevPathSerialInfiniBand (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
INFINIBAND_DEVICE_PATH *InfiniBand; INFINIBAND_DEVICE_PATH *InfiniBand;
@ -811,7 +861,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialIPv4 ( DevPathSerialIPv4 (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
IPv4_DEVICE_PATH *Ip; IPv4_DEVICE_PATH *Ip;
@ -855,7 +906,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialIPv6 ( DevPathSerialIPv6 (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
IPv6_DEVICE_PATH *Ip; IPv6_DEVICE_PATH *Ip;
@ -891,7 +943,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialScsi ( DevPathSerialScsi (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
SCSI_DEVICE_PATH *Scsi; SCSI_DEVICE_PATH *Scsi;
@ -914,7 +967,8 @@ VOID
EFIAPI EFIAPI
DevPathSerial1394 ( DevPathSerial1394 (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
F1394_DEVICE_PATH *DevicePath_F1394; F1394_DEVICE_PATH *DevicePath_F1394;
@ -938,7 +992,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialAcpi ( DevPathSerialAcpi (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
ACPI_HID_DEVICE_PATH *Acpi; ACPI_HID_DEVICE_PATH *Acpi;
@ -967,7 +1022,8 @@ VOID
EFIAPI EFIAPI
DevPathSerialDefault ( DevPathSerialDefault (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
return; return;
@ -1209,21 +1265,22 @@ GetDeviceConsistMappingInfo (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
) )
{ {
VOID (EFIAPI *SerialFun) (EFI_DEVICE_PATH_PROTOCOL *, DEVICE_CONSIST_MAPPING_INFO *); SerialDecodeFucntion SerialFun;
UINTN Index;
UINTN Index; EFI_DEVICE_PATH_PROTOCOL *OriginalDevicePath;
ASSERT(DevicePath != NULL); ASSERT(DevicePath != NULL);
ASSERT(MappingItem != NULL); ASSERT(MappingItem != NULL);
SetMem (&MappingItem->Csd, sizeof (POOL_PRINT), 0); SetMem (&MappingItem->Csd, sizeof (POOL_PRINT), 0);
OriginalDevicePath = DevicePath;
while (!IsDevicePathEnd (DevicePath)) { while (!IsDevicePathEnd (DevicePath)) {
// //
// Find the handler to dump this device path node // Find the handler to dump this device path node and
// initialize with generic function in case nothing is found
// //
SerialFun = NULL; for (SerialFun = DevPathSerialDefault, Index = 0; DevPathConsistMappingTable[Index].SerialFun != NULL; Index += 1) {
for (Index = 0; DevPathConsistMappingTable[Index].SerialFun != NULL; Index += 1) {
if (DevicePathType (DevicePath) == DevPathConsistMappingTable[Index].Type && if (DevicePathType (DevicePath) == DevPathConsistMappingTable[Index].Type &&
DevicePathSubType (DevicePath) == DevPathConsistMappingTable[Index].SubType DevicePathSubType (DevicePath) == DevPathConsistMappingTable[Index].SubType
@ -1232,14 +1289,8 @@ GetDeviceConsistMappingInfo (
break; break;
} }
} }
//
// If not found, use a generic function
//
if (!SerialFun) {
SerialFun = DevPathSerialDefault;
}
SerialFun (DevicePath, MappingItem); SerialFun (DevicePath, MappingItem, OriginalDevicePath);
// //
// Next device path node // Next device path node

View File

@ -53,6 +53,7 @@
gEfiShellProtocolGuid # ALWAYS_CONSUMED gEfiShellProtocolGuid # ALWAYS_CONSUMED
gEfiShellParametersProtocolGuid # ALWAYS_CONSUMED gEfiShellParametersProtocolGuid # ALWAYS_CONSUMED
gEfiShellDynamicCommandProtocolGuid # SOMETIMES_CONSUMED gEfiShellDynamicCommandProtocolGuid # SOMETIMES_CONSUMED
gEfiUsbIoProtocolGuid ## SOMETIMES_CONSUMED
[Guids] [Guids]
gEfiSasDevicePathGuid # ALWAYS_CONSUMED gEfiSasDevicePathGuid # ALWAYS_CONSUMED
@ -60,6 +61,7 @@
[Pcd.common] [Pcd.common]
gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel ## ALWAYS_CONSUMED gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel ## ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellMapNameLength ## ALWAYS_CONSUMED gEfiShellPkgTokenSpaceGuid.PcdShellMapNameLength ## ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdUsbExtendedDecode ## SOMETIMES_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellDecodeIScsiMapNames ## SOMETIMES_CONSUMED gEfiShellPkgTokenSpaceGuid.PcdShellDecodeIScsiMapNames ## SOMETIMES_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellVendorExtendedDecode ## SOMETIMES_CONSUMED gEfiShellPkgTokenSpaceGuid.PcdShellVendorExtendedDecode ## SOMETIMES_CONSUMED

View File

@ -129,6 +129,9 @@
## Unicode string of the shell supplier ## Unicode string of the shell supplier
gEfiShellPkgTokenSpaceGuid.PcdShellSupplier|L"EDK II"|VOID*|0x00000010 gEfiShellPkgTokenSpaceGuid.PcdShellSupplier|L"EDK II"|VOID*|0x00000010
## Do extended decode of USB for determining media type
gEfiShellPkgTokenSpaceGuid.PcdUsbExtendedDecode|TRUE|BOOLEAN|0x00000011
## Do iSCSI decode for map names. ## Do iSCSI decode for map names.
# This is disabled by default due to the length of generated strings # This is disabled by default due to the length of generated strings
gEfiShellPkgTokenSpaceGuid.PcdShellDecodeIScsiMapNames|FALSE|BOOLEAN|0x00000012 gEfiShellPkgTokenSpaceGuid.PcdShellDecodeIScsiMapNames|FALSE|BOOLEAN|0x00000012