X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellCommandLib%2FConsistMapping.c;h=3b13e62340de7c1355688967cd1899ba1fdb0c6f;hb=d69ba6a729996b288b4fb2b033969ab15cbf5d59;hp=9fbcbb3eb2621f65333bb5a90963d0ff4c59e00a;hpb=4ff7e37b4f7e336a8ecb7080b8f48eef4b52d396;p=mirror_edk2.git diff --git a/ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c b/ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c old mode 100644 new mode 100755 index 9fbcbb3eb2..3b13e62340 --- 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 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2005 - 2017, 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,28 @@ 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. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. +**/ +typedef +EFI_STATUS +(*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; @@ -56,12 +80,11 @@ typedef struct { @param Fmt The format string @param ... The data will be printed. - @return Allocated buffer with the formatted string printed in it. - The caller must free the allocated buffer. - The buffer allocation is not packed. + @retval EFI_SUCCESS The string is concatenated successfully. + @retval EFI_OUT_OF_RESOURCES Out of resources. **/ -CHAR16 * +EFI_STATUS EFIAPI CatPrint ( IN OUT POOL_PRINT *Str, @@ -72,37 +95,40 @@ CatPrint ( UINT16 *AppendStr; VA_LIST Args; UINTN StringSize; + CHAR16 *NewStr; AppendStr = AllocateZeroPool (0x1000); if (AppendStr == NULL) { - ASSERT(FALSE); - return Str->Str; + return EFI_OUT_OF_RESOURCES; } VA_START (Args, Fmt); UnicodeVSPrint (AppendStr, 0x1000, Fmt, Args); VA_END (Args); if (NULL == Str->Str) { - StringSize = StrSize (AppendStr); - Str->Str = AllocateZeroPool (StringSize); - ASSERT (Str->Str != NULL); + StringSize = StrSize (AppendStr); + NewStr = AllocateZeroPool (StringSize); } else { StringSize = StrSize (AppendStr); StringSize += (StrSize (Str->Str) - sizeof (UINT16)); - Str->Str = ReallocatePool ( - StrSize (Str->Str), - StringSize, - Str->Str + NewStr = ReallocatePool ( + StrSize (Str->Str), + StringSize, + Str->Str ); - ASSERT (Str->Str != NULL); + } + if (NewStr == NULL) { + FreePool (AppendStr); + return EFI_OUT_OF_RESOURCES; } - StrCat (Str->Str, AppendStr); + Str->Str = NewStr; + StrCatS (Str->Str, StringSize/sizeof(CHAR16), AppendStr); Str->Len = StringSize; FreePool (AppendStr); - return Str->Str; + return EFI_SUCCESS; } MTD_NAME mMTDName[] = { @@ -134,30 +160,30 @@ MTD_NAME mMTDName[] = { @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_OUT_OF_RESOURCES Out of resources. @retval EFI_SUCCESS The appending was successful. **/ EFI_STATUS -EFIAPI AppendCSDNum2 ( IN OUT POOL_PRINT *Str, IN UINT64 Num ) { - UINT64 Result; - UINT32 Rem; + EFI_STATUS Status; + UINT64 Result; + UINT32 Rem; - if (Str == NULL) { - return (EFI_INVALID_PARAMETER); - } + ASSERT (Str != NULL); Result = DivU64x32Remainder (Num, 25, &Rem); if (Result > 0) { - AppendCSDNum2 (Str, Result); + Status = AppendCSDNum2 (Str, Result); + if (EFI_ERROR (Status)) { + return Status; + } } - CatPrint (Str, L"%c", Rem + 'a'); - return (EFI_SUCCESS); + return CatPrint (Str, L"%c", Rem + 'a'); } /** @@ -166,29 +192,30 @@ AppendCSDNum2 ( @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_OUT_OF_RESOURCES Out of resources. @retval EFI_SUCCESS The appending was successful. + **/ EFI_STATUS -EFIAPI AppendCSDNum ( IN OUT DEVICE_CONSIST_MAPPING_INFO *MappingItem, IN UINT64 Num ) { - if (MappingItem == NULL) { - return EFI_INVALID_PARAMETER; - } + EFI_STATUS Status; + ASSERT (MappingItem != NULL); if (MappingItem->Digital) { - CatPrint (&MappingItem->Csd, L"%ld", Num); + Status = CatPrint (&MappingItem->Csd, L"%ld", Num); } else { - AppendCSDNum2 (&MappingItem->Csd, Num); + Status = AppendCSDNum2 (&MappingItem->Csd, Num); } - MappingItem->Digital = (BOOLEAN)!(MappingItem->Digital); + if (!EFI_ERROR (Status)) { + MappingItem->Digital = (BOOLEAN) !(MappingItem->Digital); + } - return (EFI_SUCCESS); + return Status; } /** @@ -197,21 +224,21 @@ AppendCSDNum ( @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_OUT_OF_RESOURCES Out of resources. @retval EFI_SUCCESS The appending was successful. **/ EFI_STATUS -EFIAPI AppendCSDStr ( IN OUT DEVICE_CONSIST_MAPPING_INFO *MappingItem, IN CHAR16 *Str ) { - CHAR16 *Index; + CHAR16 *Index; + EFI_STATUS Status; - if (Str == NULL || MappingItem == NULL) { - return (EFI_INVALID_PARAMETER); - } + ASSERT (Str != NULL && MappingItem != NULL); + + Status = EFI_SUCCESS; if (MappingItem->Digital) { // @@ -230,11 +257,11 @@ AppendCSDStr ( case '7': case '8': case '9': - CatPrint (&MappingItem->Csd, L"%c", *Index); + Status = CatPrint (&MappingItem->Csd, L"%c", *Index); break; case '1': - CatPrint (&MappingItem->Csd, L"16"); + Status = CatPrint (&MappingItem->Csd, L"16"); break; case 'a': @@ -243,7 +270,7 @@ AppendCSDStr ( case 'd': case 'e': case 'f': - CatPrint (&MappingItem->Csd, L"1%c", *Index - 'a' + '0'); + Status = CatPrint (&MappingItem->Csd, L"1%c", *Index - 'a' + '0'); break; case 'A': @@ -252,9 +279,13 @@ AppendCSDStr ( case 'D': case 'E': case 'F': - CatPrint (&MappingItem->Csd, L"1%c", *Index - 'A' + '0'); + Status = CatPrint (&MappingItem->Csd, L"1%c", *Index - 'A' + '0'); break; } + + if (EFI_ERROR (Status)) { + return Status; + } } } else { for (Index = Str; *Index != 0; Index++) { @@ -264,11 +295,15 @@ 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'); + Status = CatPrint (&MappingItem->Csd, L"%c", *Index - '0' + 'a'); } else if (*Index >= 'a' && *Index <= 'f') { - CatPrint (&MappingItem->Csd, L"%c", *Index - 'a' + 'k'); + Status = CatPrint (&MappingItem->Csd, L"%c", *Index - 'a' + 'k'); } else if (*Index >= 'A' && *Index <= 'F') { - CatPrint (&MappingItem->Csd, L"%c", *Index - 'A' + 'k'); + Status = CatPrint (&MappingItem->Csd, L"%c", *Index - 'A' + 'k'); + } + + if (EFI_ERROR (Status)) { + return Status; } } } @@ -284,11 +319,10 @@ AppendCSDStr ( @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. + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ EFI_STATUS -EFIAPI AppendCSDGuid ( DEVICE_CONSIST_MAPPING_INFO *MappingItem, EFI_GUID *Guid @@ -296,9 +330,7 @@ AppendCSDGuid ( { CHAR16 Buffer[64]; - if (Guid == NULL || MappingItem == NULL) { - return (EFI_INVALID_PARAMETER); - } + ASSERT (Guid != NULL && MappingItem != NULL); UnicodeSPrint ( Buffer, @@ -307,9 +339,7 @@ AppendCSDGuid ( Guid ); - AppendCSDStr (MappingItem, Buffer); - - return (EFI_SUCCESS); + return AppendCSDStr (MappingItem, Buffer); } /** @@ -422,12 +452,16 @@ DevPathCompareDefault ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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; @@ -440,7 +474,7 @@ DevPathSerialHardDrive ( MappingItem->Mtd = MTDTypeHardDisk; } - AppendCSDNum (MappingItem, Hd->PartitionNumber); + return AppendCSDNum (MappingItem, Hd->PartitionNumber); } /** @@ -448,12 +482,16 @@ DevPathSerialHardDrive ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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; @@ -462,7 +500,7 @@ DevPathSerialAtapi ( ASSERT(MappingItem != NULL); Atapi = (ATAPI_DEVICE_PATH *) DevicePathNode; - AppendCSDNum (MappingItem, (Atapi->PrimarySecondary * 2 + Atapi->SlaveMaster)); + return AppendCSDNum (MappingItem, (Atapi->PrimarySecondary * 2 + Atapi->SlaveMaster)); } /** @@ -470,12 +508,16 @@ DevPathSerialAtapi ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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; @@ -485,7 +527,7 @@ DevPathSerialCdRom ( Cd = (CDROM_DEVICE_PATH *) DevicePathNode; MappingItem->Mtd = MTDTypeCDRom; - AppendCSDNum (MappingItem, Cd->BootEntry); + return AppendCSDNum (MappingItem, Cd->BootEntry); } /** @@ -493,22 +535,30 @@ DevPathSerialCdRom ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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 ) { + EFI_STATUS Status; FIBRECHANNEL_DEVICE_PATH *Fibre; ASSERT(DevicePathNode != NULL); ASSERT(MappingItem != NULL); Fibre = (FIBRECHANNEL_DEVICE_PATH *) DevicePathNode; - AppendCSDNum (MappingItem, Fibre->WWN); - AppendCSDNum (MappingItem, Fibre->Lun); + Status = AppendCSDNum (MappingItem, Fibre->WWN); + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, Fibre->Lun); + } + return Status; } /** @@ -516,24 +566,36 @@ DevPathSerialFibre ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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; + EFI_STATUS Status; + UART_DEVICE_PATH *Uart; ASSERT(DevicePathNode != NULL); ASSERT(MappingItem != NULL); Uart = (UART_DEVICE_PATH *) DevicePathNode; - AppendCSDNum (MappingItem, Uart->BaudRate); - AppendCSDNum (MappingItem, Uart->DataBits); - AppendCSDNum (MappingItem, Uart->Parity); - AppendCSDNum (MappingItem, Uart->StopBits); + Status = AppendCSDNum (MappingItem, Uart->BaudRate); + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, Uart->DataBits); + } + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, Uart->Parity); + } + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, Uart->StopBits); + } + return Status; } /** @@ -541,22 +603,67 @@ DevPathSerialUart ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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); Usb = (USB_DEVICE_PATH *) DevicePathNode; - AppendCSDNum (MappingItem, Usb->ParentPortNumber); - AppendCSDNum (MappingItem, Usb->InterfaceNumber); + Status = AppendCSDNum (MappingItem, Usb->ParentPortNumber); + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, Usb->InterfaceNumber); + } + + if (EFI_ERROR (Status)) { + return Status; + } + + 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; + } + } + } + } + } + return Status; } /** @@ -564,32 +671,81 @@ DevPathSerialUsb ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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 ) { + EFI_STATUS Status; VENDOR_DEVICE_PATH *Vendor; SAS_DEVICE_PATH *Sas; + UINTN TargetNameLength; + UINTN Index; + CHAR16 *Buffer; + CHAR16 *NewBuffer; - if (DevicePathNode == NULL || MappingItem == NULL) { - return; - } + ASSERT(DevicePathNode != NULL); + ASSERT(MappingItem != NULL); Vendor = (VENDOR_DEVICE_PATH *) DevicePathNode; - AppendCSDGuid (MappingItem, &Vendor->Guid); + Status = AppendCSDGuid (MappingItem, &Vendor->Guid); + if (EFI_ERROR (Status)) { + return Status; + } 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); + Status = AppendCSDNum (MappingItem, Sas->SasAddress); + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, Sas->Lun); + } + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, Sas->DeviceTopology); + } + if (!EFI_ERROR (Status)) { + Status = 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)); + if (Buffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Build the string data + // + for (Index = 0; Index < TargetNameLength; Index++) { + NewBuffer = CatSPrint (Buffer, L"%02x", *((UINT8*)Vendor + sizeof (VENDOR_DEVICE_PATH) + Index)); + if (NewBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; + break; + } + Buffer = NewBuffer; + } + + // + // Append the new data block + // + if (!EFI_ERROR (Status)) { + Status = AppendCSDStr (MappingItem, Buffer); + } + + FreePool(Buffer); + } } + return Status; } /** @@ -597,12 +753,16 @@ DevPathSerialVendor ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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; @@ -611,7 +771,7 @@ DevPathSerialLun ( ASSERT(MappingItem != NULL); Lun = (DEVICE_LOGICAL_UNIT_DEVICE_PATH *) DevicePathNode; - AppendCSDNum (MappingItem, Lun->Lun); + return AppendCSDNum (MappingItem, Lun->Lun); } /** @@ -619,23 +779,33 @@ DevPathSerialLun ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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 ) { + EFI_STATUS Status; SATA_DEVICE_PATH *Sata; ASSERT(DevicePathNode != NULL); ASSERT(MappingItem != NULL); Sata = (SATA_DEVICE_PATH *) DevicePathNode; - AppendCSDNum (MappingItem, Sata->HBAPortNumber); - AppendCSDNum (MappingItem, Sata->PortMultiplierPortNumber); - AppendCSDNum (MappingItem, Sata->Lun); + Status = AppendCSDNum (MappingItem, Sata->HBAPortNumber); + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, Sata->PortMultiplierPortNumber); + } + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, Sata->Lun); + } + return Status; } /** @@ -643,21 +813,19 @@ DevPathSerialSata ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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. -// -/* + EFI_STATUS Status; ISCSI_DEVICE_PATH *IScsi; UINT8 *IScsiTargetName; CHAR16 *TargetName; @@ -667,24 +835,39 @@ 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]; + Status = EFI_SUCCESS; + + if (PcdGetBool(PcdShellDecodeIScsiMapNames)) { + IScsi = (ISCSI_DEVICE_PATH *) DevicePathNode; + Status = AppendCSDNum (MappingItem, IScsi->NetworkProtocol); + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, IScsi->LoginOption); + } + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, IScsi->Lun); + } + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, IScsi->TargetPortalGroupTag); + } + if (EFI_ERROR (Status)) { + return Status; + } + TargetNameLength = DevicePathNodeLength (DevicePathNode) - sizeof (ISCSI_DEVICE_PATH); + if (TargetNameLength > 0) { + TargetName = AllocateZeroPool ((TargetNameLength + 1) * sizeof (CHAR16)); + if (TargetName == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + IScsiTargetName = (UINT8 *) (IScsi + 1); + for (Index = 0; Index < TargetNameLength; Index++) { + TargetName[Index] = (CHAR16) IScsiTargetName[Index]; + } + Status = AppendCSDStr (MappingItem, TargetName); + FreePool (TargetName); } - AppendCSDStr (MappingItem, TargetName); - FreePool (TargetName); } } - */ + return Status; } /** @@ -692,12 +875,16 @@ DevPathSerialIScsi ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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; @@ -706,7 +893,7 @@ DevPathSerialI2O ( ASSERT(MappingItem != NULL); DevicePath_I20 = (I2O_DEVICE_PATH *) DevicePathNode; - AppendCSDNum (MappingItem, DevicePath_I20->Tid); + return AppendCSDNum (MappingItem, DevicePath_I20->Tid); } /** @@ -714,12 +901,16 @@ DevPathSerialI2O ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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; @@ -742,7 +933,7 @@ DevPathSerialMacAddr ( UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) Mac->MacAddress.Addr[Index]); } - AppendCSDStr (MappingItem, Buffer); + return AppendCSDStr (MappingItem, Buffer); } /** @@ -750,14 +941,19 @@ DevPathSerialMacAddr ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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 ) { + EFI_STATUS Status; INFINIBAND_DEVICE_PATH *InfiniBand; UINTN Index; CHAR16 Buffer[64]; @@ -771,10 +967,17 @@ DevPathSerialInfiniBand ( UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) InfiniBand->PortGid[Index]); } - AppendCSDStr (MappingItem, Buffer); - AppendCSDNum (MappingItem, InfiniBand->ServiceId); - AppendCSDNum (MappingItem, InfiniBand->TargetPortId); - AppendCSDNum (MappingItem, InfiniBand->DeviceId); + Status = AppendCSDStr (MappingItem, Buffer); + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, InfiniBand->ServiceId); + } + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, InfiniBand->TargetPortId); + } + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, InfiniBand->DeviceId); + } + return Status; } /** @@ -782,14 +985,19 @@ DevPathSerialInfiniBand ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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 ) { + EFI_STATUS Status; IPv4_DEVICE_PATH *Ip; CHAR16 Buffer[10]; @@ -806,19 +1014,26 @@ DevPathSerialIPv4 ( (UINTN) Ip->LocalIpAddress.Addr[2], (UINTN) Ip->LocalIpAddress.Addr[3] ); - AppendCSDStr (MappingItem, Buffer); - AppendCSDNum (MappingItem, Ip->LocalPort); - UnicodeSPrint ( - Buffer, - 0, - L"%02x%02x%02x%02x", - (UINTN) Ip->RemoteIpAddress.Addr[0], - (UINTN) Ip->RemoteIpAddress.Addr[1], - (UINTN) Ip->RemoteIpAddress.Addr[2], - (UINTN) Ip->RemoteIpAddress.Addr[3] - ); - AppendCSDStr (MappingItem, Buffer); - AppendCSDNum (MappingItem, Ip->RemotePort); + Status = AppendCSDStr (MappingItem, Buffer); + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, Ip->LocalPort); + } + if (!EFI_ERROR (Status)) { + UnicodeSPrint ( + Buffer, + 0, + L"%02x%02x%02x%02x", + (UINTN) Ip->RemoteIpAddress.Addr[0], + (UINTN) Ip->RemoteIpAddress.Addr[1], + (UINTN) Ip->RemoteIpAddress.Addr[2], + (UINTN) Ip->RemoteIpAddress.Addr[3] + ); + Status = AppendCSDStr (MappingItem, Buffer); + } + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, Ip->RemotePort); + } + return Status; } /** @@ -826,14 +1041,19 @@ DevPathSerialIPv4 ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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 ) { + EFI_STATUS Status; IPv6_DEVICE_PATH *Ip; UINTN Index; CHAR16 Buffer[64]; @@ -847,14 +1067,21 @@ DevPathSerialIPv6 ( UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) Ip->LocalIpAddress.Addr[Index]); } - AppendCSDStr (MappingItem, Buffer); - AppendCSDNum (MappingItem, Ip->LocalPort); - for (Index = 0, PBuffer = Buffer; Index < 16; Index++, PBuffer += 2) { - UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) Ip->RemoteIpAddress.Addr[Index]); + Status = AppendCSDStr (MappingItem, Buffer); + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, Ip->LocalPort); } + if (!EFI_ERROR (Status)) { + for (Index = 0, PBuffer = Buffer; Index < 16; Index++, PBuffer += 2) { + UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) Ip->RemoteIpAddress.Addr[Index]); + } - AppendCSDStr (MappingItem, Buffer); - AppendCSDNum (MappingItem, Ip->RemotePort); + Status = AppendCSDStr (MappingItem, Buffer); + } + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, Ip->RemotePort); + } + return Status; } /** @@ -862,22 +1089,30 @@ DevPathSerialIPv6 ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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 ) { + EFI_STATUS Status; SCSI_DEVICE_PATH *Scsi; ASSERT(DevicePathNode != NULL); ASSERT(MappingItem != NULL); Scsi = (SCSI_DEVICE_PATH *) DevicePathNode; - AppendCSDNum (MappingItem, Scsi->Pun); - AppendCSDNum (MappingItem, Scsi->Lun); + Status = AppendCSDNum (MappingItem, Scsi->Pun); + if (!EFI_ERROR (Status)) { + Status = AppendCSDNum (MappingItem, Scsi->Lun); + } + return Status; } /** @@ -885,12 +1120,16 @@ DevPathSerialScsi ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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; @@ -901,7 +1140,7 @@ DevPathSerial1394 ( DevicePath_F1394 = (F1394_DEVICE_PATH *) DevicePathNode; UnicodeSPrint (Buffer, 0, L"%lx", DevicePath_F1394->Guid); - AppendCSDStr (MappingItem, Buffer); + return AppendCSDStr (MappingItem, Buffer); } /** @@ -909,12 +1148,16 @@ DevPathSerial1394 ( @param[in] DevicePathNode The node to get info on. @param[in] MappingItem The info item to populate. + @param[in] DevicePath Ignored. + + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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; @@ -926,9 +1169,10 @@ DevPathSerialAcpi ( if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) { if (EISA_ID_TO_NUM (Acpi->HID) == 0x0604) { MappingItem->Mtd = MTDTypeFloppy; - AppendCSDNum (MappingItem, Acpi->UID); + return AppendCSDNum (MappingItem, Acpi->UID); } } + return EFI_SUCCESS; } /** @@ -936,104 +1180,148 @@ DevPathSerialAcpi ( @param[in] DevicePathNode Ignored. @param[in] MappingItem Ignored. + @param[in] DevicePath Ignored. - Does nothing. + @retval EFI_OUT_OF_RESOURCES Out of resources. + @retval EFI_SUCCESS The appending was successful. **/ -VOID -EFIAPI +EFI_STATUS 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; + return EFI_SUCCESS; } 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 + } }; /** @@ -1045,7 +1333,6 @@ DEV_PATH_CONSIST_MAPPING_TABLE DevPathConsistMappingTable[] = { @retval FALSE The node is not Hi. **/ BOOLEAN -EFIAPI IsHIDevicePathNode ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode ) @@ -1082,7 +1369,6 @@ IsHIDevicePathNode ( @return the device path portion that is Hi. **/ EFI_DEVICE_PATH_PROTOCOL * -EFIAPI GetHIDevicePath ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) @@ -1137,27 +1423,28 @@ GetHIDevicePath ( @return EFI_SUCCESS Always returns success. **/ EFI_STATUS -EFIAPI GetDeviceConsistMappingInfo ( IN DEVICE_CONSIST_MAPPING_INFO *MappingItem, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { - VOID (EFIAPI *SerialFun) (EFI_DEVICE_PATH_PROTOCOL *, DEVICE_CONSIST_MAPPING_INFO *); - - UINTN Index; + EFI_STATUS Status; + 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 @@ -1166,14 +1453,12 @@ GetDeviceConsistMappingInfo ( break; } } - // - // If not found, use a generic function - // - if (!SerialFun) { - SerialFun = DevPathSerialDefault; - } - SerialFun (DevicePath, MappingItem); + Status = SerialFun (DevicePath, MappingItem, OriginalDevicePath); + if (EFI_ERROR (Status)) { + SHELL_FREE_NON_NULL (MappingItem->Csd.Str); + return Status; + } // // Next device path node @@ -1197,20 +1482,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 @@ -1233,6 +1520,21 @@ 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)) { + FreePool (HIDevicePath); + continue; + } + } + for (Index = 0; TempTable[Index] != NULL; Index++) { if (DevicePathCompare (&TempTable[Index], &HIDevicePath) == 0) { FreePool (HIDevicePath); @@ -1303,11 +1605,11 @@ ShellCommandConsistMappingGenMappingName ( IN EFI_DEVICE_PATH_PROTOCOL **Table ) { + EFI_STATUS Status; POOL_PRINT Str; DEVICE_CONSIST_MAPPING_INFO MappingInfo; EFI_DEVICE_PATH_PROTOCOL *HIDevicePath; UINTN Index; - UINTN NewSize; ASSERT(DevicePath != NULL); ASSERT(Table != NULL); @@ -1332,7 +1634,10 @@ ShellCommandConsistMappingGenMappingName ( MappingInfo.Mtd = MTDTypeUnknown; MappingInfo.Digital = FALSE; - GetDeviceConsistMappingInfo (&MappingInfo, DevicePath); + Status = GetDeviceConsistMappingInfo (&MappingInfo, DevicePath); + if (EFI_ERROR (Status)) { + return NULL; + } SetMem (&Str, sizeof (Str), 0); for (Index = 0; mMTDName[Index].MTDType != MTDTypeEnd; Index++) { @@ -1342,25 +1647,25 @@ ShellCommandConsistMappingGenMappingName ( } if (mMTDName[Index].MTDType != MTDTypeEnd) { - CatPrint (&Str, L"%s", mMTDName[Index].Name); + Status = 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); + if (!EFI_ERROR (Status)) { + Status = CatPrint (&Str, L"%d", (UINTN) MappingInfo.Hi); + } + if (!EFI_ERROR (Status) && MappingInfo.Csd.Str != NULL) { + Status = CatPrint (&Str, L"%s", MappingInfo.Csd.Str); FreePool (MappingInfo.Csd.Str); } - if (Str.Str != NULL) { - CatPrint (&Str, L":"); + if (!EFI_ERROR (Status) && Str.Str != NULL) { + Status = CatPrint (&Str, L":"); } - - NewSize = (Str.Len + 1) * sizeof (CHAR16); - Str.Str = ReallocatePool (Str.Len, NewSize, Str.Str); - if (Str.Str == NULL) { - return (NULL); + if (EFI_ERROR (Status)) { + SHELL_FREE_NON_NULL (Str.Str); + return NULL; } - Str.Str[Str.Len] = CHAR_NULL; + return Str.Str; }