X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellCommandLib%2FConsistMapping.c;h=86e8dc59a8951bab39356886c7ec2428e32d6110;hp=3425e9e912beb65d4a171251d9f9086eb0f18cb3;hb=e9fc53878117779eeb35715666573d307e069380;hpb=a405b86d274d32b92f69842bfb9a1ab143128f57 diff --git a/ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c b/ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c index 3425e9e912..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 - 2010, 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, @@ -29,9 +35,9 @@ typedef struct { } POOL_PRINT; typedef struct { - UINTN HI; - MTD_TYPE MTD; - POOL_PRINT CSD; + UINTN Hi; + MTD_TYPE Mtd; + POOL_PRINT Csd; BOOLEAN Digital; } DEVICE_CONSIST_MAPPING_INFO; @@ -40,11 +46,27 @@ 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 (*SerialFun) (EFI_DEVICE_PATH_PROTOCOL *, DEVICE_CONSIST_MAPPING_INFO *); - INTN (*CompareFun) (EFI_DEVICE_PATH_PROTOCOL *, EFI_DEVICE_PATH_PROTOCOL *); + 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); } - StrCat (Str->Str, AppendStr); + StrCatS (Str->Str, StringSize/sizeof(CHAR16), AppendStr); Str->Len = StringSize; FreePool (AppendStr); @@ -128,7 +150,17 @@ MTD_NAME mMTDName[] = { } }; -VOID +/** + Function to append a 64 bit number / 25 onto the string. + + @param[in, out] Str The string so append onto. + @param[in] Num The number to divide and append. + + @retval EFI_INVALID_PARAMETER A parameter was NULL. + @retval EFI_SUCCESS The appending was successful. +**/ +EFI_STATUS +EFIAPI AppendCSDNum2 ( IN OUT POOL_PRINT *Str, IN UINT64 Num @@ -137,7 +169,9 @@ AppendCSDNum2 ( UINT64 Result; UINT32 Rem; - ASSERT(Str != NULL); + if (Str == NULL) { + return (EFI_INVALID_PARAMETER); + } Result = DivU64x32Remainder (Num, 25, &Rem); if (Result > 0) { @@ -145,35 +179,61 @@ AppendCSDNum2 ( } CatPrint (Str, L"%c", Rem + 'a'); + return (EFI_SUCCESS); } -VOID +/** + Function to append a 64 bit number onto the mapping info. + + @param[in, out] MappingItem The mapping info object to append onto. + @param[in] Num The info to append. + + @retval EFI_INVALID_PARAMETER A parameter was NULL. + @retval EFI_SUCCESS The appending was successful. +**/ +EFI_STATUS +EFIAPI AppendCSDNum ( - DEVICE_CONSIST_MAPPING_INFO *MappingItem, - UINT64 Num + IN OUT DEVICE_CONSIST_MAPPING_INFO *MappingItem, + IN UINT64 Num ) { - ASSERT(MappingItem != NULL); + if (MappingItem == NULL) { + return EFI_INVALID_PARAMETER; + } if (MappingItem->Digital) { - CatPrint (&MappingItem->CSD, L"%ld", Num); + CatPrint (&MappingItem->Csd, L"%ld", Num); } else { - AppendCSDNum2 (&MappingItem->CSD, Num); + AppendCSDNum2 (&MappingItem->Csd, Num); } MappingItem->Digital = (BOOLEAN)!(MappingItem->Digital); + + return (EFI_SUCCESS); } -VOID +/** + Function to append string into the mapping info. + + @param[in, out] MappingItem The mapping info object to append onto. + @param[in] Str The info to append. + + @retval EFI_INVALID_PARAMETER A parameter was NULL. + @retval EFI_SUCCESS The appending was successful. +**/ +EFI_STATUS +EFIAPI AppendCSDStr ( - DEVICE_CONSIST_MAPPING_INFO *MappingItem, - CHAR16 *Str + IN OUT DEVICE_CONSIST_MAPPING_INFO *MappingItem, + IN CHAR16 *Str ) { CHAR16 *Index; - ASSERT(Str != NULL); - ASSERT(MappingItem != NULL); + if (Str == NULL || MappingItem == NULL) { + return (EFI_INVALID_PARAMETER); + } if (MappingItem->Digital) { // @@ -192,11 +252,11 @@ AppendCSDStr ( case '7': case '8': case '9': - CatPrint (&MappingItem->CSD, L"%c", *Index); + CatPrint (&MappingItem->Csd, L"%c", *Index); break; case '1': - CatPrint (&MappingItem->CSD, L"16"); + CatPrint (&MappingItem->Csd, L"16"); break; case 'a': @@ -205,7 +265,7 @@ AppendCSDStr ( case 'd': case 'e': case 'f': - CatPrint (&MappingItem->CSD, L"1%c", *Index - 'a' + '0'); + CatPrint (&MappingItem->Csd, L"1%c", *Index - 'a' + '0'); break; case 'A': @@ -214,7 +274,7 @@ AppendCSDStr ( case 'D': case 'E': case 'F': - CatPrint (&MappingItem->CSD, L"1%c", *Index - 'A' + '0'); + CatPrint (&MappingItem->Csd, L"1%c", *Index - 'A' + '0'); break; } } @@ -226,27 +286,41 @@ AppendCSDStr ( // a b c d e f g h i j k l m n o p // if (*Index >= '0' && *Index <= '9') { - CatPrint (&MappingItem->CSD, L"%c", *Index - '0' + 'a'); + CatPrint (&MappingItem->Csd, L"%c", *Index - '0' + 'a'); } else if (*Index >= 'a' && *Index <= 'f') { - CatPrint (&MappingItem->CSD, L"%c", *Index - 'a' + 'k'); + CatPrint (&MappingItem->Csd, L"%c", *Index - 'a' + 'k'); } else if (*Index >= 'A' && *Index <= 'F') { - CatPrint (&MappingItem->CSD, L"%c", *Index - 'A' + 'k'); + CatPrint (&MappingItem->Csd, L"%c", *Index - 'A' + 'k'); } } } MappingItem->Digital = (BOOLEAN)!(MappingItem->Digital); + + return (EFI_SUCCESS); } -VOID +/** + Function to append a Guid to the mapping item. + + @param[in, out] MappingItem The item to append onto. + @param[in] Guid The guid to append. + + @retval EFI_SUCCESS The appending operation was successful. + @retval EFI_INVALID_PARAMETER A parameter was NULL. +**/ +EFI_STATUS +EFIAPI AppendCSDGuid ( DEVICE_CONSIST_MAPPING_INFO *MappingItem, EFI_GUID *Guid ) { CHAR16 Buffer[64]; - ASSERT(Guid != NULL); - ASSERT(MappingItem != NULL); + + if (Guid == NULL || MappingItem == NULL) { + return (EFI_INVALID_PARAMETER); + } UnicodeSPrint ( Buffer, @@ -254,12 +328,24 @@ AppendCSDGuid ( L"%g", Guid ); -// StrLwr (Buffer); + AppendCSDStr (MappingItem, Buffer); + + return (EFI_SUCCESS); } +/** + Function to compare 2 APCI device paths. + + @param[in] DevicePath1 The first device path to compare. + @param[in] DevicePath2 The second device path to compare. + + @retval 0 The device paths represent the same device. + @return Non zero if the devices are different, zero otherwise. +**/ INTN -_DevPathCompareAcpi ( +EFIAPI +DevPathCompareAcpi ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2 ) @@ -267,8 +353,9 @@ _DevPathCompareAcpi ( ACPI_HID_DEVICE_PATH *Acpi1; ACPI_HID_DEVICE_PATH *Acpi2; - ASSERT(DevicePath1 != NULL); - ASSERT(DevicePath2 != NULL); + if (DevicePath1 == NULL || DevicePath2 == NULL) { + return (-2); + } Acpi1 = (ACPI_HID_DEVICE_PATH *) DevicePath1; Acpi2 = (ACPI_HID_DEVICE_PATH *) DevicePath2; @@ -283,8 +370,18 @@ _DevPathCompareAcpi ( return -1; } +/** + Function to compare 2 PCI device paths. + + @param[in] DevicePath1 The first device path to compare. + @param[in] DevicePath2 The second device path to compare. + + @retval 0 The device paths represent the same device. + @return Non zero if the devices are different, zero otherwise. +**/ INTN -_DevPathComparePci ( +EFIAPI +DevPathComparePci ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2 ) @@ -347,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; @@ -361,8 +460,8 @@ DevPathSerialHardDrive ( ASSERT(MappingItem != NULL); Hd = (HARDDRIVE_DEVICE_PATH *) DevicePathNode; - if (MappingItem->MTD == MTDTypeUnknown) { - MappingItem->MTD = MTDTypeHardDisk; + if (MappingItem->Mtd == MTDTypeUnknown) { + MappingItem->Mtd = MTDTypeHardDisk; } AppendCSDNum (MappingItem, Hd->PartitionNumber); @@ -373,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; @@ -395,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; @@ -409,7 +512,7 @@ DevPathSerialCdRom ( ASSERT(MappingItem != NULL); Cd = (CDROM_DEVICE_PATH *) DevicePathNode; - MappingItem->MTD = MTDTypeCDRom; + MappingItem->Mtd = MTDTypeCDRom; AppendCSDNum (MappingItem, Cd->BootEntry); } @@ -418,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; @@ -441,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; @@ -466,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); @@ -482,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; + } + } + } + } + } } /** @@ -489,30 +632,62 @@ 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; - EFI_GUID SasVendorGuid = DEVICE_PATH_MESSAGING_SAS; + UINTN TargetNameLength; + UINTN Index; + CHAR16 *Buffer; - ASSERT(DevicePathNode != NULL); - ASSERT(MappingItem != NULL); + if (DevicePathNode == NULL || MappingItem == NULL) { + return; + } Vendor = (VENDOR_DEVICE_PATH *) DevicePathNode; AppendCSDGuid (MappingItem, &Vendor->Guid); - if (CompareGuid (&SasVendorGuid, &Vendor->Guid) == 0) { + if (CompareGuid (&gEfiSasDevicePathGuid, &Vendor->Guid)) { Sas = (SAS_DEVICE_PATH *) Vendor; AppendCSDNum (MappingItem, Sas->SasAddress); 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); + } } } @@ -521,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; @@ -543,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; @@ -567,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; @@ -591,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); } } - */ } /** @@ -616,21 +791,23 @@ 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 *I2O; + I2O_DEVICE_PATH *DevicePath_I20; ASSERT(DevicePathNode != NULL); ASSERT(MappingItem != NULL); - I2O = (I2O_DEVICE_PATH *) DevicePathNode; - AppendCSDNum (MappingItem, I2O->Tid); + DevicePath_I20 = (I2O_DEVICE_PATH *) DevicePathNode; + AppendCSDNum (MappingItem, DevicePath_I20->Tid); } /** @@ -638,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; @@ -674,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; @@ -706,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; @@ -750,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; @@ -786,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; @@ -809,22 +998,24 @@ 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 *F1394; + F1394_DEVICE_PATH *DevicePath_F1394; CHAR16 Buffer[20]; ASSERT(DevicePathNode != NULL); ASSERT(MappingItem != NULL); - F1394 = (F1394_DEVICE_PATH *) DevicePathNode; - UnicodeSPrint (Buffer, 0, L"%lx", F1394->Guid); + DevicePath_F1394 = (F1394_DEVICE_PATH *) DevicePathNode; + UnicodeSPrint (Buffer, 0, L"%lx", DevicePath_F1394->Guid); AppendCSDStr (MappingItem, Buffer); } @@ -833,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; @@ -849,7 +1042,7 @@ DevPathSerialAcpi ( Acpi = (ACPI_HID_DEVICE_PATH *) DevicePathNode; if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) { if (EISA_ID_TO_NUM (Acpi->HID) == 0x0604) { - MappingItem->MTD = MTDTypeFloppy; + MappingItem->Mtd = MTDTypeFloppy; AppendCSDNum (MappingItem, Acpi->UID); } } @@ -858,102 +1051,150 @@ DevPathSerialAcpi ( /** Empty function used for unknown devices. + @param[in] DevicePathNode Ignored. + @param[in] MappingItem Ignored. + @param[in] DevicePath Ignored. + Does nothing. **/ 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; } DEV_PATH_CONSIST_MAPPING_TABLE DevPathConsistMappingTable[] = { - HARDWARE_DEVICE_PATH, - HW_PCI_DP, - DevPathSerialDefault, - _DevPathComparePci, - ACPI_DEVICE_PATH, - ACPI_DP, - DevPathSerialAcpi, - _DevPathCompareAcpi, - MESSAGING_DEVICE_PATH, - MSG_ATAPI_DP, - DevPathSerialAtapi, - DevPathCompareDefault, - MESSAGING_DEVICE_PATH, - MSG_SCSI_DP, - DevPathSerialScsi, - DevPathCompareDefault, - MESSAGING_DEVICE_PATH, - MSG_FIBRECHANNEL_DP, - DevPathSerialFibre, - DevPathCompareDefault, - MESSAGING_DEVICE_PATH, - MSG_1394_DP, - DevPathSerial1394, - DevPathCompareDefault, - MESSAGING_DEVICE_PATH, - MSG_USB_DP, - DevPathSerialUsb, - DevPathCompareDefault, - MESSAGING_DEVICE_PATH, - MSG_I2O_DP, - DevPathSerialI2O, - DevPathCompareDefault, - MESSAGING_DEVICE_PATH, - MSG_MAC_ADDR_DP, - DevPathSerialMacAddr, - DevPathCompareDefault, - MESSAGING_DEVICE_PATH, - MSG_IPv4_DP, - DevPathSerialIPv4, - DevPathCompareDefault, - MESSAGING_DEVICE_PATH, - MSG_IPv6_DP, - DevPathSerialIPv6, - DevPathCompareDefault, - MESSAGING_DEVICE_PATH, - MSG_INFINIBAND_DP, - DevPathSerialInfiniBand, - DevPathCompareDefault, - MESSAGING_DEVICE_PATH, - MSG_UART_DP, - DevPathSerialUart, - DevPathCompareDefault, - MESSAGING_DEVICE_PATH, - MSG_VENDOR_DP, - DevPathSerialVendor, - DevPathCompareDefault, - MESSAGING_DEVICE_PATH, - MSG_DEVICE_LOGICAL_UNIT_DP, - DevPathSerialLun, - DevPathCompareDefault, - MESSAGING_DEVICE_PATH, - MSG_SATA_DP, - DevPathSerialSata, - DevPathCompareDefault, - MESSAGING_DEVICE_PATH, - MSG_ISCSI_DP, - DevPathSerialIScsi, - DevPathCompareDefault, - MEDIA_DEVICE_PATH, - MEDIA_HARDDRIVE_DP, - DevPathSerialHardDrive, - DevPathCompareDefault, - MEDIA_DEVICE_PATH, - MEDIA_CDROM_DP, - DevPathSerialCdRom, - DevPathCompareDefault, - MEDIA_DEVICE_PATH, - MEDIA_VENDOR_DP, - DevPathSerialVendor, - DevPathCompareDefault, - 0, - 0, - NULL, - NULL + { + HARDWARE_DEVICE_PATH, + HW_PCI_DP, + DevPathSerialDefault, + DevPathComparePci + }, + { + ACPI_DEVICE_PATH, + ACPI_DP, + DevPathSerialAcpi, + DevPathCompareAcpi + }, + { + MESSAGING_DEVICE_PATH, + MSG_ATAPI_DP, + DevPathSerialAtapi, + DevPathCompareDefault + }, + { + MESSAGING_DEVICE_PATH, + MSG_SCSI_DP, + DevPathSerialScsi, + DevPathCompareDefault + }, + { + MESSAGING_DEVICE_PATH, + MSG_FIBRECHANNEL_DP, + DevPathSerialFibre, + DevPathCompareDefault + }, + { + MESSAGING_DEVICE_PATH, + MSG_1394_DP, + DevPathSerial1394, + DevPathCompareDefault + }, + { + MESSAGING_DEVICE_PATH, + MSG_USB_DP, + DevPathSerialUsb, + DevPathCompareDefault + }, + { + MESSAGING_DEVICE_PATH, + MSG_I2O_DP, + DevPathSerialI2O, + DevPathCompareDefault + }, + { + MESSAGING_DEVICE_PATH, + MSG_MAC_ADDR_DP, + DevPathSerialMacAddr, + DevPathCompareDefault + }, + { + MESSAGING_DEVICE_PATH, + MSG_IPv4_DP, + DevPathSerialIPv4, + DevPathCompareDefault + }, + { + MESSAGING_DEVICE_PATH, + MSG_IPv6_DP, + DevPathSerialIPv6, + DevPathCompareDefault + }, + { + MESSAGING_DEVICE_PATH, + MSG_INFINIBAND_DP, + DevPathSerialInfiniBand, + DevPathCompareDefault + }, + { + MESSAGING_DEVICE_PATH, + MSG_UART_DP, + DevPathSerialUart, + DevPathCompareDefault + }, + { + MESSAGING_DEVICE_PATH, + MSG_VENDOR_DP, + DevPathSerialVendor, + DevPathCompareDefault + }, + { + MESSAGING_DEVICE_PATH, + MSG_DEVICE_LOGICAL_UNIT_DP, + DevPathSerialLun, + DevPathCompareDefault + }, + { + MESSAGING_DEVICE_PATH, + MSG_SATA_DP, + DevPathSerialSata, + DevPathCompareDefault + }, + { + MESSAGING_DEVICE_PATH, + MSG_ISCSI_DP, + DevPathSerialIScsi, + DevPathCompareDefault + }, + { + MEDIA_DEVICE_PATH, + MEDIA_HARDDRIVE_DP, + DevPathSerialHardDrive, + DevPathCompareDefault + }, + { + MEDIA_DEVICE_PATH, + MEDIA_CDROM_DP, + DevPathSerialCdRom, + DevPathCompareDefault + }, + { + MEDIA_DEVICE_PATH, + MEDIA_VENDOR_DP, + DevPathSerialVendor, + DevPathCompareDefault + }, + { + 0, + 0, + NULL, + NULL + } }; /** @@ -961,8 +1202,8 @@ DEV_PATH_CONSIST_MAPPING_TABLE DevPathConsistMappingTable[] = { @param[in] DevicePathNode The node to check. - @retval TRUE The node is HI. - @retval FALSE The node is not HI. + @retval TRUE The node is Hi. + @retval FALSE The node is not Hi. **/ BOOLEAN EFIAPI @@ -995,11 +1236,11 @@ IsHIDevicePathNode ( } /** - Function to convert a standard device path structure into a HI version. + Function to convert a standard device path structure into a Hi version. @param[in] DevicePath The device path to convert. - @return the device path portion that is HI. + @return the device path portion that is Hi. **/ EFI_DEVICE_PATH_PROTOCOL * EFIAPI @@ -1017,7 +1258,7 @@ GetHIDevicePath ( NonHIDevicePathNodeCount = 0; - HIDevicePath = AllocatePool (sizeof (EFI_DEVICE_PATH_PROTOCOL)); + HIDevicePath = AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL)); SetDevicePathEndNode (HIDevicePath); Node.DevPath.Type = END_DEVICE_PATH_TYPE; @@ -1063,21 +1304,22 @@ GetDeviceConsistMappingInfo ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { - VOID (*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); + 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 @@ -1086,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 @@ -1117,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 @@ -1153,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); @@ -1204,13 +1456,13 @@ ShellCommandConsistMappingUnInitialize ( } /** - Create a consistent mapped name for the device specified by DevicePath + Create a consistent mapped name for the device specified by DevicePath based on the Table. - This must be called after ShellCommandConsistMappingInitialize() and + This must be called after ShellCommandConsistMappingInitialize() and before ShellCommandConsistMappingUnInitialize() is called. - @param[in] DeviecPath The pointer to the dev path for the device. + @param[in] DevicePath The pointer to the dev path for the device. @param[in] Table The Table of mapping information. @retval NULL A consistent mapped name could not be created. @@ -1219,8 +1471,8 @@ ShellCommandConsistMappingUnInitialize ( CHAR16 * EFIAPI ShellCommandConsistMappingGenMappingName ( - EFI_DEVICE_PATH_PROTOCOL *DevicePath, - EFI_DEVICE_PATH_PROTOCOL **Table + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, + IN EFI_DEVICE_PATH_PROTOCOL **Table ) { POOL_PRINT Str; @@ -1248,15 +1500,15 @@ ShellCommandConsistMappingGenMappingName ( return NULL; } - MappingInfo.HI = Index; - MappingInfo.MTD = MTDTypeUnknown; + MappingInfo.Hi = Index; + MappingInfo.Mtd = MTDTypeUnknown; MappingInfo.Digital = FALSE; GetDeviceConsistMappingInfo (&MappingInfo, DevicePath); SetMem (&Str, sizeof (Str), 0); for (Index = 0; mMTDName[Index].MTDType != MTDTypeEnd; Index++) { - if (MappingInfo.MTD == mMTDName[Index].MTDType) { + if (MappingInfo.Mtd == mMTDName[Index].MTDType) { break; } } @@ -1265,10 +1517,10 @@ ShellCommandConsistMappingGenMappingName ( CatPrint (&Str, L"%s", mMTDName[Index].Name); } - CatPrint (&Str, L"%d", (UINTN) MappingInfo.HI); - if (MappingInfo.CSD.Str != NULL) { - CatPrint (&Str, L"%s", MappingInfo.CSD.Str); - FreePool (MappingInfo.CSD.Str); + CatPrint (&Str, L"%d", (UINTN) MappingInfo.Hi); + if (MappingInfo.Csd.Str != NULL) { + CatPrint (&Str, L"%s", MappingInfo.Csd.Str); + FreePool (MappingInfo.Csd.Str); } if (Str.Str != NULL) { @@ -1277,6 +1529,9 @@ ShellCommandConsistMappingGenMappingName ( NewSize = (Str.Len + 1) * sizeof (CHAR16); Str.Str = ReallocatePool (Str.Len, NewSize, Str.Str); + if (Str.Str == NULL) { + return (NULL); + } Str.Str[Str.Len] = CHAR_NULL; return Str.Str; }