X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellCommandLib%2FConsistMapping.c;h=86e8dc59a8951bab39356886c7ec2428e32d6110;hp=a009609ffc27e08f727fce96f64ec2c5217bbed5;hb=e9fc53878117779eeb35715666573d307e069380;hpb=531733377ac25083c7a54067a5330fb59f79bdfd diff --git a/ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c b/ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c index a009609ffc..86e8dc59a8 100644 --- a/ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c +++ b/ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c @@ -1,7 +1,7 @@ /** @file Main file for support of shell consist mapping. - Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -14,6 +14,12 @@ #include "UefiShellCommandLib.h" #include #include +#include +#include +#include +#include + + typedef enum { MTDTypeUnknown, @@ -40,10 +46,26 @@ typedef struct { CHAR16 *Name; } MTD_NAME; +/** + Serial Decode function. + + @param DevPath The Device path info. + @param MapInfo The map info. + @param OrigDevPath The original device path protocol. + +**/ +typedef +VOID +(EFIAPI *SERIAL_DECODE_FUNCTION) ( + EFI_DEVICE_PATH_PROTOCOL *DevPath, + DEVICE_CONSIST_MAPPING_INFO *MapInfo, + EFI_DEVICE_PATH_PROTOCOL *OrigDevPath + ); + typedef struct { UINT8 Type; UINT8 SubType; - VOID (EFIAPI *SerialFun) (EFI_DEVICE_PATH_PROTOCOL *DevPath, DEVICE_CONSIST_MAPPING_INFO *MapInfo); + SERIAL_DECODE_FUNCTION SerialFun; INTN (EFIAPI *CompareFun) (EFI_DEVICE_PATH_PROTOCOL *DevPath, EFI_DEVICE_PATH_PROTOCOL *DevPath2); } DEV_PATH_CONSIST_MAPPING_TABLE; @@ -98,7 +120,7 @@ CatPrint ( ASSERT (Str->Str != NULL); } - StrnCat (Str->Str, AppendStr, StringSize/sizeof(CHAR16) - 1 - StrLen(Str->Str)); + StrCatS (Str->Str, StringSize/sizeof(CHAR16), AppendStr); Str->Len = StringSize; FreePool (AppendStr); @@ -422,12 +444,14 @@ DevPathCompareDefault ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerialHardDrive ( 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; @@ -448,12 +472,14 @@ DevPathSerialHardDrive ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerialAtapi ( 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; @@ -470,12 +496,14 @@ DevPathSerialAtapi ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerialCdRom ( 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; @@ -493,12 +521,14 @@ DevPathSerialCdRom ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerialFibre ( 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; @@ -516,12 +546,14 @@ DevPathSerialFibre ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerialUart ( 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; @@ -541,15 +573,22 @@ DevPathSerialUart ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerialUsb ( 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(MappingItem != NULL); @@ -557,6 +596,35 @@ DevPathSerialUsb ( Usb = (USB_DEVICE_PATH *) DevicePathNode; AppendCSDNum (MappingItem, Usb->ParentPortNumber); 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; + } + } + } + } + } } /** @@ -564,17 +632,22 @@ DevPathSerialUsb ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerialVendor ( 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; SAS_DEVICE_PATH *Sas; + UINTN TargetNameLength; + UINTN Index; + CHAR16 *Buffer; if (DevicePathNode == NULL || MappingItem == NULL) { return; @@ -589,6 +662,32 @@ DevPathSerialVendor ( AppendCSDNum (MappingItem, Sas->Lun); AppendCSDNum (MappingItem, Sas->DeviceTopology); AppendCSDNum (MappingItem, Sas->RelativeTargetPort); + } else { + TargetNameLength = MIN(DevicePathNodeLength (DevicePathNode) - sizeof (VENDOR_DEVICE_PATH), PcdGet32(PcdShellVendorExtendedDecode)); + if (TargetNameLength != 0) { + // + // String is 2 chars per data byte, plus NULL terminator + // + Buffer = AllocateZeroPool (((TargetNameLength * 2) + 1) * sizeof(CHAR16)); + ASSERT(Buffer != NULL); + if (Buffer == NULL) { + return; + } + + // + // Build the string data + // + for (Index = 0; Index < TargetNameLength; Index++) { + Buffer = CatSPrint (Buffer, L"%02x", *((UINT8*)Vendor + sizeof (VENDOR_DEVICE_PATH) + Index)); +} + + // + // Append the new data block + // + AppendCSDStr (MappingItem, Buffer); + + FreePool(Buffer); + } } } @@ -597,12 +696,14 @@ DevPathSerialVendor ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerialLun ( 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; @@ -619,12 +720,14 @@ DevPathSerialLun ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerialSata ( 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; @@ -643,21 +746,16 @@ DevPathSerialSata ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerialIScsi ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, - IN DEVICE_CONSIST_MAPPING_INFO *MappingItem + IN DEVICE_CONSIST_MAPPING_INFO *MappingItem, + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { -///@todo make this a PCD -// -// As Csd of ISCSI node is quite long, we comment -// the code below to keep the consistent mapping -// short. Uncomment if you really need it. -// -/* ISCSI_DEVICE_PATH *IScsi; UINT8 *IScsiTargetName; CHAR16 *TargetName; @@ -667,24 +765,25 @@ DevPathSerialIScsi ( ASSERT(DevicePathNode != NULL); ASSERT(MappingItem != NULL); - IScsi = (ISCSI_DEVICE_PATH *) DevicePathNode; - AppendCSDNum (MappingItem, IScsi->NetworkProtocol); - AppendCSDNum (MappingItem, IScsi->LoginOption); - AppendCSDNum (MappingItem, IScsi->Lun); - AppendCSDNum (MappingItem, IScsi->TargetPortalGroupTag); - TargetNameLength = DevicePathNodeLength (DevicePathNode) - sizeof (ISCSI_DEVICE_PATH); - if (TargetNameLength > 0) { - TargetName = AllocateZeroPool ((TargetNameLength + 1) * sizeof (CHAR16)); - if (TargetName != NULL) { - IScsiTargetName = (UINT8 *) (IScsi + 1); - for (Index = 0; Index < TargetNameLength; Index++) { - TargetName[Index] = (CHAR16) IScsiTargetName[Index]; + if (PcdGetBool(PcdShellDecodeIScsiMapNames)) { + IScsi = (ISCSI_DEVICE_PATH *) DevicePathNode; + AppendCSDNum (MappingItem, IScsi->NetworkProtocol); + AppendCSDNum (MappingItem, IScsi->LoginOption); + AppendCSDNum (MappingItem, IScsi->Lun); + AppendCSDNum (MappingItem, IScsi->TargetPortalGroupTag); + TargetNameLength = DevicePathNodeLength (DevicePathNode) - sizeof (ISCSI_DEVICE_PATH); + if (TargetNameLength > 0) { + TargetName = AllocateZeroPool ((TargetNameLength + 1) * sizeof (CHAR16)); + if (TargetName != NULL) { + IScsiTargetName = (UINT8 *) (IScsi + 1); + for (Index = 0; Index < TargetNameLength; Index++) { + TargetName[Index] = (CHAR16) IScsiTargetName[Index]; + } + AppendCSDStr (MappingItem, TargetName); + FreePool (TargetName); } - AppendCSDStr (MappingItem, TargetName); - FreePool (TargetName); } } - */ } /** @@ -692,12 +791,14 @@ DevPathSerialIScsi ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerialI2O ( 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; @@ -714,12 +815,14 @@ DevPathSerialI2O ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerialMacAddr ( 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; @@ -750,12 +853,14 @@ DevPathSerialMacAddr ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerialInfiniBand ( 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; @@ -782,12 +887,14 @@ DevPathSerialInfiniBand ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerialIPv4 ( 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; @@ -826,12 +933,15 @@ DevPathSerialIPv4 ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + **/ VOID EFIAPI DevPathSerialIPv6 ( 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; @@ -862,12 +972,15 @@ DevPathSerialIPv6 ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + **/ VOID EFIAPI DevPathSerialScsi ( 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; @@ -885,12 +998,14 @@ DevPathSerialScsi ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerial1394 ( 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; @@ -909,12 +1024,14 @@ DevPathSerial1394 ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. **/ VOID EFIAPI DevPathSerialAcpi ( 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; @@ -936,6 +1053,7 @@ DevPathSerialAcpi ( @param[in] DevicePathNode Ignored. @param[in] MappingItem Ignored. + @param[in] DevicePath Ignored. Does nothing. **/ @@ -943,7 +1061,8 @@ VOID EFIAPI DevPathSerialDefault ( 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; @@ -1185,21 +1304,22 @@ GetDeviceConsistMappingInfo ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { - VOID (EFIAPI *SerialFun) (EFI_DEVICE_PATH_PROTOCOL *, DEVICE_CONSIST_MAPPING_INFO *); - - UINTN Index; + SERIAL_DECODE_FUNCTION SerialFun; + UINTN Index; + EFI_DEVICE_PATH_PROTOCOL *OriginalDevicePath; ASSERT(DevicePath != NULL); ASSERT(MappingItem != NULL); SetMem (&MappingItem->Csd, sizeof (POOL_PRINT), 0); + OriginalDevicePath = 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 (Index = 0; DevPathConsistMappingTable[Index].SerialFun != NULL; Index += 1) { + for (SerialFun = DevPathSerialDefault, Index = 0; DevPathConsistMappingTable[Index].SerialFun != NULL; Index += 1) { if (DevicePathType (DevicePath) == DevPathConsistMappingTable[Index].Type && DevicePathSubType (DevicePath) == DevPathConsistMappingTable[Index].SubType @@ -1208,14 +1328,8 @@ GetDeviceConsistMappingInfo ( break; } } - // - // If not found, use a generic function - // - if (!SerialFun) { - SerialFun = DevPathSerialDefault; - } - SerialFun (DevicePath, MappingItem); + SerialFun (DevicePath, MappingItem, OriginalDevicePath); // // Next device path node @@ -1239,20 +1353,22 @@ ShellCommandConsistMappingInitialize ( OUT EFI_DEVICE_PATH_PROTOCOL ***Table ) { - EFI_HANDLE *HandleBuffer; - UINTN HandleNum; - UINTN HandleLoop; - EFI_DEVICE_PATH_PROTOCOL **TempTable; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - EFI_DEVICE_PATH_PROTOCOL *HIDevicePath; - UINTN Index; - EFI_STATUS Status; + EFI_HANDLE *HandleBuffer; + UINTN HandleNum; + UINTN HandleLoop; + EFI_DEVICE_PATH_PROTOCOL **TempTable; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_DEVICE_PATH_PROTOCOL *HIDevicePath; + EFI_BLOCK_IO_PROTOCOL *BlockIo; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem; + UINTN Index; + EFI_STATUS Status; HandleBuffer = NULL; Status = gBS->LocateHandleBuffer ( - AllHandles, - NULL, + ByProtocol, + &gEfiDevicePathProtocolGuid, NULL, &HandleNum, &HandleBuffer @@ -1275,6 +1391,20 @@ ShellCommandConsistMappingInitialize ( continue; } + Status = gBS->HandleProtocol( HandleBuffer[HandleLoop], + &gEfiBlockIoProtocolGuid, + (VOID **)&BlockIo + ); + if (EFI_ERROR(Status)) { + Status = gBS->HandleProtocol( HandleBuffer[HandleLoop], + &gEfiSimpleFileSystemProtocolGuid, + (VOID **)&SimpleFileSystem + ); + if (EFI_ERROR(Status)) { + continue; + } + } + for (Index = 0; TempTable[Index] != NULL; Index++) { if (DevicePathCompare (&TempTable[Index], &HIDevicePath) == 0) { FreePool (HIDevicePath);