Follow UEFI spec to convert unrecognized device path structure from/to hex dump text.

Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15119 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Ruiyu Ni 2014-01-15 07:51:22 +00:00 committed by niruiyu
parent 875670e2c6
commit 5d6a5aee0b
3 changed files with 210 additions and 16 deletions

View File

@ -1,7 +1,7 @@
/** @file
DevicePathFromText protocol as defined in the UEFI 2.0 specification.
Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>
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}

View File

@ -1,7 +1,7 @@
/** @file
DevicePathToText protocol as defined in the UEFI 2.0 specification.
Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>
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;
}
}
GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePathLibDevPathToTextTable[] = {
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 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;
}
}

View File

@ -1,7 +1,7 @@
/** @file
Definition for Device Path library.
Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>
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;