]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Follow UEFI spec to convert unrecognized device path structure from/to hex dump text.
authorRuiyu Ni <ruiyu.ni@intel.com>
Wed, 15 Jan 2014 07:51:22 +0000 (07:51 +0000)
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 15 Jan 2014 07:51:22 +0000 (07:51 +0000)
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

MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.h

index 8943191bd4f35913f987c0181d94aa269c2fc4ae..008ec0b96c7480beb64d1c980c99230e52b5fdf7 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   DevicePathFromText protocol as defined in the UEFI 2.0 specification.\r
 \r
-Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -534,6 +534,79 @@ StrToAscii (
   *AsciiStr = Dest + 1;\r
 }\r
 \r
+/**\r
+  Converts a generic text device path node to device path structure.\r
+\r
+  @param Type            The type of the device path node.\r
+  @param TextDeviceNode  The input text device path node.\r
+\r
+  @return A pointer to device path structure.\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextGenericPath (\r
+  IN UINT8  Type,\r
+  IN CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL *Node;\r
+  CHAR16                   *SubtypeStr;\r
+  CHAR16                   *DataStr;\r
+  UINTN                    DataLength;\r
+\r
+  SubtypeStr = GetNextParamStr (&TextDeviceNode);\r
+  DataStr    = GetNextParamStr (&TextDeviceNode);\r
+\r
+  if (DataStr == NULL) {\r
+    DataLength = 0;\r
+  } else {\r
+    DataLength = StrLen (DataStr) / 2;\r
+  }\r
+  Node = CreateDeviceNode (\r
+           Type,\r
+           (UINT8) Strtoi (SubtypeStr),\r
+           (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + DataLength)\r
+           );\r
+\r
+  StrToBuf ((UINT8 *) (Node + 1), DataLength, DataStr);\r
+  return Node;\r
+}\r
+\r
+/**\r
+  Converts a generic text device path node to device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextPath (\r
+  IN CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                   *TypeStr;\r
+\r
+  TypeStr    = GetNextParamStr (&TextDeviceNode);\r
+\r
+  return DevPathFromTextGenericPath ((UINT8) Strtoi (TypeStr), TextDeviceNode);\r
+}\r
+\r
+/**\r
+  Converts a generic hardware text device path node to Hardware device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to Hardware device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextHardwarePath (\r
+  IN CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return DevPathFromTextGenericPath (HARDWARE_DEVICE_PATH, TextDeviceNode);\r
+}\r
+\r
 /**\r
   Converts a text device path node to Hardware PCI device path structure.\r
 \r
@@ -718,6 +791,22 @@ DevPathFromTextCtrl (
   return (EFI_DEVICE_PATH_PROTOCOL *) Controller;\r
 }\r
 \r
+/**\r
+  Converts a generic ACPI text device path node to ACPI device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to ACPI device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextAcpiPath (\r
+  IN CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return DevPathFromTextGenericPath (ACPI_DEVICE_PATH, TextDeviceNode);\r
+}\r
+\r
 /**\r
   Converts a string to EisaId.\r
 \r
@@ -1045,6 +1134,22 @@ DevPathFromTextAcpiAdr (
   return (EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr;\r
 }\r
 \r
+/**\r
+  Converts a generic messaging text device path node to messaging device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to messaging device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextMsg (\r
+  IN CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return DevPathFromTextGenericPath (MESSAGING_DEVICE_PATH, TextDeviceNode);\r
+}\r
+\r
 /**\r
   Converts a text device path node to Parallel Port device path structure.\r
 \r
@@ -2520,6 +2625,22 @@ DevPathFromTextVlan (
   return (EFI_DEVICE_PATH_PROTOCOL *) Vlan;\r
 }\r
 \r
+/**\r
+  Converts a media text device path node to media device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to media device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextMediaPath (\r
+  IN CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return DevPathFromTextGenericPath (MEDIA_DEVICE_PATH, TextDeviceNode);\r
+}\r
+\r
 /**\r
   Converts a text device path node to HD device path structure.\r
 \r
@@ -2775,6 +2896,23 @@ DevPathFromTextRelativeOffsetRange (
   return (EFI_DEVICE_PATH_PROTOCOL *) Offset;\r
 }\r
 \r
+\r
+/**\r
+  Converts a BBS text device path node to BBS device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to BBS device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextBbsPath (\r
+  IN CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return DevPathFromTextGenericPath (BBS_DEVICE_PATH, TextDeviceNode);\r
+}\r
+\r
 /**\r
   Converts a text device path node to BIOS Boot Specification device path structure.\r
 \r
@@ -2862,11 +3000,16 @@ DevPathFromTextSata (
 }\r
 \r
 GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevPathFromTextTable[] = {\r
+  {L"Path",                    DevPathFromTextPath                    },\r
+\r
+  {L"HardwarePath",            DevPathFromTextHardwarePath            },\r
   {L"Pci",                     DevPathFromTextPci                     },\r
   {L"PcCard",                  DevPathFromTextPcCard                  },\r
   {L"MemoryMapped",            DevPathFromTextMemoryMapped            },\r
   {L"VenHw",                   DevPathFromTextVenHw                   },\r
   {L"Ctrl",                    DevPathFromTextCtrl                    },\r
+\r
+  {L"AcpiPath",                DevPathFromTextAcpiPath                },\r
   {L"Acpi",                    DevPathFromTextAcpi                    },\r
   {L"PciRoot",                 DevPathFromTextPciRoot                 },\r
   {L"PcieRoot",                DevPathFromTextPcieRoot                },\r
@@ -2877,6 +3020,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP
   {L"AcpiEx",                  DevPathFromTextAcpiEx                  },\r
   {L"AcpiExp",                 DevPathFromTextAcpiExp                 },\r
   {L"AcpiAdr",                 DevPathFromTextAcpiAdr                 },\r
+\r
+  {L"Msg",                     DevPathFromTextMsg                     },\r
   {L"Ata",                     DevPathFromTextAta                     },\r
   {L"Scsi",                    DevPathFromTextScsi                    },\r
   {L"Fibre",                   DevPathFromTextFibre                   },\r
@@ -2918,6 +3063,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP
   {L"Unit",                    DevPathFromTextUnit                    },\r
   {L"iSCSI",                   DevPathFromTextiSCSI                   },\r
   {L"Vlan",                    DevPathFromTextVlan                    },\r
+\r
+  {L"MediaPath",               DevPathFromTextMediaPath               },\r
   {L"HD",                      DevPathFromTextHD                      },\r
   {L"CDROM",                   DevPathFromTextCDROM                   },\r
   {L"VenMedia",                DevPathFromTextVenMedia                },\r
@@ -2925,6 +3072,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP
   {L"Fv",                      DevPathFromTextFv                      },\r
   {L"FvFile",                  DevPathFromTextFvFile                  },\r
   {L"Offset",                  DevPathFromTextRelativeOffsetRange     },\r
+\r
+  {L"BbsPath",                 DevPathFromTextBbsPath                 },\r
   {L"BBS",                     DevPathFromTextBBS                     },\r
   {L"Sata",                    DevPathFromTextSata                    },\r
   {NULL, NULL}\r
index eebdbf2394276bbdb117258144f8561c49afd4cd..9b1ca8e2829c172a4b51e05390390b223041c084 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   DevicePathToText protocol as defined in the UEFI 2.0 specification.\r
 \r
-Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -1755,6 +1755,15 @@ DevPathToTextEndInstance (
   UefiDevicePathLibCatPrint (Str, L",");\r
 }\r
 \r
+GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_GENERIC_TABLE mUefiDevicePathLibToTextTableGeneric[] = {\r
+  {HARDWARE_DEVICE_PATH,  L"HardwarePath"   },\r
+  {ACPI_DEVICE_PATH,      L"AcpiPath"       },\r
+  {MESSAGING_DEVICE_PATH, L"Msg"            },\r
+  {MEDIA_DEVICE_PATH,     L"MediaPath"      },\r
+  {BBS_DEVICE_PATH,       L"BbsPath"        },\r
+  {0, NULL}\r
+};\r
+\r
 /**\r
   Converts an unknown device path structure to its string representative.\r
 \r
@@ -1769,17 +1778,48 @@ DevPathToTextEndInstance (
 \r
 **/\r
 VOID\r
-DevPathToTextNodeUnknown (\r
+DevPathToTextNodeGeneric (\r
   IN OUT POOL_PRINT  *Str,\r
   IN VOID            *DevPath,\r
   IN BOOLEAN         DisplayOnly,\r
   IN BOOLEAN         AllowShortcuts\r
   )\r
 {\r
-  UefiDevicePathLibCatPrint (Str, L"?");\r
+  EFI_DEVICE_PATH_PROTOCOL *Node;\r
+  UINTN                    Index;\r
+\r
+  Node = DevPath;\r
+\r
+  for (Index = 0; mUefiDevicePathLibToTextTableGeneric[Index].Text != NULL; Index++) {\r
+    if (DevicePathType (Node) == mUefiDevicePathLibToTextTableGeneric[Index].Type) {\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (mUefiDevicePathLibToTextTableGeneric[Index].Text == NULL) {\r
+    //\r
+    // It's a node whose type cannot be recognized\r
+    //\r
+    UefiDevicePathLibCatPrint (Str, L"Path(%d,%d", DevicePathType (Node), DevicePathSubType (Node));\r
+  } else {\r
+    //\r
+    // It's a node whose type can be recognized\r
+    //\r
+    UefiDevicePathLibCatPrint (Str, L"%s(%d", mUefiDevicePathLibToTextTableGeneric[Index].Text, DevicePathSubType (Node));\r
+  }\r
+\r
+  Index = sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
+  if (Index < DevicePathNodeLength (Node)) {\r
+    UefiDevicePathLibCatPrint (Str, L",");\r
+    for (; Index < DevicePathNodeLength (Node); Index++) {\r
+      UefiDevicePathLibCatPrint (Str, L"%02x", ((UINT8 *) Node)[Index]);\r
+    }\r
+  }\r
+\r
+  UefiDevicePathLibCatPrint (Str, L")");\r
 }\r
 \r
-GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePathLibDevPathToTextTable[] = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePathLibToTextTable[] = {\r
   {HARDWARE_DEVICE_PATH,  HW_PCI_DP,                        DevPathToTextPci            },\r
   {HARDWARE_DEVICE_PATH,  HW_PCCARD_DP,                     DevPathToTextPccard         },\r
   {HARDWARE_DEVICE_PATH,  HW_MEMMAP_DP,                     DevPathToTextMemMap         },\r
@@ -1858,12 +1898,12 @@ UefiDevicePathLibConvertDeviceNodeToText (
   // Process the device path node\r
   // If not found, use a generic function\r
   //\r
-  ToText = DevPathToTextNodeUnknown;\r
-  for (Index = 0; mUefiDevicePathLibDevPathToTextTable[Index].Function != NULL; Index++) {\r
-    if (DevicePathType (DeviceNode) == mUefiDevicePathLibDevPathToTextTable[Index].Type &&\r
-        DevicePathSubType (DeviceNode) == mUefiDevicePathLibDevPathToTextTable[Index].SubType\r
+  ToText = DevPathToTextNodeGeneric;\r
+  for (Index = 0; mUefiDevicePathLibToTextTable[Index].Function != NULL; Index++) {\r
+    if (DevicePathType (DeviceNode) == mUefiDevicePathLibToTextTable[Index].Type &&\r
+        DevicePathSubType (DeviceNode) == mUefiDevicePathLibToTextTable[Index].SubType\r
         ) {\r
-      ToText = mUefiDevicePathLibDevPathToTextTable[Index].Function;\r
+      ToText = mUefiDevicePathLibToTextTable[Index].Function;\r
       break;\r
     }\r
   }\r
@@ -1921,13 +1961,13 @@ UefiDevicePathLibConvertDevicePathToText (
     // Find the handler to dump this device path node\r
     // If not found, use a generic function\r
     //\r
-    ToText = DevPathToTextNodeUnknown;\r
-    for (Index = 0; mUefiDevicePathLibDevPathToTextTable[Index].Function != NULL; Index += 1) {\r
+    ToText = DevPathToTextNodeGeneric;\r
+    for (Index = 0; mUefiDevicePathLibToTextTable[Index].Function != NULL; Index += 1) {\r
 \r
-      if (DevicePathType (Node) == mUefiDevicePathLibDevPathToTextTable[Index].Type &&\r
-          DevicePathSubType (Node) == mUefiDevicePathLibDevPathToTextTable[Index].SubType\r
+      if (DevicePathType (Node) == mUefiDevicePathLibToTextTable[Index].Type &&\r
+          DevicePathSubType (Node) == mUefiDevicePathLibToTextTable[Index].SubType\r
           ) {\r
-        ToText = mUefiDevicePathLibDevPathToTextTable[Index].Function;\r
+        ToText = mUefiDevicePathLibToTextTable[Index].Function;\r
         break;\r
       }\r
     }\r
index a7ed53189be5085373193b098efd878e652df3b2..233844cfcc287caac3262f9cd5d0c44ef336bfc1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Definition for Device Path library.\r
 \r
-Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -68,6 +68,11 @@ typedef struct {
   DEVICE_PATH_TO_TEXT  Function;\r
 } DEVICE_PATH_TO_TEXT_TABLE;\r
 \r
+typedef struct {\r
+  UINT8                Type;\r
+  CHAR16               *Text;\r
+} DEVICE_PATH_TO_TEXT_GENERIC_TABLE;\r
+\r
 typedef struct {\r
   CHAR16                    *DevicePathNodeText;\r
   DEVICE_PATH_FROM_TEXT     Function;\r