From 5d6a5aee0ba4231fe0227c7c08e4203e4ad6d377 Mon Sep 17 00:00:00 2001 From: Ruiyu Ni Date: Wed, 15 Jan 2014 07:51:22 +0000 Subject: [PATCH] Follow UEFI spec to convert unrecognized device path structure from/to hex dump text. Signed-off-by: Ruiyu Ni Reviewed-by: Feng Tian git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15119 6f19259b-4bc3-4df7-8a09-765794883524 --- .../UefiDevicePathLib/DevicePathFromText.c | 151 +++++++++++++++++- .../UefiDevicePathLib/DevicePathToText.c | 68 ++++++-- .../UefiDevicePathLib/UefiDevicePathLib.h | 7 +- 3 files changed, 210 insertions(+), 16 deletions(-) diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c index 8943191bd4..008ec0b96c 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c @@ -1,7 +1,7 @@ /** @file DevicePathFromText protocol as defined in the UEFI 2.0 specification. -Copyright (c) 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2013 - 2014, 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 @@ -534,6 +534,79 @@ StrToAscii ( *AsciiStr = Dest + 1; } +/** + Converts a generic text device path node to device path structure. + + @param Type The type of the device path node. + @param TextDeviceNode The input text device path node. + + @return A pointer to device path structure. +**/ +EFI_DEVICE_PATH_PROTOCOL * +DevPathFromTextGenericPath ( + IN UINT8 Type, + IN CHAR16 *TextDeviceNode + ) +{ + EFI_DEVICE_PATH_PROTOCOL *Node; + CHAR16 *SubtypeStr; + CHAR16 *DataStr; + UINTN DataLength; + + SubtypeStr = GetNextParamStr (&TextDeviceNode); + DataStr = GetNextParamStr (&TextDeviceNode); + + if (DataStr == NULL) { + DataLength = 0; + } else { + DataLength = StrLen (DataStr) / 2; + } + Node = CreateDeviceNode ( + Type, + (UINT8) Strtoi (SubtypeStr), + (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + DataLength) + ); + + StrToBuf ((UINT8 *) (Node + 1), DataLength, DataStr); + return Node; +} + +/** + Converts a generic text device path node to device path structure. + + @param TextDeviceNode The input Text device path node. + + @return A pointer to device path structure. + +**/ +EFI_DEVICE_PATH_PROTOCOL * +DevPathFromTextPath ( + IN CHAR16 *TextDeviceNode + ) +{ + CHAR16 *TypeStr; + + TypeStr = GetNextParamStr (&TextDeviceNode); + + return DevPathFromTextGenericPath ((UINT8) Strtoi (TypeStr), TextDeviceNode); +} + +/** + Converts a generic hardware text device path node to Hardware device path structure. + + @param TextDeviceNode The input Text device path node. + + @return A pointer to Hardware device path structure. + +**/ +EFI_DEVICE_PATH_PROTOCOL * +DevPathFromTextHardwarePath ( + IN CHAR16 *TextDeviceNode + ) +{ + return DevPathFromTextGenericPath (HARDWARE_DEVICE_PATH, TextDeviceNode); +} + /** Converts a text device path node to Hardware PCI device path structure. @@ -718,6 +791,22 @@ DevPathFromTextCtrl ( return (EFI_DEVICE_PATH_PROTOCOL *) Controller; } +/** + Converts a generic ACPI text device path node to ACPI device path structure. + + @param TextDeviceNode The input Text device path node. + + @return A pointer to ACPI device path structure. + +**/ +EFI_DEVICE_PATH_PROTOCOL * +DevPathFromTextAcpiPath ( + IN CHAR16 *TextDeviceNode + ) +{ + return DevPathFromTextGenericPath (ACPI_DEVICE_PATH, TextDeviceNode); +} + /** Converts a string to EisaId. @@ -1045,6 +1134,22 @@ DevPathFromTextAcpiAdr ( return (EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr; } +/** + Converts a generic messaging text device path node to messaging device path structure. + + @param TextDeviceNode The input Text device path node. + + @return A pointer to messaging device path structure. + +**/ +EFI_DEVICE_PATH_PROTOCOL * +DevPathFromTextMsg ( + IN CHAR16 *TextDeviceNode + ) +{ + return DevPathFromTextGenericPath (MESSAGING_DEVICE_PATH, TextDeviceNode); +} + /** Converts a text device path node to Parallel Port device path structure. @@ -2520,6 +2625,22 @@ DevPathFromTextVlan ( return (EFI_DEVICE_PATH_PROTOCOL *) Vlan; } +/** + Converts a media text device path node to media device path structure. + + @param TextDeviceNode The input Text device path node. + + @return A pointer to media device path structure. + +**/ +EFI_DEVICE_PATH_PROTOCOL * +DevPathFromTextMediaPath ( + IN CHAR16 *TextDeviceNode + ) +{ + return DevPathFromTextGenericPath (MEDIA_DEVICE_PATH, TextDeviceNode); +} + /** Converts a text device path node to HD device path structure. @@ -2775,6 +2896,23 @@ DevPathFromTextRelativeOffsetRange ( return (EFI_DEVICE_PATH_PROTOCOL *) Offset; } + +/** + Converts a BBS text device path node to BBS device path structure. + + @param TextDeviceNode The input Text device path node. + + @return A pointer to BBS device path structure. + +**/ +EFI_DEVICE_PATH_PROTOCOL * +DevPathFromTextBbsPath ( + IN CHAR16 *TextDeviceNode + ) +{ + return DevPathFromTextGenericPath (BBS_DEVICE_PATH, TextDeviceNode); +} + /** Converts a text device path node to BIOS Boot Specification device path structure. @@ -2862,11 +3000,16 @@ DevPathFromTextSata ( } GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevPathFromTextTable[] = { + {L"Path", DevPathFromTextPath }, + + {L"HardwarePath", DevPathFromTextHardwarePath }, {L"Pci", DevPathFromTextPci }, {L"PcCard", DevPathFromTextPcCard }, {L"MemoryMapped", DevPathFromTextMemoryMapped }, {L"VenHw", DevPathFromTextVenHw }, {L"Ctrl", DevPathFromTextCtrl }, + + {L"AcpiPath", DevPathFromTextAcpiPath }, {L"Acpi", DevPathFromTextAcpi }, {L"PciRoot", DevPathFromTextPciRoot }, {L"PcieRoot", DevPathFromTextPcieRoot }, @@ -2877,6 +3020,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP {L"AcpiEx", DevPathFromTextAcpiEx }, {L"AcpiExp", DevPathFromTextAcpiExp }, {L"AcpiAdr", DevPathFromTextAcpiAdr }, + + {L"Msg", DevPathFromTextMsg }, {L"Ata", DevPathFromTextAta }, {L"Scsi", DevPathFromTextScsi }, {L"Fibre", DevPathFromTextFibre }, @@ -2918,6 +3063,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP {L"Unit", DevPathFromTextUnit }, {L"iSCSI", DevPathFromTextiSCSI }, {L"Vlan", DevPathFromTextVlan }, + + {L"MediaPath", DevPathFromTextMediaPath }, {L"HD", DevPathFromTextHD }, {L"CDROM", DevPathFromTextCDROM }, {L"VenMedia", DevPathFromTextVenMedia }, @@ -2925,6 +3072,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP {L"Fv", DevPathFromTextFv }, {L"FvFile", DevPathFromTextFvFile }, {L"Offset", DevPathFromTextRelativeOffsetRange }, + + {L"BbsPath", DevPathFromTextBbsPath }, {L"BBS", DevPathFromTextBBS }, {L"Sata", DevPathFromTextSata }, {NULL, NULL} diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c index eebdbf2394..9b1ca8e282 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c @@ -1,7 +1,7 @@ /** @file DevicePathToText protocol as defined in the UEFI 2.0 specification. -Copyright (c) 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2013 - 2014, 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 @@ -1755,6 +1755,15 @@ DevPathToTextEndInstance ( UefiDevicePathLibCatPrint (Str, L","); } +GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_GENERIC_TABLE mUefiDevicePathLibToTextTableGeneric[] = { + {HARDWARE_DEVICE_PATH, L"HardwarePath" }, + {ACPI_DEVICE_PATH, L"AcpiPath" }, + {MESSAGING_DEVICE_PATH, L"Msg" }, + {MEDIA_DEVICE_PATH, L"MediaPath" }, + {BBS_DEVICE_PATH, L"BbsPath" }, + {0, NULL} +}; + /** Converts an unknown device path structure to its string representative. @@ -1769,17 +1778,48 @@ DevPathToTextEndInstance ( **/ VOID -DevPathToTextNodeUnknown ( +DevPathToTextNodeGeneric ( IN OUT POOL_PRINT *Str, IN VOID *DevPath, IN BOOLEAN DisplayOnly, IN BOOLEAN AllowShortcuts ) { - UefiDevicePathLibCatPrint (Str, L"?"); + EFI_DEVICE_PATH_PROTOCOL *Node; + UINTN Index; + + Node = DevPath; + + for (Index = 0; mUefiDevicePathLibToTextTableGeneric[Index].Text != NULL; Index++) { + if (DevicePathType (Node) == mUefiDevicePathLibToTextTableGeneric[Index].Type) { + break; + } + } + + if (mUefiDevicePathLibToTextTableGeneric[Index].Text == NULL) { + // + // It's a node whose type cannot be recognized + // + UefiDevicePathLibCatPrint (Str, L"Path(%d,%d", DevicePathType (Node), DevicePathSubType (Node)); + } else { + // + // It's a node whose type can be recognized + // + UefiDevicePathLibCatPrint (Str, L"%s(%d", mUefiDevicePathLibToTextTableGeneric[Index].Text, DevicePathSubType (Node)); + } + + Index = sizeof (EFI_DEVICE_PATH_PROTOCOL); + if (Index < DevicePathNodeLength (Node)) { + UefiDevicePathLibCatPrint (Str, L","); + for (; Index < DevicePathNodeLength (Node); Index++) { + UefiDevicePathLibCatPrint (Str, L"%02x", ((UINT8 *) Node)[Index]); + } + } + + UefiDevicePathLibCatPrint (Str, L")"); } -GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePathLibDevPathToTextTable[] = { +GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePathLibToTextTable[] = { {HARDWARE_DEVICE_PATH, HW_PCI_DP, DevPathToTextPci }, {HARDWARE_DEVICE_PATH, HW_PCCARD_DP, DevPathToTextPccard }, {HARDWARE_DEVICE_PATH, HW_MEMMAP_DP, DevPathToTextMemMap }, @@ -1858,12 +1898,12 @@ UefiDevicePathLibConvertDeviceNodeToText ( // Process the device path node // If not found, use a generic function // - ToText = DevPathToTextNodeUnknown; - for (Index = 0; mUefiDevicePathLibDevPathToTextTable[Index].Function != NULL; Index++) { - if (DevicePathType (DeviceNode) == mUefiDevicePathLibDevPathToTextTable[Index].Type && - DevicePathSubType (DeviceNode) == mUefiDevicePathLibDevPathToTextTable[Index].SubType + ToText = DevPathToTextNodeGeneric; + for (Index = 0; mUefiDevicePathLibToTextTable[Index].Function != NULL; Index++) { + if (DevicePathType (DeviceNode) == mUefiDevicePathLibToTextTable[Index].Type && + DevicePathSubType (DeviceNode) == mUefiDevicePathLibToTextTable[Index].SubType ) { - ToText = mUefiDevicePathLibDevPathToTextTable[Index].Function; + ToText = mUefiDevicePathLibToTextTable[Index].Function; break; } } @@ -1921,13 +1961,13 @@ UefiDevicePathLibConvertDevicePathToText ( // Find the handler to dump this device path node // If not found, use a generic function // - ToText = DevPathToTextNodeUnknown; - for (Index = 0; mUefiDevicePathLibDevPathToTextTable[Index].Function != NULL; Index += 1) { + ToText = DevPathToTextNodeGeneric; + for (Index = 0; mUefiDevicePathLibToTextTable[Index].Function != NULL; Index += 1) { - if (DevicePathType (Node) == mUefiDevicePathLibDevPathToTextTable[Index].Type && - DevicePathSubType (Node) == mUefiDevicePathLibDevPathToTextTable[Index].SubType + if (DevicePathType (Node) == mUefiDevicePathLibToTextTable[Index].Type && + DevicePathSubType (Node) == mUefiDevicePathLibToTextTable[Index].SubType ) { - ToText = mUefiDevicePathLibDevPathToTextTable[Index].Function; + ToText = mUefiDevicePathLibToTextTable[Index].Function; break; } } diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.h b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.h index a7ed53189b..233844cfcc 100644 --- a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.h +++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.h @@ -1,7 +1,7 @@ /** @file Definition for Device Path library. -Copyright (c) 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2013 - 2014, 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 @@ -68,6 +68,11 @@ typedef struct { DEVICE_PATH_TO_TEXT Function; } DEVICE_PATH_TO_TEXT_TABLE; +typedef struct { + UINT8 Type; + CHAR16 *Text; +} DEVICE_PATH_TO_TEXT_GENERIC_TABLE; + typedef struct { CHAR16 *DevicePathNodeText; DEVICE_PATH_FROM_TEXT Function;