]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Add DevicePath support for PCD values
authorYonghong Zhu <yonghong.zhu@intel.com>
Wed, 27 Dec 2017 06:12:29 +0000 (14:12 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Sun, 31 Dec 2017 05:10:49 +0000 (13:10 +0800)
Use C code parse device path to output hex string, and Python
run command when PCD Value need device path parse.

https://bugzilla.tianocore.org/show_bug.cgi?id=541

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
17 files changed:
BaseTools/BinWrappers/PosixLike/DevicePath [new file with mode: 0755]
BaseTools/Source/BinaryFiles.txt
BaseTools/Source/C/Common/CommonLib.c
BaseTools/Source/C/Common/CommonLib.h
BaseTools/Source/C/DevicePath/DevicePath.c [new file with mode: 0644]
BaseTools/Source/C/DevicePath/DevicePathFromText.c [new file with mode: 0644]
BaseTools/Source/C/DevicePath/DevicePathUtilities.c [new file with mode: 0644]
BaseTools/Source/C/DevicePath/GNUmakefile [new file with mode: 0644]
BaseTools/Source/C/DevicePath/Makefile [new file with mode: 0644]
BaseTools/Source/C/DevicePath/UefiDevicePathLib.c [new file with mode: 0644]
BaseTools/Source/C/DevicePath/UefiDevicePathLib.h [new file with mode: 0644]
BaseTools/Source/C/GNUmakefile
BaseTools/Source/C/Include/IndustryStandard/Bluetooth.h [new file with mode: 0644]
BaseTools/Source/C/Include/Protocol/DevicePath.h [new file with mode: 0644]
BaseTools/Source/C/Include/Protocol/DevicePathUtilities.h [new file with mode: 0644]
BaseTools/Source/C/Makefile
BaseTools/Source/Python/Common/Misc.py

diff --git a/BaseTools/BinWrappers/PosixLike/DevicePath b/BaseTools/BinWrappers/PosixLike/DevicePath
new file mode 100755 (executable)
index 0000000..0945d86
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+
+full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
+dir=$(dirname "$full_cmd")
+cmd=${full_cmd##*/}
+
+if [ -n "$WORKSPACE" ] && [ -e "$WORKSPACE/Conf/BaseToolsCBinaries" ]
+then
+  exec "$WORKSPACE/Conf/BaseToolsCBinaries/$cmd"
+elif [ -n "$WORKSPACE" ] && [ -e "$EDK_TOOLS_PATH/Source/C" ]
+then
+  if [ ! -e "$EDK_TOOLS_PATH/Source/C/bin/$cmd" ]
+  then
+    echo "BaseTools C Tool binary was not found ($cmd)"
+    echo "You may need to run:"
+    echo "  make -C $EDK_TOOLS_PATH/Source/C"
+  else
+    exec "$EDK_TOOLS_PATH/Source/C/bin/$cmd" "$@"
+  fi
+elif [ -e "$dir/../../Source/C/bin/$cmd" ]
+then
+  exec "$dir/../../Source/C/bin/$cmd" "$@"
+else
+  echo "Unable to find the real '$cmd' to run"
+  echo "This message was printed by"
+  echo "  $0"
+  exit 127
+fi
+
index 7b014a71e43674a7eb5b66ab87f8b43e1d55e1f4..a5273d4753d48c3f65d0154afbef77f6100b2437 100644 (file)
@@ -11,7 +11,7 @@
 # must ensure that files that are required by the cx_freeze frozen binaries are \r
 # present in the Bin\Win32 directory.\r
 #\r
-# Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>\r
 #\r
 # This program and the accompanying materials are licensed and made available under\r
 # the terms and conditions of the BSD License which accompanies this distribution.\r
@@ -59,6 +59,7 @@ UPT.exe
 VfrCompile.exe\r
 VolInfo.exe\r
 Pkcs7Sign.exe\r
+DevicePath.exe\r
 \r
 [ExtraFiles.Win32]\r
 TestSigningPrivateKey.pem\r
index 4a62bec85e03d3816a823de8331b035c5fa3b460..90cc578e619d3250a317261d3021276ad154b466 100644 (file)
@@ -24,6 +24,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "CommonLib.h"\r
 #include "EfiUtilityMsgs.h"\r
 \r
+#define SAFE_STRING_CONSTRAINT_CHECK(Expression, Status)  \\r
+  do { \\r
+    ASSERT (Expression); \\r
+    if (!(Expression)) { \\r
+      return Status; \\r
+    } \\r
+  } while (FALSE)\r
+\r
 VOID\r
 PeiZeroMem (\r
   IN VOID   *Buffer,\r
@@ -731,3 +739,1624 @@ Returns:
   return PathPointer;\r
 #endif\r
 }\r
+\r
+CHAR16\r
+InternalCharToUpper (\r
+        CHAR16                    Char\r
+  )\r
+{\r
+  if (Char >= L'a' && Char <= L'z') {\r
+    return (CHAR16) (Char - (L'a' - L'A'));\r
+  }\r
+\r
+  return Char;\r
+}\r
+\r
+UINTN\r
+StrnLenS (\r
+   CONST CHAR16              *String,\r
+   UINTN                     MaxSize\r
+  )\r
+{\r
+  UINTN     Length;\r
+\r
+  ASSERT (((UINTN) String & BIT0) == 0);\r
+\r
+  //\r
+  // If String is a null pointer or MaxSize is 0, then the StrnLenS function returns zero.\r
+  //\r
+  if ((String == NULL) || (MaxSize == 0)) {\r
+    return 0;\r
+  }\r
+\r
+  Length = 0;\r
+  while (String[Length] != 0) {\r
+    if (Length >= MaxSize - 1) {\r
+      return MaxSize;\r
+    }\r
+    Length++;\r
+  }\r
+  return Length;\r
+}\r
+\r
+\r
+VOID *\r
+InternalAllocatePool (\r
+   UINTN   AllocationSize\r
+  )\r
+{\r
+  VOID * Memory;\r
+\r
+  Memory = malloc(AllocationSize);\r
+  ASSERT(Memory != NULL);\r
+  return Memory;\r
+}\r
+\r
+\r
+VOID *\r
+InternalReallocatePool (\r
+   UINTN            OldSize,\r
+   UINTN            NewSize,\r
+   VOID             *OldBuffer  OPTIONAL\r
+  )\r
+{\r
+  VOID  *NewBuffer;\r
+\r
+  NewBuffer = AllocateZeroPool (NewSize);\r
+  if (NewBuffer != NULL && OldBuffer != NULL) {\r
+    memcpy (NewBuffer, OldBuffer, MIN (OldSize, NewSize));\r
+    free(OldBuffer);\r
+  }\r
+  return NewBuffer;\r
+}\r
+\r
+VOID *\r
+ReallocatePool (\r
+   UINTN  OldSize,\r
+   UINTN  NewSize,\r
+   VOID   *OldBuffer  OPTIONAL\r
+  )\r
+{\r
+  return InternalReallocatePool (OldSize, NewSize, OldBuffer);\r
+}\r
+\r
+/**\r
+  Returns the length of a Null-terminated Unicode string.\r
+\r
+  This function returns the number of Unicode characters in the Null-terminated\r
+  Unicode string specified by String.\r
+\r
+  If String is NULL, then ASSERT().\r
+  If String is not aligned on a 16-bit boundary, then ASSERT().\r
+  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
+  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
+  Null-terminator, then ASSERT().\r
+\r
+  @param  String  A pointer to a Null-terminated Unicode string.\r
+\r
+  @return The length of String.\r
+\r
+**/\r
+UINTN\r
+StrLen (\r
+  CONST CHAR16              *String\r
+  )\r
+{\r
+  UINTN   Length;\r
+\r
+  ASSERT (String != NULL);\r
+  ASSERT (((UINTN) String & BIT0) == 0);\r
+\r
+  for (Length = 0; *String != L'\0'; String++, Length++) {\r
+    //\r
+    // If PcdMaximumUnicodeStringLength is not zero,\r
+    // length should not more than PcdMaximumUnicodeStringLength\r
+    //\r
+  }\r
+  return Length;\r
+}\r
+\r
+BOOLEAN\r
+InternalSafeStringIsOverlap (\r
+  IN VOID    *Base1,\r
+  IN UINTN   Size1,\r
+  IN VOID    *Base2,\r
+  IN UINTN   Size2\r
+  )\r
+{\r
+  if ((((UINTN)Base1 >= (UINTN)Base2) && ((UINTN)Base1 < (UINTN)Base2 + Size2)) ||\r
+      (((UINTN)Base2 >= (UINTN)Base1) && ((UINTN)Base2 < (UINTN)Base1 + Size1))) {\r
+    return TRUE;\r
+  }\r
+  return FALSE;\r
+}\r
+\r
+BOOLEAN\r
+InternalSafeStringNoStrOverlap (\r
+  IN CHAR16  *Str1,\r
+  IN UINTN   Size1,\r
+  IN CHAR16  *Str2,\r
+  IN UINTN   Size2\r
+  )\r
+{\r
+  return !InternalSafeStringIsOverlap (Str1, Size1 * sizeof(CHAR16), Str2, Size2 * sizeof(CHAR16));\r
+}\r
+\r
+RETURN_STATUS\r
+StrDecimalToUintnS (\r
+    CONST CHAR16             *String,\r
+         CHAR16             **EndPointer,  OPTIONAL\r
+         UINTN              *Data\r
+  )\r
+{\r
+  ASSERT (((UINTN) String & BIT0) == 0);\r
+\r
+  //\r
+  // 1. Neither String nor Data shall be a null pointer.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);\r
+  SAFE_STRING_CONSTRAINT_CHECK ((Data != NULL), RETURN_INVALID_PARAMETER);\r
+\r
+  //\r
+  // 2. The length of String shall not be greater than RSIZE_MAX.\r
+  //\r
+  if (RSIZE_MAX != 0) {\r
+    SAFE_STRING_CONSTRAINT_CHECK ((StrnLenS (String, RSIZE_MAX + 1) <= RSIZE_MAX), RETURN_INVALID_PARAMETER);\r
+  }\r
+\r
+  if (EndPointer != NULL) {\r
+    *EndPointer = (CHAR16 *) String;\r
+  }\r
+\r
+  //\r
+  // Ignore the pad spaces (space or tab)\r
+  //\r
+  while ((*String == L' ') || (*String == L'\t')) {\r
+    String++;\r
+  }\r
+\r
+  //\r
+  // Ignore leading Zeros after the spaces\r
+  //\r
+  while (*String == L'0') {\r
+    String++;\r
+  }\r
+\r
+  *Data = 0;\r
+\r
+  while (InternalIsDecimalDigitCharacter (*String)) {\r
+    //\r
+    // If the number represented by String overflows according to the range\r
+    // defined by UINTN, then MAX_UINTN is stored in *Data and\r
+    // RETURN_UNSUPPORTED is returned.\r
+    //\r
+    if (*Data > ((MAX_UINTN - (*String - L'0')) / 10)) {\r
+      *Data = MAX_UINTN;\r
+      if (EndPointer != NULL) {\r
+        *EndPointer = (CHAR16 *) String;\r
+      }\r
+      return RETURN_UNSUPPORTED;\r
+    }\r
+\r
+    *Data = *Data * 10 + (*String - L'0');\r
+    String++;\r
+  }\r
+\r
+  if (EndPointer != NULL) {\r
+    *EndPointer = (CHAR16 *) String;\r
+  }\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Convert a Null-terminated Unicode decimal string to a value of type UINT64.\r
+\r
+  This function outputs a value of type UINT64 by interpreting the contents of\r
+  the Unicode string specified by String as a decimal number. The format of the\r
+  input Unicode string String is:\r
+\r
+                  [spaces] [decimal digits].\r
+\r
+  The valid decimal digit character is in the range [0-9]. The function will\r
+  ignore the pad space, which includes spaces or tab characters, before\r
+  [decimal digits]. The running zero in the beginning of [decimal digits] will\r
+  be ignored. Then, the function stops at the first character that is a not a\r
+  valid decimal character or a Null-terminator, whichever one comes first.\r
+\r
+  If String is NULL, then ASSERT().\r
+  If Data is NULL, then ASSERT().\r
+  If String is not aligned in a 16-bit boundary, then ASSERT().\r
+  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
+  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
+  Null-terminator, then ASSERT().\r
+\r
+  If String has no valid decimal digits in the above format, then 0 is stored\r
+  at the location pointed to by Data.\r
+  If the number represented by String exceeds the range defined by UINT64, then\r
+  MAX_UINT64 is stored at the location pointed to by Data.\r
+\r
+  If EndPointer is not NULL, a pointer to the character that stopped the scan\r
+  is stored at the location pointed to by EndPointer. If String has no valid\r
+  decimal digits right after the optional pad spaces, the value of String is\r
+  stored at the location pointed to by EndPointer.\r
+\r
+  @param  String                   Pointer to a Null-terminated Unicode string.\r
+  @param  EndPointer               Pointer to character that stops scan.\r
+  @param  Data                     Pointer to the converted value.\r
+\r
+  @retval RETURN_SUCCESS           Value is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+                                   If PcdMaximumUnicodeStringLength is not\r
+                                   zero, and String contains more than\r
+                                   PcdMaximumUnicodeStringLength Unicode\r
+                                   characters, not including the\r
+                                   Null-terminator.\r
+  @retval RETURN_UNSUPPORTED       If the number represented by String exceeds\r
+                                   the range defined by UINT64.\r
+\r
+**/\r
+RETURN_STATUS\r
+StrDecimalToUint64S (\r
+    CONST CHAR16             *String,\r
+         CHAR16             **EndPointer,  OPTIONAL\r
+         UINT64             *Data\r
+  )\r
+{\r
+  ASSERT (((UINTN) String & BIT0) == 0);\r
+\r
+  //\r
+  // 1. Neither String nor Data shall be a null pointer.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);\r
+  SAFE_STRING_CONSTRAINT_CHECK ((Data != NULL), RETURN_INVALID_PARAMETER);\r
+\r
+  //\r
+  // 2. The length of String shall not be greater than RSIZE_MAX.\r
+  //\r
+  if (RSIZE_MAX != 0) {\r
+    SAFE_STRING_CONSTRAINT_CHECK ((StrnLenS (String, RSIZE_MAX + 1) <= RSIZE_MAX), RETURN_INVALID_PARAMETER);\r
+  }\r
+\r
+  if (EndPointer != NULL) {\r
+    *EndPointer = (CHAR16 *) String;\r
+  }\r
+\r
+  //\r
+  // Ignore the pad spaces (space or tab)\r
+  //\r
+  while ((*String == L' ') || (*String == L'\t')) {\r
+    String++;\r
+  }\r
+\r
+  //\r
+  // Ignore leading Zeros after the spaces\r
+  //\r
+  while (*String == L'0') {\r
+    String++;\r
+  }\r
+\r
+  *Data = 0;\r
+\r
+  while (InternalIsDecimalDigitCharacter (*String)) {\r
+    //\r
+    // If the number represented by String overflows according to the range\r
+    // defined by UINT64, then MAX_UINT64 is stored in *Data and\r
+    // RETURN_UNSUPPORTED is returned.\r
+    //\r
+    if (*Data > ((MAX_UINT64 - (*String - L'0'))/10)) {\r
+      *Data = MAX_UINT64;\r
+      if (EndPointer != NULL) {\r
+        *EndPointer = (CHAR16 *) String;\r
+      }\r
+      return RETURN_UNSUPPORTED;\r
+    }\r
+\r
+    *Data = (*Data) * 10 + (*String - L'0');\r
+    String++;\r
+  }\r
+\r
+  if (EndPointer != NULL) {\r
+    *EndPointer = (CHAR16 *) String;\r
+  }\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Convert a Null-terminated Unicode hexadecimal string to a value of type\r
+  UINTN.\r
+\r
+  This function outputs a value of type UINTN by interpreting the contents of\r
+  the Unicode string specified by String as a hexadecimal number. The format of\r
+  the input Unicode string String is:\r
+\r
+                  [spaces][zeros][x][hexadecimal digits].\r
+\r
+  The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r
+  The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.\r
+  If "x" appears in the input string, it must be prefixed with at least one 0.\r
+  The function will ignore the pad space, which includes spaces or tab\r
+  characters, before [zeros], [x] or [hexadecimal digit]. The running zero\r
+  before [x] or [hexadecimal digit] will be ignored. Then, the decoding starts\r
+  after [x] or the first valid hexadecimal digit. Then, the function stops at\r
+  the first character that is a not a valid hexadecimal character or NULL,\r
+  whichever one comes first.\r
+\r
+  If String is NULL, then ASSERT().\r
+  If Data is NULL, then ASSERT().\r
+  If String is not aligned in a 16-bit boundary, then ASSERT().\r
+  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
+  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
+  Null-terminator, then ASSERT().\r
+\r
+  If String has no valid hexadecimal digits in the above format, then 0 is\r
+  stored at the location pointed to by Data.\r
+  If the number represented by String exceeds the range defined by UINTN, then\r
+  MAX_UINTN is stored at the location pointed to by Data.\r
+\r
+  If EndPointer is not NULL, a pointer to the character that stopped the scan\r
+  is stored at the location pointed to by EndPointer. If String has no valid\r
+  hexadecimal digits right after the optional pad spaces, the value of String\r
+  is stored at the location pointed to by EndPointer.\r
+\r
+  @param  String                   Pointer to a Null-terminated Unicode string.\r
+  @param  EndPointer               Pointer to character that stops scan.\r
+  @param  Data                     Pointer to the converted value.\r
+\r
+  @retval RETURN_SUCCESS           Value is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+                                   If PcdMaximumUnicodeStringLength is not\r
+                                   zero, and String contains more than\r
+                                   PcdMaximumUnicodeStringLength Unicode\r
+                                   characters, not including the\r
+                                   Null-terminator.\r
+  @retval RETURN_UNSUPPORTED       If the number represented by String exceeds\r
+                                   the range defined by UINTN.\r
+\r
+**/\r
+RETURN_STATUS\r
+StrHexToUintnS (\r
+    CONST CHAR16             *String,\r
+         CHAR16             **EndPointer,  OPTIONAL\r
+         UINTN              *Data\r
+  )\r
+{\r
+  ASSERT (((UINTN) String & BIT0) == 0);\r
+\r
+  //\r
+  // 1. Neither String nor Data shall be a null pointer.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);\r
+  SAFE_STRING_CONSTRAINT_CHECK ((Data != NULL), RETURN_INVALID_PARAMETER);\r
+\r
+  //\r
+  // 2. The length of String shall not be greater than RSIZE_MAX.\r
+  //\r
+  if (RSIZE_MAX != 0) {\r
+    SAFE_STRING_CONSTRAINT_CHECK ((StrnLenS (String, RSIZE_MAX + 1) <= RSIZE_MAX), RETURN_INVALID_PARAMETER);\r
+  }\r
+\r
+  if (EndPointer != NULL) {\r
+    *EndPointer = (CHAR16 *) String;\r
+  }\r
+\r
+  //\r
+  // Ignore the pad spaces (space or tab)\r
+  //\r
+  while ((*String == L' ') || (*String == L'\t')) {\r
+    String++;\r
+  }\r
+\r
+  //\r
+  // Ignore leading Zeros after the spaces\r
+  //\r
+  while (*String == L'0') {\r
+    String++;\r
+  }\r
+\r
+  if (InternalCharToUpper (*String) == L'X') {\r
+    if (*(String - 1) != L'0') {\r
+      *Data = 0;\r
+      return RETURN_SUCCESS;\r
+    }\r
+    //\r
+    // Skip the 'X'\r
+    //\r
+    String++;\r
+  }\r
+\r
+  *Data = 0;\r
+\r
+  while (InternalIsHexaDecimalDigitCharacter (*String)) {\r
+    //\r
+    // If the number represented by String overflows according to the range\r
+    // defined by UINTN, then MAX_UINTN is stored in *Data and\r
+    // RETURN_UNSUPPORTED is returned.\r
+    //\r
+    if (*Data > ((MAX_UINTN - InternalHexCharToUintn (*String)) >> 4)) {\r
+      *Data = MAX_UINTN;\r
+      if (EndPointer != NULL) {\r
+        *EndPointer = (CHAR16 *) String;\r
+      }\r
+      return RETURN_UNSUPPORTED;\r
+    }\r
+\r
+    *Data = (*Data << 4) + InternalHexCharToUintn (*String);\r
+    String++;\r
+  }\r
+\r
+  if (EndPointer != NULL) {\r
+    *EndPointer = (CHAR16 *) String;\r
+  }\r
+  return RETURN_SUCCESS;\r
+}\r
+RETURN_STATUS\r
+StrHexToUint64S (\r
+    CONST CHAR16             *String,\r
+         CHAR16             **EndPointer,  OPTIONAL\r
+         UINT64             *Data\r
+  )\r
+{\r
+  ASSERT (((UINTN) String & BIT0) == 0);\r
+\r
+  //\r
+  // 1. Neither String nor Data shall be a null pointer.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);\r
+  SAFE_STRING_CONSTRAINT_CHECK ((Data != NULL), RETURN_INVALID_PARAMETER);\r
+\r
+  //\r
+  // 2. The length of String shall not be greater than RSIZE_MAX.\r
+  //\r
+  if (RSIZE_MAX != 0) {\r
+    SAFE_STRING_CONSTRAINT_CHECK ((StrnLenS (String, RSIZE_MAX + 1) <= RSIZE_MAX), RETURN_INVALID_PARAMETER);\r
+  }\r
+\r
+  if (EndPointer != NULL) {\r
+    *EndPointer = (CHAR16 *) String;\r
+  }\r
+\r
+  //\r
+  // Ignore the pad spaces (space or tab)\r
+  //\r
+  while ((*String == L' ') || (*String == L'\t')) {\r
+    String++;\r
+  }\r
+\r
+  //\r
+  // Ignore leading Zeros after the spaces\r
+  //\r
+  while (*String == L'0') {\r
+    String++;\r
+  }\r
+\r
+  if (InternalCharToUpper (*String) == L'X') {\r
+    if (*(String - 1) != L'0') {\r
+      *Data = 0;\r
+      return RETURN_SUCCESS;\r
+    }\r
+    //\r
+    // Skip the 'X'\r
+    //\r
+    String++;\r
+  }\r
+\r
+  *Data = 0;\r
+\r
+  while (InternalIsHexaDecimalDigitCharacter (*String)) {\r
+    //\r
+    // If the number represented by String overflows according to the range\r
+    // defined by UINT64, then MAX_UINT64 is stored in *Data and\r
+    // RETURN_UNSUPPORTED is returned.\r
+    //\r
+    if (*Data > ((MAX_UINT64 - InternalHexCharToUintn (*String))>>4)) {\r
+      *Data = MAX_UINT64;\r
+      if (EndPointer != NULL) {\r
+        *EndPointer = (CHAR16 *) String;\r
+      }\r
+      return RETURN_UNSUPPORTED;\r
+    }\r
+\r
+    *Data =  ((*Data) << 4) + InternalHexCharToUintn (*String);\r
+    String++;\r
+  }\r
+\r
+  if (EndPointer != NULL) {\r
+    *EndPointer = (CHAR16 *) String;\r
+  }\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+UINT64\r
+StrDecimalToUint64 (\r
+  CONST CHAR16              *String\r
+  )\r
+{\r
+  UINT64     Result;\r
+\r
+  StrDecimalToUint64S (String, (CHAR16 **) NULL, &Result);\r
+  return Result;\r
+}\r
+\r
+\r
+UINT64\r
+StrHexToUint64 (\r
+  CONST CHAR16             *String\r
+  )\r
+{\r
+  UINT64    Result;\r
+\r
+  StrHexToUint64S (String, (CHAR16 **) NULL, &Result);\r
+  return Result;\r
+}\r
+\r
+UINTN\r
+StrDecimalToUintn (\r
+  CONST CHAR16              *String\r
+  )\r
+{\r
+  UINTN     Result;\r
+\r
+  StrDecimalToUintnS (String, (CHAR16 **) NULL, &Result);\r
+  return Result;\r
+}\r
+\r
+UINTN\r
+StrHexToUintn (\r
+  CONST CHAR16              *String\r
+  )\r
+{\r
+  UINTN     Result;\r
+\r
+  StrHexToUintnS (String, (CHAR16 **) NULL, &Result);\r
+  return Result;\r
+}\r
+\r
+UINTN\r
+StrSize (\r
+  CONST CHAR16              *String\r
+  )\r
+{\r
+  return (StrLen (String) + 1) * sizeof (*String);\r
+}\r
+\r
+\r
+UINT64\r
+ReadUnaligned64 (\r
+   CONST UINT64              *Buffer\r
+  )\r
+{\r
+  ASSERT (Buffer != NULL);\r
+\r
+  return *Buffer;\r
+}\r
+\r
+UINT64\r
+WriteUnaligned64 (\r
+   UINT64                    *Buffer,\r
+   UINT64                    Value\r
+  )\r
+{\r
+  ASSERT (Buffer != NULL);\r
+\r
+  return *Buffer = Value;\r
+}\r
+\r
+\r
+EFI_GUID *\r
+CopyGuid (\r
+   EFI_GUID         *DestinationGuid,\r
+   CONST EFI_GUID  *SourceGuid\r
+  )\r
+{\r
+  WriteUnaligned64 (\r
+    (UINT64*)DestinationGuid,\r
+    ReadUnaligned64 ((CONST UINT64*)SourceGuid)\r
+    );\r
+  WriteUnaligned64 (\r
+    (UINT64*)DestinationGuid + 1,\r
+    ReadUnaligned64 ((CONST UINT64*)SourceGuid + 1)\r
+    );\r
+  return DestinationGuid;\r
+}\r
+\r
+UINT16\r
+SwapBytes16 (\r
+  UINT16                    Value\r
+  )\r
+{\r
+  return (UINT16) ((Value<< 8) | (Value>> 8));\r
+}\r
+\r
+\r
+UINT32\r
+SwapBytes32 (\r
+  UINT32                    Value\r
+  )\r
+{\r
+  UINT32  LowerBytes;\r
+  UINT32  HigherBytes;\r
+\r
+  LowerBytes  = (UINT32) SwapBytes16 ((UINT16) Value);\r
+  HigherBytes = (UINT32) SwapBytes16 ((UINT16) (Value >> 16));\r
+  return (LowerBytes << 16 | HigherBytes);\r
+}\r
+\r
+BOOLEAN\r
+InternalIsDecimalDigitCharacter (\r
+  CHAR16                    Char\r
+  )\r
+{\r
+  return (BOOLEAN) (Char >= L'0' && Char <= L'9');\r
+}\r
+\r
+VOID *\r
+InternalAllocateCopyPool (\r
+   UINTN            AllocationSize,\r
+   CONST VOID       *Buffer\r
+  )\r
+{\r
+  VOID  *Memory;\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r
+\r
+  Memory = malloc (AllocationSize);\r
+  if (Memory != NULL) {\r
+     Memory = memcpy (Memory, Buffer, AllocationSize);\r
+  }\r
+  return Memory;\r
+}\r
+\r
+BOOLEAN\r
+InternalIsHexaDecimalDigitCharacter (\r
+  CHAR16                    Char\r
+  )\r
+{\r
+\r
+  return (BOOLEAN) (InternalIsDecimalDigitCharacter (Char) ||\r
+    (Char >= L'A' && Char <= L'F') ||\r
+    (Char >= L'a' && Char <= L'f'));\r
+}\r
+\r
+UINTN\r
+InternalHexCharToUintn (\r
+        CHAR16                    Char\r
+  )\r
+{\r
+  if (InternalIsDecimalDigitCharacter (Char)) {\r
+    return Char - L'0';\r
+  }\r
+\r
+  return (10 + InternalCharToUpper (Char) - L'A');\r
+}\r
+\r
+\r
+/**\r
+  Convert a Null-terminated Unicode hexadecimal string to a byte array.\r
+\r
+  This function outputs a byte array by interpreting the contents of\r
+  the Unicode string specified by String in hexadecimal format. The format of\r
+  the input Unicode string String is:\r
+\r
+                  [XX]*\r
+\r
+  X is a hexadecimal digit character in the range [0-9], [a-f] and [A-F].\r
+  The function decodes every two hexadecimal digit characters as one byte. The\r
+  decoding stops after Length of characters and outputs Buffer containing\r
+  (Length / 2) bytes.\r
+\r
+  If String is not aligned in a 16-bit boundary, then ASSERT().\r
+\r
+  If String is NULL, then ASSERT().\r
+\r
+  If Buffer is NULL, then ASSERT().\r
+\r
+  If Length is not multiple of 2, then ASSERT().\r
+\r
+  If PcdMaximumUnicodeStringLength is not zero and Length is greater than\r
+  PcdMaximumUnicodeStringLength, then ASSERT().\r
+\r
+  If MaxBufferSize is less than (Length / 2), then ASSERT().\r
+\r
+  @param  String                   Pointer to a Null-terminated Unicode string.\r
+  @param  Length                   The number of Unicode characters to decode.\r
+  @param  Buffer                   Pointer to the converted bytes array.\r
+  @param  MaxBufferSize            The maximum size of Buffer.\r
+\r
+  @retval RETURN_SUCCESS           Buffer is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+                                   If Length is not multiple of 2.\r
+                                   If PcdMaximumUnicodeStringLength is not zero,\r
+                                    and Length is greater than\r
+                                    PcdMaximumUnicodeStringLength.\r
+  @retval RETURN_UNSUPPORTED       If Length of characters from String contain\r
+                                    a character that is not valid hexadecimal\r
+                                    digit characters, or a Null-terminator.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If MaxBufferSize is less than (Length / 2).\r
+**/\r
+RETURN_STATUS\r
+StrHexToBytes (\r
+   CONST CHAR16       *String,\r
+   UINTN              Length,\r
+   UINT8              *Buffer,\r
+   UINTN              MaxBufferSize\r
+  )\r
+{\r
+  UINTN                  Index;\r
+\r
+  ASSERT (((UINTN) String & BIT0) == 0);\r
+\r
+  //\r
+  // 1. None of String or Buffer shall be a null pointer.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);\r
+  SAFE_STRING_CONSTRAINT_CHECK ((Buffer != NULL), RETURN_INVALID_PARAMETER);\r
+\r
+  //\r
+  // 2. Length shall not be greater than RSIZE_MAX.\r
+  //\r
+  if (RSIZE_MAX != 0) {\r
+    SAFE_STRING_CONSTRAINT_CHECK ((Length <= RSIZE_MAX), RETURN_INVALID_PARAMETER);\r
+  }\r
+\r
+  //\r
+  // 3. Length shall not be odd.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK (((Length & BIT0) == 0), RETURN_INVALID_PARAMETER);\r
+\r
+  //\r
+  // 4. MaxBufferSize shall equal to or greater than Length / 2.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK ((MaxBufferSize >= Length / 2), RETURN_BUFFER_TOO_SMALL);\r
+\r
+  //\r
+  // 5. String shall not contains invalid hexadecimal digits.\r
+  //\r
+  for (Index = 0; Index < Length; Index++) {\r
+    if (!InternalIsHexaDecimalDigitCharacter (String[Index])) {\r
+      break;\r
+    }\r
+  }\r
+  if (Index != Length) {\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Convert the hex string to bytes.\r
+  //\r
+  for(Index = 0; Index < Length; Index++) {\r
+\r
+    //\r
+    // For even characters, write the upper nibble for each buffer byte,\r
+    // and for even characters, the lower nibble.\r
+    //\r
+    if ((Index & BIT0) == 0) {\r
+      Buffer[Index / 2]  = (UINT8) InternalHexCharToUintn (String[Index]) << 4;\r
+    } else {\r
+      Buffer[Index / 2] |= (UINT8) InternalHexCharToUintn (String[Index]);\r
+    }\r
+  }\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Convert a Null-terminated Unicode GUID string to a value of type\r
+  EFI_GUID.\r
+\r
+  This function outputs a GUID value by interpreting the contents of\r
+  the Unicode string specified by String. The format of the input\r
+  Unicode string String consists of 36 characters, as follows:\r
+\r
+                  aabbccdd-eeff-gghh-iijj-kkllmmnnoopp\r
+\r
+  The pairs aa - pp are two characters in the range [0-9], [a-f] and\r
+  [A-F], with each pair representing a single byte hexadecimal value.\r
+\r
+  The mapping between String and the EFI_GUID structure is as follows:\r
+                  aa          Data1[24:31]\r
+                  bb          Data1[16:23]\r
+                  cc          Data1[8:15]\r
+                  dd          Data1[0:7]\r
+                  ee          Data2[8:15]\r
+                  ff          Data2[0:7]\r
+                  gg          Data3[8:15]\r
+                  hh          Data3[0:7]\r
+                  ii          Data4[0:7]\r
+                  jj          Data4[8:15]\r
+                  kk          Data4[16:23]\r
+                  ll          Data4[24:31]\r
+                  mm          Data4[32:39]\r
+                  nn          Data4[40:47]\r
+                  oo          Data4[48:55]\r
+                  pp          Data4[56:63]\r
+\r
+  If String is NULL, then ASSERT().\r
+  If Guid is NULL, then ASSERT().\r
+  If String is not aligned in a 16-bit boundary, then ASSERT().\r
+\r
+  @param  String                   Pointer to a Null-terminated Unicode string.\r
+  @param  Guid                     Pointer to the converted GUID.\r
+\r
+  @retval RETURN_SUCCESS           Guid is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+  @retval RETURN_UNSUPPORTED       If String is not as the above format.\r
+\r
+**/\r
+RETURN_STATUS\r
+StrToGuid (\r
+   CONST CHAR16       *String,\r
+   EFI_GUID           *Guid\r
+  )\r
+{\r
+  RETURN_STATUS          Status;\r
+  EFI_GUID               LocalGuid;\r
+\r
+  ASSERT (((UINTN) String & BIT0) == 0);\r
+\r
+  //\r
+  // 1. None of String or Guid shall be a null pointer.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);\r
+  SAFE_STRING_CONSTRAINT_CHECK ((Guid != NULL), RETURN_INVALID_PARAMETER);\r
+\r
+  //\r
+  // Get aabbccdd in big-endian.\r
+  //\r
+  Status = StrHexToBytes (String, 2 * sizeof (LocalGuid.Data1), (UINT8 *) &LocalGuid.Data1, sizeof (LocalGuid.Data1));\r
+  if (RETURN_ERROR (Status) || String[2 * sizeof (LocalGuid.Data1)] != L'-') {\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Convert big-endian to little-endian.\r
+  //\r
+  LocalGuid.Data1 = SwapBytes32 (LocalGuid.Data1);\r
+  String += 2 * sizeof (LocalGuid.Data1) + 1;\r
+\r
+  //\r
+  // Get eeff in big-endian.\r
+  //\r
+  Status = StrHexToBytes (String, 2 * sizeof (LocalGuid.Data2), (UINT8 *) &LocalGuid.Data2, sizeof (LocalGuid.Data2));\r
+  if (RETURN_ERROR (Status) || String[2 * sizeof (LocalGuid.Data2)] != L'-') {\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Convert big-endian to little-endian.\r
+  //\r
+  LocalGuid.Data2 = SwapBytes16 (LocalGuid.Data2);\r
+  String += 2 * sizeof (LocalGuid.Data2) + 1;\r
+\r
+  //\r
+  // Get gghh in big-endian.\r
+  //\r
+  Status = StrHexToBytes (String, 2 * sizeof (LocalGuid.Data3), (UINT8 *) &LocalGuid.Data3, sizeof (LocalGuid.Data3));\r
+  if (RETURN_ERROR (Status) || String[2 * sizeof (LocalGuid.Data3)] != L'-') {\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Convert big-endian to little-endian.\r
+  //\r
+  LocalGuid.Data3 = SwapBytes16 (LocalGuid.Data3);\r
+  String += 2 * sizeof (LocalGuid.Data3) + 1;\r
+\r
+  //\r
+  // Get iijj.\r
+  //\r
+  Status = StrHexToBytes (String, 2 * 2, &LocalGuid.Data4[0], 2);\r
+  if (RETURN_ERROR (Status) || String[2 * 2] != L'-') {\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+  String += 2 * 2 + 1;\r
+\r
+  //\r
+  // Get kkllmmnnoopp.\r
+  //\r
+  Status = StrHexToBytes (String, 2 * 6, &LocalGuid.Data4[2], 6);\r
+  if (RETURN_ERROR (Status)) {\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+\r
+  CopyGuid (Guid, &LocalGuid);\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Compares up to a specified length the contents of two Null-terminated Unicode strings,\r
+  and returns the difference between the first mismatched Unicode characters.\r
+\r
+  This function compares the Null-terminated Unicode string FirstString to the\r
+  Null-terminated Unicode string SecondString. At most, Length Unicode\r
+  characters will be compared. If Length is 0, then 0 is returned. If\r
+  FirstString is identical to SecondString, then 0 is returned. Otherwise, the\r
+  value returned is the first mismatched Unicode character in SecondString\r
+  subtracted from the first mismatched Unicode character in FirstString.\r
+\r
+  If Length > 0 and FirstString is NULL, then ASSERT().\r
+  If Length > 0 and FirstString is not aligned on a 16-bit boundary, then ASSERT().\r
+  If Length > 0 and SecondString is NULL, then ASSERT().\r
+  If Length > 0 and SecondString is not aligned on a 16-bit boundary, then ASSERT().\r
+  If PcdMaximumUnicodeStringLength is not zero, and Length is greater than\r
+  PcdMaximumUnicodeStringLength, then ASSERT().\r
+  If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more than\r
+  PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r
+  then ASSERT().\r
+  If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more than\r
+  PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r
+  then ASSERT().\r
+\r
+  @param  FirstString   A pointer to a Null-terminated Unicode string.\r
+  @param  SecondString  A pointer to a Null-terminated Unicode string.\r
+  @param  Length        The maximum number of Unicode characters to compare.\r
+\r
+  @retval 0      FirstString is identical to SecondString.\r
+  @return others FirstString is not identical to SecondString.\r
+\r
+**/\r
+INTN\r
+StrnCmp (\r
+        CONST CHAR16              *FirstString,\r
+        CONST CHAR16              *SecondString,\r
+        UINTN                     Length\r
+  )\r
+{\r
+  if (Length == 0) {\r
+    return 0;\r
+  }\r
+\r
+  //\r
+  // ASSERT both strings are less long than PcdMaximumUnicodeStringLength.\r
+  // Length tests are performed inside StrLen().\r
+  //\r
+  ASSERT (StrSize (FirstString) != 0);\r
+  ASSERT (StrSize (SecondString) != 0);\r
+\r
+  while ((*FirstString != L'\0') &&\r
+         (*SecondString != L'\0') &&\r
+         (*FirstString == *SecondString) &&\r
+         (Length > 1)) {\r
+    FirstString++;\r
+    SecondString++;\r
+    Length--;\r
+  }\r
+\r
+  return *FirstString - *SecondString;\r
+}\r
+\r
+VOID *\r
+AllocateCopyPool (\r
+   UINTN       AllocationSize,\r
+   CONST VOID  *Buffer\r
+  )\r
+{\r
+  return InternalAllocateCopyPool (AllocationSize, Buffer);\r
+}\r
+\r
+INTN\r
+StrCmp (\r
+  CONST CHAR16              *FirstString,\r
+  CONST CHAR16              *SecondString\r
+  )\r
+{\r
+  //\r
+  // ASSERT both strings are less long than PcdMaximumUnicodeStringLength\r
+  //\r
+  ASSERT (StrSize (FirstString) != 0);\r
+  ASSERT (StrSize (SecondString) != 0);\r
+\r
+  while ((*FirstString != L'\0') && (*FirstString == *SecondString)) {\r
+    FirstString++;\r
+    SecondString++;\r
+  }\r
+  return *FirstString - *SecondString;\r
+}\r
+\r
+UINT64\r
+SwapBytes64 (\r
+  UINT64                    Value\r
+  )\r
+{\r
+  return InternalMathSwapBytes64 (Value);\r
+}\r
+\r
+UINT64\r
+InternalMathSwapBytes64 (\r
+  UINT64                    Operand\r
+  )\r
+{\r
+  UINT64  LowerBytes;\r
+  UINT64  HigherBytes;\r
+\r
+  LowerBytes  = (UINT64) SwapBytes32 ((UINT32) Operand);\r
+  HigherBytes = (UINT64) SwapBytes32 ((UINT32) (Operand >> 32));\r
+\r
+  return (LowerBytes << 32 | HigherBytes);\r
+}\r
+\r
+RETURN_STATUS\r
+StrToIpv4Address (\r
+  CONST CHAR16       *String,\r
+  CHAR16             **EndPointer,\r
+  EFI_IPv4_ADDRESS       *Address,\r
+  UINT8              *PrefixLength\r
+  )\r
+{\r
+  RETURN_STATUS          Status;\r
+  UINTN                  AddressIndex;\r
+  UINTN                  Uintn;\r
+  EFI_IPv4_ADDRESS       LocalAddress;\r
+  UINT8                  LocalPrefixLength;\r
+  CHAR16                 *Pointer;\r
+\r
+  LocalPrefixLength = MAX_UINT8;\r
+  LocalAddress.Addr[0] = 0;\r
+\r
+  ASSERT (((UINTN) String & BIT0) == 0);\r
+\r
+  //\r
+  // 1. None of String or Guid shall be a null pointer.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);\r
+  SAFE_STRING_CONSTRAINT_CHECK ((Address != NULL), RETURN_INVALID_PARAMETER);\r
+\r
+  for (Pointer = (CHAR16 *) String, AddressIndex = 0; AddressIndex < ARRAY_SIZE (Address->Addr) + 1;) {\r
+    if (!InternalIsDecimalDigitCharacter (*Pointer)) {\r
+      //\r
+      // D or P contains invalid characters.\r
+      //\r
+      break;\r
+    }\r
+\r
+    //\r
+    // Get D or P.\r
+    //\r
+    Status = StrDecimalToUintnS ((CONST CHAR16 *) Pointer, &Pointer, &Uintn);\r
+    if (RETURN_ERROR (Status)) {\r
+      return RETURN_UNSUPPORTED;\r
+    }\r
+    if (AddressIndex == ARRAY_SIZE (Address->Addr)) {\r
+      //\r
+      // It's P.\r
+      //\r
+      if (Uintn > 32) {\r
+        return RETURN_UNSUPPORTED;\r
+      }\r
+      LocalPrefixLength = (UINT8) Uintn;\r
+    } else {\r
+      //\r
+      // It's D.\r
+      //\r
+      if (Uintn > MAX_UINT8) {\r
+        return RETURN_UNSUPPORTED;\r
+      }\r
+      LocalAddress.Addr[AddressIndex] = (UINT8) Uintn;\r
+      AddressIndex++;\r
+    }\r
+\r
+    //\r
+    // Check the '.' or '/', depending on the AddressIndex.\r
+    //\r
+    if (AddressIndex == ARRAY_SIZE (Address->Addr)) {\r
+      if (*Pointer == L'/') {\r
+        //\r
+        // '/P' is in the String.\r
+        // Skip "/" and get P in next loop.\r
+        //\r
+        Pointer++;\r
+      } else {\r
+        //\r
+        // '/P' is not in the String.\r
+        //\r
+        break;\r
+      }\r
+    } else if (AddressIndex < ARRAY_SIZE (Address->Addr)) {\r
+      if (*Pointer == L'.') {\r
+        //\r
+        // D should be followed by '.'\r
+        //\r
+        Pointer++;\r
+      } else {\r
+        return RETURN_UNSUPPORTED;\r
+      }\r
+    }\r
+  }\r
+\r
+  if (AddressIndex < ARRAY_SIZE (Address->Addr)) {\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+\r
+  memcpy (Address, &LocalAddress, sizeof (*Address));\r
+  if (PrefixLength != NULL) {\r
+    *PrefixLength = LocalPrefixLength;\r
+  }\r
+  if (EndPointer != NULL) {\r
+    *EndPointer = Pointer;\r
+  }\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+RETURN_STATUS\r
+StrToIpv6Address (\r
+  CONST CHAR16       *String,\r
+  CHAR16             **EndPointer,\r
+  EFI_IPv6_ADDRESS   *Address,\r
+  UINT8              *PrefixLength\r
+  )\r
+{\r
+  RETURN_STATUS          Status;\r
+  UINTN                  AddressIndex;\r
+  UINTN                  Uintn;\r
+  EFI_IPv6_ADDRESS       LocalAddress;\r
+  UINT8                  LocalPrefixLength;\r
+  CONST CHAR16           *Pointer;\r
+  CHAR16                 *End;\r
+  UINTN                  CompressStart;\r
+  BOOLEAN                ExpectPrefix;\r
+\r
+  LocalPrefixLength = MAX_UINT8;\r
+  CompressStart     = ARRAY_SIZE (Address->Addr);\r
+  ExpectPrefix      = FALSE;\r
+\r
+  ASSERT (((UINTN) String & BIT0) == 0);\r
+\r
+  //\r
+  // 1. None of String or Guid shall be a null pointer.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);\r
+  SAFE_STRING_CONSTRAINT_CHECK ((Address != NULL), RETURN_INVALID_PARAMETER);\r
+\r
+  for (Pointer = String, AddressIndex = 0; AddressIndex < ARRAY_SIZE (Address->Addr) + 1;) {\r
+    if (!InternalIsHexaDecimalDigitCharacter (*Pointer)) {\r
+      if (*Pointer != L':') {\r
+        //\r
+        // ":" or "/" should be followed by digit characters.\r
+        //\r
+        return RETURN_UNSUPPORTED;\r
+      }\r
+\r
+      //\r
+      // Meet second ":" after previous ":" or "/"\r
+      // or meet first ":" in the beginning of String.\r
+      //\r
+      if (ExpectPrefix) {\r
+        //\r
+        // ":" shall not be after "/"\r
+        //\r
+        return RETURN_UNSUPPORTED;\r
+      }\r
+\r
+      if (CompressStart != ARRAY_SIZE (Address->Addr) || AddressIndex == ARRAY_SIZE (Address->Addr)) {\r
+        //\r
+        // "::" can only appear once.\r
+        // "::" can only appear when address is not full length.\r
+        //\r
+        return RETURN_UNSUPPORTED;\r
+      } else {\r
+        //\r
+        // Remember the start of zero compressing.\r
+        //\r
+        CompressStart = AddressIndex;\r
+        Pointer++;\r
+\r
+        if (CompressStart == 0) {\r
+          if (*Pointer != L':') {\r
+            //\r
+            // Single ":" shall not be in the beginning of String.\r
+            //\r
+            return RETURN_UNSUPPORTED;\r
+          }\r
+          Pointer++;\r
+        }\r
+      }\r
+    }\r
+\r
+    if (!InternalIsHexaDecimalDigitCharacter (*Pointer)) {\r
+      if (*Pointer == L'/') {\r
+        //\r
+        // Might be optional "/P" after "::".\r
+        //\r
+        if (CompressStart != AddressIndex) {\r
+          return RETURN_UNSUPPORTED;\r
+        }\r
+      } else {\r
+        break;\r
+      }\r
+    } else {\r
+      if (!ExpectPrefix) {\r
+        //\r
+        // Get X.\r
+        //\r
+        Status = StrHexToUintnS (Pointer, &End, &Uintn);\r
+        if (RETURN_ERROR (Status) || End - Pointer > 4) {\r
+          //\r
+          // Number of hexadecimal digit characters is no more than 4.\r
+          //\r
+          return RETURN_UNSUPPORTED;\r
+        }\r
+        Pointer = End;\r
+        //\r
+        // Uintn won't exceed MAX_UINT16 if number of hexadecimal digit characters is no more than 4.\r
+        //\r
+        ASSERT (AddressIndex + 1 < ARRAY_SIZE (Address->Addr));\r
+        LocalAddress.Addr[AddressIndex] = (UINT8) ((UINT16) Uintn >> 8);\r
+        LocalAddress.Addr[AddressIndex + 1] = (UINT8) Uintn;\r
+        AddressIndex += 2;\r
+      } else {\r
+        //\r
+        // Get P, then exit the loop.\r
+        //\r
+        Status = StrDecimalToUintnS (Pointer, &End, &Uintn);\r
+        if (RETURN_ERROR (Status) || End == Pointer || Uintn > 128) {\r
+          //\r
+          // Prefix length should not exceed 128.\r
+          //\r
+          return RETURN_UNSUPPORTED;\r
+        }\r
+        LocalPrefixLength = (UINT8) Uintn;\r
+        Pointer = End;\r
+        break;\r
+      }\r
+    }\r
+\r
+    //\r
+    // Skip ':' or "/"\r
+    //\r
+    if (*Pointer == L'/') {\r
+      ExpectPrefix = TRUE;\r
+    } else if (*Pointer == L':') {\r
+      if (AddressIndex == ARRAY_SIZE (Address->Addr)) {\r
+        //\r
+        // Meet additional ":" after all 8 16-bit address\r
+        //\r
+        break;\r
+      }\r
+    } else {\r
+      //\r
+      // Meet other character that is not "/" or ":" after all 8 16-bit address\r
+      //\r
+      break;\r
+    }\r
+    Pointer++;\r
+  }\r
+\r
+  if ((AddressIndex == ARRAY_SIZE (Address->Addr) && CompressStart != ARRAY_SIZE (Address->Addr)) ||\r
+    (AddressIndex != ARRAY_SIZE (Address->Addr) && CompressStart == ARRAY_SIZE (Address->Addr))\r
+      ) {\r
+    //\r
+    // Full length of address shall not have compressing zeros.\r
+    // Non-full length of address shall have compressing zeros.\r
+    //\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+  memcpy (&Address->Addr[0], &LocalAddress.Addr[0], CompressStart);\r
+  memset (&Address->Addr[CompressStart], 0,  ARRAY_SIZE (Address->Addr) - AddressIndex);\r
+  if (AddressIndex > CompressStart) {\r
+    memcpy (\r
+      &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressIndex],\r
+      &LocalAddress.Addr[CompressStart],\r
+      AddressIndex - CompressStart\r
+      );\r
+  }\r
+\r
+  if (PrefixLength != NULL) {\r
+    *PrefixLength = LocalPrefixLength;\r
+  }\r
+  if (EndPointer != NULL) {\r
+    *EndPointer = (CHAR16 *) Pointer;\r
+  }\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+\r
+RETURN_STATUS\r
+UnicodeStrToAsciiStrS (\r
+  CONST CHAR16              *Source,\r
+  CHAR8                     *Destination,\r
+  UINTN                     DestMax\r
+  )\r
+{\r
+  UINTN            SourceLen;\r
+\r
+  ASSERT (((UINTN) Source & BIT0) == 0);\r
+\r
+  //\r
+  // 1. Neither Destination nor Source shall be a null pointer.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK ((Destination != NULL), RETURN_INVALID_PARAMETER);\r
+  SAFE_STRING_CONSTRAINT_CHECK ((Source != NULL), RETURN_INVALID_PARAMETER);\r
+\r
+  //\r
+  // 2. DestMax shall not be greater than ASCII_RSIZE_MAX or RSIZE_MAX.\r
+  //\r
+  if (ASCII_RSIZE_MAX != 0) {\r
+    SAFE_STRING_CONSTRAINT_CHECK ((DestMax <= ASCII_RSIZE_MAX), RETURN_INVALID_PARAMETER);\r
+  }\r
+  if (RSIZE_MAX != 0) {\r
+    SAFE_STRING_CONSTRAINT_CHECK ((DestMax <= RSIZE_MAX), RETURN_INVALID_PARAMETER);\r
+  }\r
+\r
+  //\r
+  // 3. DestMax shall not equal zero.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK ((DestMax != 0), RETURN_INVALID_PARAMETER);\r
+\r
+  //\r
+  // 4. DestMax shall be greater than StrnLenS (Source, DestMax).\r
+  //\r
+  SourceLen = StrnLenS (Source, DestMax);\r
+  SAFE_STRING_CONSTRAINT_CHECK ((DestMax > SourceLen), RETURN_BUFFER_TOO_SMALL);\r
+\r
+  //\r
+  // 5. Copying shall not take place between objects that overlap.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK (!InternalSafeStringIsOverlap (Destination, DestMax, (VOID *)Source, (SourceLen + 1) * sizeof(CHAR16)), RETURN_ACCESS_DENIED);\r
+\r
+  //\r
+  // convert string\r
+  //\r
+  while (*Source != '\0') {\r
+    //\r
+    // If any Unicode characters in Source contain\r
+    // non-zero value in the upper 8 bits, then ASSERT().\r
+    //\r
+    ASSERT (*Source < 0x100);\r
+    *(Destination++) = (CHAR8) *(Source++);\r
+  }\r
+  *Destination = '\0';\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+RETURN_STATUS\r
+StrCpyS (\r
+  CHAR16       *Destination,\r
+  UINTN        DestMax,\r
+  CONST CHAR16 *Source\r
+  )\r
+{\r
+  UINTN            SourceLen;\r
+\r
+  ASSERT (((UINTN) Destination & BIT0) == 0);\r
+  ASSERT (((UINTN) Source & BIT0) == 0);\r
+\r
+  //\r
+  // 1. Neither Destination nor Source shall be a null pointer.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK ((Destination != NULL), RETURN_INVALID_PARAMETER);\r
+  SAFE_STRING_CONSTRAINT_CHECK ((Source != NULL), RETURN_INVALID_PARAMETER);\r
+\r
+  //\r
+  // 2. DestMax shall not be greater than RSIZE_MAX.\r
+  //\r
+  if (RSIZE_MAX != 0) {\r
+    SAFE_STRING_CONSTRAINT_CHECK ((DestMax <= RSIZE_MAX), RETURN_INVALID_PARAMETER);\r
+  }\r
+\r
+  //\r
+  // 3. DestMax shall not equal zero.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK ((DestMax != 0), RETURN_INVALID_PARAMETER);\r
+\r
+  //\r
+  // 4. DestMax shall be greater than StrnLenS(Source, DestMax).\r
+  //\r
+  SourceLen = StrnLenS (Source, DestMax);\r
+  SAFE_STRING_CONSTRAINT_CHECK ((DestMax > SourceLen), RETURN_BUFFER_TOO_SMALL);\r
+\r
+  //\r
+  // 5. Copying shall not take place between objects that overlap.\r
+  //\r
+  SAFE_STRING_CONSTRAINT_CHECK (InternalSafeStringNoStrOverlap (Destination, DestMax, (CHAR16 *)Source, SourceLen + 1), RETURN_ACCESS_DENIED);\r
+\r
+  //\r
+  // The StrCpyS function copies the string pointed to by Source (including the terminating\r
+  // null character) into the array pointed to by Destination.\r
+  //\r
+  while (*Source != 0) {\r
+    *(Destination++) = *(Source++);\r
+  }\r
+  *Destination = 0;\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+VOID *\r
+AllocateZeroPool (\r
+  UINTN  AllocationSize\r
+  )\r
+{\r
+  VOID * Memory;\r
+  Memory = malloc(AllocationSize);\r
+  ASSERT (Memory != NULL);\r
+  if (Memory == NULL) {\r
+    fprintf(stderr, "Not memory for malloc\n");\r
+  }\r
+  memset(Memory, 0, AllocationSize);\r
+  return Memory;\r
+}\r
+\r
+VOID *\r
+AllocatePool (\r
+  UINTN  AllocationSize\r
+  )\r
+{\r
+  return InternalAllocatePool (AllocationSize);\r
+}\r
+\r
+UINT16\r
+WriteUnaligned16 (\r
+  UINT16                    *Buffer,\r
+  UINT16                    Value\r
+  )\r
+{\r
+  ASSERT (Buffer != NULL);\r
+\r
+  return *Buffer = Value;\r
+}\r
+\r
+UINT16\r
+ReadUnaligned16 (\r
+  CONST UINT16              *Buffer\r
+  )\r
+{\r
+  ASSERT (Buffer != NULL);\r
+\r
+  return *Buffer;\r
+}\r
+/**\r
+  Return whether the integer string is a hex string.\r
+\r
+  @param Str             The integer string\r
+\r
+  @retval TRUE   Hex string\r
+  @retval FALSE  Decimal string\r
+\r
+**/\r
+BOOLEAN\r
+IsHexStr (\r
+   CHAR16   *Str\r
+  )\r
+{\r
+  //\r
+  // skip preceeding white space\r
+  //\r
+  while ((*Str != 0) && *Str == L' ') {\r
+    Str ++;\r
+  }\r
+  //\r
+  // skip preceeding zeros\r
+  //\r
+  while ((*Str != 0) && *Str == L'0') {\r
+    Str ++;\r
+  }\r
+\r
+  return (BOOLEAN) (*Str == L'x' || *Str == L'X');\r
+}\r
+\r
+/**\r
+\r
+  Convert integer string to uint.\r
+\r
+  @param Str             The integer string. If leading with "0x" or "0X", it's hexadecimal.\r
+\r
+  @return A UINTN value represented by Str\r
+\r
+**/\r
+UINTN\r
+Strtoi (\r
+   CHAR16  *Str\r
+  )\r
+{\r
+  if (IsHexStr (Str)) {\r
+    return StrHexToUintn (Str);\r
+  } else {\r
+    return StrDecimalToUintn (Str);\r
+  }\r
+}\r
+\r
+/**\r
+\r
+  Convert integer string to 64 bit data.\r
+\r
+  @param Str             The integer string. If leading with "0x" or "0X", it's hexadecimal.\r
+  @param Data            A pointer to the UINT64 value represented by Str\r
+\r
+**/\r
+VOID\r
+Strtoi64 (\r
+    CHAR16  *Str,\r
+   UINT64  *Data\r
+  )\r
+{\r
+  if (IsHexStr (Str)) {\r
+    *Data = StrHexToUint64 (Str);\r
+  } else {\r
+    *Data = StrDecimalToUint64 (Str);\r
+  }\r
+}\r
+\r
+/**\r
+  Converts a Unicode string to ASCII string.\r
+\r
+  @param Str             The equivalent Unicode string\r
+  @param AsciiStr        On input, it points to destination ASCII string buffer; on output, it points\r
+                         to the next ASCII string next to it\r
+\r
+**/\r
+VOID\r
+StrToAscii (\r
+       CHAR16 *Str,\r
+    CHAR8  **AsciiStr\r
+  )\r
+{\r
+  CHAR8 *Dest;\r
+\r
+  Dest = *AsciiStr;\r
+  while (!IS_NULL (*Str)) {\r
+    *(Dest++) = (CHAR8) *(Str++);\r
+  }\r
+  *Dest = 0;\r
+\r
+  //\r
+  // Return the string next to it\r
+  //\r
+  *AsciiStr = Dest + 1;\r
+}\r
+\r
+/**\r
+  Gets current sub-string from a string list, before return\r
+  the list header is moved to next sub-string. The sub-string is separated\r
+  by the specified character. For example, the separator is ',', the string\r
+  list is "2,0,3", it returns "2", the remain list move to "0,3"\r
+\r
+  @param  List        A string list separated by the specified separator\r
+  @param  Separator   The separator character\r
+\r
+  @return A pointer to the current sub-string\r
+\r
+**/\r
+CHAR16 *\r
+SplitStr (\r
+    CHAR16 **List,\r
+       CHAR16 Separator\r
+  )\r
+{\r
+  CHAR16  *Str;\r
+  CHAR16  *ReturnStr;\r
+\r
+  Str = *List;\r
+  ReturnStr = Str;\r
+\r
+  if (IS_NULL (*Str)) {\r
+    return ReturnStr;\r
+  }\r
+\r
+  //\r
+  // Find first occurrence of the separator\r
+  //\r
+  while (!IS_NULL (*Str)) {\r
+    if (*Str == Separator) {\r
+      break;\r
+    }\r
+    Str++;\r
+  }\r
+\r
+  if (*Str == Separator) {\r
+    //\r
+    // Find a sub-string, terminate it\r
+    //\r
+    *Str = L'\0';\r
+    Str++;\r
+  }\r
+\r
+  //\r
+  // Move to next sub-string\r
+  //\r
+  *List = Str;\r
+  return ReturnStr;\r
+}\r
+\r
index 2041b89e2d0bc93577880431e82e92ce32db7d4e..9da16e8cd30156958de599de5cb62fcb7438cfac 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Common library assistance routines.\r
 \r
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, 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
@@ -17,10 +17,31 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Common/UefiBaseTypes.h>\r
 #include <Common/BuildVersion.h>\r
+#include <assert.h>\r
 #define PRINTED_GUID_BUFFER_SIZE  37  // including null-termination\r
 \r
 #define MAX_LONG_FILE_PATH 500\r
 \r
+#define MAX_UINTN MAX_ADDRESS\r
+#define MAX_UINT64 ((UINT64)0xFFFFFFFFFFFFFFFFULL)\r
+#define MAX_UINT16  ((UINT16)0xFFFF)\r
+#define MAX_UINT8   ((UINT8)0xFF)\r
+#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0]))\r
+#define ASCII_RSIZE_MAX 1000000\r
+#ifndef RSIZE_MAX\r
+#define RSIZE_MAX 1000000\r
+#endif\r
+\r
+#define IS_COMMA(a)                ((a) == L',')\r
+#define IS_HYPHEN(a)               ((a) == L'-')\r
+#define IS_DOT(a)                  ((a) == L'.')\r
+#define IS_LEFT_PARENTH(a)         ((a) == L'(')\r
+#define IS_RIGHT_PARENTH(a)        ((a) == L')')\r
+#define IS_SLASH(a)                ((a) == L'/')\r
+#define IS_NULL(a)                 ((a) == L'\0')\r
+\r
+#define ASSERT(x) assert(x)\r
+\r
 #ifdef __cplusplus\r
 extern "C" {\r
 #endif\r
@@ -149,6 +170,285 @@ CHAR8 *
 LongFilePath (\r
  IN CHAR8 *FileName\r
 );\r
+\r
+UINTN\r
+StrLen (\r
+  CONST CHAR16   *String\r
+  );\r
+\r
+VOID *\r
+AllocateCopyPool (\r
+  UINTN       AllocationSize,\r
+  CONST VOID  *Buffer\r
+  );\r
+\r
+INTN\r
+StrnCmp (\r
+  CONST CHAR16              *FirstString,\r
+  CONST CHAR16              *SecondString,\r
+  UINTN                     Length\r
+  );\r
+\r
+RETURN_STATUS\r
+StrToGuid (\r
+  CONST CHAR16       *String,\r
+  EFI_GUID               *Guid\r
+  );\r
+\r
+RETURN_STATUS\r
+StrHexToBytes (\r
+  CONST CHAR16       *String,\r
+  UINTN              Length,\r
+  UINT8              *Buffer,\r
+  UINTN              MaxBufferSize\r
+  );\r
+\r
+UINTN\r
+InternalHexCharToUintn (\r
+  CHAR16                    Char\r
+  );\r
+\r
+VOID *\r
+InternalAllocateCopyPool (\r
+   UINTN            AllocationSize,\r
+   CONST VOID       *Buffer\r
+  );\r
+\r
+BOOLEAN\r
+InternalIsDecimalDigitCharacter (\r
+        CHAR16                    Char\r
+  );\r
+\r
+UINT32\r
+SwapBytes32 (\r
+        UINT32                    Value\r
+  );\r
+\r
+UINT16\r
+SwapBytes16 (\r
+        UINT16                    Value\r
+  );\r
+\r
+EFI_GUID *\r
+CopyGuid (\r
+   EFI_GUID       *DestinationGuid,\r
+   CONST EFI_GUID  *SourceGuid\r
+  );\r
+\r
+UINT64\r
+WriteUnaligned64 (\r
+   UINT64                    *Buffer,\r
+   UINT64                    Value\r
+  );\r
+\r
+UINT64\r
+ReadUnaligned64 (\r
+   CONST UINT64              *Buffer\r
+  );\r
+\r
+UINTN\r
+StrSize (\r
+  CONST CHAR16              *String\r
+  );\r
+\r
+UINTN\r
+StrHexToUintn (\r
+  CONST CHAR16              *String\r
+  );\r
+\r
+UINTN\r
+StrDecimalToUintn (\r
+  CONST CHAR16              *String\r
+  );\r
+\r
+UINT64\r
+StrHexToUint64 (\r
+  CONST CHAR16             *String\r
+  );\r
+\r
+UINT64\r
+StrDecimalToUint64 (\r
+  CONST CHAR16              *String\r
+  );\r
+\r
+RETURN_STATUS\r
+StrHexToUint64S (\r
+    CONST CHAR16       *String,\r
+    CHAR16             **EndPointer,\r
+    UINT64             *Data\r
+  );\r
+\r
+RETURN_STATUS\r
+StrHexToUintnS (\r
+    CONST CHAR16             *String,\r
+         CHAR16             **EndPointer,  OPTIONAL\r
+         UINTN              *Data\r
+  );\r
+\r
+RETURN_STATUS\r
+StrDecimalToUint64S (\r
+    CONST CHAR16             *String,\r
+         CHAR16             **EndPointer,  OPTIONAL\r
+         UINT64             *Data\r
+  );\r
+\r
+RETURN_STATUS\r
+StrDecimalToUintnS (\r
+    CONST CHAR16             *String,\r
+         CHAR16             **EndPointer,  OPTIONAL\r
+         UINTN              *Data\r
+  );\r
+\r
+VOID *\r
+ReallocatePool (\r
+   UINTN  OldSize,\r
+   UINTN  NewSize,\r
+   VOID   *OldBuffer  OPTIONAL\r
+  );\r
+\r
+VOID *\r
+InternalReallocatePool (\r
+   UINTN            OldSize,\r
+   UINTN            NewSize,\r
+   VOID             *OldBuffer  OPTIONAL\r
+  );\r
+\r
+VOID *\r
+InternalAllocateZeroPool (\r
+   UINTN            AllocationSize\r
+  ) ;\r
+\r
+VOID *\r
+InternalAllocatePool (\r
+   UINTN            AllocationSize\r
+  );\r
+\r
+UINTN\r
+StrnLenS (\r
+   CONST CHAR16              *String,\r
+   UINTN                     MaxSize\r
+  );\r
+\r
+CHAR16\r
+InternalCharToUpper (\r
+        CHAR16                    Char\r
+  );\r
+\r
+INTN\r
+StrCmp (\r
+  CONST CHAR16              *FirstString,\r
+  CONST CHAR16              *SecondString\r
+  );\r
+\r
+UINT64\r
+SwapBytes64 (\r
+  UINT64                    Value\r
+  );\r
+\r
+UINT64\r
+InternalMathSwapBytes64 (\r
+  UINT64                    Operand\r
+  );\r
+\r
+RETURN_STATUS\r
+StrToIpv4Address (\r
+  CONST CHAR16       *String,\r
+  CHAR16             **EndPointer,\r
+  EFI_IPv4_ADDRESS       *Address,\r
+  UINT8              *PrefixLength\r
+  );\r
+\r
+RETURN_STATUS\r
+StrToIpv6Address (\r
+  CONST CHAR16       *String,\r
+  CHAR16             **EndPointer,\r
+  EFI_IPv6_ADDRESS       *Address,\r
+  UINT8              *PrefixLength\r
+  );\r
+\r
+RETURN_STATUS\r
+StrCpyS (\r
+  CHAR16       *Destination,\r
+  UINTN        DestMax,\r
+  CONST CHAR16 *Source\r
+  );\r
+\r
+RETURN_STATUS\r
+UnicodeStrToAsciiStrS (\r
+  CONST CHAR16              *Source,\r
+  CHAR8                     *Destination,\r
+  UINTN                     DestMax\r
+  );\r
+VOID *\r
+AllocatePool (\r
+  UINTN  AllocationSize\r
+  );\r
+\r
+UINT16\r
+WriteUnaligned16 (\r
+  UINT16                    *Buffer,\r
+  UINT16                    Value\r
+  );\r
+\r
+UINT16\r
+ReadUnaligned16 (\r
+  CONST UINT16              *Buffer\r
+  );\r
+\r
+VOID *\r
+AllocateZeroPool (\r
+  UINTN  AllocationSize\r
+  );\r
+\r
+BOOLEAN\r
+InternalIsHexaDecimalDigitCharacter (\r
+  CHAR16                    Char\r
+  );\r
+\r
+BOOLEAN\r
+InternalSafeStringIsOverlap (\r
+  IN VOID    *Base1,\r
+  IN UINTN   Size1,\r
+  IN VOID    *Base2,\r
+  IN UINTN   Size2\r
+  );\r
+\r
+BOOLEAN\r
+InternalSafeStringNoStrOverlap (\r
+  IN CHAR16  *Str1,\r
+  IN UINTN   Size1,\r
+  IN CHAR16  *Str2,\r
+  IN UINTN   Size2\r
+  );\r
+\r
+BOOLEAN\r
+IsHexStr (\r
+   CHAR16   *Str\r
+  );\r
+\r
+UINTN\r
+Strtoi (\r
+   CHAR16  *Str\r
+  );\r
+\r
+VOID\r
+Strtoi64 (\r
+    CHAR16  *Str,\r
+   UINT64  *Data\r
+  );\r
+\r
+VOID\r
+StrToAscii (\r
+       CHAR16 *Str,\r
+    CHAR8  **AsciiStr\r
+  );\r
+\r
+CHAR16 *\r
+SplitStr (\r
+    CHAR16 **List,\r
+       CHAR16 Separator\r
+  );\r
+\r
 /*++\r
 \r
 Routine Description:\r
@@ -166,8 +466,6 @@ Returns:
 }\r
 #endif\r
 \r
-#define ASSERT(x) assert(x)\r
-\r
 #ifdef __GNUC__\r
 #include <stdio.h>\r
 #include <sys/stat.h>\r
diff --git a/BaseTools/Source/C/DevicePath/DevicePath.c b/BaseTools/Source/C/DevicePath/DevicePath.c
new file mode 100644 (file)
index 0000000..4c87163
--- /dev/null
@@ -0,0 +1,186 @@
+/** @file\r
+  Definition for Device Path Tool.\r
+\r
+Copyright (c) 2017, 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
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "UefiDevicePathLib.h"\r
+\r
+//\r
+// Utility Name\r
+//\r
+#define UTILITY_NAME  "DevicePath"\r
+\r
+//\r
+// Utility version information\r
+//\r
+#define UTILITY_MAJOR_VERSION 0\r
+#define UTILITY_MINOR_VERSION 1\r
+\r
+EFI_GUID gEfiDebugPortDevicePathGuid = DEVICE_PATH_MESSAGING_DEBUGPORT;\r
+EFI_GUID gEfiPcAnsiGuid = EFI_PC_ANSI_GUID;\r
+EFI_GUID gEfiVT100Guid = EFI_VT_100_GUID;\r
+EFI_GUID gEfiVT100PlusGuid = EFI_VT_100_PLUS_GUID;\r
+EFI_GUID gEfiVTUTF8Guid = EFI_VT_UTF8_GUID;\r
+EFI_GUID gEfiUartDevicePathGuid = EFI_UART_DEVICE_PATH_GUID;\r
+EFI_GUID gEfiSasDevicePathGuid = EFI_SAS_DEVICE_PATH_GUID;\r
+EFI_GUID gEfiVirtualDiskGuid = EFI_VIRTUAL_DISK_GUID;\r
+EFI_GUID gEfiVirtualCdGuid = EFI_VIRTUAL_CD_GUID;\r
+EFI_GUID gEfiPersistentVirtualDiskGuid = EFI_PERSISTENT_VIRTUAL_DISK_GUID;\r
+EFI_GUID gEfiPersistentVirtualCdGuid = EFI_PERSISTENT_VIRTUAL_CD_GUID;\r
+\r
+STATIC\r
+VOID\r
+Version (\r
+  VOID\r
+)\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Displays the standard utility information to SDTOUT\r
+\r
+Arguments:\r
+\r
+  None\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  fprintf (stdout, "%s Version %d.%d %s \n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);\r
+}\r
+\r
+STATIC\r
+VOID\r
+Usage (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Displays the utility usage syntax to STDOUT\r
+\r
+Arguments:\r
+\r
+  None\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  //\r
+  // Summary usage\r
+  //\r
+  fprintf (stdout, "\nUsage: %s [options]\n\n", UTILITY_NAME);\r
+\r
+  //\r
+  // Copyright declaration\r
+  //\r
+  fprintf (stdout, "Copyright (c) 2017, Intel Corporation. All rights reserved.\n\n");\r
+  //\r
+  // Details Option\r
+  //\r
+  fprintf (stdout, "Options:\n");\r
+  fprintf (stdout, "  DevicePathString      Device Path string is specified, no space character.\n"\r
+                   "                        Example: \"PciRoot(0)/Pci(0,0)\"\n");\r
+\r
+  fprintf (stdout, "  --version             Show program's version number and exit.\n");\r
+  fprintf (stdout, "  -h, --help            Show this help message and exit.\n");\r
+}\r
+\r
+\r
+void print_mem(void const *vp, size_t n)\r
+{\r
+    unsigned char const *p = vp;\r
+    for (size_t i=0; i<n; i++) {\r
+        printf("0x%02x ", p[i]);\r
+  }\r
+}\r
+\r
+VOID\r
+Ascii2UnicodeString (\r
+  CHAR8    *String,\r
+  CHAR16   *UniString\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Write ascii string as unicode string format to FILE\r
+\r
+Arguments:\r
+\r
+  String      - Pointer to string that is written to FILE.\r
+  UniString   - Pointer to unicode string\r
+\r
+Returns:\r
+\r
+  NULL\r
+\r
+--*/\r
+{\r
+  while (*String != '\0') {\r
+    *(UniString++) = (CHAR16) *(String++);\r
+  }\r
+  //\r
+  // End the UniString with a NULL.\r
+  //\r
+  *UniString = '\0';\r
+}\r
+\r
+int main(int argc, CHAR8 *argv[])\r
+{\r
+  CHAR8 * Str;\r
+  CHAR16* Str16;\r
+  EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
+\r
+  if (argc == 1) {\r
+    Error (NULL, 0, 1001, "Missing options", "No input options specified.");\r
+    Usage ();\r
+    return STATUS_ERROR;\r
+  }\r
+  if ((stricmp (argv[1], "-h") == 0) || (stricmp (argv[1], "--help") == 0)) {\r
+    Version ();\r
+    Usage ();\r
+    return STATUS_SUCCESS;\r
+  }\r
+\r
+  if (stricmp (argv[1], "--version") == 0) {\r
+    Version ();\r
+    return STATUS_SUCCESS;\r
+  }\r
+  Str = argv[1];\r
+  if (Str == NULL) {\r
+    fprintf(stderr, "Invalid option value, Device Path can't be NULL");\r
+    return STATUS_ERROR;\r
+  }\r
+  Str16 = (CHAR16 *)malloc(1024);\r
+  if (Str16 == NULL) {\r
+    fprintf(stderr, "Resource, memory cannot be allcoated");\r
+    return STATUS_ERROR;\r
+  }\r
+  Ascii2UnicodeString(Str, Str16);\r
+  DevicePath = UefiDevicePathLibConvertTextToDevicePath(Str16);\r
+  while (!((DevicePath->Type == END_DEVICE_PATH_TYPE) && (DevicePath->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE)) )\r
+  {\r
+    print_mem(DevicePath, (DevicePath->Length[0] | DevicePath->Length[1] << 8));\r
+    DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)DevicePath + (DevicePath->Length[0] | DevicePath->Length[1] << 8));\r
+  }\r
+  print_mem(DevicePath, (DevicePath->Length[0] | DevicePath->Length[1] << 8));\r
+  putchar('\n');\r
+  return STATUS_SUCCESS;\r
+}\r
diff --git a/BaseTools/Source/C/DevicePath/DevicePathFromText.c b/BaseTools/Source/C/DevicePath/DevicePathFromText.c
new file mode 100644 (file)
index 0000000..3d2f5a8
--- /dev/null
@@ -0,0 +1,3349 @@
+/** @file\r
+  DevicePathFromText protocol as defined in the UEFI 2.0 specification.\r
+\r
+Copyright (c) 2017, 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
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "UefiDevicePathLib.h"\r
+\r
+/**\r
+\r
+  Duplicates a string.\r
+\r
+  @param  Src  Source string.\r
+\r
+  @return The duplicated string.\r
+\r
+**/\r
+CHAR16 *\r
+UefiDevicePathLibStrDuplicate (\r
+   CONST CHAR16  *Src\r
+  )\r
+{\r
+  return AllocateCopyPool (StrSize (Src), Src);\r
+}\r
+\r
+/**\r
+\r
+  Get parameter in a pair of parentheses follow the given node name.\r
+  For example, given the "Pci(0,1)" and NodeName "Pci", it returns "0,1".\r
+\r
+  @param  Str      Device Path Text.\r
+  @param  NodeName Name of the node.\r
+\r
+  @return Parameter text for the node.\r
+\r
+**/\r
+CHAR16 *\r
+GetParamByNodeName (\r
+   CHAR16 *Str,\r
+   CHAR16 *NodeName\r
+  )\r
+{\r
+  CHAR16  *ParamStr;\r
+  CHAR16  *StrPointer;\r
+  UINTN   NodeNameLength;\r
+  UINTN   ParameterLength;\r
+\r
+  //\r
+  // Check whether the node name matchs\r
+  //\r
+  NodeNameLength = StrLen (NodeName);\r
+  if (StrnCmp (Str, NodeName, NodeNameLength) != 0) {\r
+    return NULL;\r
+  }\r
+\r
+  ParamStr = Str + NodeNameLength;\r
+  if (!IS_LEFT_PARENTH (*ParamStr)) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Skip the found '(' and find first occurrence of ')'\r
+  //\r
+  ParamStr++;\r
+  ParameterLength = 0;\r
+  StrPointer = ParamStr;\r
+  while (!IS_NULL (*StrPointer)) {\r
+    if (IS_RIGHT_PARENTH (*StrPointer)) {\r
+      break;\r
+    }\r
+    StrPointer++;\r
+    ParameterLength++;\r
+  }\r
+  if (IS_NULL (*StrPointer)) {\r
+    //\r
+    // ')' not found\r
+    //\r
+    return NULL;\r
+  }\r
+\r
+  ParamStr = AllocateCopyPool ((ParameterLength + 1) * sizeof (CHAR16), ParamStr);\r
+  if (ParamStr == NULL) {\r
+    return NULL;\r
+  }\r
+  //\r
+  // Terminate the parameter string\r
+  //\r
+  ParamStr[ParameterLength] = L'\0';\r
+\r
+  return ParamStr;\r
+}\r
+\r
+/**\r
+  Gets the next parameter string from the list.\r
+\r
+  @param List            A string list separated by the specified separator\r
+\r
+  @return A pointer to the current sub-string\r
+\r
+**/\r
+CHAR16 *\r
+GetNextParamStr (\r
+    CHAR16 **List\r
+  )\r
+{\r
+  //\r
+  // The separator is comma\r
+  //\r
+  return SplitStr (List, L',');\r
+}\r
+\r
+/**\r
+  Get one device node from entire device path text.\r
+\r
+  @param DevicePath      On input, the current Device Path node; on output, the next device path node\r
+  @param IsInstanceEnd   This node is the end of a device path instance\r
+\r
+  @return A device node text or NULL if no more device node available\r
+\r
+**/\r
+CHAR16 *\r
+GetNextDeviceNodeStr (\r
+    CHAR16   **DevicePath,\r
+      BOOLEAN  *IsInstanceEnd\r
+  )\r
+{\r
+  CHAR16  *Str;\r
+  CHAR16  *ReturnStr;\r
+  UINTN   ParenthesesStack;\r
+\r
+  Str = *DevicePath;\r
+  if (IS_NULL (*Str)) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Skip the leading '/', '(', ')' and ','\r
+  //\r
+  while (!IS_NULL (*Str)) {\r
+    if (!IS_SLASH (*Str) &&\r
+        !IS_COMMA (*Str) &&\r
+        !IS_LEFT_PARENTH (*Str) &&\r
+        !IS_RIGHT_PARENTH (*Str)) {\r
+      break;\r
+    }\r
+    Str++;\r
+  }\r
+\r
+  ReturnStr = Str;\r
+\r
+  //\r
+  // Scan for the separator of this device node, '/' or ','\r
+  //\r
+  ParenthesesStack = 0;\r
+  while (!IS_NULL (*Str)) {\r
+    if ((IS_COMMA (*Str) || IS_SLASH (*Str)) && (ParenthesesStack == 0)) {\r
+      break;\r
+    }\r
+\r
+    if (IS_LEFT_PARENTH (*Str)) {\r
+      ParenthesesStack++;\r
+    } else if (IS_RIGHT_PARENTH (*Str)) {\r
+      ParenthesesStack--;\r
+    }\r
+\r
+    Str++;\r
+  }\r
+\r
+  if (ParenthesesStack != 0) {\r
+    //\r
+    // The '(' doesn't pair with ')', invalid device path text\r
+    //\r
+    return NULL;\r
+  }\r
+\r
+  if (IS_COMMA (*Str)) {\r
+    *IsInstanceEnd = TRUE;\r
+    *Str = L'\0';\r
+    Str++;\r
+  } else {\r
+    *IsInstanceEnd = FALSE;\r
+    if (!IS_NULL (*Str)) {\r
+      *Str = L'\0';\r
+      Str++;\r
+    }\r
+  }\r
+\r
+  *DevicePath = Str;\r
+\r
+  return ReturnStr;\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
+   UINT8  Type,\r
+   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
+  StrHexToBytes (DataStr, DataLength * 2, (UINT8 *) (Node + 1), DataLength);\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
+   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
+   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
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to Hardware PCI device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextPci (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16          *FunctionStr;\r
+  CHAR16          *DeviceStr;\r
+  PCI_DEVICE_PATH *Pci;\r
+\r
+  DeviceStr   = GetNextParamStr (&TextDeviceNode);\r
+  FunctionStr = GetNextParamStr (&TextDeviceNode);\r
+  Pci         = (PCI_DEVICE_PATH *) CreateDeviceNode (\r
+                                      HARDWARE_DEVICE_PATH,\r
+                                      HW_PCI_DP,\r
+                                      (UINT16) sizeof (PCI_DEVICE_PATH)\r
+                                      );\r
+\r
+  Pci->Function = (UINT8) Strtoi (FunctionStr);\r
+  Pci->Device   = (UINT8) Strtoi (DeviceStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Pci;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Hardware PC card device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to Hardware PC card device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextPcCard (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16              *FunctionNumberStr;\r
+  PCCARD_DEVICE_PATH  *Pccard;\r
+\r
+  FunctionNumberStr = GetNextParamStr (&TextDeviceNode);\r
+  Pccard            = (PCCARD_DEVICE_PATH *) CreateDeviceNode (\r
+                                               HARDWARE_DEVICE_PATH,\r
+                                               HW_PCCARD_DP,\r
+                                               (UINT16) sizeof (PCCARD_DEVICE_PATH)\r
+                                               );\r
+\r
+  Pccard->FunctionNumber  = (UINT8) Strtoi (FunctionNumberStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Pccard;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Hardware memory map device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to Hardware memory map device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextMemoryMapped (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16              *MemoryTypeStr;\r
+  CHAR16              *StartingAddressStr;\r
+  CHAR16              *EndingAddressStr;\r
+  MEMMAP_DEVICE_PATH  *MemMap;\r
+\r
+  MemoryTypeStr      = GetNextParamStr (&TextDeviceNode);\r
+  StartingAddressStr = GetNextParamStr (&TextDeviceNode);\r
+  EndingAddressStr   = GetNextParamStr (&TextDeviceNode);\r
+  MemMap             = (MEMMAP_DEVICE_PATH *) CreateDeviceNode (\r
+                                               HARDWARE_DEVICE_PATH,\r
+                                               HW_MEMMAP_DP,\r
+                                               (UINT16) sizeof (MEMMAP_DEVICE_PATH)\r
+                                               );\r
+\r
+  MemMap->MemoryType = (UINT32) Strtoi (MemoryTypeStr);\r
+  Strtoi64 (StartingAddressStr, &MemMap->StartingAddress);\r
+  Strtoi64 (EndingAddressStr, &MemMap->EndingAddress);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) MemMap;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Vendor device path structure based on the input Type\r
+  and SubType.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+  @param Type            The type of device path node.\r
+  @param SubType         The subtype of device path node.\r
+\r
+  @return A pointer to the newly-created Vendor device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+ConvertFromTextVendor (\r
+   CHAR16 *TextDeviceNode,\r
+   UINT8  Type,\r
+   UINT8  SubType\r
+  )\r
+{\r
+  CHAR16              *GuidStr;\r
+  CHAR16              *DataStr;\r
+  UINTN               Length;\r
+  VENDOR_DEVICE_PATH  *Vendor;\r
+\r
+  GuidStr = GetNextParamStr (&TextDeviceNode);\r
+\r
+  DataStr = GetNextParamStr (&TextDeviceNode);\r
+  Length  = StrLen (DataStr);\r
+  //\r
+  // Two hex characters make up 1 buffer byte\r
+  //\r
+  Length  = (Length + 1) / 2;\r
+\r
+  Vendor  = (VENDOR_DEVICE_PATH *) CreateDeviceNode (\r
+                                     Type,\r
+                                     SubType,\r
+                                     (UINT16) (sizeof (VENDOR_DEVICE_PATH) + Length)\r
+                                     );\r
+\r
+  StrToGuid (GuidStr, &Vendor->Guid);\r
+  StrHexToBytes (DataStr, Length * 2, (UINT8 *) (Vendor + 1), Length);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Vendor Hardware device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Vendor Hardware device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextVenHw (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return ConvertFromTextVendor (\r
+           TextDeviceNode,\r
+           HARDWARE_DEVICE_PATH,\r
+           HW_VENDOR_DP\r
+           );\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Hardware Controller device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Hardware Controller device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextCtrl (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                  *ControllerStr;\r
+  CONTROLLER_DEVICE_PATH  *Controller;\r
+\r
+  ControllerStr = GetNextParamStr (&TextDeviceNode);\r
+  Controller    = (CONTROLLER_DEVICE_PATH *) CreateDeviceNode (\r
+                                               HARDWARE_DEVICE_PATH,\r
+                                               HW_CONTROLLER_DP,\r
+                                               (UINT16) sizeof (CONTROLLER_DEVICE_PATH)\r
+                                               );\r
+  Controller->ControllerNumber = (UINT32) Strtoi (ControllerStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Controller;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to BMC device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created BMC device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextBmc (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                *InterfaceTypeStr;\r
+  CHAR16                *BaseAddressStr;\r
+  BMC_DEVICE_PATH       *BmcDp;\r
+\r
+  InterfaceTypeStr = GetNextParamStr (&TextDeviceNode);\r
+  BaseAddressStr   = GetNextParamStr (&TextDeviceNode);\r
+  BmcDp            = (BMC_DEVICE_PATH *) CreateDeviceNode (\r
+                                           HARDWARE_DEVICE_PATH,\r
+                                           HW_BMC_DP,\r
+                                           (UINT16) sizeof (BMC_DEVICE_PATH)\r
+                                           );\r
+\r
+  BmcDp->InterfaceType = (UINT8) Strtoi (InterfaceTypeStr);\r
+  WriteUnaligned64 (\r
+    (UINT64 *) (&BmcDp->BaseAddress),\r
+    StrHexToUint64 (BaseAddressStr)\r
+    );\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) BmcDp;\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
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return DevPathFromTextGenericPath (ACPI_DEVICE_PATH, TextDeviceNode);\r
+}\r
+\r
+/**\r
+  Converts a string to EisaId.\r
+\r
+  @param Text   The input string.\r
+\r
+  @return UINT32 EISA ID.\r
+**/\r
+UINT32\r
+EisaIdFromText (\r
+   CHAR16 *Text\r
+  )\r
+{\r
+  return (((Text[0] - 'A' + 1) & 0x1f) << 10)\r
+       + (((Text[1] - 'A' + 1) & 0x1f) <<  5)\r
+       + (((Text[2] - 'A' + 1) & 0x1f) <<  0)\r
+       + (UINT32) (StrHexToUintn (&Text[3]) << 16)\r
+       ;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to ACPI HID device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created ACPI HID device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextAcpi (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                *HIDStr;\r
+  CHAR16                *UIDStr;\r
+  ACPI_HID_DEVICE_PATH  *Acpi;\r
+\r
+  HIDStr = GetNextParamStr (&TextDeviceNode);\r
+  UIDStr = GetNextParamStr (&TextDeviceNode);\r
+  Acpi   = (ACPI_HID_DEVICE_PATH *) CreateDeviceNode (\r
+                                      ACPI_DEVICE_PATH,\r
+                                      ACPI_DP,\r
+                                      (UINT16) sizeof (ACPI_HID_DEVICE_PATH)\r
+                                      );\r
+\r
+  Acpi->HID = EisaIdFromText (HIDStr);\r
+  Acpi->UID = (UINT32) Strtoi (UIDStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to ACPI HID device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+  @param PnPId           The input plug and play identification.\r
+\r
+  @return A pointer to the newly-created ACPI HID device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+ConvertFromTextAcpi (\r
+   CHAR16 *TextDeviceNode,\r
+   UINT32  PnPId\r
+  )\r
+{\r
+  CHAR16                *UIDStr;\r
+  ACPI_HID_DEVICE_PATH  *Acpi;\r
+\r
+  UIDStr = GetNextParamStr (&TextDeviceNode);\r
+  Acpi   = (ACPI_HID_DEVICE_PATH *) CreateDeviceNode (\r
+                                      ACPI_DEVICE_PATH,\r
+                                      ACPI_DP,\r
+                                      (UINT16) sizeof (ACPI_HID_DEVICE_PATH)\r
+                                      );\r
+\r
+  Acpi->HID = EFI_PNP_ID (PnPId);\r
+  Acpi->UID = (UINT32) Strtoi (UIDStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to PCI root device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created PCI root device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextPciRoot (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return ConvertFromTextAcpi (TextDeviceNode, 0x0a03);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to PCIE root device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created PCIE root device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextPcieRoot (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return ConvertFromTextAcpi (TextDeviceNode, 0x0a08);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Floppy device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Floppy device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextFloppy (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return ConvertFromTextAcpi (TextDeviceNode, 0x0604);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Keyboard device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created  Keyboard device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextKeyboard (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return ConvertFromTextAcpi (TextDeviceNode, 0x0301);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Serial device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Serial device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextSerial (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return ConvertFromTextAcpi (TextDeviceNode, 0x0501);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Parallel Port device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Parallel Port device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextParallelPort (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return ConvertFromTextAcpi (TextDeviceNode, 0x0401);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to ACPI extension device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created ACPI extension device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextAcpiEx (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                         *HIDStr;\r
+  CHAR16                         *CIDStr;\r
+  CHAR16                         *UIDStr;\r
+  CHAR16                         *HIDSTRStr;\r
+  CHAR16                         *CIDSTRStr;\r
+  CHAR16                         *UIDSTRStr;\r
+  CHAR8                          *AsciiStr;\r
+  UINT16                         Length;\r
+  ACPI_EXTENDED_HID_DEVICE_PATH  *AcpiEx;\r
+\r
+  HIDStr    = GetNextParamStr (&TextDeviceNode);\r
+  CIDStr    = GetNextParamStr (&TextDeviceNode);\r
+  UIDStr    = GetNextParamStr (&TextDeviceNode);\r
+  HIDSTRStr = GetNextParamStr (&TextDeviceNode);\r
+  CIDSTRStr = GetNextParamStr (&TextDeviceNode);\r
+  UIDSTRStr = GetNextParamStr (&TextDeviceNode);\r
+\r
+  Length    = (UINT16) (sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (HIDSTRStr) + 1);\r
+  Length    = (UINT16) (Length + StrLen (UIDSTRStr) + 1);\r
+  Length    = (UINT16) (Length + StrLen (CIDSTRStr) + 1);\r
+  AcpiEx = (ACPI_EXTENDED_HID_DEVICE_PATH *) CreateDeviceNode (\r
+                                               ACPI_DEVICE_PATH,\r
+                                               ACPI_EXTENDED_DP,\r
+                                               Length\r
+                                               );\r
+\r
+  AcpiEx->HID = EisaIdFromText (HIDStr);\r
+  AcpiEx->CID = EisaIdFromText (CIDStr);\r
+  AcpiEx->UID = (UINT32) Strtoi (UIDStr);\r
+\r
+  AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));\r
+  StrToAscii (HIDSTRStr, &AsciiStr);\r
+  StrToAscii (UIDSTRStr, &AsciiStr);\r
+  StrToAscii (CIDSTRStr, &AsciiStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) AcpiEx;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to ACPI extension device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created ACPI extension device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextAcpiExp (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                         *HIDStr;\r
+  CHAR16                         *CIDStr;\r
+  CHAR16                         *UIDSTRStr;\r
+  CHAR8                          *AsciiStr;\r
+  UINT16                         Length;\r
+  ACPI_EXTENDED_HID_DEVICE_PATH  *AcpiEx;\r
+\r
+  HIDStr    = GetNextParamStr (&TextDeviceNode);\r
+  CIDStr    = GetNextParamStr (&TextDeviceNode);\r
+  UIDSTRStr = GetNextParamStr (&TextDeviceNode);\r
+  Length    = (UINT16) (sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (UIDSTRStr) + 3);\r
+  AcpiEx    = (ACPI_EXTENDED_HID_DEVICE_PATH *) CreateDeviceNode (\r
+                                                  ACPI_DEVICE_PATH,\r
+                                                  ACPI_EXTENDED_DP,\r
+                                                  Length\r
+                                                  );\r
+\r
+  AcpiEx->HID = EisaIdFromText (HIDStr);\r
+  AcpiEx->CID = EisaIdFromText (CIDStr);\r
+  AcpiEx->UID = 0;\r
+\r
+  AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));\r
+  //\r
+  // HID string is NULL\r
+  //\r
+  *AsciiStr = '\0';\r
+  //\r
+  // Convert UID string\r
+  //\r
+  AsciiStr++;\r
+  StrToAscii (UIDSTRStr, &AsciiStr);\r
+  //\r
+  // CID string is NULL\r
+  //\r
+  *AsciiStr = '\0';\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) AcpiEx;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to ACPI _ADR device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created ACPI _ADR device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextAcpiAdr (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                *DisplayDeviceStr;\r
+  ACPI_ADR_DEVICE_PATH  *AcpiAdr;\r
+  UINTN                 Index;\r
+  UINTN                 Length;\r
+\r
+  AcpiAdr = (ACPI_ADR_DEVICE_PATH *) CreateDeviceNode (\r
+                                       ACPI_DEVICE_PATH,\r
+                                       ACPI_ADR_DP,\r
+                                       (UINT16) sizeof (ACPI_ADR_DEVICE_PATH)\r
+                                       );\r
+  ASSERT (AcpiAdr != NULL);\r
+\r
+  for (Index = 0; ; Index++) {\r
+    DisplayDeviceStr = GetNextParamStr (&TextDeviceNode);\r
+    if (IS_NULL (*DisplayDeviceStr)) {\r
+      break;\r
+    }\r
+    if (Index > 0) {\r
+      Length  = DevicePathNodeLength (AcpiAdr);\r
+      AcpiAdr = ReallocatePool (\r
+                  Length,\r
+                  Length + sizeof (UINT32),\r
+                  AcpiAdr\r
+                  );\r
+      ASSERT (AcpiAdr != NULL);\r
+      SetDevicePathNodeLength (AcpiAdr, Length + sizeof (UINT32));\r
+    }\r
+\r
+    (&AcpiAdr->ADR)[Index] = (UINT32) Strtoi (DisplayDeviceStr);\r
+  }\r
+\r
+  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
+   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
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Parallel Port device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextAta (\r
+ CHAR16 *TextDeviceNode\r
+)\r
+{\r
+  CHAR16            *PrimarySecondaryStr;\r
+  CHAR16            *SlaveMasterStr;\r
+  CHAR16            *LunStr;\r
+  ATAPI_DEVICE_PATH *Atapi;\r
+\r
+  Atapi = (ATAPI_DEVICE_PATH *) CreateDeviceNode (\r
+    MESSAGING_DEVICE_PATH,\r
+    MSG_ATAPI_DP,\r
+    (UINT16) sizeof (ATAPI_DEVICE_PATH)\r
+    );\r
+\r
+  PrimarySecondaryStr = GetNextParamStr (&TextDeviceNode);\r
+  SlaveMasterStr      = GetNextParamStr (&TextDeviceNode);\r
+  LunStr              = GetNextParamStr (&TextDeviceNode);\r
+\r
+  if (StrCmp (PrimarySecondaryStr, L"Primary") == 0) {\r
+    Atapi->PrimarySecondary = 0;\r
+  } else if (StrCmp (PrimarySecondaryStr, L"Secondary") == 0) {\r
+    Atapi->PrimarySecondary = 1;\r
+  } else {\r
+    Atapi->PrimarySecondary = (UINT8) Strtoi (PrimarySecondaryStr);\r
+  }\r
+  if (StrCmp (SlaveMasterStr, L"Master") == 0) {\r
+    Atapi->SlaveMaster      = 0;\r
+  } else if (StrCmp (SlaveMasterStr, L"Slave") == 0) {\r
+    Atapi->SlaveMaster      = 1;\r
+  } else {\r
+    Atapi->SlaveMaster      = (UINT8) Strtoi (SlaveMasterStr);\r
+  }\r
+\r
+  Atapi->Lun                = (UINT16) Strtoi (LunStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Atapi;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to SCSI device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created SCSI device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextScsi (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16            *PunStr;\r
+  CHAR16            *LunStr;\r
+  SCSI_DEVICE_PATH  *Scsi;\r
+\r
+  PunStr = GetNextParamStr (&TextDeviceNode);\r
+  LunStr = GetNextParamStr (&TextDeviceNode);\r
+  Scsi   = (SCSI_DEVICE_PATH *) CreateDeviceNode (\r
+                                   MESSAGING_DEVICE_PATH,\r
+                                   MSG_SCSI_DP,\r
+                                   (UINT16) sizeof (SCSI_DEVICE_PATH)\r
+                                   );\r
+\r
+  Scsi->Pun = (UINT16) Strtoi (PunStr);\r
+  Scsi->Lun = (UINT16) Strtoi (LunStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Scsi;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Fibre device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Fibre device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextFibre (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                    *WWNStr;\r
+  CHAR16                    *LunStr;\r
+  FIBRECHANNEL_DEVICE_PATH  *Fibre;\r
+\r
+  WWNStr = GetNextParamStr (&TextDeviceNode);\r
+  LunStr = GetNextParamStr (&TextDeviceNode);\r
+  Fibre  = (FIBRECHANNEL_DEVICE_PATH *) CreateDeviceNode (\r
+                                          MESSAGING_DEVICE_PATH,\r
+                                          MSG_FIBRECHANNEL_DP,\r
+                                          (UINT16) sizeof (FIBRECHANNEL_DEVICE_PATH)\r
+                                          );\r
+\r
+  Fibre->Reserved = 0;\r
+  Strtoi64 (WWNStr, &Fibre->WWN);\r
+  Strtoi64 (LunStr, &Fibre->Lun);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Fibre;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to FibreEx device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created FibreEx device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextFibreEx (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                      *WWNStr;\r
+  CHAR16                      *LunStr;\r
+  FIBRECHANNELEX_DEVICE_PATH  *FibreEx;\r
+\r
+  WWNStr  = GetNextParamStr (&TextDeviceNode);\r
+  LunStr  = GetNextParamStr (&TextDeviceNode);\r
+  FibreEx = (FIBRECHANNELEX_DEVICE_PATH *) CreateDeviceNode (\r
+                                             MESSAGING_DEVICE_PATH,\r
+                                             MSG_FIBRECHANNELEX_DP,\r
+                                             (UINT16) sizeof (FIBRECHANNELEX_DEVICE_PATH)\r
+                                             );\r
+\r
+  FibreEx->Reserved = 0;\r
+  Strtoi64 (WWNStr, (UINT64 *) (&FibreEx->WWN));\r
+  Strtoi64 (LunStr, (UINT64 *) (&FibreEx->Lun));\r
+\r
+  *(UINT64 *) (&FibreEx->WWN) = SwapBytes64 (*(UINT64 *) (&FibreEx->WWN));\r
+  *(UINT64 *) (&FibreEx->Lun) = SwapBytes64 (*(UINT64 *) (&FibreEx->Lun));\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) FibreEx;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to 1394 device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created 1394 device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromText1394 (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16            *GuidStr;\r
+  F1394_DEVICE_PATH *F1394DevPath;\r
+\r
+  GuidStr = GetNextParamStr (&TextDeviceNode);\r
+  F1394DevPath  = (F1394_DEVICE_PATH *) CreateDeviceNode (\r
+                                          MESSAGING_DEVICE_PATH,\r
+                                          MSG_1394_DP,\r
+                                          (UINT16) sizeof (F1394_DEVICE_PATH)\r
+                                          );\r
+\r
+  F1394DevPath->Reserved = 0;\r
+  F1394DevPath->Guid     = StrHexToUint64 (GuidStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) F1394DevPath;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsb (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16          *PortStr;\r
+  CHAR16          *InterfaceStr;\r
+  USB_DEVICE_PATH *Usb;\r
+\r
+  PortStr               = GetNextParamStr (&TextDeviceNode);\r
+  InterfaceStr          = GetNextParamStr (&TextDeviceNode);\r
+  Usb                   = (USB_DEVICE_PATH *) CreateDeviceNode (\r
+                                                MESSAGING_DEVICE_PATH,\r
+                                                MSG_USB_DP,\r
+                                                (UINT16) sizeof (USB_DEVICE_PATH)\r
+                                                );\r
+\r
+  Usb->ParentPortNumber = (UINT8) Strtoi (PortStr);\r
+  Usb->InterfaceNumber  = (UINT8) Strtoi (InterfaceStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Usb;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to I20 device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created I20 device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextI2O (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16          *TIDStr;\r
+  I2O_DEVICE_PATH *I2ODevPath;\r
+\r
+  TIDStr     = GetNextParamStr (&TextDeviceNode);\r
+  I2ODevPath = (I2O_DEVICE_PATH *) CreateDeviceNode (\r
+                                    MESSAGING_DEVICE_PATH,\r
+                                    MSG_I2O_DP,\r
+                                    (UINT16) sizeof (I2O_DEVICE_PATH)\r
+                                    );\r
+\r
+  I2ODevPath->Tid  = (UINT32) Strtoi (TIDStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) I2ODevPath;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Infini Band device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Infini Band device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextInfiniband (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                  *FlagsStr;\r
+  CHAR16                  *GuidStr;\r
+  CHAR16                  *SidStr;\r
+  CHAR16                  *TidStr;\r
+  CHAR16                  *DidStr;\r
+  INFINIBAND_DEVICE_PATH  *InfiniBand;\r
+\r
+  FlagsStr   = GetNextParamStr (&TextDeviceNode);\r
+  GuidStr    = GetNextParamStr (&TextDeviceNode);\r
+  SidStr     = GetNextParamStr (&TextDeviceNode);\r
+  TidStr     = GetNextParamStr (&TextDeviceNode);\r
+  DidStr     = GetNextParamStr (&TextDeviceNode);\r
+  InfiniBand = (INFINIBAND_DEVICE_PATH *) CreateDeviceNode (\r
+                                            MESSAGING_DEVICE_PATH,\r
+                                            MSG_INFINIBAND_DP,\r
+                                            (UINT16) sizeof (INFINIBAND_DEVICE_PATH)\r
+                                            );\r
+\r
+  InfiniBand->ResourceFlags = (UINT32) Strtoi (FlagsStr);\r
+  StrToGuid (GuidStr, (EFI_GUID *) InfiniBand->PortGid);\r
+  Strtoi64 (SidStr, &InfiniBand->ServiceId);\r
+  Strtoi64 (TidStr, &InfiniBand->TargetPortId);\r
+  Strtoi64 (DidStr, &InfiniBand->DeviceId);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) InfiniBand;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Vendor-Defined Messaging device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Vendor-Defined Messaging device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextVenMsg (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return ConvertFromTextVendor (\r
+            TextDeviceNode,\r
+            MESSAGING_DEVICE_PATH,\r
+            MSG_VENDOR_DP\r
+            );\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Vendor defined PC-ANSI device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Vendor defined PC-ANSI device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextVenPcAnsi (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  VENDOR_DEVICE_PATH  *Vendor;\r
+\r
+  Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (\r
+                                    MESSAGING_DEVICE_PATH,\r
+                                    MSG_VENDOR_DP,\r
+                                    (UINT16) sizeof (VENDOR_DEVICE_PATH));\r
+  CopyGuid (&Vendor->Guid, &gEfiPcAnsiGuid);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Vendor defined VT100 device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Vendor defined VT100 device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextVenVt100 (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  VENDOR_DEVICE_PATH  *Vendor;\r
+\r
+  Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (\r
+                                    MESSAGING_DEVICE_PATH,\r
+                                    MSG_VENDOR_DP,\r
+                                    (UINT16) sizeof (VENDOR_DEVICE_PATH));\r
+  CopyGuid (&Vendor->Guid, &gEfiVT100Guid);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Vendor defined VT100 Plus device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Vendor defined VT100 Plus device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextVenVt100Plus (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  VENDOR_DEVICE_PATH  *Vendor;\r
+\r
+  Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (\r
+                                    MESSAGING_DEVICE_PATH,\r
+                                    MSG_VENDOR_DP,\r
+                                    (UINT16) sizeof (VENDOR_DEVICE_PATH));\r
+  CopyGuid (&Vendor->Guid, &gEfiVT100PlusGuid);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Vendor defined UTF8 device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Vendor defined UTF8 device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextVenUtf8 (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  VENDOR_DEVICE_PATH  *Vendor;\r
+\r
+  Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (\r
+                                    MESSAGING_DEVICE_PATH,\r
+                                    MSG_VENDOR_DP,\r
+                                    (UINT16) sizeof (VENDOR_DEVICE_PATH));\r
+  CopyGuid (&Vendor->Guid, &gEfiVTUTF8Guid);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to UART Flow Control device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created UART Flow Control device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUartFlowCtrl (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                        *ValueStr;\r
+  UART_FLOW_CONTROL_DEVICE_PATH *UartFlowControl;\r
+\r
+  ValueStr        = GetNextParamStr (&TextDeviceNode);\r
+  UartFlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *) CreateDeviceNode (\r
+                                                        MESSAGING_DEVICE_PATH,\r
+                                                        MSG_VENDOR_DP,\r
+                                                        (UINT16) sizeof (UART_FLOW_CONTROL_DEVICE_PATH)\r
+                                                        );\r
+\r
+  CopyGuid (&UartFlowControl->Guid, &gEfiUartDevicePathGuid);\r
+  if (StrCmp (ValueStr, L"XonXoff") == 0) {\r
+    UartFlowControl->FlowControlMap = 2;\r
+  } else if (StrCmp (ValueStr, L"Hardware") == 0) {\r
+    UartFlowControl->FlowControlMap = 1;\r
+  } else {\r
+    UartFlowControl->FlowControlMap = 0;\r
+  }\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) UartFlowControl;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Serial Attached SCSI device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Serial Attached SCSI device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextSAS (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16          *AddressStr;\r
+  CHAR16          *LunStr;\r
+  CHAR16          *RTPStr;\r
+  CHAR16          *SASSATAStr;\r
+  CHAR16          *LocationStr;\r
+  CHAR16          *ConnectStr;\r
+  CHAR16          *DriveBayStr;\r
+  CHAR16          *ReservedStr;\r
+  UINT16          Info;\r
+  UINT16          Uint16;\r
+  SAS_DEVICE_PATH *Sas;\r
+\r
+  AddressStr  = GetNextParamStr (&TextDeviceNode);\r
+  LunStr      = GetNextParamStr (&TextDeviceNode);\r
+  RTPStr      = GetNextParamStr (&TextDeviceNode);\r
+  SASSATAStr  = GetNextParamStr (&TextDeviceNode);\r
+  LocationStr = GetNextParamStr (&TextDeviceNode);\r
+  ConnectStr  = GetNextParamStr (&TextDeviceNode);\r
+  DriveBayStr = GetNextParamStr (&TextDeviceNode);\r
+  ReservedStr = GetNextParamStr (&TextDeviceNode);\r
+  Sas         = (SAS_DEVICE_PATH *) CreateDeviceNode (\r
+                                       MESSAGING_DEVICE_PATH,\r
+                                       MSG_VENDOR_DP,\r
+                                       (UINT16) sizeof (SAS_DEVICE_PATH)\r
+                                       );\r
+\r
+  CopyGuid (&Sas->Guid, &gEfiSasDevicePathGuid);\r
+  Strtoi64 (AddressStr, &Sas->SasAddress);\r
+  Strtoi64 (LunStr, &Sas->Lun);\r
+  Sas->RelativeTargetPort = (UINT16) Strtoi (RTPStr);\r
+\r
+  if (StrCmp (SASSATAStr, L"NoTopology") == 0) {\r
+    Info = 0x0;\r
+\r
+  } else if ((StrCmp (SASSATAStr, L"SATA") == 0) || (StrCmp (SASSATAStr, L"SAS") == 0)) {\r
+\r
+    Uint16 = (UINT16) Strtoi (DriveBayStr);\r
+    if (Uint16 == 0) {\r
+      Info = 0x1;\r
+    } else {\r
+      Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));\r
+    }\r
+\r
+    if (StrCmp (SASSATAStr, L"SATA") == 0) {\r
+      Info |= BIT4;\r
+    }\r
+\r
+    //\r
+    // Location is an integer between 0 and 1 or else\r
+    // the keyword Internal (0) or External (1).\r
+    //\r
+    if (StrCmp (LocationStr, L"External") == 0) {\r
+      Uint16 = 1;\r
+    } else if (StrCmp (LocationStr, L"Internal") == 0) {\r
+      Uint16 = 0;\r
+    } else {\r
+      Uint16 = ((UINT16) Strtoi (LocationStr) & BIT0);\r
+    }\r
+    Info |= (Uint16 << 5);\r
+\r
+    //\r
+    // Connect is an integer between 0 and 3 or else\r
+    // the keyword Direct (0) or Expanded (1).\r
+    //\r
+    if (StrCmp (ConnectStr, L"Expanded") == 0) {\r
+      Uint16 = 1;\r
+    } else if (StrCmp (ConnectStr, L"Direct") == 0) {\r
+      Uint16 = 0;\r
+    } else {\r
+      Uint16 = ((UINT16) Strtoi (ConnectStr) & (BIT0 | BIT1));\r
+    }\r
+    Info |= (Uint16 << 6);\r
+\r
+  } else {\r
+    Info = (UINT16) Strtoi (SASSATAStr);\r
+  }\r
+\r
+  Sas->DeviceTopology = Info;\r
+  Sas->Reserved       = (UINT32) Strtoi (ReservedStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Sas;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Serial Attached SCSI Ex device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Serial Attached SCSI Ex device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextSasEx (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16            *AddressStr;\r
+  CHAR16            *LunStr;\r
+  CHAR16            *RTPStr;\r
+  CHAR16            *SASSATAStr;\r
+  CHAR16            *LocationStr;\r
+  CHAR16            *ConnectStr;\r
+  CHAR16            *DriveBayStr;\r
+  UINT16            Info;\r
+  UINT16            Uint16;\r
+  UINT64            SasAddress;\r
+  UINT64            Lun;\r
+  SASEX_DEVICE_PATH *SasEx;\r
+\r
+  AddressStr  = GetNextParamStr (&TextDeviceNode);\r
+  LunStr      = GetNextParamStr (&TextDeviceNode);\r
+  RTPStr      = GetNextParamStr (&TextDeviceNode);\r
+  SASSATAStr  = GetNextParamStr (&TextDeviceNode);\r
+  LocationStr = GetNextParamStr (&TextDeviceNode);\r
+  ConnectStr  = GetNextParamStr (&TextDeviceNode);\r
+  DriveBayStr = GetNextParamStr (&TextDeviceNode);\r
+  SasEx       = (SASEX_DEVICE_PATH *) CreateDeviceNode (\r
+                                        MESSAGING_DEVICE_PATH,\r
+                                        MSG_SASEX_DP,\r
+                                        (UINT16) sizeof (SASEX_DEVICE_PATH)\r
+                                        );\r
+\r
+  Strtoi64 (AddressStr, &SasAddress);\r
+  Strtoi64 (LunStr,     &Lun);\r
+  WriteUnaligned64 ((UINT64 *) &SasEx->SasAddress, SwapBytes64 (SasAddress));\r
+  WriteUnaligned64 ((UINT64 *) &SasEx->Lun,        SwapBytes64 (Lun));\r
+  SasEx->RelativeTargetPort      = (UINT16) Strtoi (RTPStr);\r
+\r
+  if (StrCmp (SASSATAStr, L"NoTopology") == 0) {\r
+    Info = 0x0;\r
+\r
+  } else if ((StrCmp (SASSATAStr, L"SATA") == 0) || (StrCmp (SASSATAStr, L"SAS") == 0)) {\r
+\r
+    Uint16 = (UINT16) Strtoi (DriveBayStr);\r
+    if (Uint16 == 0) {\r
+      Info = 0x1;\r
+    } else {\r
+      Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));\r
+    }\r
+\r
+    if (StrCmp (SASSATAStr, L"SATA") == 0) {\r
+      Info |= BIT4;\r
+    }\r
+\r
+    //\r
+    // Location is an integer between 0 and 1 or else\r
+    // the keyword Internal (0) or External (1).\r
+    //\r
+    if (StrCmp (LocationStr, L"External") == 0) {\r
+      Uint16 = 1;\r
+    } else if (StrCmp (LocationStr, L"Internal") == 0) {\r
+      Uint16 = 0;\r
+    } else {\r
+      Uint16 = ((UINT16) Strtoi (LocationStr) & BIT0);\r
+    }\r
+    Info |= (Uint16 << 5);\r
+\r
+    //\r
+    // Connect is an integer between 0 and 3 or else\r
+    // the keyword Direct (0) or Expanded (1).\r
+    //\r
+    if (StrCmp (ConnectStr, L"Expanded") == 0) {\r
+      Uint16 = 1;\r
+    } else if (StrCmp (ConnectStr, L"Direct") == 0) {\r
+      Uint16 = 0;\r
+    } else {\r
+      Uint16 = ((UINT16) Strtoi (ConnectStr) & (BIT0 | BIT1));\r
+    }\r
+    Info |= (Uint16 << 6);\r
+\r
+  } else {\r
+    Info = (UINT16) Strtoi (SASSATAStr);\r
+  }\r
+\r
+  SasEx->DeviceTopology = Info;\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) SasEx;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to NVM Express Namespace device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created NVM Express Namespace device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextNVMe (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                     *NamespaceIdStr;\r
+  CHAR16                     *NamespaceUuidStr;\r
+  NVME_NAMESPACE_DEVICE_PATH *Nvme;\r
+  UINT8                      *Uuid;\r
+  UINTN                      Index;\r
+\r
+  NamespaceIdStr   = GetNextParamStr (&TextDeviceNode);\r
+  NamespaceUuidStr = GetNextParamStr (&TextDeviceNode);\r
+  Nvme = (NVME_NAMESPACE_DEVICE_PATH *) CreateDeviceNode (\r
+    MESSAGING_DEVICE_PATH,\r
+    MSG_NVME_NAMESPACE_DP,\r
+    (UINT16) sizeof (NVME_NAMESPACE_DEVICE_PATH)\r
+    );\r
+\r
+  Nvme->NamespaceId = (UINT32) Strtoi (NamespaceIdStr);\r
+  Uuid = (UINT8 *) &Nvme->NamespaceUuid;\r
+\r
+  Index = sizeof (Nvme->NamespaceUuid) / sizeof (UINT8);\r
+  while (Index-- != 0) {\r
+    Uuid[Index] = (UINT8) StrHexToUintn (SplitStr (&NamespaceUuidStr, L'-'));\r
+  }\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Nvme;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to UFS device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created UFS device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUfs (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16            *PunStr;\r
+  CHAR16            *LunStr;\r
+  UFS_DEVICE_PATH   *Ufs;\r
+\r
+  PunStr = GetNextParamStr (&TextDeviceNode);\r
+  LunStr = GetNextParamStr (&TextDeviceNode);\r
+  Ufs    = (UFS_DEVICE_PATH *) CreateDeviceNode (\r
+                                 MESSAGING_DEVICE_PATH,\r
+                                 MSG_UFS_DP,\r
+                                 (UINT16) sizeof (UFS_DEVICE_PATH)\r
+                                 );\r
+\r
+  Ufs->Pun = (UINT8) Strtoi (PunStr);\r
+  Ufs->Lun = (UINT8) Strtoi (LunStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Ufs;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to SD (Secure Digital) device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created SD device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextSd (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16            *SlotNumberStr;\r
+  SD_DEVICE_PATH    *Sd;\r
+\r
+  SlotNumberStr = GetNextParamStr (&TextDeviceNode);\r
+  Sd            = (SD_DEVICE_PATH *) CreateDeviceNode (\r
+                                       MESSAGING_DEVICE_PATH,\r
+                                       MSG_SD_DP,\r
+                                       (UINT16) sizeof (SD_DEVICE_PATH)\r
+                                       );\r
+\r
+  Sd->SlotNumber = (UINT8) Strtoi (SlotNumberStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Sd;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to EMMC (Embedded MMC) device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created EMMC device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextEmmc (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16            *SlotNumberStr;\r
+  EMMC_DEVICE_PATH  *Emmc;\r
+\r
+  SlotNumberStr = GetNextParamStr (&TextDeviceNode);\r
+  Emmc          = (EMMC_DEVICE_PATH *) CreateDeviceNode (\r
+                                       MESSAGING_DEVICE_PATH,\r
+                                       MSG_EMMC_DP,\r
+                                       (UINT16) sizeof (EMMC_DEVICE_PATH)\r
+                                       );\r
+\r
+  Emmc->SlotNumber = (UINT8) Strtoi (SlotNumberStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Emmc;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Debug Port device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Debug Port device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextDebugPort (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  VENDOR_DEFINED_MESSAGING_DEVICE_PATH  *Vend;\r
+\r
+  Vend = (VENDOR_DEFINED_MESSAGING_DEVICE_PATH *) CreateDeviceNode (\r
+                                                    MESSAGING_DEVICE_PATH,\r
+                                                    MSG_VENDOR_DP,\r
+                                                    (UINT16) sizeof (VENDOR_DEFINED_MESSAGING_DEVICE_PATH)\r
+                                                    );\r
+\r
+  CopyGuid (&Vend->Guid, &gEfiDebugPortDevicePathGuid);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Vend;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to MAC device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created MAC device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextMAC (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                *AddressStr;\r
+  CHAR16                *IfTypeStr;\r
+  UINTN                 Length;\r
+  MAC_ADDR_DEVICE_PATH  *MACDevPath;\r
+\r
+  AddressStr    = GetNextParamStr (&TextDeviceNode);\r
+  IfTypeStr     = GetNextParamStr (&TextDeviceNode);\r
+  MACDevPath    = (MAC_ADDR_DEVICE_PATH *) CreateDeviceNode (\r
+                                              MESSAGING_DEVICE_PATH,\r
+                                              MSG_MAC_ADDR_DP,\r
+                                              (UINT16) sizeof (MAC_ADDR_DEVICE_PATH)\r
+                                              );\r
+\r
+  MACDevPath->IfType   = (UINT8) Strtoi (IfTypeStr);\r
+\r
+  Length = sizeof (EFI_MAC_ADDRESS);\r
+  if (MACDevPath->IfType == 0x01 || MACDevPath->IfType == 0x00) {\r
+    Length = 6;\r
+  }\r
+\r
+  StrHexToBytes (AddressStr, Length * 2, MACDevPath->MacAddress.Addr, Length);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) MACDevPath;\r
+}\r
+\r
+\r
+/**\r
+  Converts a text format to the network protocol ID.\r
+\r
+  @param Text  String of protocol field.\r
+\r
+  @return Network protocol ID .\r
+\r
+**/\r
+UINTN\r
+NetworkProtocolFromText (\r
+   CHAR16 *Text\r
+  )\r
+{\r
+  if (StrCmp (Text, L"UDP") == 0) {\r
+    return RFC_1700_UDP_PROTOCOL;\r
+  }\r
+\r
+  if (StrCmp (Text, L"TCP") == 0) {\r
+    return RFC_1700_TCP_PROTOCOL;\r
+  }\r
+\r
+  return Strtoi (Text);\r
+}\r
+\r
+\r
+/**\r
+  Converts a text device path node to IPV4 device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created IPV4 device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextIPv4 (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16            *RemoteIPStr;\r
+  CHAR16            *ProtocolStr;\r
+  CHAR16            *TypeStr;\r
+  CHAR16            *LocalIPStr;\r
+  CHAR16            *GatewayIPStr;\r
+  CHAR16            *SubnetMaskStr;\r
+  IPv4_DEVICE_PATH  *IPv4;\r
+\r
+  RemoteIPStr           = GetNextParamStr (&TextDeviceNode);\r
+  ProtocolStr           = GetNextParamStr (&TextDeviceNode);\r
+  TypeStr               = GetNextParamStr (&TextDeviceNode);\r
+  LocalIPStr            = GetNextParamStr (&TextDeviceNode);\r
+  GatewayIPStr          = GetNextParamStr (&TextDeviceNode);\r
+  SubnetMaskStr         = GetNextParamStr (&TextDeviceNode);\r
+  IPv4                  = (IPv4_DEVICE_PATH *) CreateDeviceNode (\r
+                                                 MESSAGING_DEVICE_PATH,\r
+                                                 MSG_IPv4_DP,\r
+                                                 (UINT16) sizeof (IPv4_DEVICE_PATH)\r
+                                                 );\r
+\r
+  StrToIpv4Address (RemoteIPStr, NULL, &IPv4->RemoteIpAddress, NULL);\r
+  IPv4->Protocol = (UINT16) NetworkProtocolFromText (ProtocolStr);\r
+  if (StrCmp (TypeStr, L"Static") == 0) {\r
+    IPv4->StaticIpAddress = TRUE;\r
+  } else {\r
+    IPv4->StaticIpAddress = FALSE;\r
+  }\r
+\r
+  StrToIpv4Address (LocalIPStr, NULL, &IPv4->LocalIpAddress, NULL);\r
+  if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*SubnetMaskStr)) {\r
+    StrToIpv4Address (GatewayIPStr,  NULL, &IPv4->GatewayIpAddress, NULL);\r
+    StrToIpv4Address (SubnetMaskStr, NULL, &IPv4->SubnetMask,       NULL);\r
+  } else {\r
+    ZeroMem (&IPv4->GatewayIpAddress, sizeof (IPv4->GatewayIpAddress));\r
+    ZeroMem (&IPv4->SubnetMask,    sizeof (IPv4->SubnetMask));\r
+  }\r
+\r
+  IPv4->LocalPort       = 0;\r
+  IPv4->RemotePort      = 0;\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) IPv4;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to IPV6 device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created IPV6 device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextIPv6 (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16            *RemoteIPStr;\r
+  CHAR16            *ProtocolStr;\r
+  CHAR16            *TypeStr;\r
+  CHAR16            *LocalIPStr;\r
+  CHAR16            *GatewayIPStr;\r
+  CHAR16            *PrefixLengthStr;\r
+  IPv6_DEVICE_PATH  *IPv6;\r
+\r
+  RemoteIPStr           = GetNextParamStr (&TextDeviceNode);\r
+  ProtocolStr           = GetNextParamStr (&TextDeviceNode);\r
+  TypeStr               = GetNextParamStr (&TextDeviceNode);\r
+  LocalIPStr            = GetNextParamStr (&TextDeviceNode);\r
+  PrefixLengthStr       = GetNextParamStr (&TextDeviceNode);\r
+  GatewayIPStr          = GetNextParamStr (&TextDeviceNode);\r
+  IPv6                  = (IPv6_DEVICE_PATH *) CreateDeviceNode (\r
+                                                 MESSAGING_DEVICE_PATH,\r
+                                                 MSG_IPv6_DP,\r
+                                                 (UINT16) sizeof (IPv6_DEVICE_PATH)\r
+                                                 );\r
+\r
+  StrToIpv6Address (RemoteIPStr, NULL, &IPv6->RemoteIpAddress, NULL);\r
+  IPv6->Protocol        = (UINT16) NetworkProtocolFromText (ProtocolStr);\r
+  if (StrCmp (TypeStr, L"Static") == 0) {\r
+    IPv6->IpAddressOrigin = 0;\r
+  } else if (StrCmp (TypeStr, L"StatelessAutoConfigure") == 0) {\r
+    IPv6->IpAddressOrigin = 1;\r
+  } else {\r
+    IPv6->IpAddressOrigin = 2;\r
+  }\r
+\r
+  StrToIpv6Address (LocalIPStr, NULL, &IPv6->LocalIpAddress, NULL);\r
+  if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*PrefixLengthStr)) {\r
+    StrToIpv6Address (GatewayIPStr, NULL, &IPv6->GatewayIpAddress, NULL);\r
+    IPv6->PrefixLength = (UINT8) Strtoi (PrefixLengthStr);\r
+  } else {\r
+    ZeroMem (&IPv6->GatewayIpAddress, sizeof (IPv6->GatewayIpAddress));\r
+    IPv6->PrefixLength = 0;\r
+  }\r
+\r
+  IPv6->LocalPort       = 0;\r
+  IPv6->RemotePort      = 0;\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) IPv6;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to UART device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created UART device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUart (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16            *BaudStr;\r
+  CHAR16            *DataBitsStr;\r
+  CHAR16            *ParityStr;\r
+  CHAR16            *StopBitsStr;\r
+  UART_DEVICE_PATH  *Uart;\r
+\r
+  BaudStr         = GetNextParamStr (&TextDeviceNode);\r
+  DataBitsStr     = GetNextParamStr (&TextDeviceNode);\r
+  ParityStr       = GetNextParamStr (&TextDeviceNode);\r
+  StopBitsStr     = GetNextParamStr (&TextDeviceNode);\r
+  Uart            = (UART_DEVICE_PATH *) CreateDeviceNode (\r
+                                           MESSAGING_DEVICE_PATH,\r
+                                           MSG_UART_DP,\r
+                                           (UINT16) sizeof (UART_DEVICE_PATH)\r
+                                           );\r
+\r
+  if (StrCmp (BaudStr, L"DEFAULT") == 0) {\r
+    Uart->BaudRate = 115200;\r
+  } else {\r
+    Strtoi64 (BaudStr, &Uart->BaudRate);\r
+  }\r
+  Uart->DataBits  = (UINT8) ((StrCmp (DataBitsStr, L"DEFAULT") == 0) ? 8 : Strtoi (DataBitsStr));\r
+  switch (*ParityStr) {\r
+  case L'D':\r
+    Uart->Parity = 0;\r
+    break;\r
+\r
+  case L'N':\r
+    Uart->Parity = 1;\r
+    break;\r
+\r
+  case L'E':\r
+    Uart->Parity = 2;\r
+    break;\r
+\r
+  case L'O':\r
+    Uart->Parity = 3;\r
+    break;\r
+\r
+  case L'M':\r
+    Uart->Parity = 4;\r
+    break;\r
+\r
+  case L'S':\r
+    Uart->Parity = 5;\r
+    break;\r
+\r
+  default:\r
+    Uart->Parity = (UINT8) Strtoi (ParityStr);\r
+    break;\r
+  }\r
+\r
+  if (StrCmp (StopBitsStr, L"D") == 0) {\r
+    Uart->StopBits = (UINT8) 0;\r
+  } else if (StrCmp (StopBitsStr, L"1") == 0) {\r
+    Uart->StopBits = (UINT8) 1;\r
+  } else if (StrCmp (StopBitsStr, L"1.5") == 0) {\r
+    Uart->StopBits = (UINT8) 2;\r
+  } else if (StrCmp (StopBitsStr, L"2") == 0) {\r
+    Uart->StopBits = (UINT8) 3;\r
+  } else {\r
+    Uart->StopBits = (UINT8) Strtoi (StopBitsStr);\r
+  }\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Uart;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB class device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+  @param UsbClassText    A pointer to USB_CLASS_TEXT structure to be integrated to USB Class Text.\r
+\r
+  @return A pointer to the newly-created USB class device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+ConvertFromTextUsbClass (\r
+   CHAR16         *TextDeviceNode,\r
+   USB_CLASS_TEXT *UsbClassText\r
+  )\r
+{\r
+  CHAR16                *VIDStr;\r
+  CHAR16                *PIDStr;\r
+  CHAR16                *ClassStr;\r
+  CHAR16                *SubClassStr;\r
+  CHAR16                *ProtocolStr;\r
+  USB_CLASS_DEVICE_PATH *UsbClass;\r
+\r
+  UsbClass    = (USB_CLASS_DEVICE_PATH *) CreateDeviceNode (\r
+                                            MESSAGING_DEVICE_PATH,\r
+                                            MSG_USB_CLASS_DP,\r
+                                            (UINT16) sizeof (USB_CLASS_DEVICE_PATH)\r
+                                            );\r
+\r
+  VIDStr      = GetNextParamStr (&TextDeviceNode);\r
+  PIDStr      = GetNextParamStr (&TextDeviceNode);\r
+  if (UsbClassText->ClassExist) {\r
+    ClassStr = GetNextParamStr (&TextDeviceNode);\r
+    UsbClass->DeviceClass = (UINT8) Strtoi (ClassStr);\r
+  } else {\r
+    UsbClass->DeviceClass = UsbClassText->Class;\r
+  }\r
+  if (UsbClassText->SubClassExist) {\r
+    SubClassStr = GetNextParamStr (&TextDeviceNode);\r
+    UsbClass->DeviceSubClass = (UINT8) Strtoi (SubClassStr);\r
+  } else {\r
+    UsbClass->DeviceSubClass = UsbClassText->SubClass;\r
+  }\r
+\r
+  ProtocolStr = GetNextParamStr (&TextDeviceNode);\r
+\r
+  UsbClass->VendorId        = (UINT16) Strtoi (VIDStr);\r
+  UsbClass->ProductId       = (UINT16) Strtoi (PIDStr);\r
+  UsbClass->DeviceProtocol  = (UINT8) Strtoi (ProtocolStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) UsbClass;\r
+}\r
+\r
+\r
+/**\r
+  Converts a text device path node to USB class device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB class device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbClass (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = TRUE;\r
+  UsbClassText.SubClassExist = TRUE;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB audio device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB audio device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbAudio (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = FALSE;\r
+  UsbClassText.Class         = USB_CLASS_AUDIO;\r
+  UsbClassText.SubClassExist = TRUE;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB CDC Control device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB CDC Control device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbCDCControl (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = FALSE;\r
+  UsbClassText.Class         = USB_CLASS_CDCCONTROL;\r
+  UsbClassText.SubClassExist = TRUE;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB HID device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB HID device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbHID (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = FALSE;\r
+  UsbClassText.Class         = USB_CLASS_HID;\r
+  UsbClassText.SubClassExist = TRUE;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB Image device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB Image device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbImage (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = FALSE;\r
+  UsbClassText.Class         = USB_CLASS_IMAGE;\r
+  UsbClassText.SubClassExist = TRUE;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB Print device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB Print device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbPrinter (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = FALSE;\r
+  UsbClassText.Class         = USB_CLASS_PRINTER;\r
+  UsbClassText.SubClassExist = TRUE;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB mass storage device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB mass storage device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbMassStorage (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = FALSE;\r
+  UsbClassText.Class         = USB_CLASS_MASS_STORAGE;\r
+  UsbClassText.SubClassExist = TRUE;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB HUB device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB HUB device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbHub (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = FALSE;\r
+  UsbClassText.Class         = USB_CLASS_HUB;\r
+  UsbClassText.SubClassExist = TRUE;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB CDC data device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB CDC data device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbCDCData (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = FALSE;\r
+  UsbClassText.Class         = USB_CLASS_CDCDATA;\r
+  UsbClassText.SubClassExist = TRUE;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB smart card device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB smart card device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbSmartCard (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = FALSE;\r
+  UsbClassText.Class         = USB_CLASS_SMART_CARD;\r
+  UsbClassText.SubClassExist = TRUE;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB video device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB video device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbVideo (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = FALSE;\r
+  UsbClassText.Class         = USB_CLASS_VIDEO;\r
+  UsbClassText.SubClassExist = TRUE;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB diagnostic device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB diagnostic device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbDiagnostic (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = FALSE;\r
+  UsbClassText.Class         = USB_CLASS_DIAGNOSTIC;\r
+  UsbClassText.SubClassExist = TRUE;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB wireless device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB wireless device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbWireless (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = FALSE;\r
+  UsbClassText.Class         = USB_CLASS_WIRELESS;\r
+  UsbClassText.SubClassExist = TRUE;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB device firmware update device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB device firmware update device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbDeviceFirmwareUpdate (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = FALSE;\r
+  UsbClassText.Class         = USB_CLASS_RESERVE;\r
+  UsbClassText.SubClassExist = FALSE;\r
+  UsbClassText.SubClass      = USB_SUBCLASS_FW_UPDATE;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB IRDA bridge device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB IRDA bridge device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbIrdaBridge (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = FALSE;\r
+  UsbClassText.Class         = USB_CLASS_RESERVE;\r
+  UsbClassText.SubClassExist = FALSE;\r
+  UsbClassText.SubClass      = USB_SUBCLASS_IRDA_BRIDGE;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB text and measurement device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB text and measurement device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbTestAndMeasurement (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  USB_CLASS_TEXT  UsbClassText;\r
+\r
+  UsbClassText.ClassExist    = FALSE;\r
+  UsbClassText.Class         = USB_CLASS_RESERVE;\r
+  UsbClassText.SubClassExist = FALSE;\r
+  UsbClassText.SubClass      = USB_SUBCLASS_TEST;\r
+\r
+  return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);\r
+}\r
+\r
+/**\r
+  Converts a text device path node to USB WWID device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created USB WWID device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUsbWwid (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                *VIDStr;\r
+  CHAR16                *PIDStr;\r
+  CHAR16                *InterfaceNumStr;\r
+  CHAR16                *SerialNumberStr;\r
+  USB_WWID_DEVICE_PATH  *UsbWwid;\r
+  UINTN                 SerialNumberStrLen;\r
+\r
+  VIDStr                   = GetNextParamStr (&TextDeviceNode);\r
+  PIDStr                   = GetNextParamStr (&TextDeviceNode);\r
+  InterfaceNumStr          = GetNextParamStr (&TextDeviceNode);\r
+  SerialNumberStr          = GetNextParamStr (&TextDeviceNode);\r
+  SerialNumberStrLen       = StrLen (SerialNumberStr);\r
+  if (SerialNumberStrLen >= 2 &&\r
+      SerialNumberStr[0] == L'\"' &&\r
+      SerialNumberStr[SerialNumberStrLen - 1] == L'\"'\r
+    ) {\r
+    SerialNumberStr[SerialNumberStrLen - 1] = L'\0';\r
+    SerialNumberStr++;\r
+    SerialNumberStrLen -= 2;\r
+  }\r
+  UsbWwid                  = (USB_WWID_DEVICE_PATH *) CreateDeviceNode (\r
+                                                         MESSAGING_DEVICE_PATH,\r
+                                                         MSG_USB_WWID_DP,\r
+                                                         (UINT16) (sizeof (USB_WWID_DEVICE_PATH) + SerialNumberStrLen * sizeof (CHAR16))\r
+                                                         );\r
+  UsbWwid->VendorId        = (UINT16) Strtoi (VIDStr);\r
+  UsbWwid->ProductId       = (UINT16) Strtoi (PIDStr);\r
+  UsbWwid->InterfaceNumber = (UINT16) Strtoi (InterfaceNumStr);\r
+\r
+  //\r
+  // There is no memory allocated in UsbWwid for the '\0' in SerialNumberStr.\r
+  // Therefore, the '\0' will not be copied.\r
+  //\r
+  memcpy (\r
+    (UINT8 *) UsbWwid + sizeof (USB_WWID_DEVICE_PATH),\r
+    SerialNumberStr,\r
+    SerialNumberStrLen * sizeof (CHAR16)\r
+    );\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) UsbWwid;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Logic Unit device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Logic Unit device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUnit (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                          *LunStr;\r
+  DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;\r
+\r
+  LunStr      = GetNextParamStr (&TextDeviceNode);\r
+  LogicalUnit = (DEVICE_LOGICAL_UNIT_DEVICE_PATH *) CreateDeviceNode (\r
+                                                      MESSAGING_DEVICE_PATH,\r
+                                                      MSG_DEVICE_LOGICAL_UNIT_DP,\r
+                                                      (UINT16) sizeof (DEVICE_LOGICAL_UNIT_DEVICE_PATH)\r
+                                                      );\r
+\r
+  LogicalUnit->Lun  = (UINT8) Strtoi (LunStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) LogicalUnit;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to iSCSI device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created iSCSI device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextiSCSI (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  UINT16                      Options;\r
+  CHAR16                      *NameStr;\r
+  CHAR16                      *PortalGroupStr;\r
+  CHAR16                      *LunStr;\r
+  CHAR16                      *HeaderDigestStr;\r
+  CHAR16                      *DataDigestStr;\r
+  CHAR16                      *AuthenticationStr;\r
+  CHAR16                      *ProtocolStr;\r
+  CHAR8                       *AsciiStr;\r
+  ISCSI_DEVICE_PATH_WITH_NAME *ISCSIDevPath;\r
+\r
+  NameStr           = GetNextParamStr (&TextDeviceNode);\r
+  PortalGroupStr    = GetNextParamStr (&TextDeviceNode);\r
+  LunStr            = GetNextParamStr (&TextDeviceNode);\r
+  HeaderDigestStr   = GetNextParamStr (&TextDeviceNode);\r
+  DataDigestStr     = GetNextParamStr (&TextDeviceNode);\r
+  AuthenticationStr = GetNextParamStr (&TextDeviceNode);\r
+  ProtocolStr       = GetNextParamStr (&TextDeviceNode);\r
+  ISCSIDevPath      = (ISCSI_DEVICE_PATH_WITH_NAME *) CreateDeviceNode (\r
+                                                        MESSAGING_DEVICE_PATH,\r
+                                                        MSG_ISCSI_DP,\r
+                                                        (UINT16) (sizeof (ISCSI_DEVICE_PATH_WITH_NAME) + StrLen (NameStr))\r
+                                                        );\r
+\r
+  AsciiStr = ISCSIDevPath->TargetName;\r
+  StrToAscii (NameStr, &AsciiStr);\r
+\r
+  ISCSIDevPath->TargetPortalGroupTag = (UINT16) Strtoi (PortalGroupStr);\r
+  Strtoi64 (LunStr, &ISCSIDevPath->Lun);\r
+\r
+  Options = 0x0000;\r
+  if (StrCmp (HeaderDigestStr, L"CRC32C") == 0) {\r
+    Options |= 0x0002;\r
+  }\r
+\r
+  if (StrCmp (DataDigestStr, L"CRC32C") == 0) {\r
+    Options |= 0x0008;\r
+  }\r
+\r
+  if (StrCmp (AuthenticationStr, L"None") == 0) {\r
+    Options |= 0x0800;\r
+  }\r
+\r
+  if (StrCmp (AuthenticationStr, L"CHAP_UNI") == 0) {\r
+    Options |= 0x1000;\r
+  }\r
+\r
+  ISCSIDevPath->LoginOption      = (UINT16) Options;\r
+\r
+  if (StrCmp (ProtocolStr, L"TCP") == 0) {\r
+    ISCSIDevPath->NetworkProtocol = 0;\r
+  } else {\r
+    //\r
+    // Undefined and reserved.\r
+    //\r
+    ISCSIDevPath->NetworkProtocol = 1;\r
+  }\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) ISCSIDevPath;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to VLAN device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created VLAN device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextVlan (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16            *VlanStr;\r
+  VLAN_DEVICE_PATH  *Vlan;\r
+\r
+  VlanStr = GetNextParamStr (&TextDeviceNode);\r
+  Vlan    = (VLAN_DEVICE_PATH *) CreateDeviceNode (\r
+                                   MESSAGING_DEVICE_PATH,\r
+                                   MSG_VLAN_DP,\r
+                                   (UINT16) sizeof (VLAN_DEVICE_PATH)\r
+                                   );\r
+\r
+  Vlan->VlanId = (UINT16) Strtoi (VlanStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Vlan;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Bluetooth device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Bluetooth device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextBluetooth (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                  *BluetoothStr;\r
+  BLUETOOTH_DEVICE_PATH   *BluetoothDp;\r
+\r
+  BluetoothStr = GetNextParamStr (&TextDeviceNode);\r
+  BluetoothDp  = (BLUETOOTH_DEVICE_PATH *) CreateDeviceNode (\r
+                                             MESSAGING_DEVICE_PATH,\r
+                                             MSG_BLUETOOTH_DP,\r
+                                             (UINT16) sizeof (BLUETOOTH_DEVICE_PATH)\r
+                                             );\r
+  StrHexToBytes (\r
+    BluetoothStr,\r
+    sizeof (BLUETOOTH_ADDRESS) * 2,\r
+    BluetoothDp->BD_ADDR.Address,\r
+    sizeof (BLUETOOTH_ADDRESS)\r
+    );\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothDp;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Wi-Fi device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Wi-Fi device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextWiFi (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                *SSIdStr;\r
+  CHAR8                 AsciiStr[33];\r
+  UINTN                 DataLen;\r
+  WIFI_DEVICE_PATH      *WiFiDp;\r
+\r
+  SSIdStr = GetNextParamStr (&TextDeviceNode);\r
+  WiFiDp  = (WIFI_DEVICE_PATH *) CreateDeviceNode (\r
+                                   MESSAGING_DEVICE_PATH,\r
+                                   MSG_WIFI_DP,\r
+                                   (UINT16) sizeof (WIFI_DEVICE_PATH)\r
+                                   );\r
+\r
+  if (NULL != SSIdStr) {\r
+    DataLen = StrLen (SSIdStr);\r
+    if (StrLen (SSIdStr) > 32) {\r
+      SSIdStr[32] = L'\0';\r
+      DataLen     = 32;\r
+    }\r
+\r
+    UnicodeStrToAsciiStrS (SSIdStr, AsciiStr, sizeof (AsciiStr));\r
+    memcpy (WiFiDp->SSId, AsciiStr, DataLen);\r
+  }\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) WiFiDp;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to URI device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created URI device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUri (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16           *UriStr;\r
+  UINTN            UriLength;\r
+  URI_DEVICE_PATH  *Uri;\r
+\r
+  UriStr = GetNextParamStr (&TextDeviceNode);\r
+  UriLength = StrnLenS (UriStr, MAX_UINT16 - sizeof (URI_DEVICE_PATH));\r
+  Uri    = (URI_DEVICE_PATH *) CreateDeviceNode (\r
+                                 MESSAGING_DEVICE_PATH,\r
+                                 MSG_URI_DP,\r
+                                 (UINT16) (sizeof (URI_DEVICE_PATH) + UriLength)\r
+                                 );\r
+\r
+  while (UriLength-- != 0) {\r
+    Uri->Uri[UriLength] = (CHAR8) UriStr[UriLength];\r
+  }\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Uri;\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
+   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
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created HD device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextHD (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                *PartitionStr;\r
+  CHAR16                *TypeStr;\r
+  CHAR16                *SignatureStr;\r
+  CHAR16                *StartStr;\r
+  CHAR16                *SizeStr;\r
+  UINT32                Signature32;\r
+  HARDDRIVE_DEVICE_PATH *Hd;\r
+\r
+  PartitionStr        = GetNextParamStr (&TextDeviceNode);\r
+  TypeStr             = GetNextParamStr (&TextDeviceNode);\r
+  SignatureStr        = GetNextParamStr (&TextDeviceNode);\r
+  StartStr            = GetNextParamStr (&TextDeviceNode);\r
+  SizeStr             = GetNextParamStr (&TextDeviceNode);\r
+  Hd                  = (HARDDRIVE_DEVICE_PATH *) CreateDeviceNode (\r
+                                                    MEDIA_DEVICE_PATH,\r
+                                                    MEDIA_HARDDRIVE_DP,\r
+                                                    (UINT16) sizeof (HARDDRIVE_DEVICE_PATH)\r
+                                                    );\r
+\r
+  Hd->PartitionNumber = (UINT32) Strtoi (PartitionStr);\r
+\r
+  ZeroMem (Hd->Signature, 16);\r
+  Hd->MBRType = (UINT8) 0;\r
+\r
+  if (StrCmp (TypeStr, L"MBR") == 0) {\r
+    Hd->SignatureType = SIGNATURE_TYPE_MBR;\r
+    Hd->MBRType       = 0x01;\r
+\r
+    Signature32       = (UINT32) Strtoi (SignatureStr);\r
+    memcpy (Hd->Signature, &Signature32, sizeof (UINT32));\r
+  } else if (StrCmp (TypeStr, L"GPT") == 0) {\r
+    Hd->SignatureType = SIGNATURE_TYPE_GUID;\r
+    Hd->MBRType       = 0x02;\r
+\r
+    StrToGuid (SignatureStr, (EFI_GUID *) Hd->Signature);\r
+  } else {\r
+    Hd->SignatureType = (UINT8) Strtoi (TypeStr);\r
+  }\r
+\r
+  Strtoi64 (StartStr, &Hd->PartitionStart);\r
+  Strtoi64 (SizeStr, &Hd->PartitionSize);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Hd;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to CDROM device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created CDROM device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextCDROM (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16            *EntryStr;\r
+  CHAR16            *StartStr;\r
+  CHAR16            *SizeStr;\r
+  CDROM_DEVICE_PATH *CDROMDevPath;\r
+\r
+  EntryStr              = GetNextParamStr (&TextDeviceNode);\r
+  StartStr              = GetNextParamStr (&TextDeviceNode);\r
+  SizeStr               = GetNextParamStr (&TextDeviceNode);\r
+  CDROMDevPath          = (CDROM_DEVICE_PATH *) CreateDeviceNode (\r
+                                                  MEDIA_DEVICE_PATH,\r
+                                                  MEDIA_CDROM_DP,\r
+                                                  (UINT16) sizeof (CDROM_DEVICE_PATH)\r
+                                                  );\r
+\r
+  CDROMDevPath->BootEntry = (UINT32) Strtoi (EntryStr);\r
+  Strtoi64 (StartStr, &CDROMDevPath->PartitionStart);\r
+  Strtoi64 (SizeStr, &CDROMDevPath->PartitionSize);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) CDROMDevPath;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Vendor-defined media device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Vendor-defined media device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextVenMedia (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return ConvertFromTextVendor (\r
+           TextDeviceNode,\r
+           MEDIA_DEVICE_PATH,\r
+           MEDIA_VENDOR_DP\r
+           );\r
+}\r
+\r
+/**\r
+  Converts a text device path node to File device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created File device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextFilePath (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  FILEPATH_DEVICE_PATH  *File;\r
+\r
+  File = (FILEPATH_DEVICE_PATH *) CreateDeviceNode (\r
+                                    MEDIA_DEVICE_PATH,\r
+                                    MEDIA_FILEPATH_DP,\r
+                                    (UINT16) (sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) * 2)\r
+                                    );\r
+\r
+  StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) File;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Media protocol device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Media protocol device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextMedia (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                      *GuidStr;\r
+  MEDIA_PROTOCOL_DEVICE_PATH  *Media;\r
+\r
+  GuidStr = GetNextParamStr (&TextDeviceNode);\r
+  Media   = (MEDIA_PROTOCOL_DEVICE_PATH *) CreateDeviceNode (\r
+                                             MEDIA_DEVICE_PATH,\r
+                                             MEDIA_PROTOCOL_DP,\r
+                                             (UINT16) sizeof (MEDIA_PROTOCOL_DEVICE_PATH)\r
+                                             );\r
+\r
+  StrToGuid (GuidStr, &Media->Protocol);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Media;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to firmware volume device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created firmware volume device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextFv (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                    *GuidStr;\r
+  MEDIA_FW_VOL_DEVICE_PATH  *Fv;\r
+\r
+  GuidStr = GetNextParamStr (&TextDeviceNode);\r
+  Fv      = (MEDIA_FW_VOL_DEVICE_PATH *) CreateDeviceNode (\r
+                                           MEDIA_DEVICE_PATH,\r
+                                           MEDIA_PIWG_FW_VOL_DP,\r
+                                           (UINT16) sizeof (MEDIA_FW_VOL_DEVICE_PATH)\r
+                                           );\r
+\r
+  StrToGuid (GuidStr, &Fv->FvName);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Fv;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to firmware file device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created firmware file device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextFvFile (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                             *GuidStr;\r
+  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH  *FvFile;\r
+\r
+  GuidStr = GetNextParamStr (&TextDeviceNode);\r
+  FvFile  = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) CreateDeviceNode (\r
+                                                    MEDIA_DEVICE_PATH,\r
+                                                    MEDIA_PIWG_FW_FILE_DP,\r
+                                                    (UINT16) sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH)\r
+                                                    );\r
+\r
+  StrToGuid (GuidStr, &FvFile->FvFileName);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) FvFile;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to text relative offset device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Text device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextRelativeOffsetRange (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                                  *StartingOffsetStr;\r
+  CHAR16                                  *EndingOffsetStr;\r
+  MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset;\r
+\r
+  StartingOffsetStr = GetNextParamStr (&TextDeviceNode);\r
+  EndingOffsetStr   = GetNextParamStr (&TextDeviceNode);\r
+  Offset            = (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *) CreateDeviceNode (\r
+                                                                    MEDIA_DEVICE_PATH,\r
+                                                                    MEDIA_RELATIVE_OFFSET_RANGE_DP,\r
+                                                                    (UINT16) sizeof (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH)\r
+                                                                    );\r
+\r
+  Strtoi64 (StartingOffsetStr, &Offset->StartingOffset);\r
+  Strtoi64 (EndingOffsetStr, &Offset->EndingOffset);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Offset;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to text ram disk device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Text device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextRamDisk (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                                  *StartingAddrStr;\r
+  CHAR16                                  *EndingAddrStr;\r
+  CHAR16                                  *TypeGuidStr;\r
+  CHAR16                                  *InstanceStr;\r
+  MEDIA_RAM_DISK_DEVICE_PATH              *RamDisk;\r
+  UINT64                                  StartingAddr;\r
+  UINT64                                  EndingAddr;\r
+\r
+  StartingAddrStr = GetNextParamStr (&TextDeviceNode);\r
+  EndingAddrStr   = GetNextParamStr (&TextDeviceNode);\r
+  InstanceStr     = GetNextParamStr (&TextDeviceNode);\r
+  TypeGuidStr     = GetNextParamStr (&TextDeviceNode);\r
+  RamDisk         = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (\r
+                                                     MEDIA_DEVICE_PATH,\r
+                                                     MEDIA_RAM_DISK_DP,\r
+                                                     (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)\r
+                                                     );\r
+\r
+  Strtoi64 (StartingAddrStr, &StartingAddr);\r
+  WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);\r
+  Strtoi64 (EndingAddrStr, &EndingAddr);\r
+  WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);\r
+  RamDisk->Instance = (UINT16) Strtoi (InstanceStr);\r
+  StrToGuid (TypeGuidStr, &RamDisk->TypeGuid);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to text virtual disk device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Text device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextVirtualDisk (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                                  *StartingAddrStr;\r
+  CHAR16                                  *EndingAddrStr;\r
+  CHAR16                                  *InstanceStr;\r
+  MEDIA_RAM_DISK_DEVICE_PATH              *RamDisk;\r
+  UINT64                                  StartingAddr;\r
+  UINT64                                  EndingAddr;\r
+\r
+  StartingAddrStr = GetNextParamStr (&TextDeviceNode);\r
+  EndingAddrStr   = GetNextParamStr (&TextDeviceNode);\r
+  InstanceStr     = GetNextParamStr (&TextDeviceNode);\r
+\r
+  RamDisk         = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (\r
+                                                     MEDIA_DEVICE_PATH,\r
+                                                     MEDIA_RAM_DISK_DP,\r
+                                                     (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)\r
+                                                     );\r
+\r
+  Strtoi64 (StartingAddrStr, &StartingAddr);\r
+  WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);\r
+  Strtoi64 (EndingAddrStr, &EndingAddr);\r
+  WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);\r
+  RamDisk->Instance = (UINT16) Strtoi (InstanceStr);\r
+  CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to text virtual cd device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Text device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextVirtualCd (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                                  *StartingAddrStr;\r
+  CHAR16                                  *EndingAddrStr;\r
+  CHAR16                                  *InstanceStr;\r
+  MEDIA_RAM_DISK_DEVICE_PATH              *RamDisk;\r
+  UINT64                                  StartingAddr;\r
+  UINT64                                  EndingAddr;\r
+\r
+  StartingAddrStr = GetNextParamStr (&TextDeviceNode);\r
+  EndingAddrStr   = GetNextParamStr (&TextDeviceNode);\r
+  InstanceStr     = GetNextParamStr (&TextDeviceNode);\r
+\r
+  RamDisk         = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (\r
+                                                     MEDIA_DEVICE_PATH,\r
+                                                     MEDIA_RAM_DISK_DP,\r
+                                                     (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)\r
+                                                     );\r
+\r
+  Strtoi64 (StartingAddrStr, &StartingAddr);\r
+  WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);\r
+  Strtoi64 (EndingAddrStr, &EndingAddr);\r
+  WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);\r
+  RamDisk->Instance = (UINT16) Strtoi (InstanceStr);\r
+  CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to text persistent virtual disk device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Text device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextPersistentVirtualDisk (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                                  *StartingAddrStr;\r
+  CHAR16                                  *EndingAddrStr;\r
+  CHAR16                                  *InstanceStr;\r
+  MEDIA_RAM_DISK_DEVICE_PATH              *RamDisk;\r
+  UINT64                                  StartingAddr;\r
+  UINT64                                  EndingAddr;\r
+\r
+  StartingAddrStr = GetNextParamStr (&TextDeviceNode);\r
+  EndingAddrStr   = GetNextParamStr (&TextDeviceNode);\r
+  InstanceStr     = GetNextParamStr (&TextDeviceNode);\r
+\r
+  RamDisk         = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (\r
+                                                     MEDIA_DEVICE_PATH,\r
+                                                     MEDIA_RAM_DISK_DP,\r
+                                                     (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)\r
+                                                     );\r
+\r
+  Strtoi64 (StartingAddrStr, &StartingAddr);\r
+  WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);\r
+  Strtoi64 (EndingAddrStr, &EndingAddr);\r
+  WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);\r
+  RamDisk->Instance = (UINT16) Strtoi (InstanceStr);\r
+  CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to text persistent virtual cd device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Text device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextPersistentVirtualCd (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                                  *StartingAddrStr;\r
+  CHAR16                                  *EndingAddrStr;\r
+  CHAR16                                  *InstanceStr;\r
+  MEDIA_RAM_DISK_DEVICE_PATH              *RamDisk;\r
+  UINT64                                  StartingAddr;\r
+  UINT64                                  EndingAddr;\r
+\r
+  StartingAddrStr = GetNextParamStr (&TextDeviceNode);\r
+  EndingAddrStr   = GetNextParamStr (&TextDeviceNode);\r
+  InstanceStr     = GetNextParamStr (&TextDeviceNode);\r
+\r
+  RamDisk         = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (\r
+                                                     MEDIA_DEVICE_PATH,\r
+                                                     MEDIA_RAM_DISK_DP,\r
+                                                     (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)\r
+                                                     );\r
+\r
+  Strtoi64 (StartingAddrStr, &StartingAddr);\r
+  WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);\r
+  Strtoi64 (EndingAddrStr, &EndingAddr);\r
+  WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);\r
+  RamDisk->Instance = (UINT16) Strtoi (InstanceStr);\r
+  CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;\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
+   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
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created BIOS Boot Specification device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextBBS (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16              *TypeStr;\r
+  CHAR16              *IdStr;\r
+  CHAR16              *FlagsStr;\r
+  CHAR8               *AsciiStr;\r
+  BBS_BBS_DEVICE_PATH *Bbs;\r
+\r
+  TypeStr   = GetNextParamStr (&TextDeviceNode);\r
+  IdStr     = GetNextParamStr (&TextDeviceNode);\r
+  FlagsStr  = GetNextParamStr (&TextDeviceNode);\r
+  Bbs       = (BBS_BBS_DEVICE_PATH *) CreateDeviceNode (\r
+                                        BBS_DEVICE_PATH,\r
+                                        BBS_BBS_DP,\r
+                                        (UINT16) (sizeof (BBS_BBS_DEVICE_PATH) + StrLen (IdStr))\r
+                                        );\r
+\r
+  if (StrCmp (TypeStr, L"Floppy") == 0) {\r
+    Bbs->DeviceType = BBS_TYPE_FLOPPY;\r
+  } else if (StrCmp (TypeStr, L"HD") == 0) {\r
+    Bbs->DeviceType = BBS_TYPE_HARDDRIVE;\r
+  } else if (StrCmp (TypeStr, L"CDROM") == 0) {\r
+    Bbs->DeviceType = BBS_TYPE_CDROM;\r
+  } else if (StrCmp (TypeStr, L"PCMCIA") == 0) {\r
+    Bbs->DeviceType = BBS_TYPE_PCMCIA;\r
+  } else if (StrCmp (TypeStr, L"USB") == 0) {\r
+    Bbs->DeviceType = BBS_TYPE_USB;\r
+  } else if (StrCmp (TypeStr, L"Network") == 0) {\r
+    Bbs->DeviceType = BBS_TYPE_EMBEDDED_NETWORK;\r
+  } else {\r
+    Bbs->DeviceType = (UINT16) Strtoi (TypeStr);\r
+  }\r
+\r
+  AsciiStr = Bbs->String;\r
+  StrToAscii (IdStr, &AsciiStr);\r
+\r
+  Bbs->StatusFlag = (UINT16) Strtoi (FlagsStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Bbs;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to SATA device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created SATA device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextSata (\r
+   CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  SATA_DEVICE_PATH *Sata;\r
+  CHAR16           *Param1;\r
+  CHAR16           *Param2;\r
+  CHAR16           *Param3;\r
+\r
+  Param1 = GetNextParamStr (&TextDeviceNode);\r
+  Param2 = GetNextParamStr (&TextDeviceNode);\r
+  Param3 = GetNextParamStr (&TextDeviceNode);\r
+\r
+  Sata = (SATA_DEVICE_PATH *) CreateDeviceNode (\r
+                                MESSAGING_DEVICE_PATH,\r
+                                MSG_SATA_DP,\r
+                                (UINT16) sizeof (SATA_DEVICE_PATH)\r
+                                );\r
+  Sata->HBAPortNumber            = (UINT16) Strtoi (Param1);\r
+  Sata->PortMultiplierPortNumber = (UINT16) Strtoi (Param2);\r
+  Sata->Lun                      = (UINT16) Strtoi (Param3);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Sata;\r
+}\r
+\r
+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
+  {L"BMC",                     DevPathFromTextBmc                     },\r
+\r
+  {L"AcpiPath",                DevPathFromTextAcpiPath                },\r
+  {L"Acpi",                    DevPathFromTextAcpi                    },\r
+  {L"PciRoot",                 DevPathFromTextPciRoot                 },\r
+  {L"PcieRoot",                DevPathFromTextPcieRoot                },\r
+  {L"Floppy",                  DevPathFromTextFloppy                  },\r
+  {L"Keyboard",                DevPathFromTextKeyboard                },\r
+  {L"Serial",                  DevPathFromTextSerial                  },\r
+  {L"ParallelPort",            DevPathFromTextParallelPort            },\r
+  {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
+  {L"FibreEx",                 DevPathFromTextFibreEx                 },\r
+  {L"I1394",                   DevPathFromText1394                    },\r
+  {L"USB",                     DevPathFromTextUsb                     },\r
+  {L"I2O",                     DevPathFromTextI2O                     },\r
+  {L"Infiniband",              DevPathFromTextInfiniband              },\r
+  {L"VenMsg",                  DevPathFromTextVenMsg                  },\r
+  {L"VenPcAnsi",               DevPathFromTextVenPcAnsi               },\r
+  {L"VenVt100",                DevPathFromTextVenVt100                },\r
+  {L"VenVt100Plus",            DevPathFromTextVenVt100Plus            },\r
+  {L"VenUtf8",                 DevPathFromTextVenUtf8                 },\r
+  {L"UartFlowCtrl",            DevPathFromTextUartFlowCtrl            },\r
+  {L"SAS",                     DevPathFromTextSAS                     },\r
+  {L"SasEx",                   DevPathFromTextSasEx                   },\r
+  {L"NVMe",                    DevPathFromTextNVMe                    },\r
+  {L"UFS",                     DevPathFromTextUfs                     },\r
+  {L"SD",                      DevPathFromTextSd                      },\r
+  {L"eMMC",                    DevPathFromTextEmmc                    },\r
+  {L"DebugPort",               DevPathFromTextDebugPort               },\r
+  {L"MAC",                     DevPathFromTextMAC                     },\r
+  {L"IPv4",                    DevPathFromTextIPv4                    },\r
+  {L"IPv6",                    DevPathFromTextIPv6                    },\r
+  {L"Uart",                    DevPathFromTextUart                    },\r
+  {L"UsbClass",                DevPathFromTextUsbClass                },\r
+  {L"UsbAudio",                DevPathFromTextUsbAudio                },\r
+  {L"UsbCDCControl",           DevPathFromTextUsbCDCControl           },\r
+  {L"UsbHID",                  DevPathFromTextUsbHID                  },\r
+  {L"UsbImage",                DevPathFromTextUsbImage                },\r
+  {L"UsbPrinter",              DevPathFromTextUsbPrinter              },\r
+  {L"UsbMassStorage",          DevPathFromTextUsbMassStorage          },\r
+  {L"UsbHub",                  DevPathFromTextUsbHub                  },\r
+  {L"UsbCDCData",              DevPathFromTextUsbCDCData              },\r
+  {L"UsbSmartCard",            DevPathFromTextUsbSmartCard            },\r
+  {L"UsbVideo",                DevPathFromTextUsbVideo                },\r
+  {L"UsbDiagnostic",           DevPathFromTextUsbDiagnostic           },\r
+  {L"UsbWireless",             DevPathFromTextUsbWireless             },\r
+  {L"UsbDeviceFirmwareUpdate", DevPathFromTextUsbDeviceFirmwareUpdate },\r
+  {L"UsbIrdaBridge",           DevPathFromTextUsbIrdaBridge           },\r
+  {L"UsbTestAndMeasurement",   DevPathFromTextUsbTestAndMeasurement   },\r
+  {L"UsbWwid",                 DevPathFromTextUsbWwid                 },\r
+  {L"Unit",                    DevPathFromTextUnit                    },\r
+  {L"iSCSI",                   DevPathFromTextiSCSI                   },\r
+  {L"Vlan",                    DevPathFromTextVlan                    },\r
+  {L"Uri",                     DevPathFromTextUri                     },\r
+  {L"Bluetooth",               DevPathFromTextBluetooth               },\r
+  {L"Wi-Fi",                   DevPathFromTextWiFi                    },\r
+  {L"MediaPath",               DevPathFromTextMediaPath               },\r
+  {L"HD",                      DevPathFromTextHD                      },\r
+  {L"CDROM",                   DevPathFromTextCDROM                   },\r
+  {L"VenMedia",                DevPathFromTextVenMedia                },\r
+  {L"Media",                   DevPathFromTextMedia                   },\r
+  {L"Fv",                      DevPathFromTextFv                      },\r
+  {L"FvFile",                  DevPathFromTextFvFile                  },\r
+  {L"Offset",                  DevPathFromTextRelativeOffsetRange     },\r
+  {L"RamDisk",                 DevPathFromTextRamDisk                 },\r
+  {L"VirtualDisk",             DevPathFromTextVirtualDisk             },\r
+  {L"VirtualCD",               DevPathFromTextVirtualCd               },\r
+  {L"PersistentVirtualDisk",   DevPathFromTextPersistentVirtualDisk   },\r
+  {L"PersistentVirtualCD",     DevPathFromTextPersistentVirtualCd     },\r
+\r
+  {L"BbsPath",                 DevPathFromTextBbsPath                 },\r
+  {L"BBS",                     DevPathFromTextBBS                     },\r
+  {L"Sata",                    DevPathFromTextSata                    },\r
+  {NULL, NULL}\r
+};\r
+\r
+/**\r
+  Convert text to the binary representation of a device node.\r
+\r
+  @param TextDeviceNode  TextDeviceNode points to the text representation of a device\r
+                         node. Conversion starts with the first character and continues\r
+                         until the first non-device node character.\r
+\r
+  @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was\r
+          insufficient memory or text unsupported.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibConvertTextToDeviceNode (\r
+   CONST CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  DEVICE_PATH_FROM_TEXT    FromText;\r
+  CHAR16                   *ParamStr;\r
+  EFI_DEVICE_PATH_PROTOCOL *DeviceNode;\r
+  CHAR16                   *DeviceNodeStr;\r
+  UINTN                    Index;\r
+\r
+  if ((TextDeviceNode == NULL) || (IS_NULL (*TextDeviceNode))) {\r
+    return NULL;\r
+  }\r
+\r
+  ParamStr      = NULL;\r
+  FromText      = NULL;\r
+  DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);\r
+  ASSERT (DeviceNodeStr != NULL);\r
+\r
+  for (Index = 0; mUefiDevicePathLibDevPathFromTextTable[Index].Function != NULL; Index++) {\r
+    ParamStr = GetParamByNodeName (DeviceNodeStr, mUefiDevicePathLibDevPathFromTextTable[Index].DevicePathNodeText);\r
+    if (ParamStr != NULL) {\r
+      FromText = mUefiDevicePathLibDevPathFromTextTable[Index].Function;\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (FromText == NULL) {\r
+    //\r
+    // A file path\r
+    //\r
+    FromText = DevPathFromTextFilePath;\r
+    DeviceNode = FromText (DeviceNodeStr);\r
+  } else {\r
+    DeviceNode = FromText (ParamStr);\r
+    free (ParamStr);\r
+  }\r
+\r
+  free (DeviceNodeStr);\r
+\r
+  return DeviceNode;\r
+}\r
+\r
+/**\r
+  Convert text to the binary representation of a device path.\r
+\r
+\r
+  @param TextDevicePath  TextDevicePath points to the text representation of a device\r
+                         path. Conversion starts with the first character and continues\r
+                         until the first non-device node character.\r
+\r
+  @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or\r
+          there was insufficient memory.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibConvertTextToDevicePath (\r
+   CONST CHAR16 *TextDevicePath\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL *DeviceNode;\r
+  EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;\r
+  CHAR16                   *DevicePathStr;\r
+  CHAR16                   *Str;\r
+  CHAR16                   *DeviceNodeStr;\r
+  BOOLEAN                  IsInstanceEnd;\r
+  EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
+\r
+  if ((TextDevicePath == NULL) || (IS_NULL (*TextDevicePath))) {\r
+    return NULL;\r
+  }\r
+\r
+  DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);\r
+  ASSERT (DevicePath != NULL);\r
+  SetDevicePathEndNode (DevicePath);\r
+\r
+  DevicePathStr = UefiDevicePathLibStrDuplicate (TextDevicePath);\r
+\r
+  Str           = DevicePathStr;\r
+  while ((DeviceNodeStr = GetNextDeviceNodeStr (&Str, &IsInstanceEnd)) != NULL) {\r
+    DeviceNode = UefiDevicePathLibConvertTextToDeviceNode (DeviceNodeStr);\r
+\r
+    NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);\r
+    free (DevicePath);\r
+    free (DeviceNode);\r
+    DevicePath = NewDevicePath;\r
+\r
+    if (IsInstanceEnd) {\r
+      DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);\r
+      ASSERT (DeviceNode != NULL);\r
+      SetDevicePathEndNode (DeviceNode);\r
+      DeviceNode->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;\r
+\r
+      NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);\r
+      free (DevicePath);\r
+      free (DeviceNode);\r
+      DevicePath = NewDevicePath;\r
+    }\r
+  }\r
+\r
+  free (DevicePathStr);\r
+  return DevicePath;\r
+}\r
diff --git a/BaseTools/Source/C/DevicePath/DevicePathUtilities.c b/BaseTools/Source/C/DevicePath/DevicePathUtilities.c
new file mode 100644 (file)
index 0000000..d4ec274
--- /dev/null
@@ -0,0 +1,875 @@
+/** @file\r
+  Device Path services. The thing to remember is device paths are built out of\r
+  nodes. The device path is terminated by an end node that is length\r
+  sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)\r
+  all over this file.\r
+\r
+  The only place where multi-instance device paths are supported is in\r
+  environment varibles. Multi-instance device paths should never be placed\r
+  on a Handle.\r
+\r
+  Copyright (c) 2017, 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
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "UefiDevicePathLib.h"\r
+#include <Protocol/DevicePathUtilities.h>\r
+\r
+//\r
+// Template for an end-of-device path node.\r
+//\r
+CONST EFI_DEVICE_PATH_PROTOCOL  mUefiDevicePathLibEndDevicePath = {\r
+  END_DEVICE_PATH_TYPE,\r
+  END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+  {\r
+    END_DEVICE_PATH_LENGTH,\r
+    0\r
+  }\r
+};\r
+\r
+/**\r
+  Determine whether a given device path is valid.\r
+  If DevicePath is NULL, then ASSERT().\r
+\r
+  @param  DevicePath  A pointer to a device path data structure.\r
+  @param  MaxSize     The maximum size of the device path data structure.\r
+\r
+  @retval TRUE        DevicePath is valid.\r
+  @retval FALSE       The length of any node node in the DevicePath is less\r
+                      than sizeof (EFI_DEVICE_PATH_PROTOCOL).\r
+  @retval FALSE       If MaxSize is not zero, the size of the DevicePath\r
+                      exceeds MaxSize.\r
+  @retval FALSE       If PcdMaximumDevicePathNodeCount is not zero, the node\r
+                      count of the DevicePath exceeds PcdMaximumDevicePathNodeCount.\r
+**/\r
+BOOLEAN\r
+IsDevicePathValid (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
+   UINTN                    MaxSize\r
+  )\r
+{\r
+  UINTN Count;\r
+  UINTN Size;\r
+  UINTN NodeLength;\r
+\r
+  ASSERT (DevicePath != NULL);\r
+\r
+  if (MaxSize == 0) {\r
+    MaxSize = MAX_UINTN;\r
+ }\r
+\r
+  //\r
+  // Validate the input size big enough to touch the first node.\r
+  //\r
+  if (MaxSize < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
+    return FALSE;\r
+  }\r
+\r
+  for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {\r
+    NodeLength = DevicePathNodeLength (DevicePath);\r
+    if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
+      return FALSE;\r
+    }\r
+\r
+    if (NodeLength > MAX_UINTN - Size) {\r
+      return FALSE;\r
+    }\r
+    Size += NodeLength;\r
+\r
+    //\r
+    // Validate next node before touch it.\r
+    //\r
+    if (Size > MaxSize - END_DEVICE_PATH_LENGTH ) {\r
+      return FALSE;\r
+    }\r
+\r
+    Count++;\r
+    if (Count >= MAX_DEVICE_PATH_NODE_COUNT) {\r
+      return FALSE;\r
+      }\r
+\r
+  }\r
+\r
+  //\r
+  // Only return TRUE when the End Device Path node is valid.\r
+  //\r
+  return (BOOLEAN) (DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);\r
+}\r
+\r
+\r
+/**\r
+  Returns the Type field of a device path node.\r
+\r
+  Returns the Type field of the device path node specified by Node.\r
+\r
+  If Node is NULL, then ASSERT().\r
+\r
+  @param  Node      A pointer to a device path node data structure.\r
+\r
+  @return The Type field of the device path node specified by Node.\r
+\r
+**/\r
+UINT8\r
+DevicePathType (\r
+   CONST VOID  *Node\r
+  )\r
+{\r
+  ASSERT (Node != NULL);\r
+  return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Type;\r
+}\r
+\r
+/**\r
+  Returns the SubType field of a device path node.\r
+\r
+  Returns the SubType field of the device path node specified by Node.\r
+\r
+  If Node is NULL, then ASSERT().\r
+\r
+  @param  Node      A pointer to a device path node data structure.\r
+\r
+  @return The SubType field of the device path node specified by Node.\r
+\r
+**/\r
+UINT8\r
+DevicePathSubType (\r
+   CONST VOID  *Node\r
+  )\r
+{\r
+  ASSERT (Node != NULL);\r
+  return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->SubType;\r
+}\r
+\r
+/**\r
+  Returns the 16-bit Length field of a device path node.\r
+\r
+  Returns the 16-bit Length field of the device path node specified by Node.\r
+  Node is not required to be aligned on a 16-bit boundary, so it is recommended\r
+  that a function such as ReadUnaligned16() be used to extract the contents of\r
+  the Length field.\r
+\r
+  If Node is NULL, then ASSERT().\r
+\r
+  @param  Node      A pointer to a device path node data structure.\r
+\r
+  @return The 16-bit Length field of the device path node specified by Node.\r
+\r
+**/\r
+UINTN\r
+DevicePathNodeLength (\r
+   CONST VOID  *Node\r
+  )\r
+{\r
+  ASSERT (Node != NULL);\r
+  return ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0]);\r
+}\r
+\r
+/**\r
+  Returns a pointer to the next node in a device path.\r
+\r
+  Returns a pointer to the device path node that follows the device path node\r
+  specified by Node.\r
+\r
+  If Node is NULL, then ASSERT().\r
+\r
+  @param  Node      A pointer to a device path node data structure.\r
+\r
+  @return a pointer to the device path node that follows the device path node\r
+  specified by Node.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+NextDevicePathNode (\r
+   CONST VOID  *Node\r
+  )\r
+{\r
+  ASSERT (Node != NULL);\r
+  return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node));\r
+}\r
+\r
+/**\r
+  Determines if a device path node is an end node of a device path.\r
+  This includes nodes that are the end of a device path instance and nodes that\r
+  are the end of an entire device path.\r
+\r
+  Determines if the device path node specified by Node is an end node of a device path.\r
+  This includes nodes that are the end of a device path instance and nodes that are the\r
+  end of an entire device path.  If Node represents an end node of a device path,\r
+  then TRUE is returned.  Otherwise, FALSE is returned.\r
+\r
+  If Node is NULL, then ASSERT().\r
+\r
+  @param  Node      A pointer to a device path node data structure.\r
+\r
+  @retval TRUE      The device path node specified by Node is an end node of a\r
+                    device path.\r
+  @retval FALSE     The device path node specified by Node is not an end node of\r
+                    a device path.\r
+\r
+**/\r
+BOOLEAN\r
+IsDevicePathEndType (\r
+   CONST VOID  *Node\r
+  )\r
+{\r
+  ASSERT (Node != NULL);\r
+  return (BOOLEAN) (DevicePathType (Node) == END_DEVICE_PATH_TYPE);\r
+}\r
+\r
+/**\r
+  Determines if a device path node is an end node of an entire device path.\r
+\r
+  Determines if a device path node specified by Node is an end node of an entire\r
+  device path. If Node represents the end of an entire device path, then TRUE is\r
+  returned.  Otherwise, FALSE is returned.\r
+\r
+  If Node is NULL, then ASSERT().\r
+\r
+  @param  Node      A pointer to a device path node data structure.\r
+\r
+  @retval TRUE      The device path node specified by Node is the end of an entire\r
+                    device path.\r
+  @retval FALSE     The device path node specified by Node is not the end of an\r
+                    entire device path.\r
+\r
+**/\r
+BOOLEAN\r
+IsDevicePathEnd (\r
+   CONST VOID  *Node\r
+  )\r
+{\r
+  ASSERT (Node != NULL);\r
+  return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);\r
+}\r
+\r
+/**\r
+  Determines if a device path node is an end node of a device path instance.\r
+\r
+  Determines if a device path node specified by Node is an end node of a device\r
+  path instance. If Node represents the end of a device path instance, then TRUE\r
+  is returned.  Otherwise, FALSE is returned.\r
+\r
+  If Node is NULL, then ASSERT().\r
+\r
+  @param  Node      A pointer to a device path node data structure.\r
+\r
+  @retval TRUE      The device path node specified by Node is the end of a device\r
+                    path instance.\r
+  @retval FALSE     The device path node specified by Node is not the end of a\r
+                    device path instance.\r
+\r
+**/\r
+BOOLEAN\r
+IsDevicePathEndInstance (\r
+   CONST VOID  *Node\r
+  )\r
+{\r
+  ASSERT (Node != NULL);\r
+  return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);\r
+}\r
+\r
+/**\r
+  Sets the length, in bytes, of a device path node.\r
+\r
+  Sets the length of the device path node specified by Node to the value specified\r
+  by NodeLength.  NodeLength is returned.  Node is not required to be aligned on\r
+  a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()\r
+  be used to set the contents of the Length field.\r
+\r
+  If Node is NULL, then ASSERT().\r
+  If NodeLength >= SIZE_64KB, then ASSERT().\r
+  If NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL), then ASSERT().\r
+\r
+  @param  Node      A pointer to a device path node data structure.\r
+  @param  Length    The length, in bytes, of the device path node.\r
+\r
+  @return Length\r
+\r
+**/\r
+UINT16\r
+SetDevicePathNodeLength (\r
+    VOID  *Node,\r
+   UINTN     Length\r
+  )\r
+{\r
+  ASSERT (Node != NULL);\r
+  ASSERT ((Length >= sizeof (EFI_DEVICE_PATH_PROTOCOL)) && (Length < SIZE_64KB));\r
+  return WriteUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0], (UINT16)(Length));\r
+}\r
+\r
+/**\r
+  Fills in all the fields of a device path node that is the end of an entire device path.\r
+\r
+  Fills in all the fields of a device path node specified by Node so Node represents\r
+  the end of an entire device path.  The Type field of Node is set to\r
+  END_DEVICE_PATH_TYPE, the SubType field of Node is set to\r
+  END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to\r
+  END_DEVICE_PATH_LENGTH.  Node is not required to be aligned on a 16-bit boundary,\r
+  so it is recommended that a function such as WriteUnaligned16() be used to set\r
+  the contents of the Length field.\r
+\r
+  If Node is NULL, then ASSERT().\r
+\r
+  @param  Node      A pointer to a device path node data structure.\r
+\r
+**/\r
+VOID\r
+SetDevicePathEndNode (\r
+   VOID  *Node\r
+  )\r
+{\r
+  ASSERT (Node != NULL);\r
+  memcpy (Node, &mUefiDevicePathLibEndDevicePath, sizeof (mUefiDevicePathLibEndDevicePath));\r
+}\r
+\r
+/**\r
+  Returns the size of a device path in bytes.\r
+\r
+  This function returns the size, in bytes, of the device path data structure\r
+  specified by DevicePath including the end of device path node.\r
+  If DevicePath is NULL or invalid, then 0 is returned.\r
+\r
+  @param  DevicePath  A pointer to a device path data structure.\r
+\r
+  @retval 0           If DevicePath is NULL or invalid.\r
+  @retval Others      The size of a device path in bytes.\r
+\r
+**/\r
+UINTN\r
+UefiDevicePathLibGetDevicePathSize (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  )\r
+{\r
+  CONST EFI_DEVICE_PATH_PROTOCOL  *Start;\r
+\r
+  if (DevicePath == NULL) {\r
+    return 0;\r
+  }\r
+\r
+  if (!IsDevicePathValid (DevicePath, 0)) {\r
+    return 0;\r
+  }\r
+\r
+  //\r
+  // Search for the end of the device path structure\r
+  //\r
+  Start = DevicePath;\r
+  while (!IsDevicePathEnd (DevicePath)) {\r
+    DevicePath = NextDevicePathNode (DevicePath);\r
+  }\r
+\r
+  //\r
+  // Compute the size and add back in the size of the end device path structure\r
+  //\r
+  return ((UINTN) DevicePath - (UINTN) Start) + DevicePathNodeLength (DevicePath);\r
+}\r
+\r
+/**\r
+  Creates a new copy of an existing device path.\r
+\r
+  This function allocates space for a new copy of the device path specified by DevicePath.\r
+  If DevicePath is NULL, then NULL is returned.  If the memory is successfully\r
+  allocated, then the contents of DevicePath are copied to the newly allocated\r
+  buffer, and a pointer to that buffer is returned.  Otherwise, NULL is returned.\r
+  The memory for the new device path is allocated from EFI boot services memory.\r
+  It is the responsibility of the caller to free the memory allocated.\r
+\r
+  @param  DevicePath    A pointer to a device path data structure.\r
+\r
+  @retval NULL          DevicePath is NULL or invalid.\r
+  @retval Others        A pointer to the duplicated device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibDuplicateDevicePath (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  )\r
+{\r
+  UINTN                     Size;\r
+\r
+  //\r
+  // Compute the size\r
+  //\r
+  Size = GetDevicePathSize (DevicePath);\r
+  if (Size == 0) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Allocate space for duplicate device path\r
+  //\r
+\r
+  return AllocateCopyPool (Size, DevicePath);\r
+}\r
+\r
+/**\r
+  Creates a new device path by appending a second device path to a first device path.\r
+\r
+  This function creates a new device path by appending a copy of SecondDevicePath\r
+  to a copy of FirstDevicePath in a newly allocated buffer.  Only the end-of-device-path\r
+  device node from SecondDevicePath is retained. The newly created device path is\r
+  returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of\r
+  SecondDevicePath is returned.  If SecondDevicePath is NULL, then it is ignored,\r
+  and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and\r
+  SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.\r
+\r
+  If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
+  The memory for the new device path is allocated from EFI boot services memory.\r
+  It is the responsibility of the caller to free the memory allocated.\r
+\r
+  @param  FirstDevicePath            A pointer to a device path data structure.\r
+  @param  SecondDevicePath           A pointer to a device path data structure.\r
+\r
+  @retval NULL      If there is not enough memory for the newly allocated buffer.\r
+  @retval NULL      If FirstDevicePath or SecondDevicePath is invalid.\r
+  @retval Others    A pointer to the new device path if success.\r
+                    Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibAppendDevicePath (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath,\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *SecondDevicePath\r
+  )\r
+{\r
+  UINTN                     Size;\r
+  UINTN                     Size1;\r
+  UINTN                     Size2;\r
+  EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath2;\r
+\r
+  //\r
+  // If there's only 1 path, just duplicate it.\r
+  //\r
+  if (FirstDevicePath == NULL) {\r
+    return DuplicateDevicePath ((SecondDevicePath != NULL) ? SecondDevicePath : &mUefiDevicePathLibEndDevicePath);\r
+  }\r
+\r
+  if (SecondDevicePath == NULL) {\r
+    return DuplicateDevicePath (FirstDevicePath);\r
+  }\r
+\r
+  if (!IsDevicePathValid (FirstDevicePath, 0) || !IsDevicePathValid (SecondDevicePath, 0)) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Allocate space for the combined device path. It only has one end node of\r
+  // length EFI_DEVICE_PATH_PROTOCOL.\r
+  //\r
+  Size1         = GetDevicePathSize (FirstDevicePath);\r
+  Size2         = GetDevicePathSize (SecondDevicePath);\r
+  Size          = Size1 + Size2 - END_DEVICE_PATH_LENGTH;\r
+\r
+  NewDevicePath = AllocatePool (Size);\r
+\r
+  if (NewDevicePath != NULL) {\r
+    NewDevicePath = memcpy (NewDevicePath, FirstDevicePath, Size1);\r
+    //\r
+    // Over write FirstDevicePath EndNode and do the copy\r
+    //\r
+    DevicePath2 = (EFI_DEVICE_PATH_PROTOCOL *) ((CHAR8 *) NewDevicePath +\r
+                  (Size1 - END_DEVICE_PATH_LENGTH));\r
+    memcpy (DevicePath2, SecondDevicePath, Size2);\r
+  }\r
+\r
+  return NewDevicePath;\r
+}\r
+\r
+/**\r
+  Creates a new path by appending the device node to the device path.\r
+\r
+  This function creates a new device path by appending a copy of the device node\r
+  specified by DevicePathNode to a copy of the device path specified by DevicePath\r
+  in an allocated buffer. The end-of-device-path device node is moved after the\r
+  end of the appended device node.\r
+  If DevicePathNode is NULL then a copy of DevicePath is returned.\r
+  If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device\r
+  path device node is returned.\r
+  If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path\r
+  device node is returned.\r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
+  of the caller to free the memory allocated.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+  @param  DevicePathNode             A pointer to a single device path node.\r
+\r
+  @retval NULL      If there is not enough memory for the new device path.\r
+  @retval Others    A pointer to the new device path if success.\r
+                    A copy of DevicePathNode followed by an end-of-device-path node\r
+                    if both FirstDevicePath and SecondDevicePath are NULL.\r
+                    A copy of an end-of-device-path node if both FirstDevicePath\r
+                    and SecondDevicePath are NULL.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibAppendDevicePathNode (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *NextNode;\r
+  EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;\r
+  UINTN                     NodeLength;\r
+\r
+  if (DevicePathNode == NULL) {\r
+    return DuplicateDevicePath ((DevicePath != NULL) ? DevicePath : &mUefiDevicePathLibEndDevicePath);\r
+  }\r
+  //\r
+  // Build a Node that has a terminator on it\r
+  //\r
+  NodeLength = DevicePathNodeLength (DevicePathNode);\r
+\r
+  TempDevicePath = AllocatePool (NodeLength + END_DEVICE_PATH_LENGTH);\r
+  if (TempDevicePath == NULL) {\r
+    return NULL;\r
+  }\r
+  TempDevicePath = memcpy (TempDevicePath, DevicePathNode, NodeLength);\r
+  //\r
+  // Add and end device path node to convert Node to device path\r
+  //\r
+  NextNode = NextDevicePathNode (TempDevicePath);\r
+  SetDevicePathEndNode (NextNode);\r
+  //\r
+  // Append device paths\r
+  //\r
+  NewDevicePath = AppendDevicePath (DevicePath, TempDevicePath);\r
+\r
+  free (TempDevicePath);\r
+\r
+  return NewDevicePath;\r
+}\r
+\r
+/**\r
+  Creates a new device path by appending the specified device path instance to the specified device\r
+  path.\r
+\r
+  This function creates a new device path by appending a copy of the device path\r
+  instance specified by DevicePathInstance to a copy of the device path specified\r
+  by DevicePath in a allocated buffer.\r
+  The end-of-device-path device node is moved after the end of the appended device\r
+  path instance and a new end-of-device-path-instance node is inserted between.\r
+  If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
+  If DevicePathInstance is NULL, then NULL is returned.\r
+  If DevicePath or DevicePathInstance is invalid, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
+  of the caller to free the memory allocated.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+  @param  DevicePathInstance         A pointer to a device path instance.\r
+\r
+  @return A pointer to the new device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibAppendDevicePathInstance (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathInstance\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;\r
+  UINTN                     SrcSize;\r
+  UINTN                     InstanceSize;\r
+\r
+  if (DevicePath == NULL) {\r
+    return DuplicateDevicePath (DevicePathInstance);\r
+  }\r
+\r
+  if (DevicePathInstance == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  if (!IsDevicePathValid (DevicePath, 0) || !IsDevicePathValid (DevicePathInstance, 0)) {\r
+    return NULL;\r
+  }\r
+\r
+  SrcSize       = GetDevicePathSize (DevicePath);\r
+  InstanceSize  = GetDevicePathSize (DevicePathInstance);\r
+\r
+  NewDevicePath = AllocatePool (SrcSize + InstanceSize);\r
+  if (NewDevicePath != NULL) {\r
+\r
+    TempDevicePath = memcpy (NewDevicePath, DevicePath, SrcSize);;\r
+\r
+    while (!IsDevicePathEnd (TempDevicePath)) {\r
+      TempDevicePath = NextDevicePathNode (TempDevicePath);\r
+    }\r
+\r
+    TempDevicePath->SubType  = END_INSTANCE_DEVICE_PATH_SUBTYPE;\r
+    TempDevicePath           = NextDevicePathNode (TempDevicePath);\r
+    memcpy (TempDevicePath, DevicePathInstance, InstanceSize);\r
+  }\r
+\r
+  return NewDevicePath;\r
+}\r
+\r
+/**\r
+  Creates a copy of the current device path instance and returns a pointer to the next device path\r
+  instance.\r
+\r
+  This function creates a copy of the current device path instance. It also updates\r
+  DevicePath to point to the next device path instance in the device path (or NULL\r
+  if no more) and updates Size to hold the size of the device path instance copy.\r
+  If DevicePath is NULL, then NULL is returned.\r
+  If DevicePath points to a invalid device path, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
+  of the caller to free the memory allocated.\r
+  If Size is NULL, then ASSERT().\r
+\r
+  @param  DevicePath                 On input, this holds the pointer to the current\r
+                                     device path instance. On output, this holds\r
+                                     the pointer to the next device path instance\r
+                                     or NULL if there are no more device path\r
+                                     instances in the device path pointer to a\r
+                                     device path data structure.\r
+  @param  Size                       On output, this holds the size of the device\r
+                                     path instance, in bytes or zero, if DevicePath\r
+                                     is NULL.\r
+\r
+  @return A pointer to the current device path instance.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibGetNextDevicePathInstance (\r
+   EFI_DEVICE_PATH_PROTOCOL    **DevicePath,\r
+   UINTN                          *Size\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevPath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ReturnValue;\r
+  UINT8                     Temp;\r
+\r
+  ASSERT (Size != NULL);\r
+\r
+  if (DevicePath == NULL || *DevicePath == NULL) {\r
+    *Size = 0;\r
+    return NULL;\r
+  }\r
+\r
+  if (!IsDevicePathValid (*DevicePath, 0)) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Find the end of the device path instance\r
+  //\r
+  DevPath = *DevicePath;\r
+  while (!IsDevicePathEndType (DevPath)) {\r
+    DevPath = NextDevicePathNode (DevPath);\r
+  }\r
+\r
+  //\r
+  // Compute the size of the device path instance\r
+  //\r
+  *Size = ((UINTN) DevPath - (UINTN) (*DevicePath)) + sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
+\r
+  //\r
+  // Make a copy and return the device path instance\r
+  //\r
+  Temp              = DevPath->SubType;\r
+  DevPath->SubType  = END_ENTIRE_DEVICE_PATH_SUBTYPE;\r
+  ReturnValue       = DuplicateDevicePath (*DevicePath);\r
+  DevPath->SubType  = Temp;\r
+\r
+  //\r
+  // If DevPath is the end of an entire device path, then another instance\r
+  // does not follow, so *DevicePath is set to NULL.\r
+  //\r
+  if (DevicePathSubType (DevPath) == END_ENTIRE_DEVICE_PATH_SUBTYPE) {\r
+    *DevicePath = NULL;\r
+  } else {\r
+    *DevicePath = NextDevicePathNode (DevPath);\r
+  }\r
+\r
+  return ReturnValue;\r
+}\r
+\r
+/**\r
+  Creates a device node.\r
+\r
+  This function creates a new device node in a newly allocated buffer of size\r
+  NodeLength and initializes the device path node header with NodeType and NodeSubType.\r
+  The new device path node is returned.\r
+  If NodeLength is smaller than a device path header, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
+  of the caller to free the memory allocated.\r
+\r
+  @param  NodeType                   The device node type for the new device node.\r
+  @param  NodeSubType                The device node sub-type for the new device node.\r
+  @param  NodeLength                 The length of the new device node.\r
+\r
+  @return The new device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibCreateDeviceNode (\r
+   UINT8                           NodeType,\r
+   UINT8                           NodeSubType,\r
+   UINT16                          NodeLength\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;\r
+\r
+  if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
+    //\r
+    // NodeLength is less than the size of the header.\r
+    //\r
+    return NULL;\r
+  }\r
+\r
+  DevicePath = AllocateZeroPool (NodeLength);\r
+  if (DevicePath != NULL) {\r
+     DevicePath->Type    = NodeType;\r
+     DevicePath->SubType = NodeSubType;\r
+     SetDevicePathNodeLength (DevicePath, NodeLength);\r
+  }\r
+\r
+  return DevicePath;\r
+}\r
+\r
+/**\r
+  Determines if a device path is single or multi-instance.\r
+\r
+  This function returns TRUE if the device path specified by DevicePath is\r
+  multi-instance.\r
+  Otherwise, FALSE is returned.\r
+  If DevicePath is NULL or invalid, then FALSE is returned.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+\r
+  @retval  TRUE                      DevicePath is multi-instance.\r
+  @retval  FALSE                     DevicePath is not multi-instance, or DevicePath\r
+                                     is NULL or invalid.\r
+\r
+**/\r
+BOOLEAN\r
+UefiDevicePathLibIsDevicePathMultiInstance (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  )\r
+{\r
+  CONST EFI_DEVICE_PATH_PROTOCOL     *Node;\r
+\r
+  if (DevicePath == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
+  if (!IsDevicePathValid (DevicePath, 0)) {\r
+    return FALSE;\r
+  }\r
+\r
+  Node = DevicePath;\r
+  while (!IsDevicePathEnd (Node)) {\r
+    if (IsDevicePathEndInstance (Node)) {\r
+      return TRUE;\r
+    }\r
+\r
+    Node = NextDevicePathNode (Node);\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+\r
+/**\r
+  Retrieves the device path protocol from a handle.\r
+\r
+  This function returns the device path protocol from the handle specified by Handle.\r
+  If Handle is NULL or Handle does not contain a device path protocol, then NULL\r
+  is returned.\r
+\r
+  @param  Handle                     The handle from which to retrieve the device\r
+                                     path protocol.\r
+\r
+  @return The device path protocol from the handle specified by Handle.\r
+\r
+**/\r
+/*\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevicePathFromHandle (\r
+   EFI_HANDLE                      Handle\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_STATUS                Status;\r
+\r
+  Status = gBS->HandleProtocol (\r
+                  Handle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID *) &DevicePath\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    DevicePath = NULL;\r
+  }\r
+  return DevicePath;\r
+}\r
+*/\r
+/**\r
+  Allocates a device path for a file and appends it to an existing device path.\r
+\r
+  If Device is a valid device handle that contains a device path protocol, then a device path for\r
+  the file specified by FileName  is allocated and appended to the device path associated with the\r
+  handle Device.  The allocated device path is returned.  If Device is NULL or Device is a handle\r
+  that does not support the device path protocol, then a device path containing a single device\r
+  path node for the file specified by FileName is allocated and returned.\r
+  The memory for the new device path is allocated from EFI boot services memory. It is the responsibility\r
+  of the caller to free the memory allocated.\r
+\r
+  If FileName is NULL, then ASSERT().\r
+  If FileName is not aligned on a 16-bit boundary, then ASSERT().\r
+\r
+  @param  Device                     A pointer to a device handle.  This parameter\r
+                                     is optional and may be NULL.\r
+  @param  FileName                   A pointer to a Null-terminated Unicode string.\r
+\r
+  @return The allocated device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+FileDevicePath (\r
+   EFI_HANDLE                      Device,     OPTIONAL\r
+   CONST CHAR16                    *FileName\r
+  )\r
+{\r
+  UINTN                     Size;\r
+  FILEPATH_DEVICE_PATH      *FilePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *FileDevicePath;\r
+\r
+  DevicePath = NULL;\r
+\r
+  Size = StrSize (FileName);\r
+  FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);\r
+  if (FileDevicePath != NULL) {\r
+    FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;\r
+    FilePath->Header.Type    = MEDIA_DEVICE_PATH;\r
+    FilePath->Header.SubType = MEDIA_FILEPATH_DP;\r
+    memcpy (&FilePath->PathName, FileName, Size);\r
+    SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);\r
+    SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));\r
+\r
+    //if (Device != NULL) {\r
+    //  DevicePath = DevicePathFromHandle (Device);\r
+    //}\r
+\r
+    DevicePath = AppendDevicePath (DevicePath, FileDevicePath);\r
+    free (FileDevicePath);\r
+  }\r
+\r
+  return DevicePath;\r
+}\r
diff --git a/BaseTools/Source/C/DevicePath/GNUmakefile b/BaseTools/Source/C/DevicePath/GNUmakefile
new file mode 100644 (file)
index 0000000..27f6fa1
--- /dev/null
@@ -0,0 +1,30 @@
+## @file\r
+# GNU/Linux makefile for 'DevicePath' module build.\r
+#\r
+# Copyright (c) 2017, 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
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+ARCH ?= IA32\r
+MAKEROOT ?= ..\r
+\r
+APPNAME = DevicePath\r
+\r
+OBJECTS = DevicePath.o UefiDevicePathLib.o DevicePathFromText.o  DevicePathUtilities.o\r
+\r
+include $(MAKEROOT)/Makefiles/app.makefile\r
+\r
+LIBS = -lCommon\r
+ifeq ($(CYGWIN), CYGWIN)\r
+  LIBS += -L/lib/e2fsprogs -luuid\r
+endif\r
+\r
+ifeq ($(LINUX), Linux)\r
+  LIBS += -luuid\r
+endif\r
+\r
diff --git a/BaseTools/Source/C/DevicePath/Makefile b/BaseTools/Source/C/DevicePath/Makefile
new file mode 100644 (file)
index 0000000..a069c22
--- /dev/null
@@ -0,0 +1,24 @@
+## @file\r
+# Windows makefile for 'DevicePath' module build.\r
+#\r
+# Copyright (c) 2017, 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
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+!INCLUDE ..\Makefiles\ms.common\r
+\r
+APPNAME = DevicePath\r
+\r
+LIBS = $(LIB_PATH)\Common.lib\r
+\r
+OBJECTS = DevicePath.obj UefiDevicePathLib.obj DevicePathFromText.obj  DevicePathUtilities.obj\r
+\r
+#CFLAGS = $(CFLAGS) /nodefaultlib:libc.lib\r
+\r
+!INCLUDE ..\Makefiles\ms.app\r
+\r
diff --git a/BaseTools/Source/C/DevicePath/UefiDevicePathLib.c b/BaseTools/Source/C/DevicePath/UefiDevicePathLib.c
new file mode 100644 (file)
index 0000000..a2e0322
--- /dev/null
@@ -0,0 +1,298 @@
+/** @file\r
+  Device Path services. The thing to remember is device paths are built out of\r
+  nodes. The device path is terminated by an end node that is length\r
+  sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)\r
+  all over this file.\r
+\r
+  The only place where multi-instance device paths are supported is in\r
+  environment varibles. Multi-instance device paths should never be placed\r
+  on a Handle.\r
+\r
+  Copyright (c) 2017, 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
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+\r
+#include "UefiDevicePathLib.h"\r
+\r
+/**\r
+  Returns the size of a device path in bytes.\r
+\r
+  This function returns the size, in bytes, of the device path data structure\r
+  specified by DevicePath including the end of device path node.\r
+  If DevicePath is NULL or invalid, then 0 is returned.\r
+\r
+  @param  DevicePath  A pointer to a device path data structure.\r
+\r
+  @retval 0           If DevicePath is NULL or invalid.\r
+  @retval Others      The size of a device path in bytes.\r
+\r
+**/\r
+UINTN\r
+GetDevicePathSize (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  )\r
+{\r
+  return UefiDevicePathLibGetDevicePathSize (DevicePath);\r
+}\r
+\r
+/**\r
+  Creates a new copy of an existing device path.\r
+\r
+  This function allocates space for a new copy of the device path specified by DevicePath.\r
+  If DevicePath is NULL, then NULL is returned.  If the memory is successfully\r
+  allocated, then the contents of DevicePath are copied to the newly allocated\r
+  buffer, and a pointer to that buffer is returned.  Otherwise, NULL is returned.\r
+  The memory for the new device path is allocated from EFI boot services memory.\r
+  It is the responsibility of the caller to free the memory allocated.\r
+\r
+  @param  DevicePath    A pointer to a device path data structure.\r
+\r
+  @retval NULL          DevicePath is NULL or invalid.\r
+  @retval Others        A pointer to the duplicated device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DuplicateDevicePath (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  )\r
+{\r
+  return UefiDevicePathLibDuplicateDevicePath (DevicePath);\r
+}\r
+\r
+/**\r
+  Creates a new device path by appending a second device path to a first device path.\r
+\r
+  This function creates a new device path by appending a copy of SecondDevicePath\r
+  to a copy of FirstDevicePath in a newly allocated buffer.  Only the end-of-device-path\r
+  device node from SecondDevicePath is retained. The newly created device path is\r
+  returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of\r
+  SecondDevicePath is returned.  If SecondDevicePath is NULL, then it is ignored,\r
+  and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and\r
+  SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.\r
+\r
+  If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
+  The memory for the new device path is allocated from EFI boot services memory.\r
+  It is the responsibility of the caller to free the memory allocated.\r
+\r
+  @param  FirstDevicePath            A pointer to a device path data structure.\r
+  @param  SecondDevicePath           A pointer to a device path data structure.\r
+\r
+  @retval NULL      If there is not enough memory for the newly allocated buffer.\r
+  @retval NULL      If FirstDevicePath or SecondDevicePath is invalid.\r
+  @retval Others    A pointer to the new device path if success.\r
+                    Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+AppendDevicePath (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath,  OPTIONAL\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *SecondDevicePath  OPTIONAL\r
+  )\r
+{\r
+  return UefiDevicePathLibAppendDevicePath (FirstDevicePath, SecondDevicePath);\r
+}\r
+\r
+/**\r
+  Creates a new path by appending the device node to the device path.\r
+\r
+  This function creates a new device path by appending a copy of the device node\r
+  specified by DevicePathNode to a copy of the device path specified by DevicePath\r
+  in an allocated buffer. The end-of-device-path device node is moved after the\r
+  end of the appended device node.\r
+  If DevicePathNode is NULL then a copy of DevicePath is returned.\r
+  If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device\r
+  path device node is returned.\r
+  If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path\r
+  device node is returned.\r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
+  of the caller to free the memory allocated.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+  @param  DevicePathNode             A pointer to a single device path node.\r
+\r
+  @retval NULL      If there is not enough memory for the new device path.\r
+  @retval Others    A pointer to the new device path if success.\r
+                    A copy of DevicePathNode followed by an end-of-device-path node\r
+                    if both FirstDevicePath and SecondDevicePath are NULL.\r
+                    A copy of an end-of-device-path node if both FirstDevicePath\r
+                    and SecondDevicePath are NULL.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+AppendDevicePathNode (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,     OPTIONAL\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode  OPTIONAL\r
+  )\r
+{\r
+  return UefiDevicePathLibAppendDevicePathNode (DevicePath, DevicePathNode);\r
+}\r
+\r
+/**\r
+  Creates a new device path by appending the specified device path instance to the specified device\r
+  path.\r
+\r
+  This function creates a new device path by appending a copy of the device path\r
+  instance specified by DevicePathInstance to a copy of the device path specified\r
+  by DevicePath in a allocated buffer.\r
+  The end-of-device-path device node is moved after the end of the appended device\r
+  path instance and a new end-of-device-path-instance node is inserted between.\r
+  If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
+  If DevicePathInstance is NULL, then NULL is returned.\r
+  If DevicePath or DevicePathInstance is invalid, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
+  of the caller to free the memory allocated.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+  @param  DevicePathInstance         A pointer to a device path instance.\r
+\r
+  @return A pointer to the new device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+AppendDevicePathInstance (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,        OPTIONAL\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathInstance OPTIONAL\r
+  )\r
+{\r
+  return UefiDevicePathLibAppendDevicePathInstance (DevicePath, DevicePathInstance);\r
+}\r
+\r
+/**\r
+  Creates a copy of the current device path instance and returns a pointer to the next device path\r
+  instance.\r
+\r
+  This function creates a copy of the current device path instance. It also updates\r
+  DevicePath to point to the next device path instance in the device path (or NULL\r
+  if no more) and updates Size to hold the size of the device path instance copy.\r
+  If DevicePath is NULL, then NULL is returned.\r
+  If DevicePath points to a invalid device path, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
+  of the caller to free the memory allocated.\r
+  If Size is NULL, then ASSERT().\r
+\r
+  @param  DevicePath                 On input, this holds the pointer to the current\r
+                                     device path instance. On output, this holds\r
+                                     the pointer to the next device path instance\r
+                                     or NULL if there are no more device path\r
+                                     instances in the device path pointer to a\r
+                                     device path data structure.\r
+  @param  Size                       On output, this holds the size of the device\r
+                                     path instance, in bytes or zero, if DevicePath\r
+                                     is NULL.\r
+\r
+  @return A pointer to the current device path instance.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+GetNextDevicePathInstance (\r
+    EFI_DEVICE_PATH_PROTOCOL    **DevicePath,\r
+   UINTN                          *Size\r
+  )\r
+{\r
+  return UefiDevicePathLibGetNextDevicePathInstance (DevicePath, Size);\r
+}\r
+\r
+/**\r
+  Creates a device node.\r
+\r
+  This function creates a new device node in a newly allocated buffer of size\r
+  NodeLength and initializes the device path node header with NodeType and NodeSubType.\r
+  The new device path node is returned.\r
+  If NodeLength is smaller than a device path header, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
+  of the caller to free the memory allocated.\r
+\r
+  @param  NodeType                   The device node type for the new device node.\r
+  @param  NodeSubType                The device node sub-type for the new device node.\r
+  @param  NodeLength                 The length of the new device node.\r
+\r
+  @return The new device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+CreateDeviceNode (\r
+   UINT8                           NodeType,\r
+   UINT8                           NodeSubType,\r
+   UINT16                          NodeLength\r
+  )\r
+{\r
+  return UefiDevicePathLibCreateDeviceNode (NodeType, NodeSubType, NodeLength);\r
+}\r
+\r
+/**\r
+  Determines if a device path is single or multi-instance.\r
+\r
+  This function returns TRUE if the device path specified by DevicePath is\r
+  multi-instance.\r
+  Otherwise, FALSE is returned.\r
+  If DevicePath is NULL or invalid, then FALSE is returned.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+\r
+  @retval  TRUE                      DevicePath is multi-instance.\r
+  @retval  FALSE                     DevicePath is not multi-instance, or DevicePath\r
+                                     is NULL or invalid.\r
+\r
+**/\r
+BOOLEAN\r
+IsDevicePathMultiInstance (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  )\r
+{\r
+  return UefiDevicePathLibIsDevicePathMultiInstance (DevicePath);\r
+}\r
+\r
+/**\r
+  Convert text to the binary representation of a device node.\r
+\r
+  @param TextDeviceNode  TextDeviceNode points to the text representation of a device\r
+                         node. Conversion starts with the first character and continues\r
+                         until the first non-device node character.\r
+\r
+  @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was\r
+          insufficient memory or text unsupported.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+ConvertTextToDeviceNode (\r
+   CONST CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  return UefiDevicePathLibConvertTextToDeviceNode (TextDeviceNode);\r
+}\r
+\r
+/**\r
+  Convert text to the binary representation of a device path.\r
+\r
+\r
+  @param TextDevicePath  TextDevicePath points to the text representation of a device\r
+                         path. Conversion starts with the first character and continues\r
+                         until the first non-device node character.\r
+\r
+  @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or\r
+          there was insufficient memory.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+ConvertTextToDevicePath (\r
+   CONST CHAR16 *TextDevicePath\r
+ )\r
+{\r
+  return UefiDevicePathLibConvertTextToDevicePath (TextDevicePath);\r
+}\r
diff --git a/BaseTools/Source/C/DevicePath/UefiDevicePathLib.h b/BaseTools/Source/C/DevicePath/UefiDevicePathLib.h
new file mode 100644 (file)
index 0000000..7bc974d
--- /dev/null
@@ -0,0 +1,452 @@
+/** @file\r
+  Definition for Device Path library.\r
+\r
+Copyright (c) 2017, 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
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _UEFI_DEVICE_PATH_LIB_H_\r
+#define _UEFI_DEVICE_PATH_LIB_H_\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <ctype.h>\r
+#include <assert.h>\r
+#ifdef __GNUC__\r
+#include <unistd.h>\r
+#else\r
+#include <direct.h>\r
+#endif\r
+#include <Common/UefiBaseTypes.h>\r
+#include <Protocol/DevicePath.h>\r
+#include <Protocol/DevicePathUtilities.h>\r
+#include "CommonLib.h"\r
+#include "EfiUtilityMsgs.h"\r
+\r
+#define END_DEVICE_PATH_LENGTH               (sizeof (EFI_DEVICE_PATH_PROTOCOL))\r
+#define MAX_DEVICE_PATH_NODE_COUNT   1024\r
+#define SIZE_64KB   0x00010000\r
+\r
+//\r
+// Private Data structure\r
+//\r
+typedef\r
+EFI_DEVICE_PATH_PROTOCOL  *\r
+(*DEVICE_PATH_FROM_TEXT) (\r
+  IN  CHAR16 *Str\r
+ );\r
+\r
+typedef struct {\r
+  CHAR16  *Str;\r
+  UINTN   Count;\r
+  UINTN   Capacity;\r
+} POOL_PRINT;\r
+\r
+\r
+typedef struct {\r
+  CHAR16                    *DevicePathNodeText;\r
+  DEVICE_PATH_FROM_TEXT     Function;\r
+} DEVICE_PATH_FROM_TEXT_TABLE;\r
+\r
+typedef struct {\r
+  BOOLEAN ClassExist;\r
+  UINT8   Class;\r
+  BOOLEAN SubClassExist;\r
+  UINT8   SubClass;\r
+} USB_CLASS_TEXT;\r
+\r
+#define USB_CLASS_AUDIO            1\r
+#define USB_CLASS_CDCCONTROL       2\r
+#define USB_CLASS_HID              3\r
+#define USB_CLASS_IMAGE            6\r
+#define USB_CLASS_PRINTER          7\r
+#define USB_CLASS_MASS_STORAGE     8\r
+#define USB_CLASS_HUB              9\r
+#define USB_CLASS_CDCDATA          10\r
+#define USB_CLASS_SMART_CARD       11\r
+#define USB_CLASS_VIDEO            14\r
+#define USB_CLASS_DIAGNOSTIC       220\r
+#define USB_CLASS_WIRELESS         224\r
+\r
+#define USB_CLASS_RESERVE          254\r
+#define USB_SUBCLASS_FW_UPDATE     1\r
+#define USB_SUBCLASS_IRDA_BRIDGE   2\r
+#define USB_SUBCLASS_TEST          3\r
+\r
+#define RFC_1700_UDP_PROTOCOL      17\r
+#define RFC_1700_TCP_PROTOCOL      6\r
+\r
+#pragma pack(1)\r
+\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL  Header;\r
+  EFI_GUID                  Guid;\r
+  UINT8                     VendorDefinedData[1];\r
+} VENDOR_DEFINED_HARDWARE_DEVICE_PATH;\r
+\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL  Header;\r
+  EFI_GUID                  Guid;\r
+  UINT8                     VendorDefinedData[1];\r
+} VENDOR_DEFINED_MESSAGING_DEVICE_PATH;\r
+\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL  Header;\r
+  EFI_GUID                  Guid;\r
+  UINT8                     VendorDefinedData[1];\r
+} VENDOR_DEFINED_MEDIA_DEVICE_PATH;\r
+\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL  Header;\r
+  UINT32                    Hid;\r
+  UINT32                    Uid;\r
+  UINT32                    Cid;\r
+  CHAR8                     HidUidCidStr[3];\r
+} ACPI_EXTENDED_HID_DEVICE_PATH_WITH_STR;\r
+\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL  Header;\r
+  UINT16                    NetworkProtocol;\r
+  UINT16                    LoginOption;\r
+  UINT64                    Lun;\r
+  UINT16                    TargetPortalGroupTag;\r
+  CHAR8                     TargetName[1];\r
+} ISCSI_DEVICE_PATH_WITH_NAME;\r
+\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL  Header;\r
+  EFI_GUID                  Guid;\r
+  UINT8                     VendorDefinedData[1];\r
+} VENDOR_DEVICE_PATH_WITH_DATA;\r
+\r
+#pragma pack()\r
+\r
+/**\r
+  Returns the size of a device path in bytes.\r
+\r
+  This function returns the size, in bytes, of the device path data structure\r
+  specified by DevicePath including the end of device path node.\r
+  If DevicePath is NULL or invalid, then 0 is returned.\r
+\r
+  @param  DevicePath  A pointer to a device path data structure.\r
+\r
+  @retval 0           If DevicePath is NULL or invalid.\r
+  @retval Others      The size of a device path in bytes.\r
+\r
+**/\r
+UINTN\r
+UefiDevicePathLibGetDevicePathSize (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  );\r
+\r
+/**\r
+  Creates a new copy of an existing device path.\r
+\r
+  This function allocates space for a new copy of the device path specified by DevicePath.\r
+  If DevicePath is NULL, then NULL is returned.  If the memory is successfully\r
+  allocated, then the contents of DevicePath are copied to the newly allocated\r
+  buffer, and a pointer to that buffer is returned.  Otherwise, NULL is returned.\r
+  The memory for the new device path is allocated from EFI boot services memory.\r
+  It is the responsibility of the caller to free the memory allocated.\r
+\r
+  @param  DevicePath    A pointer to a device path data structure.\r
+\r
+  @retval NULL          DevicePath is NULL or invalid.\r
+  @retval Others        A pointer to the duplicated device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibDuplicateDevicePath (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  );\r
+\r
+/**\r
+  Creates a new device path by appending a second device path to a first device path.\r
+\r
+  This function creates a new device path by appending a copy of SecondDevicePath\r
+  to a copy of FirstDevicePath in a newly allocated buffer.  Only the end-of-device-path\r
+  device node from SecondDevicePath is retained. The newly created device path is\r
+  returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of\r
+  SecondDevicePath is returned.  If SecondDevicePath is NULL, then it is ignored,\r
+  and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and\r
+  SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.\r
+\r
+  If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
+  The memory for the new device path is allocated from EFI boot services memory.\r
+  It is the responsibility of the caller to free the memory allocated.\r
+\r
+  @param  FirstDevicePath            A pointer to a device path data structure.\r
+  @param  SecondDevicePath           A pointer to a device path data structure.\r
+\r
+  @retval NULL      If there is not enough memory for the newly allocated buffer.\r
+  @retval NULL      If FirstDevicePath or SecondDevicePath is invalid.\r
+  @retval Others    A pointer to the new device path if success.\r
+                    Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibAppendDevicePath (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath,  OPTIONAL\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *SecondDevicePath  OPTIONAL\r
+  );\r
+\r
+/**\r
+  Creates a new path by appending the device node to the device path.\r
+\r
+  This function creates a new device path by appending a copy of the device node\r
+  specified by DevicePathNode to a copy of the device path specified by DevicePath\r
+  in an allocated buffer. The end-of-device-path device node is moved after the\r
+  end of the appended device node.\r
+  If DevicePathNode is NULL then a copy of DevicePath is returned.\r
+  If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device\r
+  path device node is returned.\r
+  If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path\r
+  device node is returned.\r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
+  of the caller to free the memory allocated.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+  @param  DevicePathNode             A pointer to a single device path node.\r
+\r
+  @retval NULL      If there is not enough memory for the new device path.\r
+  @retval Others    A pointer to the new device path if success.\r
+                    A copy of DevicePathNode followed by an end-of-device-path node\r
+                    if both FirstDevicePath and SecondDevicePath are NULL.\r
+                    A copy of an end-of-device-path node if both FirstDevicePath\r
+                    and SecondDevicePath are NULL.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibAppendDevicePathNode (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,     OPTIONAL\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode  OPTIONAL\r
+  );\r
+\r
+/**\r
+  Creates a new device path by appending the specified device path instance to the specified device\r
+  path.\r
+\r
+  This function creates a new device path by appending a copy of the device path\r
+  instance specified by DevicePathInstance to a copy of the device path specified\r
+  by DevicePath in a allocated buffer.\r
+  The end-of-device-path device node is moved after the end of the appended device\r
+  path instance and a new end-of-device-path-instance node is inserted between.\r
+  If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
+  If DevicePathInstance is NULL, then NULL is returned.\r
+  If DevicePath or DevicePathInstance is invalid, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
+  of the caller to free the memory allocated.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+  @param  DevicePathInstance         A pointer to a device path instance.\r
+\r
+  @return A pointer to the new device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibAppendDevicePathInstance (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,        OPTIONAL\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathInstance OPTIONAL\r
+  );\r
+\r
+/**\r
+  Creates a copy of the current device path instance and returns a pointer to the next device path\r
+  instance.\r
+\r
+  This function creates a copy of the current device path instance. It also updates\r
+  DevicePath to point to the next device path instance in the device path (or NULL\r
+  if no more) and updates Size to hold the size of the device path instance copy.\r
+  If DevicePath is NULL, then NULL is returned.\r
+  If DevicePath points to a invalid device path, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
+  of the caller to free the memory allocated.\r
+  If Size is NULL, then ASSERT().\r
+\r
+  @param  DevicePath                 On input, this holds the pointer to the current\r
+                                     device path instance. On output, this holds\r
+                                     the pointer to the next device path instance\r
+                                     or NULL if there are no more device path\r
+                                     instances in the device path pointer to a\r
+                                     device path data structure.\r
+  @param  Size                       On output, this holds the size of the device\r
+                                     path instance, in bytes or zero, if DevicePath\r
+                                     is NULL.\r
+\r
+  @return A pointer to the current device path instance.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibGetNextDevicePathInstance (\r
+   EFI_DEVICE_PATH_PROTOCOL    **DevicePath,\r
+   UINTN                          *Size\r
+  );\r
+\r
+/**\r
+  Creates a device node.\r
+\r
+  This function creates a new device node in a newly allocated buffer of size\r
+  NodeLength and initializes the device path node header with NodeType and NodeSubType.\r
+  The new device path node is returned.\r
+  If NodeLength is smaller than a device path header, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
+  of the caller to free the memory allocated.\r
+\r
+  @param  NodeType                   The device node type for the new device node.\r
+  @param  NodeSubType                The device node sub-type for the new device node.\r
+  @param  NodeLength                 The length of the new device node.\r
+\r
+  @return The new device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibCreateDeviceNode (\r
+   UINT8                           NodeType,\r
+   UINT8                           NodeSubType,\r
+   UINT16                          NodeLength\r
+  );\r
+\r
+/**\r
+  Determines if a device path is single or multi-instance.\r
+\r
+  This function returns TRUE if the device path specified by DevicePath is\r
+  multi-instance.\r
+  Otherwise, FALSE is returned.\r
+  If DevicePath is NULL or invalid, then FALSE is returned.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+\r
+  @retval  TRUE                      DevicePath is multi-instance.\r
+  @retval  FALSE                     DevicePath is not multi-instance, or DevicePath\r
+                                     is NULL or invalid.\r
+\r
+**/\r
+BOOLEAN\r
+UefiDevicePathLibIsDevicePathMultiInstance (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  );\r
+\r
+/**\r
+  Convert text to the binary representation of a device node.\r
+\r
+  @param TextDeviceNode  TextDeviceNode points to the text representation of a device\r
+                         node. Conversion starts with the first character and continues\r
+                         until the first non-device node character.\r
+\r
+  @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was\r
+          insufficient memory or text unsupported.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibConvertTextToDeviceNode (\r
+   CONST CHAR16 *TextDeviceNode\r
+  );\r
+\r
+/**\r
+  Convert text to the binary representation of a device path.\r
+\r
+\r
+  @param TextDevicePath  TextDevicePath points to the text representation of a device\r
+                         path. Conversion starts with the first character and continues\r
+                         until the first non-device node character.\r
+\r
+  @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or\r
+          there was insufficient memory.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibConvertTextToDevicePath (\r
+   CONST CHAR16 *TextDevicePath\r
+  );\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+CreateDeviceNode (\r
+   UINT8                           NodeType,\r
+   UINT8                           NodeSubType,\r
+   UINT16                          NodeLength\r
+  );\r
+\r
+ EFI_DEVICE_PATH_PROTOCOL *\r
+CreateDeviceNode (\r
+   UINT8                           NodeType,\r
+   UINT8                           NodeSubType,\r
+   UINT16                          NodeLength\r
+  );\r
+\r
+BOOLEAN\r
+IsDevicePathMultiInstance (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  );\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+GetNextDevicePathInstance (\r
+    EFI_DEVICE_PATH_PROTOCOL    **DevicePath,\r
+   UINTN                          *Size\r
+  );\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+AppendDevicePathInstance (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,        OPTIONAL\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathInstance OPTIONAL\r
+  );\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+AppendDevicePathNode (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,     OPTIONAL\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode  OPTIONAL\r
+  );\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+AppendDevicePath (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath,  OPTIONAL\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *SecondDevicePath  OPTIONAL\r
+  );\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DuplicateDevicePath (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  );\r
+\r
+UINTN\r
+GetDevicePathSize (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  );\r
+\r
+CHAR16 *\r
+ConvertDeviceNodeToText (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DeviceNode,\r
+   BOOLEAN                         DisplayOnly,\r
+   BOOLEAN                         AllowShortcuts\r
+  );\r
+\r
+CHAR16 *\r
+ConvertDevicePathToText (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL   *DevicePath,\r
+   BOOLEAN                          DisplayOnly,\r
+   BOOLEAN                          AllowShortcuts\r
+  );\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+ConvertTextToDeviceNode (\r
+   CONST CHAR16 *TextDeviceNode\r
+  );\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+ConvertTextToDevicePath (\r
+   CONST CHAR16 *TextDevicePath\r
+  );\r
+\r
+#endif\r
index 0dc748267d9e817dc8c2288d13eda781af1de6ea..37421ad9f00b3d3b7e126029a18d19ffd01f8c19 100644 (file)
@@ -67,7 +67,8 @@ APPLICATIONS = \
   LzmaCompress \\r
   Split \\r
   TianoCompress \\r
-  VolInfo\r
+  VolInfo \\r
+  DevicePath\r
 \r
 SUBDIRS := $(LIBRARIES) $(APPLICATIONS)\r
 \r
diff --git a/BaseTools/Source/C/Include/IndustryStandard/Bluetooth.h b/BaseTools/Source/C/Include/IndustryStandard/Bluetooth.h
new file mode 100644 (file)
index 0000000..d6e6d75
--- /dev/null
@@ -0,0 +1,62 @@
+/** @file\r
+  This file contains the Bluetooth definitions that are consumed by drivers.\r
+  These definitions are from Bluetooth Core Specification Version 4.0 June, 2010\r
+\r
+  Copyright (c) 2017, 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
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _BLUETOOTH_H_\r
+#define _BLUETOOTH_H_\r
+\r
+#pragma pack(1)\r
+\r
+///\r
+/// BLUETOOTH_ADDRESS\r
+///\r
+typedef struct {\r
+  ///\r
+  /// 48bit Bluetooth device address.\r
+  ///\r
+  UINT8      Address[6];\r
+} BLUETOOTH_ADDRESS;\r
+\r
+///\r
+/// BLUETOOTH_CLASS_OF_DEVICE. See Bluetooth specification for detail.\r
+///\r
+typedef struct {\r
+  UINT8      FormatType:2;\r
+  UINT8      MinorDeviceClass: 6;\r
+  UINT16     MajorDeviceClass: 5;\r
+  UINT16     MajorServiceClass:11;\r
+} BLUETOOTH_CLASS_OF_DEVICE;\r
+\r
+///\r
+/// BLUETOOTH_LE_ADDRESS\r
+///\r
+typedef struct {\r
+  ///\r
+  /// 48-bit Bluetooth device address\r
+  ///\r
+  UINT8      Address[6];\r
+  ///\r
+  /// 0x00 - Public Device Address\r
+  /// 0x01 - Random Device Address\r
+  ///\r
+  UINT8      Type;\r
+} BLUETOOTH_LE_ADDRESS;\r
+\r
+#pragma pack()\r
+\r
+#define BLUETOOTH_HCI_COMMAND_LOCAL_READABLE_NAME_MAX_SIZE    248\r
+\r
+#define BLUETOOTH_HCI_LINK_KEY_SIZE                           16\r
+\r
+#endif\r
diff --git a/BaseTools/Source/C/Include/Protocol/DevicePath.h b/BaseTools/Source/C/Include/Protocol/DevicePath.h
new file mode 100644 (file)
index 0000000..a5d8eea
--- /dev/null
@@ -0,0 +1,1391 @@
+/** @file\r
+  The device path protocol as defined in UEFI 2.0.\r
+\r
+  The device path represents a programmatic path to a device,\r
+  from a software point of view. The path must persist from boot to boot, so\r
+  it can not contain things like PCI bus numbers that change from boot to boot.\r
+\r
+Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EFI_DEVICE_PATH_H__\r
+#define __EFI_DEVICE_PATH_H__\r
+\r
+#include <Guid/PcAnsi.h>\r
+#include <IndustryStandard/Acpi3_0.h>\r
+#include <IndustryStandard/Bluetooth.h>\r
+\r
+///\r
+/// Device Path protocol.\r
+///\r
+#define EFI_DEVICE_PATH_PROTOCOL_GUID \\r
+  { \\r
+    0x9576e91, 0x6d3f, 0x11d2, {0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \\r
+  }\r
+\r
+///\r
+/// Device Path guid definition for backward-compatible with EFI1.1.\r
+///\r
+#define DEVICE_PATH_PROTOCOL  EFI_DEVICE_PATH_PROTOCOL_GUID\r
+\r
+#pragma pack(1)\r
+\r
+/**\r
+  This protocol can be used on any device handle to obtain generic path/location\r
+  information concerning the physical device or logical device. If the handle does\r
+  not logically map to a physical device, the handle may not necessarily support\r
+  the device path protocol. The device path describes the location of the device\r
+  the handle is for. The size of the Device Path can be determined from the structures\r
+  that make up the Device Path.\r
+**/\r
+typedef struct {\r
+  UINT8 Type;       ///< 0x01 Hardware Device Path.\r
+                    ///< 0x02 ACPI Device Path.\r
+                    ///< 0x03 Messaging Device Path.\r
+                    ///< 0x04 Media Device Path.\r
+                    ///< 0x05 BIOS Boot Specification Device Path.\r
+                    ///< 0x7F End of Hardware Device Path.\r
+\r
+  UINT8 SubType;    ///< Varies by Type\r
+                    ///< 0xFF End Entire Device Path, or\r
+                    ///< 0x01 End This Instance of a Device Path and start a new\r
+                    ///< Device Path.\r
+\r
+  UINT8 Length[2];  ///< Specific Device Path data. Type and Sub-Type define\r
+                    ///< type of data. Size of data is included in Length.\r
+\r
+} EFI_DEVICE_PATH_PROTOCOL;\r
+\r
+///\r
+/// Device Path protocol definition for backward-compatible with EFI1.1.\r
+///\r
+typedef EFI_DEVICE_PATH_PROTOCOL  EFI_DEVICE_PATH;\r
+\r
+///\r
+/// Hardware Device Paths.\r
+///\r
+#define HARDWARE_DEVICE_PATH      0x01\r
+\r
+///\r
+/// PCI Device Path SubType.\r
+///\r
+#define HW_PCI_DP                 0x01\r
+\r
+///\r
+/// PCI Device Path.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// PCI Function Number.\r
+  ///\r
+  UINT8                           Function;\r
+  ///\r
+  /// PCI Device Number.\r
+  ///\r
+  UINT8                           Device;\r
+} PCI_DEVICE_PATH;\r
+\r
+///\r
+/// PCCARD Device Path SubType.\r
+///\r
+#define HW_PCCARD_DP              0x02\r
+\r
+///\r
+/// PCCARD Device Path.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Function Number (0 = First Function).\r
+  ///\r
+  UINT8                           FunctionNumber;\r
+} PCCARD_DEVICE_PATH;\r
+\r
+///\r
+/// Memory Mapped Device Path SubType.\r
+///\r
+#define HW_MEMMAP_DP             0x03\r
+\r
+///\r
+/// Memory Mapped Device Path.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// EFI_MEMORY_TYPE\r
+  ///\r
+  UINT32                          MemoryType;\r
+  ///\r
+  /// Starting Memory Address.\r
+  ///\r
+  EFI_PHYSICAL_ADDRESS            StartingAddress;\r
+  ///\r
+  /// Ending Memory Address.\r
+  ///\r
+  EFI_PHYSICAL_ADDRESS            EndingAddress;\r
+} MEMMAP_DEVICE_PATH;\r
+\r
+///\r
+/// Hardware Vendor Device Path SubType.\r
+///\r
+#define HW_VENDOR_DP              0x04\r
+\r
+///\r
+/// The Vendor Device Path allows the creation of vendor-defined Device Paths. A vendor must\r
+/// allocate a Vendor GUID for a Device Path. The Vendor GUID can then be used to define the\r
+/// contents on the n bytes that follow in the Vendor Device Path node.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Vendor-assigned GUID that defines the data that follows.\r
+  ///\r
+  EFI_GUID                        Guid;\r
+  ///\r
+  /// Vendor-defined variable size data.\r
+  ///\r
+} VENDOR_DEVICE_PATH;\r
+\r
+///\r
+/// Controller Device Path SubType.\r
+///\r
+#define HW_CONTROLLER_DP          0x05\r
+\r
+///\r
+/// Controller Device Path.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Controller number.\r
+  ///\r
+  UINT32                          ControllerNumber;\r
+} CONTROLLER_DEVICE_PATH;\r
+\r
+///\r
+/// BMC Device Path SubType.\r
+///\r
+#define HW_BMC_DP                 0x06\r
+\r
+///\r
+/// BMC Device Path.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Interface Type.\r
+  ///\r
+  UINT8                           InterfaceType;\r
+  ///\r
+  /// Base Address.\r
+  ///\r
+  UINT8                           BaseAddress[8];\r
+} BMC_DEVICE_PATH;\r
+\r
+///\r
+/// ACPI Device Paths.\r
+///\r
+#define ACPI_DEVICE_PATH          0x02\r
+\r
+///\r
+/// ACPI Device Path SubType.\r
+///\r
+#define ACPI_DP                   0x01\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Device's PnP hardware ID stored in a numeric 32-bit\r
+  /// compressed EISA-type ID. This value must match the\r
+  /// corresponding _HID in the ACPI name space.\r
+  ///\r
+  UINT32                          HID;\r
+  ///\r
+  /// Unique ID that is required by ACPI if two devices have the\r
+  /// same _HID. This value must also match the corresponding\r
+  /// _UID/_HID pair in the ACPI name space. Only the 32-bit\r
+  /// numeric value type of _UID is supported. Thus, strings must\r
+  /// not be used for the _UID in the ACPI name space.\r
+  ///\r
+  UINT32                          UID;\r
+} ACPI_HID_DEVICE_PATH;\r
+\r
+///\r
+/// Expanded ACPI Device Path SubType.\r
+///\r
+#define ACPI_EXTENDED_DP          0x02\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Device's PnP hardware ID stored in a numeric 32-bit\r
+  /// compressed EISA-type ID. This value must match the\r
+  /// corresponding _HID in the ACPI name space.\r
+  ///\r
+  UINT32                          HID;\r
+  ///\r
+  /// Unique ID that is required by ACPI if two devices have the\r
+  /// same _HID. This value must also match the corresponding\r
+  /// _UID/_HID pair in the ACPI name space.\r
+  ///\r
+  UINT32                          UID;\r
+  ///\r
+  /// Device's compatible PnP hardware ID stored in a numeric\r
+  /// 32-bit compressed EISA-type ID. This value must match at\r
+  /// least one of the compatible device IDs returned by the\r
+  /// corresponding _CID in the ACPI name space.\r
+  ///\r
+  UINT32                          CID;\r
+  ///\r
+  /// Optional variable length _HIDSTR.\r
+  /// Optional variable length _UIDSTR.\r
+  /// Optional variable length _CIDSTR.\r
+  ///\r
+} ACPI_EXTENDED_HID_DEVICE_PATH;\r
+\r
+//\r
+//  EISA ID Macro\r
+//  EISA ID Definition 32-bits\r
+//   bits[15:0] - three character compressed ASCII EISA ID.\r
+//   bits[31:16] - binary number\r
+//    Compressed ASCII is 5 bits per character 0b00001 = 'A' 0b11010 = 'Z'\r
+//\r
+#define PNP_EISA_ID_CONST         0x41d0\r
+#define EISA_ID(_Name, _Num)      ((UINT32)((_Name) | (_Num) << 16))\r
+#define EISA_PNP_ID(_PNPId)       (EISA_ID(PNP_EISA_ID_CONST, (_PNPId)))\r
+#define EFI_PNP_ID(_PNPId)        (EISA_ID(PNP_EISA_ID_CONST, (_PNPId)))\r
+\r
+#define PNP_EISA_ID_MASK          0xffff\r
+#define EISA_ID_TO_NUM(_Id)       ((_Id) >> 16)\r
+\r
+///\r
+/// ACPI _ADR Device Path SubType.\r
+///\r
+#define ACPI_ADR_DP               0x03\r
+\r
+///\r
+/// The _ADR device path is used to contain video output device attributes to support the Graphics\r
+/// Output Protocol. The device path can contain multiple _ADR entries if multiple video output\r
+/// devices are displaying the same output.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// _ADR value. For video output devices the value of this\r
+  /// field comes from Table B-2 of the ACPI 3.0 specification. At\r
+  /// least one _ADR value is required.\r
+  ///\r
+  UINT32                          ADR;\r
+  //\r
+  // This device path may optionally contain more than one _ADR entry.\r
+  //\r
+} ACPI_ADR_DEVICE_PATH;\r
+\r
+#define ACPI_ADR_DISPLAY_TYPE_OTHER             0\r
+#define ACPI_ADR_DISPLAY_TYPE_VGA               1\r
+#define ACPI_ADR_DISPLAY_TYPE_TV                2\r
+#define ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL  3\r
+#define ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL  4\r
+\r
+#define ACPI_DISPLAY_ADR(_DeviceIdScheme, _HeadId, _NonVgaOutput, _BiosCanDetect, _VendorInfo, _Type, _Port, _Index) \\r
+          ((UINT32)(  ((UINT32)((_DeviceIdScheme) & 0x1) << 31) |  \\r
+                      (((_HeadId)                 & 0x7) << 18) |  \\r
+                      (((_NonVgaOutput)           & 0x1) << 17) |  \\r
+                      (((_BiosCanDetect)          & 0x1) << 16) |  \\r
+                      (((_VendorInfo)             & 0xf) << 12) |  \\r
+                      (((_Type)                   & 0xf) << 8)  |  \\r
+                      (((_Port)                   & 0xf) << 4)  |  \\r
+                       ((_Index)                  & 0xf) ))\r
+\r
+///\r
+/// Messaging Device Paths.\r
+/// This Device Path is used to describe the connection of devices outside the resource domain of the\r
+/// system. This Device Path can describe physical messaging information like SCSI ID, or abstract\r
+/// information like networking protocol IP addresses.\r
+///\r
+#define MESSAGING_DEVICE_PATH     0x03\r
+\r
+///\r
+/// ATAPI Device Path SubType\r
+///\r
+#define MSG_ATAPI_DP              0x01\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Set to zero for primary, or one for secondary.\r
+  ///\r
+  UINT8                           PrimarySecondary;\r
+  ///\r
+  /// Set to zero for master, or one for slave mode.\r
+  ///\r
+  UINT8                           SlaveMaster;\r
+  ///\r
+  /// Logical Unit Number.\r
+  ///\r
+  UINT16                          Lun;\r
+} ATAPI_DEVICE_PATH;\r
+\r
+///\r
+/// SCSI Device Path SubType.\r
+///\r
+#define MSG_SCSI_DP               0x02\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Target ID on the SCSI bus (PUN).\r
+  ///\r
+  UINT16                          Pun;\r
+  ///\r
+  /// Logical Unit Number (LUN).\r
+  ///\r
+  UINT16                          Lun;\r
+} SCSI_DEVICE_PATH;\r
+\r
+///\r
+/// Fibre Channel SubType.\r
+///\r
+#define MSG_FIBRECHANNEL_DP       0x03\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Reserved for the future.\r
+  ///\r
+  UINT32                          Reserved;\r
+  ///\r
+  /// Fibre Channel World Wide Number.\r
+  ///\r
+  UINT64                          WWN;\r
+  ///\r
+  /// Fibre Channel Logical Unit Number.\r
+  ///\r
+  UINT64                          Lun;\r
+} FIBRECHANNEL_DEVICE_PATH;\r
+\r
+///\r
+/// Fibre Channel Ex SubType.\r
+///\r
+#define MSG_FIBRECHANNELEX_DP     0x15\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Reserved for the future.\r
+  ///\r
+  UINT32                          Reserved;\r
+  ///\r
+  /// 8 byte array containing Fibre Channel End Device Port Name.\r
+  ///\r
+  UINT8                           WWN[8];\r
+  ///\r
+  /// 8 byte array containing Fibre Channel Logical Unit Number.\r
+  ///\r
+  UINT8                           Lun[8];\r
+} FIBRECHANNELEX_DEVICE_PATH;\r
+\r
+///\r
+/// 1394 Device Path SubType\r
+///\r
+#define MSG_1394_DP               0x04\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Reserved for the future.\r
+  ///\r
+  UINT32                          Reserved;\r
+  ///\r
+  /// 1394 Global Unique ID (GUID).\r
+  ///\r
+  UINT64                          Guid;\r
+} F1394_DEVICE_PATH;\r
+\r
+///\r
+/// USB Device Path SubType.\r
+///\r
+#define MSG_USB_DP                0x05\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL      Header;\r
+  ///\r
+  /// USB Parent Port Number.\r
+  ///\r
+  UINT8                         ParentPortNumber;\r
+  ///\r
+  /// USB Interface Number.\r
+  ///\r
+  UINT8                         InterfaceNumber;\r
+} USB_DEVICE_PATH;\r
+\r
+///\r
+/// USB Class Device Path SubType.\r
+///\r
+#define MSG_USB_CLASS_DP          0x0f\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL      Header;\r
+  ///\r
+  /// Vendor ID assigned by USB-IF. A value of 0xFFFF will\r
+  /// match any Vendor ID.\r
+  ///\r
+  UINT16                        VendorId;\r
+  ///\r
+  /// Product ID assigned by USB-IF. A value of 0xFFFF will\r
+  /// match any Product ID.\r
+  ///\r
+  UINT16                        ProductId;\r
+  ///\r
+  /// The class code assigned by the USB-IF. A value of 0xFF\r
+  /// will match any class code.\r
+  ///\r
+  UINT8                         DeviceClass;\r
+  ///\r
+  /// The subclass code assigned by the USB-IF. A value of\r
+  /// 0xFF will match any subclass code.\r
+  ///\r
+  UINT8                         DeviceSubClass;\r
+  ///\r
+  /// The protocol code assigned by the USB-IF. A value of\r
+  /// 0xFF will match any protocol code.\r
+  ///\r
+  UINT8                         DeviceProtocol;\r
+} USB_CLASS_DEVICE_PATH;\r
+\r
+///\r
+/// USB WWID Device Path SubType.\r
+///\r
+#define MSG_USB_WWID_DP           0x10\r
+\r
+///\r
+/// This device path describes a USB device using its serial number.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL      Header;\r
+  ///\r
+  /// USB interface number.\r
+  ///\r
+  UINT16                        InterfaceNumber;\r
+  ///\r
+  /// USB vendor id of the device.\r
+  ///\r
+  UINT16                        VendorId;\r
+  ///\r
+  /// USB product id of the device.\r
+  ///\r
+  UINT16                        ProductId;\r
+  ///\r
+  /// Last 64-or-fewer UTF-16 characters of the USB\r
+  /// serial number. The length of the string is\r
+  /// determined by the Length field less the offset of the\r
+  /// Serial Number field (10)\r
+  ///\r
+  /// CHAR16                     SerialNumber[...];\r
+} USB_WWID_DEVICE_PATH;\r
+\r
+///\r
+/// Device Logical Unit SubType.\r
+///\r
+#define MSG_DEVICE_LOGICAL_UNIT_DP  0x11\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL      Header;\r
+  ///\r
+  /// Logical Unit Number for the interface.\r
+  ///\r
+  UINT8                         Lun;\r
+} DEVICE_LOGICAL_UNIT_DEVICE_PATH;\r
+\r
+///\r
+/// SATA Device Path SubType.\r
+///\r
+#define MSG_SATA_DP               0x12\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// The HBA port number that facilitates the connection to the\r
+  /// device or a port multiplier. The value 0xFFFF is reserved.\r
+  ///\r
+  UINT16                          HBAPortNumber;\r
+  ///\r
+  /// The Port multiplier port number that facilitates the connection\r
+  /// to the device. Must be set to 0xFFFF if the device is directly\r
+  /// connected to the HBA.\r
+  ///\r
+  UINT16                          PortMultiplierPortNumber;\r
+  ///\r
+  /// Logical Unit Number.\r
+  ///\r
+  UINT16                          Lun;\r
+} SATA_DEVICE_PATH;\r
+\r
+///\r
+/// Flag for if the device is directly connected to the HBA.\r
+///\r
+#define SATA_HBA_DIRECT_CONNECT_FLAG 0x8000\r
+\r
+///\r
+/// I2O Device Path SubType.\r
+///\r
+#define MSG_I2O_DP                0x06\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Target ID (TID) for a device.\r
+  ///\r
+  UINT32                          Tid;\r
+} I2O_DEVICE_PATH;\r
+\r
+///\r
+/// MAC Address Device Path SubType.\r
+///\r
+#define MSG_MAC_ADDR_DP           0x0b\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// The MAC address for a network interface padded with 0s.\r
+  ///\r
+  EFI_MAC_ADDRESS                 MacAddress;\r
+  ///\r
+  /// Network interface type(i.e. 802.3, FDDI).\r
+  ///\r
+  UINT8                           IfType;\r
+} MAC_ADDR_DEVICE_PATH;\r
+\r
+///\r
+/// IPv4 Device Path SubType\r
+///\r
+#define MSG_IPv4_DP               0x0c\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// The local IPv4 address.\r
+  ///\r
+  EFI_IPv4_ADDRESS                LocalIpAddress;\r
+  ///\r
+  /// The remote IPv4 address.\r
+  ///\r
+  EFI_IPv4_ADDRESS                RemoteIpAddress;\r
+  ///\r
+  /// The local port number.\r
+  ///\r
+  UINT16                          LocalPort;\r
+  ///\r
+  /// The remote port number.\r
+  ///\r
+  UINT16                          RemotePort;\r
+  ///\r
+  /// The network protocol(i.e. UDP, TCP).\r
+  ///\r
+  UINT16                          Protocol;\r
+  ///\r
+  /// 0x00 - The Source IP Address was assigned though DHCP.\r
+  /// 0x01 - The Source IP Address is statically bound.\r
+  ///\r
+  BOOLEAN                         StaticIpAddress;\r
+  ///\r
+  /// The gateway IP address\r
+  ///\r
+  EFI_IPv4_ADDRESS                GatewayIpAddress;\r
+  ///\r
+  /// The subnet mask\r
+  ///\r
+  EFI_IPv4_ADDRESS                SubnetMask;\r
+} IPv4_DEVICE_PATH;\r
+\r
+///\r
+/// IPv6 Device Path SubType.\r
+///\r
+#define MSG_IPv6_DP               0x0d\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// The local IPv6 address.\r
+  ///\r
+  EFI_IPv6_ADDRESS                LocalIpAddress;\r
+  ///\r
+  /// The remote IPv6 address.\r
+  ///\r
+  EFI_IPv6_ADDRESS                RemoteIpAddress;\r
+  ///\r
+  /// The local port number.\r
+  ///\r
+  UINT16                          LocalPort;\r
+  ///\r
+  /// The remote port number.\r
+  ///\r
+  UINT16                          RemotePort;\r
+  ///\r
+  /// The network protocol(i.e. UDP, TCP).\r
+  ///\r
+  UINT16                          Protocol;\r
+  ///\r
+  /// 0x00 - The Local IP Address was manually configured.\r
+  /// 0x01 - The Local IP Address is assigned through IPv6\r
+  /// stateless auto-configuration.\r
+  /// 0x02 - The Local IP Address is assigned through IPv6\r
+  /// stateful configuration.\r
+  ///\r
+  UINT8                           IpAddressOrigin;\r
+  ///\r
+  /// The prefix length\r
+  ///\r
+  UINT8                           PrefixLength;\r
+  ///\r
+  /// The gateway IP address\r
+  ///\r
+  EFI_IPv6_ADDRESS                GatewayIpAddress;\r
+} IPv6_DEVICE_PATH;\r
+\r
+///\r
+/// InfiniBand Device Path SubType.\r
+///\r
+#define MSG_INFINIBAND_DP         0x09\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Flags to help identify/manage InfiniBand device path elements:\r
+  /// Bit 0 - IOC/Service (0b = IOC, 1b = Service).\r
+  /// Bit 1 - Extend Boot Environment.\r
+  /// Bit 2 - Console Protocol.\r
+  /// Bit 3 - Storage Protocol.\r
+  /// Bit 4 - Network Protocol.\r
+  /// All other bits are reserved.\r
+  ///\r
+  UINT32                          ResourceFlags;\r
+  ///\r
+  /// 128-bit Global Identifier for remote fabric port.\r
+  ///\r
+  UINT8                           PortGid[16];\r
+  ///\r
+  /// 64-bit unique identifier to remote IOC or server process.\r
+  /// Interpretation of field specified by Resource Flags (bit 0).\r
+  ///\r
+  UINT64                          ServiceId;\r
+  ///\r
+  /// 64-bit persistent ID of remote IOC port.\r
+  ///\r
+  UINT64                          TargetPortId;\r
+  ///\r
+  /// 64-bit persistent ID of remote device.\r
+  ///\r
+  UINT64                          DeviceId;\r
+} INFINIBAND_DEVICE_PATH;\r
+\r
+#define INFINIBAND_RESOURCE_FLAG_IOC_SERVICE                0x01\r
+#define INFINIBAND_RESOURCE_FLAG_EXTENDED_BOOT_ENVIRONMENT  0x02\r
+#define INFINIBAND_RESOURCE_FLAG_CONSOLE_PROTOCOL           0x04\r
+#define INFINIBAND_RESOURCE_FLAG_STORAGE_PROTOCOL           0x08\r
+#define INFINIBAND_RESOURCE_FLAG_NETWORK_PROTOCOL           0x10\r
+\r
+///\r
+/// UART Device Path SubType.\r
+///\r
+#define MSG_UART_DP               0x0e\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Reserved.\r
+  ///\r
+  UINT32                          Reserved;\r
+  ///\r
+  /// The baud rate setting for the UART style device. A value of 0\r
+  /// means that the device's default baud rate will be used.\r
+  ///\r
+  UINT64                          BaudRate;\r
+  ///\r
+  /// The number of data bits for the UART style device. A value\r
+  /// of 0 means that the device's default number of data bits will be used.\r
+  ///\r
+  UINT8                           DataBits;\r
+  ///\r
+  /// The parity setting for the UART style device.\r
+  /// Parity 0x00 - Default Parity.\r
+  /// Parity 0x01 - No Parity.\r
+  /// Parity 0x02 - Even Parity.\r
+  /// Parity 0x03 - Odd Parity.\r
+  /// Parity 0x04 - Mark Parity.\r
+  /// Parity 0x05 - Space Parity.\r
+  ///\r
+  UINT8                           Parity;\r
+  ///\r
+  /// The number of stop bits for the UART style device.\r
+  /// Stop Bits 0x00 - Default Stop Bits.\r
+  /// Stop Bits 0x01 - 1 Stop Bit.\r
+  /// Stop Bits 0x02 - 1.5 Stop Bits.\r
+  /// Stop Bits 0x03 - 2 Stop Bits.\r
+  ///\r
+  UINT8                           StopBits;\r
+} UART_DEVICE_PATH;\r
+\r
+//\r
+// Use VENDOR_DEVICE_PATH struct\r
+//\r
+#define MSG_VENDOR_DP             0x0a\r
+typedef VENDOR_DEVICE_PATH        VENDOR_DEFINED_DEVICE_PATH;\r
+\r
+#define DEVICE_PATH_MESSAGING_PC_ANSI     EFI_PC_ANSI_GUID\r
+#define DEVICE_PATH_MESSAGING_VT_100      EFI_VT_100_GUID\r
+#define DEVICE_PATH_MESSAGING_VT_100_PLUS EFI_VT_100_PLUS_GUID\r
+#define DEVICE_PATH_MESSAGING_VT_UTF8     EFI_VT_UTF8_GUID\r
+\r
+///\r
+/// A new device path node is defined to declare flow control characteristics.\r
+/// UART Flow Control Messaging Device Path\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// DEVICE_PATH_MESSAGING_UART_FLOW_CONTROL GUID.\r
+  ///\r
+  EFI_GUID                        Guid;\r
+  ///\r
+  /// Bitmap of supported flow control types.\r
+  /// Bit 0 set indicates hardware flow control.\r
+  /// Bit 1 set indicates Xon/Xoff flow control.\r
+  /// All other bits are reserved and are clear.\r
+  ///\r
+  UINT32                          FlowControlMap;\r
+} UART_FLOW_CONTROL_DEVICE_PATH;\r
+\r
+#define UART_FLOW_CONTROL_HARDWARE         0x00000001\r
+#define UART_FLOW_CONTROL_XON_XOFF         0x00000010\r
+\r
+#define DEVICE_PATH_MESSAGING_SAS          EFI_SAS_DEVICE_PATH_GUID\r
+///\r
+/// Serial Attached SCSI (SAS) Device Path.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// DEVICE_PATH_MESSAGING_SAS GUID.\r
+  ///\r
+  EFI_GUID                        Guid;\r
+  ///\r
+  /// Reserved for future use.\r
+  ///\r
+  UINT32                          Reserved;\r
+  ///\r
+  /// SAS Address for Serial Attached SCSI Target.\r
+  ///\r
+  UINT64                          SasAddress;\r
+  ///\r
+  /// SAS Logical Unit Number.\r
+  ///\r
+  UINT64                          Lun;\r
+  ///\r
+  /// More Information about the device and its interconnect.\r
+  ///\r
+  UINT16                          DeviceTopology;\r
+  ///\r
+  /// Relative Target Port (RTP).\r
+  ///\r
+  UINT16                          RelativeTargetPort;\r
+} SAS_DEVICE_PATH;\r
+\r
+///\r
+/// Serial Attached SCSI (SAS) Ex Device Path SubType\r
+///\r
+#define MSG_SASEX_DP              0x16\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// 8-byte array of the SAS Address for Serial Attached SCSI Target Port.\r
+  ///\r
+  UINT8                           SasAddress[8];\r
+  ///\r
+  /// 8-byte array of the SAS Logical Unit Number.\r
+  ///\r
+  UINT8                           Lun[8];\r
+  ///\r
+  /// More Information about the device and its interconnect.\r
+  ///\r
+  UINT16                          DeviceTopology;\r
+  ///\r
+  /// Relative Target Port (RTP).\r
+  ///\r
+  UINT16                          RelativeTargetPort;\r
+} SASEX_DEVICE_PATH;\r
+\r
+///\r
+/// NvmExpress Namespace Device Path SubType.\r
+///\r
+#define MSG_NVME_NAMESPACE_DP     0x17\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  UINT32                          NamespaceId;\r
+  UINT64                          NamespaceUuid;\r
+} NVME_NAMESPACE_DEVICE_PATH;\r
+\r
+///\r
+/// DNS Device Path SubType\r
+///\r
+#define MSG_DNS_DP                0x1F\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Indicates the DNS server address is IPv4 or IPv6 address.\r
+  ///\r
+  UINT8                           IsIPv6;\r
+  ///\r
+  /// Instance of the DNS server address.\r
+  ///\r
+  EFI_IP_ADDRESS                  DnsServerIp[1024];\r
+} DNS_DEVICE_PATH;\r
+\r
+///\r
+/// Uniform Resource Identifiers (URI) Device Path SubType\r
+///\r
+#define MSG_URI_DP                0x18\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Instance of the URI pursuant to RFC 3986.\r
+  ///\r
+  CHAR8                           Uri[1024];\r
+} URI_DEVICE_PATH;\r
+\r
+///\r
+/// Universal Flash Storage (UFS) Device Path SubType.\r
+///\r
+#define MSG_UFS_DP                0x19\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Target ID on the UFS bus (PUN).\r
+  ///\r
+  UINT8                           Pun;\r
+  ///\r
+  /// Logical Unit Number (LUN).\r
+  ///\r
+  UINT8                           Lun;\r
+} UFS_DEVICE_PATH;\r
+\r
+///\r
+/// SD (Secure Digital) Device Path SubType.\r
+///\r
+#define MSG_SD_DP                 0x1A\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  UINT8                           SlotNumber;\r
+} SD_DEVICE_PATH;\r
+\r
+///\r
+/// EMMC (Embedded MMC) Device Path SubType.\r
+///\r
+#define MSG_EMMC_DP                 0x1D\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  UINT8                           SlotNumber;\r
+} EMMC_DEVICE_PATH;\r
+\r
+///\r
+/// iSCSI Device Path SubType\r
+///\r
+#define MSG_ISCSI_DP              0x13\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Network Protocol (0 = TCP, 1+ = reserved).\r
+  ///\r
+  UINT16                          NetworkProtocol;\r
+  ///\r
+  /// iSCSI Login Options.\r
+  ///\r
+  UINT16                          LoginOption;\r
+  ///\r
+  /// iSCSI Logical Unit Number.\r
+  ///\r
+  UINT64                          Lun;\r
+  ///\r
+  /// iSCSI Target Portal group tag the initiator intends\r
+  /// to establish a session with.\r
+  ///\r
+  UINT16                          TargetPortalGroupTag;\r
+  ///\r
+  /// iSCSI NodeTarget Name. The length of the name\r
+  /// is determined by subtracting the offset of this field from Length.\r
+  ///\r
+  /// CHAR8                        iSCSI Target Name.\r
+} ISCSI_DEVICE_PATH;\r
+\r
+#define ISCSI_LOGIN_OPTION_NO_HEADER_DIGEST             0x0000\r
+#define ISCSI_LOGIN_OPTION_HEADER_DIGEST_USING_CRC32C   0x0002\r
+#define ISCSI_LOGIN_OPTION_NO_DATA_DIGEST               0x0000\r
+#define ISCSI_LOGIN_OPTION_DATA_DIGEST_USING_CRC32C     0x0008\r
+#define ISCSI_LOGIN_OPTION_AUTHMETHOD_CHAP              0x0000\r
+#define ISCSI_LOGIN_OPTION_AUTHMETHOD_NON               0x1000\r
+#define ISCSI_LOGIN_OPTION_CHAP_BI                      0x0000\r
+#define ISCSI_LOGIN_OPTION_CHAP_UNI                     0x2000\r
+\r
+///\r
+/// VLAN Device Path SubType.\r
+///\r
+#define MSG_VLAN_DP               0x14\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// VLAN identifier (0-4094).\r
+  ///\r
+  UINT16                          VlanId;\r
+} VLAN_DEVICE_PATH;\r
+\r
+///\r
+/// Bluetooth Device Path SubType.\r
+///\r
+#define MSG_BLUETOOTH_DP     0x1b\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// 48bit Bluetooth device address.\r
+  ///\r
+  BLUETOOTH_ADDRESS               BD_ADDR;\r
+} BLUETOOTH_DEVICE_PATH;\r
+\r
+///\r
+/// Wi-Fi Device Path SubType.\r
+///\r
+#define MSG_WIFI_DP               0x1C\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Service set identifier. A 32-byte octets string.\r
+  ///\r
+  UINT8                           SSId[32];\r
+} WIFI_DEVICE_PATH;\r
+\r
+///\r
+/// Bluetooth LE Device Path SubType.\r
+///\r
+#define MSG_BLUETOOTH_LE_DP       0x1E\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  BLUETOOTH_LE_ADDRESS            Address;\r
+} BLUETOOTH_LE_DEVICE_PATH;\r
+\r
+//\r
+// Media Device Path\r
+//\r
+#define MEDIA_DEVICE_PATH         0x04\r
+\r
+///\r
+/// Hard Drive Media Device Path SubType.\r
+///\r
+#define MEDIA_HARDDRIVE_DP        0x01\r
+\r
+///\r
+/// The Hard Drive Media Device Path is used to represent a partition on a hard drive.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Describes the entry in a partition table, starting with entry 1.\r
+  /// Partition number zero represents the entire device. Valid\r
+  /// partition numbers for a MBR partition are [1, 4]. Valid\r
+  /// partition numbers for a GPT partition are [1, NumberOfPartitionEntries].\r
+  ///\r
+  UINT32                          PartitionNumber;\r
+  ///\r
+  /// Starting LBA of the partition on the hard drive.\r
+  ///\r
+  UINT64                          PartitionStart;\r
+  ///\r
+  /// Size of the partition in units of Logical Blocks.\r
+  ///\r
+  UINT64                          PartitionSize;\r
+  ///\r
+  /// Signature unique to this partition:\r
+  /// If SignatureType is 0, this field has to be initialized with 16 zeros.\r
+  /// If SignatureType is 1, the MBR signature is stored in the first 4 bytes of this field.\r
+  /// The other 12 bytes are initialized with zeros.\r
+  /// If SignatureType is 2, this field contains a 16 byte signature.\r
+  ///\r
+  UINT8                           Signature[16];\r
+  ///\r
+  /// Partition Format: (Unused values reserved).\r
+  /// 0x01 - PC-AT compatible legacy MBR.\r
+  /// 0x02 - GUID Partition Table.\r
+  ///\r
+  UINT8                           MBRType;\r
+  ///\r
+  /// Type of Disk Signature: (Unused values reserved).\r
+  /// 0x00 - No Disk Signature.\r
+  /// 0x01 - 32-bit signature from address 0x1b8 of the type 0x01 MBR.\r
+  /// 0x02 - GUID signature.\r
+  ///\r
+  UINT8                           SignatureType;\r
+} HARDDRIVE_DEVICE_PATH;\r
+\r
+#define MBR_TYPE_PCAT             0x01\r
+#define MBR_TYPE_EFI_PARTITION_TABLE_HEADER 0x02\r
+\r
+#define NO_DISK_SIGNATURE         0x00\r
+#define SIGNATURE_TYPE_MBR        0x01\r
+#define SIGNATURE_TYPE_GUID       0x02\r
+\r
+///\r
+/// CD-ROM Media Device Path SubType.\r
+///\r
+#define MEDIA_CDROM_DP            0x02\r
+\r
+///\r
+/// The CD-ROM Media Device Path is used to define a system partition that exists on a CD-ROM.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Boot Entry number from the Boot Catalog. The Initial/Default entry is defined as zero.\r
+  ///\r
+  UINT32                          BootEntry;\r
+  ///\r
+  /// Starting RBA of the partition on the medium. CD-ROMs use Relative logical Block Addressing.\r
+  ///\r
+  UINT64                          PartitionStart;\r
+  ///\r
+  /// Size of the partition in units of Blocks, also called Sectors.\r
+  ///\r
+  UINT64                          PartitionSize;\r
+} CDROM_DEVICE_PATH;\r
+\r
+//\r
+// Use VENDOR_DEVICE_PATH struct\r
+//\r
+#define MEDIA_VENDOR_DP           0x03  ///< Media vendor device path subtype.\r
+\r
+///\r
+/// File Path Media Device Path SubType\r
+///\r
+#define MEDIA_FILEPATH_DP         0x04\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// A NULL-terminated Path string including directory and file names.\r
+  ///\r
+  CHAR16                          PathName[1];\r
+} FILEPATH_DEVICE_PATH;\r
+\r
+#define SIZE_OF_FILEPATH_DEVICE_PATH  OFFSET_OF(FILEPATH_DEVICE_PATH,PathName)\r
+\r
+///\r
+/// Media Protocol Device Path SubType.\r
+///\r
+#define MEDIA_PROTOCOL_DP         0x05\r
+\r
+///\r
+/// The Media Protocol Device Path is used to denote the protocol that is being\r
+/// used in a device path at the location of the path specified.\r
+/// Many protocols are inherent to the style of device path.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// The ID of the protocol.\r
+  ///\r
+  EFI_GUID                        Protocol;\r
+} MEDIA_PROTOCOL_DEVICE_PATH;\r
+\r
+///\r
+/// PIWG Firmware File SubType.\r
+///\r
+#define MEDIA_PIWG_FW_FILE_DP     0x06\r
+\r
+///\r
+/// This device path is used by systems implementing the UEFI PI Specification 1.0 to describe a firmware file.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Firmware file name\r
+  ///\r
+  EFI_GUID                        FvFileName;\r
+} MEDIA_FW_VOL_FILEPATH_DEVICE_PATH;\r
+\r
+///\r
+/// PIWG Firmware Volume Device Path SubType.\r
+///\r
+#define MEDIA_PIWG_FW_VOL_DP      0x07\r
+\r
+///\r
+/// This device path is used by systems implementing the UEFI PI Specification 1.0 to describe a firmware volume.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Firmware volume name.\r
+  ///\r
+  EFI_GUID                        FvName;\r
+} MEDIA_FW_VOL_DEVICE_PATH;\r
+\r
+///\r
+/// Media relative offset range device path.\r
+///\r
+#define MEDIA_RELATIVE_OFFSET_RANGE_DP 0x08\r
+\r
+///\r
+/// Used to describe the offset range of media relative.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL  Header;\r
+  UINT32                    Reserved;\r
+  UINT64                    StartingOffset;\r
+  UINT64                    EndingOffset;\r
+} MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH;\r
+\r
+///\r
+/// This GUID defines a RAM Disk supporting a raw disk format in volatile memory.\r
+///\r
+#define EFI_VIRTUAL_DISK_GUID \\r
+  { \\r
+    0x77AB535A, 0x45FC, 0x624B, {0x55, 0x60, 0xF7, 0xB2, 0x81, 0xD1, 0xF9, 0x6E } \\r
+  }\r
+\r
+extern  EFI_GUID                            gEfiVirtualDiskGuid;\r
+\r
+///\r
+/// This GUID defines a RAM Disk supporting an ISO image in volatile memory.\r
+///\r
+#define EFI_VIRTUAL_CD_GUID \\r
+  { \\r
+    0x3D5ABD30, 0x4175, 0x87CE, {0x6D, 0x64, 0xD2, 0xAD, 0xE5, 0x23, 0xC4, 0xBB } \\r
+  }\r
+extern  EFI_GUID                            gEfiVirtualCdGuid;\r
+\r
+///\r
+/// This GUID defines a RAM Disk supporting a raw disk format in persistent memory.\r
+///\r
+#define EFI_PERSISTENT_VIRTUAL_DISK_GUID \\r
+  { \\r
+    0x5CEA02C9, 0x4D07, 0x69D3, {0x26, 0x9F ,0x44, 0x96, 0xFB, 0xE0, 0x96, 0xF9 } \\r
+  }\r
+\r
+extern  EFI_GUID                            gEfiPersistentVirtualDiskGuid;\r
+\r
+///\r
+/// This GUID defines a RAM Disk supporting an ISO image in persistent memory.\r
+///\r
+#define EFI_PERSISTENT_VIRTUAL_CD_GUID \\r
+  { \\r
+    0x08018188, 0x42CD, 0xBB48, {0x10, 0x0F, 0x53, 0x87, 0xD5, 0x3D, 0xED, 0x3D } \\r
+  }\r
+\r
+extern  EFI_GUID                            gEfiPersistentVirtualCdGuid;\r
+\r
+///\r
+/// Media ram disk device path.\r
+///\r
+#define MEDIA_RAM_DISK_DP         0x09\r
+\r
+///\r
+/// Used to describe the ram disk device path.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Starting Memory Address.\r
+  ///\r
+  UINT32                          StartingAddr[2];\r
+  ///\r
+  /// Ending Memory Address.\r
+  ///\r
+  UINT32                          EndingAddr[2];\r
+  ///\r
+  /// GUID that defines the type of the RAM Disk.\r
+  ///\r
+  EFI_GUID                        TypeGuid;\r
+  ///\r
+  /// RAM Diskinstance number, if supported. The default value is zero.\r
+  ///\r
+  UINT16                          Instance;\r
+} MEDIA_RAM_DISK_DEVICE_PATH;\r
+\r
+///\r
+/// BIOS Boot Specification Device Path.\r
+///\r
+#define BBS_DEVICE_PATH           0x05\r
+\r
+///\r
+/// BIOS Boot Specification Device Path SubType.\r
+///\r
+#define BBS_BBS_DP                0x01\r
+\r
+///\r
+/// This Device Path is used to describe the booting of non-EFI-aware operating systems.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL        Header;\r
+  ///\r
+  /// Device Type as defined by the BIOS Boot Specification.\r
+  ///\r
+  UINT16                          DeviceType;\r
+  ///\r
+  /// Status Flags as defined by the BIOS Boot Specification.\r
+  ///\r
+  UINT16                          StatusFlag;\r
+  ///\r
+  /// Null-terminated ASCII string that describes the boot device to a user.\r
+  ///\r
+  CHAR8                           String[1];\r
+} BBS_BBS_DEVICE_PATH;\r
+\r
+//\r
+// DeviceType definitions - from BBS specification\r
+//\r
+#define BBS_TYPE_FLOPPY           0x01\r
+#define BBS_TYPE_HARDDRIVE        0x02\r
+#define BBS_TYPE_CDROM            0x03\r
+#define BBS_TYPE_PCMCIA           0x04\r
+#define BBS_TYPE_USB              0x05\r
+#define BBS_TYPE_EMBEDDED_NETWORK 0x06\r
+#define BBS_TYPE_BEV              0x80\r
+#define BBS_TYPE_UNKNOWN          0xFF\r
+\r
+\r
+///\r
+/// Union of all possible Device Paths and pointers to Device Paths.\r
+///\r
+typedef union {\r
+  EFI_DEVICE_PATH_PROTOCOL                   DevPath;\r
+  PCI_DEVICE_PATH                            Pci;\r
+  PCCARD_DEVICE_PATH                         PcCard;\r
+  MEMMAP_DEVICE_PATH                         MemMap;\r
+  VENDOR_DEVICE_PATH                         Vendor;\r
+\r
+  CONTROLLER_DEVICE_PATH                     Controller;\r
+  BMC_DEVICE_PATH                            Bmc;\r
+  ACPI_HID_DEVICE_PATH                       Acpi;\r
+  ACPI_EXTENDED_HID_DEVICE_PATH              ExtendedAcpi;\r
+  ACPI_ADR_DEVICE_PATH                       AcpiAdr;\r
+\r
+  ATAPI_DEVICE_PATH                          Atapi;\r
+  SCSI_DEVICE_PATH                           Scsi;\r
+  ISCSI_DEVICE_PATH                          Iscsi;\r
+  FIBRECHANNEL_DEVICE_PATH                   FibreChannel;\r
+  FIBRECHANNELEX_DEVICE_PATH                 FibreChannelEx;\r
+\r
+  F1394_DEVICE_PATH                          F1394;\r
+  USB_DEVICE_PATH                            Usb;\r
+  SATA_DEVICE_PATH                           Sata;\r
+  USB_CLASS_DEVICE_PATH                      UsbClass;\r
+  USB_WWID_DEVICE_PATH                       UsbWwid;\r
+  DEVICE_LOGICAL_UNIT_DEVICE_PATH            LogicUnit;\r
+  I2O_DEVICE_PATH                            I2O;\r
+  MAC_ADDR_DEVICE_PATH                       MacAddr;\r
+  IPv4_DEVICE_PATH                           Ipv4;\r
+  IPv6_DEVICE_PATH                           Ipv6;\r
+  VLAN_DEVICE_PATH                           Vlan;\r
+  INFINIBAND_DEVICE_PATH                     InfiniBand;\r
+  UART_DEVICE_PATH                           Uart;\r
+  UART_FLOW_CONTROL_DEVICE_PATH              UartFlowControl;\r
+  SAS_DEVICE_PATH                            Sas;\r
+  SASEX_DEVICE_PATH                          SasEx;\r
+  NVME_NAMESPACE_DEVICE_PATH                 NvmeNamespace;\r
+  DNS_DEVICE_PATH                            Dns;\r
+  URI_DEVICE_PATH                            Uri;\r
+  BLUETOOTH_DEVICE_PATH                      Bluetooth;\r
+  WIFI_DEVICE_PATH                           WiFi;\r
+  UFS_DEVICE_PATH                            Ufs;\r
+  SD_DEVICE_PATH                             Sd;\r
+  EMMC_DEVICE_PATH                           Emmc;\r
+  HARDDRIVE_DEVICE_PATH                      HardDrive;\r
+  CDROM_DEVICE_PATH                          CD;\r
+\r
+  FILEPATH_DEVICE_PATH                       FilePath;\r
+  MEDIA_PROTOCOL_DEVICE_PATH                 MediaProtocol;\r
+\r
+  MEDIA_FW_VOL_DEVICE_PATH                   FirmwareVolume;\r
+  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH          FirmwareFile;\r
+  MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH    Offset;\r
+  MEDIA_RAM_DISK_DEVICE_PATH                 RamDisk;\r
+  BBS_BBS_DEVICE_PATH                        Bbs;\r
+} EFI_DEV_PATH;\r
+\r
+\r
+\r
+typedef union {\r
+  EFI_DEVICE_PATH_PROTOCOL                   *DevPath;\r
+  PCI_DEVICE_PATH                            *Pci;\r
+  PCCARD_DEVICE_PATH                         *PcCard;\r
+  MEMMAP_DEVICE_PATH                         *MemMap;\r
+  VENDOR_DEVICE_PATH                         *Vendor;\r
+\r
+  CONTROLLER_DEVICE_PATH                     *Controller;\r
+  BMC_DEVICE_PATH                            *Bmc;\r
+  ACPI_HID_DEVICE_PATH                       *Acpi;\r
+  ACPI_EXTENDED_HID_DEVICE_PATH              *ExtendedAcpi;\r
+  ACPI_ADR_DEVICE_PATH                       *AcpiAdr;\r
+\r
+  ATAPI_DEVICE_PATH                          *Atapi;\r
+  SCSI_DEVICE_PATH                           *Scsi;\r
+  ISCSI_DEVICE_PATH                          *Iscsi;\r
+  FIBRECHANNEL_DEVICE_PATH                   *FibreChannel;\r
+  FIBRECHANNELEX_DEVICE_PATH                 *FibreChannelEx;\r
+\r
+  F1394_DEVICE_PATH                          *F1394;\r
+  USB_DEVICE_PATH                            *Usb;\r
+  SATA_DEVICE_PATH                           *Sata;\r
+  USB_CLASS_DEVICE_PATH                      *UsbClass;\r
+  USB_WWID_DEVICE_PATH                       *UsbWwid;\r
+  DEVICE_LOGICAL_UNIT_DEVICE_PATH            *LogicUnit;\r
+  I2O_DEVICE_PATH                            *I2O;\r
+  MAC_ADDR_DEVICE_PATH                       *MacAddr;\r
+  IPv4_DEVICE_PATH                           *Ipv4;\r
+  IPv6_DEVICE_PATH                           *Ipv6;\r
+  VLAN_DEVICE_PATH                           *Vlan;\r
+  INFINIBAND_DEVICE_PATH                     *InfiniBand;\r
+  UART_DEVICE_PATH                           *Uart;\r
+  UART_FLOW_CONTROL_DEVICE_PATH              *UartFlowControl;\r
+  SAS_DEVICE_PATH                            *Sas;\r
+  SASEX_DEVICE_PATH                          *SasEx;\r
+  NVME_NAMESPACE_DEVICE_PATH                 *NvmeNamespace;\r
+  DNS_DEVICE_PATH                            *Dns;\r
+  URI_DEVICE_PATH                            *Uri;\r
+  BLUETOOTH_DEVICE_PATH                      *Bluetooth;\r
+  WIFI_DEVICE_PATH                           *WiFi;\r
+  UFS_DEVICE_PATH                            *Ufs;\r
+  SD_DEVICE_PATH                             *Sd;\r
+  EMMC_DEVICE_PATH                           *Emmc;\r
+  HARDDRIVE_DEVICE_PATH                      *HardDrive;\r
+  CDROM_DEVICE_PATH                          *CD;\r
+\r
+  FILEPATH_DEVICE_PATH                       *FilePath;\r
+  MEDIA_PROTOCOL_DEVICE_PATH                 *MediaProtocol;\r
+\r
+  MEDIA_FW_VOL_DEVICE_PATH                   *FirmwareVolume;\r
+  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH          *FirmwareFile;\r
+  MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH    *Offset;\r
+  MEDIA_RAM_DISK_DEVICE_PATH                 *RamDisk;\r
+  BBS_BBS_DEVICE_PATH                        *Bbs;\r
+  UINT8                                      *Raw;\r
+} EFI_DEV_PATH_PTR;\r
+\r
+#define EFI_DEBUGPORT_PROTOCOL_GUID \\r
+  { \\r
+    0xEBA4E8D2, 0x3858, 0x41EC, {0xA2, 0x81, 0x26, 0x47, 0xBA, 0x96, 0x60, 0xD0 } \\r
+  }\r
+//\r
+// DEBUGPORT variable definitions...\r
+//\r
+#define EFI_DEBUGPORT_VARIABLE_NAME L"DEBUGPORT"\r
+#define EFI_DEBUGPORT_VARIABLE_GUID EFI_DEBUGPORT_PROTOCOL_GUID\r
+extern EFI_GUID  gEfiDebugPortVariableGuid;\r
+\r
+//\r
+// DebugPort device path definitions...\r
+//\r
+#define DEVICE_PATH_MESSAGING_DEBUGPORT EFI_DEBUGPORT_PROTOCOL_GUID\r
+extern EFI_GUID  gEfiDebugPortDevicePathGuid;\r
+\r
+typedef struct {\r
+  EFI_DEVICE_PATH_PROTOCOL  Header;\r
+  EFI_GUID                  Guid;\r
+} DEBUGPORT_DEVICE_PATH;\r
+\r
+#pragma pack()\r
+\r
+#define END_DEVICE_PATH_TYPE                 0x7f\r
+#define END_ENTIRE_DEVICE_PATH_SUBTYPE       0xFF\r
+#define END_INSTANCE_DEVICE_PATH_SUBTYPE     0x01\r
+\r
+extern EFI_GUID gEfiDevicePathProtocolGuid;\r
+\r
+#endif\r
diff --git a/BaseTools/Source/C/Include/Protocol/DevicePathUtilities.h b/BaseTools/Source/C/Include/Protocol/DevicePathUtilities.h
new file mode 100644 (file)
index 0000000..d046c86
--- /dev/null
@@ -0,0 +1,294 @@
+/** @file\r
+  EFI_DEVICE_PATH_UTILITIES_PROTOCOL as defined in UEFI 2.0.\r
+  Use to create and manipulate device paths and device nodes.\r
+\r
+  Copyright (c) 2017, 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
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __DEVICE_PATH_UTILITIES_H__\r
+#define __DEVICE_PATH_UTILITIES_H__\r
+\r
+///\r
+/// Device Path Utilities protocol\r
+///\r
+#define EFI_DEVICE_PATH_UTILITIES_GUID \\r
+  { \\r
+    0x379be4e, 0xd706, 0x437d, {0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4 } \\r
+  }\r
+\r
+/**\r
+  Returns the size of the device path, in bytes.\r
+\r
+  @param  DevicePath Points to the start of the EFI device path.\r
+\r
+  @return Size  Size of the specified device path, in bytes, including the end-of-path tag.\r
+  @retval 0     DevicePath is NULL\r
+\r
+**/\r
+typedef\r
+UINTN\r
+( *EFI_DEVICE_PATH_UTILS_GET_DEVICE_PATH_SIZE)(\r
+   CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
+  );\r
+\r
+\r
+/**\r
+  Create a duplicate of the specified path.\r
+\r
+  @param  DevicePath Points to the source EFI device path.\r
+\r
+  @retval Pointer    A pointer to the duplicate device path.\r
+  @retval NULL       insufficient memory or DevicePath is NULL\r
+\r
+**/\r
+typedef\r
+EFI_DEVICE_PATH_PROTOCOL*\r
+( *EFI_DEVICE_PATH_UTILS_DUP_DEVICE_PATH)(\r
+   CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
+  );\r
+\r
+/**\r
+  Create a new path by appending the second device path to the first.\r
+  If Src1 is NULL and Src2 is non-NULL, then a duplicate of Src2 is returned.\r
+  If Src1 is non-NULL and Src2 is NULL, then a duplicate of Src1 is returned.\r
+  If Src1 and Src2 are both NULL, then a copy of an end-of-device-path is returned.\r
+\r
+  @param  Src1 Points to the first device path.\r
+  @param  Src2 Points to the second device path.\r
+\r
+  @retval Pointer  A pointer to the newly created device path.\r
+  @retval NULL     Memory could not be allocated\r
+\r
+**/\r
+typedef\r
+EFI_DEVICE_PATH_PROTOCOL*\r
+( *EFI_DEVICE_PATH_UTILS_APPEND_PATH)(\r
+   CONST EFI_DEVICE_PATH_PROTOCOL *Src1,\r
+   CONST EFI_DEVICE_PATH_PROTOCOL *Src2\r
+  );\r
+\r
+/**\r
+  Creates a new path by appending the device node to the device path.\r
+  If DeviceNode is NULL then a copy of DevicePath is returned.\r
+  If DevicePath is NULL then a copy of DeviceNode, followed by an end-of-device path device node is returned.\r
+  If both DeviceNode and DevicePath are NULL then a copy of an end-of-device-path device node is returned.\r
+\r
+  @param  DevicePath Points to the device path.\r
+  @param  DeviceNode Points to the device node.\r
+\r
+  @retval Pointer    A pointer to the allocated device node.\r
+  @retval NULL       There was insufficient memory.\r
+\r
+**/\r
+typedef\r
+EFI_DEVICE_PATH_PROTOCOL*\r
+( *EFI_DEVICE_PATH_UTILS_APPEND_NODE)(\r
+   CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
+   CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode\r
+  );\r
+\r
+/**\r
+  Creates a new path by appending the specified device path instance to the specified device path.\r
+\r
+  @param  DevicePath         Points to the device path. If NULL, then ignored.\r
+  @param  DevicePathInstance Points to the device path instance.\r
+\r
+  @retval Pointer            A pointer to the newly created device path\r
+  @retval NULL               Memory could not be allocated or DevicePathInstance is NULL.\r
+\r
+**/\r
+typedef\r
+EFI_DEVICE_PATH_PROTOCOL*\r
+( *EFI_DEVICE_PATH_UTILS_APPEND_INSTANCE)(\r
+   CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
+   CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance\r
+  );\r
+\r
+/**\r
+  Creates a copy of the current device path instance and returns a pointer to the next device path\r
+  instance.\r
+\r
+  @param  DevicePathInstance     On input, this holds the pointer to the current device path\r
+                                 instance. On output, this holds the pointer to the next\r
+                                 device path instance or NULL if there are no more device\r
+                                 path instances in the device path.\r
+  @param  DevicePathInstanceSize On output, this holds the size of the device path instance,\r
+                                 in bytes or zero, if DevicePathInstance is NULL.\r
+                                 If NULL, then the instance size is not output.\r
+\r
+  @retval Pointer                A pointer to the copy of the current device path instance.\r
+  @retval NULL                   DevicePathInstace was NULL on entry or there was insufficient memory.\r
+\r
+**/\r
+typedef\r
+EFI_DEVICE_PATH_PROTOCOL*\r
+( *EFI_DEVICE_PATH_UTILS_GET_NEXT_INSTANCE)(\r
+     EFI_DEVICE_PATH_PROTOCOL  **DevicePathInstance,\r
+   UINTN                         *DevicePathInstanceSize\r
+  );\r
+\r
+/**\r
+  Creates a device node\r
+\r
+  @param  NodeType    NodeType is the device node type (EFI_DEVICE_PATH.Type) for\r
+                      the new device node.\r
+  @param  NodeSubType NodeSubType is the device node sub-type\r
+                      EFI_DEVICE_PATH.SubType) for the new device node.\r
+  @param  NodeLength  NodeLength is the length of the device node\r
+                      (EFI_DEVICE_PATH.Length) for the new device node.\r
+\r
+  @retval Pointer     A pointer to the newly created device node.\r
+  @retval NULL        NodeLength is less than\r
+                      the size of the header or there was insufficient memory.\r
+\r
+**/\r
+typedef\r
+EFI_DEVICE_PATH_PROTOCOL*\r
+( *EFI_DEVICE_PATH_UTILS_CREATE_NODE)(\r
+   UINT8                          NodeType,\r
+   UINT8                          NodeSubType,\r
+   UINT16                         NodeLength\r
+);\r
+\r
+/**\r
+  Returns whether a device path is multi-instance.\r
+\r
+  @param  DevicePath Points to the device path. If NULL, then ignored.\r
+\r
+  @retval TRUE       The device path has more than one instance\r
+  @retval FALSE      The device path is empty or contains only a single instance.\r
+\r
+**/\r
+typedef\r
+BOOLEAN\r
+( *EFI_DEVICE_PATH_UTILS_IS_MULTI_INSTANCE)(\r
+   CONST EFI_DEVICE_PATH_PROTOCOL         *DevicePath\r
+  );\r
+\r
+///\r
+/// This protocol is used to creates and manipulates device paths and device nodes.\r
+///\r
+typedef struct {\r
+  EFI_DEVICE_PATH_UTILS_GET_DEVICE_PATH_SIZE GetDevicePathSize;\r
+  EFI_DEVICE_PATH_UTILS_DUP_DEVICE_PATH      DuplicateDevicePath;\r
+  EFI_DEVICE_PATH_UTILS_APPEND_PATH          AppendDevicePath;\r
+  EFI_DEVICE_PATH_UTILS_APPEND_NODE          AppendDeviceNode;\r
+  EFI_DEVICE_PATH_UTILS_APPEND_INSTANCE      AppendDevicePathInstance;\r
+  EFI_DEVICE_PATH_UTILS_GET_NEXT_INSTANCE    GetNextDevicePathInstance;\r
+  EFI_DEVICE_PATH_UTILS_IS_MULTI_INSTANCE    IsDevicePathMultiInstance;\r
+  EFI_DEVICE_PATH_UTILS_CREATE_NODE          CreateDeviceNode;\r
+} EFI_DEVICE_PATH_UTILITIES_PROTOCOL;\r
+\r
+extern EFI_GUID gEfiDevicePathUtilitiesProtocolGuid;\r
+\r
+VOID\r
+SetDevicePathEndNode (\r
+   VOID  *Node\r
+  );\r
+\r
+BOOLEAN\r
+IsDevicePathValid (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
+   UINTN                    MaxSize\r
+  );\r
+\r
+UINT8\r
+DevicePathType (\r
+   CONST VOID  *Node\r
+  );\r
+\r
+UINT8\r
+DevicePathSubType (\r
+   CONST VOID  *Node\r
+  );\r
+\r
+UINTN\r
+DevicePathNodeLength (\r
+   CONST VOID  *Node\r
+  );\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+NextDevicePathNode (\r
+   CONST VOID  *Node\r
+  );\r
+\r
+BOOLEAN\r
+IsDevicePathEndType (\r
+   CONST VOID  *Node\r
+  );\r
+\r
+BOOLEAN\r
+IsDevicePathEnd (\r
+   CONST VOID  *Node\r
+  );\r
+BOOLEAN\r
+IsDevicePathEndInstance (\r
+   CONST VOID  *Node\r
+  );\r
+\r
+UINT16\r
+SetDevicePathNodeLength (\r
+    VOID  *Node,\r
+   UINTN     Length\r
+  );\r
+\r
+VOID\r
+SetDevicePathEndNode (\r
+   VOID  *Node\r
+  );\r
+\r
+UINTN\r
+UefiDevicePathLibGetDevicePathSize (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  );\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibDuplicateDevicePath (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  );\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibAppendDevicePath (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath,\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *SecondDevicePath\r
+  );\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibAppendDevicePathNode (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode\r
+  );\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibAppendDevicePathInstance (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathInstance\r
+  );\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibGetNextDevicePathInstance (\r
+    EFI_DEVICE_PATH_PROTOCOL    **DevicePath,\r
+   UINTN                          *Size\r
+  );\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UefiDevicePathLibCreateDeviceNode (\r
+   UINT8                           NodeType,\r
+   UINT8                           NodeSubType,\r
+   UINT16                          NodeLength\r
+  );\r
+\r
+BOOLEAN\r
+UefiDevicePathLibIsDevicePathMultiInstance (\r
+   CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  );\r
+\r
+#endif\r
index 50be773d57779c672e21021de4c1a7273b1d4a80..542818044dd62a707792e7acefca5877c5d8b4d2 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Windows makefile for C tools build.\r
 #\r
-# Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2009 - 2017, 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
@@ -32,7 +32,8 @@ APPLICATIONS = \
   Split \\r
   TianoCompress \\r
   VolInfo \\r
-  VfrCompile\r
+  VfrCompile \\r
+  DevicePath\r
 \r
 all: libs apps install\r
 \r
index 59d1ba2639433cdd27a581590e639bba7c21c93f..15ad9e4f2eca37851748f578708b3328c1d467dc 100644 (file)
@@ -38,7 +38,7 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 import uuid\r
 from CommonDataClass.Exceptions import BadExpression\r
-\r
+import subprocess\r
 ## Regular expression used to find out place holders in string template\r
 gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)\r
 \r
@@ -1474,7 +1474,37 @@ def AnalyzePcdExpression(Setting):
     return FieldList\r
 \r
 def ParseDevPathValue (Value):\r
-    pass\r
+    DevPathList = [ "Path","HardwarePath","Pci","PcCard","MemoryMapped","VenHw","Ctrl","BMC","AcpiPath","Acpi","PciRoot",\r
+                    "PcieRoot","Floppy","Keyboard","Serial","ParallelPort","AcpiEx","AcpiExp","AcpiAdr","Msg","Ata","Scsi",\r
+                    "Fibre","FibreEx","I1394","USB","I2O","Infiniband","VenMsg","VenPcAnsi","VenVt100","VenVt100Plus",\r
+                    "VenUtf8","UartFlowCtrl","SAS","SasEx","NVMe","UFS","SD","eMMC","DebugPort","MAC","IPv4","IPv6","Uart",\r
+                    "UsbClass","UsbAudio","UsbCDCControl","UsbHID","UsbImage","UsbPrinter","UsbMassStorage","UsbHub",\r
+                    "UsbCDCData","UsbSmartCard","UsbVideo","UsbDiagnostic","UsbWireless","UsbDeviceFirmwareUpdate",\r
+                    "UsbIrdaBridge","UsbTestAndMeasurement","UsbWwid","Unit","iSCSI","Vlan","Uri","Bluetooth","Wi-Fi",\r
+                    "MediaPath","HD","CDROM","VenMedia","Media","Fv","FvFile","Offset","RamDisk","VirtualDisk","VirtualCD",\r
+                    "PersistentVirtualDisk","PersistentVirtualCD","BbsPath","BBS","Sata" ]\r
+    if '\\' in Value:\r
+        Value.replace('\\', '/').replace(' ', '')\r
+    for Item in Value.split('/'):\r
+        Key = Item.strip().split('(')[0]\r
+        if Key not in DevPathList:\r
+            pass\r
+\r
+    Cmd = 'DevicePath ' + '"' + Value + '"'\r
+    try:\r
+        p = subprocess.Popen(Cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)\r
+        out, err = p.communicate()\r
+    except Exception, X:\r
+        raise BadExpression("DevicePath: %s" % (str(X)) )\r
+    finally:\r
+        subprocess._cleanup()\r
+        p.stdout.close()\r
+        p.stderr.close()\r
+    if err:\r
+        raise BadExpression("DevicePath: %s" % str(err))\r
+    Size = len(out.split())\r
+    out = ','.join(out.split())\r
+    return '{' + out + '}', Size\r
 \r
 def ParseFieldValue (Value):\r
     if type(Value) == type(0):\r