2 * Copyright (c) 2017 Netflix, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * Routines to format EFI_DEVICE_PATHs from the UEFI standard. Much of
28 * this file is taken from EDK2 and rototilled.
31 #include <sys/cdefs.h>
40 #include "efi-osdep.h"
41 #include "efivar-dp.h"
43 #include "uefi-dplib.h"
45 /* XXX STUBS -- this stuff doesn't work yet */
46 #define StrToIpv4Address(str, unk, ipv4ptr, unk2) (void)(str)
47 #define StrToIpv6Address(str, unk, ipv6ptr, unk2) (void)(str)
50 * OK. Now this is evil. Can't typedef it again. Sure beats changing them all.
51 * Since we're doing it all as narrow characters since wchar_t can't be used on
52 * FreeBSD and CHAR16 strings generally aren't a good fit. Since this parsing
53 * doesn't need Unicode for anything, this works out well.
58 * Taken from MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
62 DevicePathFromText protocol as defined in the UEFI 2.0 specification.
64 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
65 SPDX-License-Identifier: BSD-2-Clause-Patent
69 // #include "UefiDevicePathLib.h"
75 @param Src Source string.
77 @return The duplicated string.
82 UefiDevicePathLibStrDuplicate (
86 return AllocateCopyPool (StrSize (Src), Src);
91 Get parameter in a pair of parentheses follow the given node name.
92 For example, given the "Pci(0,1)" and NodeName "Pci", it returns "0,1".
94 @param Str Device Path Text.
95 @param NodeName Name of the node.
97 @return Parameter text for the node.
104 IN const CHAR16 *NodeName
109 UINTN NodeNameLength;
110 UINTN ParameterLength;
113 // Check whether the node name matchs
115 NodeNameLength = StrLen (NodeName);
116 if (StrnCmp (Str, NodeName, NodeNameLength) != 0) {
120 ParamStr = Str + NodeNameLength;
121 if (!IS_LEFT_PARENTH (*ParamStr)) {
126 // Skip the found '(' and find first occurrence of ')'
130 StrPointer = ParamStr;
131 while (!IS_NULL (*StrPointer)) {
132 if (IS_RIGHT_PARENTH (*StrPointer)) {
140 if (IS_NULL (*StrPointer)) {
147 ParamStr = AllocateCopyPool ((ParameterLength + 1) * sizeof (CHAR16), ParamStr);
148 if (ParamStr == NULL) {
153 // Terminate the parameter string
155 ParamStr[ParameterLength] = '\0';
161 Gets current sub-string from a string list, before return
162 the list header is moved to next sub-string. The sub-string is separated
163 by the specified character. For example, the separator is ',', the string
164 list is "2,0,3", it returns "2", the remain list move to "0,3"
166 @param List A string list separated by the specified separator
167 @param Separator The separator character
169 @return A pointer to the current sub-string
175 IN OUT CHAR16 **List,
185 if (IS_NULL (*Str)) {
190 // Find first occurrence of the separator
192 while (!IS_NULL (*Str)) {
193 if (*Str == Separator) {
200 if (*Str == Separator) {
202 // Find a sub-string, terminate it
209 // Move to next sub-string
217 Gets the next parameter string from the list.
219 @param List A string list separated by the specified separator
221 @return A pointer to the current sub-string
231 // The separator is comma
233 return SplitStr (List, ',');
237 Get one device node from entire device path text.
239 @param DevicePath On input, the current Device Path node; on output, the next device path node
240 @param IsInstanceEnd This node is the end of a device path instance
242 @return A device node text or NULL if no more device node available
247 GetNextDeviceNodeStr (
248 IN OUT CHAR16 **DevicePath,
249 OUT BOOLEAN *IsInstanceEnd
254 UINTN ParenthesesStack;
257 if (IS_NULL (*Str)) {
262 // Skip the leading '/', '(', ')' and ','
264 while (!IS_NULL (*Str)) {
265 if (!IS_SLASH (*Str) &&
267 !IS_LEFT_PARENTH (*Str) &&
268 !IS_RIGHT_PARENTH (*Str))
279 // Scan for the separator of this device node, '/' or ','
281 ParenthesesStack = 0;
282 while (!IS_NULL (*Str)) {
283 if ((IS_COMMA (*Str) || IS_SLASH (*Str)) && (ParenthesesStack == 0)) {
287 if (IS_LEFT_PARENTH (*Str)) {
289 } else if (IS_RIGHT_PARENTH (*Str)) {
296 if (ParenthesesStack != 0) {
298 // The '(' doesn't pair with ')', invalid device path text
303 if (IS_COMMA (*Str)) {
304 *IsInstanceEnd = TRUE;
308 *IsInstanceEnd = FALSE;
309 if (!IS_NULL (*Str)) {
323 Return whether the integer string is a hex string.
325 @param Str The integer string
327 @retval TRUE Hex string
328 @retval FALSE Decimal string
338 // skip preceeding white space
340 while ((*Str != 0) && *Str == ' ') {
345 // skip preceeding zeros
347 while ((*Str != 0) && *Str == '0') {
351 return (BOOLEAN)(*Str == 'x' || *Str == 'X');
356 Convert integer string to uint.
358 @param Str The integer string. If leading with "0x" or "0X", it's hexadecimal.
360 @return A UINTN value represented by Str
369 if (IsHexStr (Str)) {
370 return StrHexToUintn (Str);
372 return StrDecimalToUintn (Str);
378 Convert integer string to 64 bit data.
380 @param Str The integer string. If leading with "0x" or "0X", it's hexadecimal.
381 @param Data A pointer to the UINT64 value represented by Str
391 if (IsHexStr (Str)) {
392 *Data = StrHexToUint64 (Str);
394 *Data = StrDecimalToUint64 (Str);
400 Converts a Unicode string to ASCII string.
402 @param Str The equivalent Unicode string
403 @param AsciiStr On input, it points to destination ASCII string buffer; on output, it points
404 to the next ASCII string next to it
411 IN OUT CHAR8 **AsciiStr
417 while (!IS_NULL (*Str)) {
418 *(Dest++) = (CHAR8)*(Str++);
424 // Return the string next to it
426 *AsciiStr = Dest + 1;
430 Converts a generic text device path node to device path structure.
432 @param Type The type of the device path node.
433 @param TextDeviceNode The input text device path node.
435 @return A pointer to device path structure.
438 EFI_DEVICE_PATH_PROTOCOL *
439 DevPathFromTextGenericPath (
441 IN CHAR16 *TextDeviceNode
444 EFI_DEVICE_PATH_PROTOCOL *Node;
449 SubtypeStr = GetNextParamStr (&TextDeviceNode);
450 DataStr = GetNextParamStr (&TextDeviceNode);
452 if (DataStr == NULL) {
455 DataLength = StrLen (DataStr) / 2;
458 Node = CreateDeviceNode (
460 (UINT8)Strtoi (SubtypeStr),
461 (UINT16)(sizeof (EFI_DEVICE_PATH_PROTOCOL) + DataLength)
464 StrHexToBytes (DataStr, DataLength * 2, (UINT8 *)(Node + 1), DataLength);
469 Converts a generic text device path node to device path structure.
471 @param TextDeviceNode The input Text device path node.
473 @return A pointer to device path structure.
477 EFI_DEVICE_PATH_PROTOCOL *
478 DevPathFromTextPath (
479 IN CHAR16 *TextDeviceNode
484 TypeStr = GetNextParamStr (&TextDeviceNode);
486 return DevPathFromTextGenericPath ((UINT8)Strtoi (TypeStr), TextDeviceNode);
490 Converts a generic hardware text device path node to Hardware device path structure.
492 @param TextDeviceNode The input Text device path node.
494 @return A pointer to Hardware device path structure.
498 EFI_DEVICE_PATH_PROTOCOL *
499 DevPathFromTextHardwarePath (
500 IN CHAR16 *TextDeviceNode
503 return DevPathFromTextGenericPath (HARDWARE_DEVICE_PATH, TextDeviceNode);
507 Converts a text device path node to Hardware PCI device path structure.
509 @param TextDeviceNode The input Text device path node.
511 @return A pointer to Hardware PCI device path structure.
515 EFI_DEVICE_PATH_PROTOCOL *
517 IN CHAR16 *TextDeviceNode
522 PCI_DEVICE_PATH *Pci;
524 DeviceStr = GetNextParamStr (&TextDeviceNode);
525 FunctionStr = GetNextParamStr (&TextDeviceNode);
526 Pci = (PCI_DEVICE_PATH *)CreateDeviceNode (
527 HARDWARE_DEVICE_PATH,
529 (UINT16)sizeof (PCI_DEVICE_PATH)
532 Pci->Function = (UINT8)Strtoi (FunctionStr);
533 Pci->Device = (UINT8)Strtoi (DeviceStr);
535 return (EFI_DEVICE_PATH_PROTOCOL *)Pci;
539 Converts a text device path node to Hardware PC card device path structure.
541 @param TextDeviceNode The input Text device path node.
543 @return A pointer to Hardware PC card device path structure.
547 EFI_DEVICE_PATH_PROTOCOL *
548 DevPathFromTextPcCard (
549 IN CHAR16 *TextDeviceNode
552 CHAR16 *FunctionNumberStr;
553 PCCARD_DEVICE_PATH *Pccard;
555 FunctionNumberStr = GetNextParamStr (&TextDeviceNode);
556 Pccard = (PCCARD_DEVICE_PATH *)CreateDeviceNode (
557 HARDWARE_DEVICE_PATH,
559 (UINT16)sizeof (PCCARD_DEVICE_PATH)
562 Pccard->FunctionNumber = (UINT8)Strtoi (FunctionNumberStr);
564 return (EFI_DEVICE_PATH_PROTOCOL *)Pccard;
568 Converts a text device path node to Hardware memory map device path structure.
570 @param TextDeviceNode The input Text device path node.
572 @return A pointer to Hardware memory map device path structure.
576 EFI_DEVICE_PATH_PROTOCOL *
577 DevPathFromTextMemoryMapped (
578 IN CHAR16 *TextDeviceNode
581 CHAR16 *MemoryTypeStr;
582 CHAR16 *StartingAddressStr;
583 CHAR16 *EndingAddressStr;
584 MEMMAP_DEVICE_PATH *MemMap;
586 MemoryTypeStr = GetNextParamStr (&TextDeviceNode);
587 StartingAddressStr = GetNextParamStr (&TextDeviceNode);
588 EndingAddressStr = GetNextParamStr (&TextDeviceNode);
589 MemMap = (MEMMAP_DEVICE_PATH *)CreateDeviceNode (
590 HARDWARE_DEVICE_PATH,
592 (UINT16)sizeof (MEMMAP_DEVICE_PATH)
595 MemMap->MemoryType = (UINT32)Strtoi (MemoryTypeStr);
596 Strtoi64 (StartingAddressStr, &MemMap->StartingAddress);
597 Strtoi64 (EndingAddressStr, &MemMap->EndingAddress);
599 return (EFI_DEVICE_PATH_PROTOCOL *)MemMap;
603 Converts a text device path node to Vendor device path structure based on the input Type
606 @param TextDeviceNode The input Text device path node.
607 @param Type The type of device path node.
608 @param SubType The subtype of device path node.
610 @return A pointer to the newly-created Vendor device path structure.
614 EFI_DEVICE_PATH_PROTOCOL *
615 ConvertFromTextVendor (
616 IN CHAR16 *TextDeviceNode,
624 VENDOR_DEVICE_PATH *Vendor;
626 GuidStr = GetNextParamStr (&TextDeviceNode);
628 DataStr = GetNextParamStr (&TextDeviceNode);
629 Length = StrLen (DataStr);
631 // Two hex characters make up 1 buffer byte
633 Length = (Length + 1) / 2;
635 Vendor = (VENDOR_DEVICE_PATH *)CreateDeviceNode (
638 (UINT16)(sizeof (VENDOR_DEVICE_PATH) + Length)
641 StrToGuid (GuidStr, &Vendor->Guid);
642 StrHexToBytes (DataStr, Length * 2, (UINT8 *)(Vendor + 1), Length);
644 return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
648 Converts a text device path node to Vendor Hardware device path structure.
650 @param TextDeviceNode The input Text device path node.
652 @return A pointer to the newly-created Vendor Hardware device path structure.
656 EFI_DEVICE_PATH_PROTOCOL *
657 DevPathFromTextVenHw (
658 IN CHAR16 *TextDeviceNode
661 return ConvertFromTextVendor (
663 HARDWARE_DEVICE_PATH,
669 Converts a text device path node to Hardware Controller device path structure.
671 @param TextDeviceNode The input Text device path node.
673 @return A pointer to the newly-created Hardware Controller device path structure.
677 EFI_DEVICE_PATH_PROTOCOL *
678 DevPathFromTextCtrl (
679 IN CHAR16 *TextDeviceNode
682 CHAR16 *ControllerStr;
683 CONTROLLER_DEVICE_PATH *Controller;
685 ControllerStr = GetNextParamStr (&TextDeviceNode);
686 Controller = (CONTROLLER_DEVICE_PATH *)CreateDeviceNode (
687 HARDWARE_DEVICE_PATH,
689 (UINT16)sizeof (CONTROLLER_DEVICE_PATH)
691 Controller->ControllerNumber = (UINT32)Strtoi (ControllerStr);
693 return (EFI_DEVICE_PATH_PROTOCOL *)Controller;
697 Converts a text device path node to BMC device path structure.
699 @param TextDeviceNode The input Text device path node.
701 @return A pointer to the newly-created BMC device path structure.
705 EFI_DEVICE_PATH_PROTOCOL *
707 IN CHAR16 *TextDeviceNode
710 CHAR16 *InterfaceTypeStr;
711 CHAR16 *BaseAddressStr;
712 BMC_DEVICE_PATH *BmcDp;
714 InterfaceTypeStr = GetNextParamStr (&TextDeviceNode);
715 BaseAddressStr = GetNextParamStr (&TextDeviceNode);
716 BmcDp = (BMC_DEVICE_PATH *)CreateDeviceNode (
717 HARDWARE_DEVICE_PATH,
719 (UINT16)sizeof (BMC_DEVICE_PATH)
722 BmcDp->InterfaceType = (UINT8)Strtoi (InterfaceTypeStr);
724 (UINT64 *)(&BmcDp->BaseAddress),
725 StrHexToUint64 (BaseAddressStr)
728 return (EFI_DEVICE_PATH_PROTOCOL *)BmcDp;
732 Converts a generic ACPI text device path node to ACPI device path structure.
734 @param TextDeviceNode The input Text device path node.
736 @return A pointer to ACPI device path structure.
740 EFI_DEVICE_PATH_PROTOCOL *
741 DevPathFromTextAcpiPath (
742 IN CHAR16 *TextDeviceNode
745 return DevPathFromTextGenericPath (ACPI_DEVICE_PATH, TextDeviceNode);
749 Converts a string to EisaId.
751 @param Text The input string.
753 @return UINT32 EISA ID.
761 return (((Text[0] - 'A' + 1) & 0x1f) << 10)
762 + (((Text[1] - 'A' + 1) & 0x1f) << 5)
763 + (((Text[2] - 'A' + 1) & 0x1f) << 0)
764 + (UINT32)(StrHexToUintn (&Text[3]) << 16)
769 Converts a text device path node to ACPI HID device path structure.
771 @param TextDeviceNode The input Text device path node.
773 @return A pointer to the newly-created ACPI HID device path structure.
777 EFI_DEVICE_PATH_PROTOCOL *
778 DevPathFromTextAcpi (
779 IN CHAR16 *TextDeviceNode
784 ACPI_HID_DEVICE_PATH *Acpi;
786 HIDStr = GetNextParamStr (&TextDeviceNode);
787 UIDStr = GetNextParamStr (&TextDeviceNode);
788 Acpi = (ACPI_HID_DEVICE_PATH *)CreateDeviceNode (
791 (UINT16)sizeof (ACPI_HID_DEVICE_PATH)
794 Acpi->HID = EisaIdFromText (HIDStr);
795 Acpi->UID = (UINT32)Strtoi (UIDStr);
797 return (EFI_DEVICE_PATH_PROTOCOL *)Acpi;
801 Converts a text device path node to ACPI HID device path structure.
803 @param TextDeviceNode The input Text device path node.
804 @param PnPId The input plug and play identification.
806 @return A pointer to the newly-created ACPI HID device path structure.
810 EFI_DEVICE_PATH_PROTOCOL *
811 ConvertFromTextAcpi (
812 IN CHAR16 *TextDeviceNode,
817 ACPI_HID_DEVICE_PATH *Acpi;
819 UIDStr = GetNextParamStr (&TextDeviceNode);
820 Acpi = (ACPI_HID_DEVICE_PATH *)CreateDeviceNode (
823 (UINT16)sizeof (ACPI_HID_DEVICE_PATH)
826 Acpi->HID = EFI_PNP_ID (PnPId);
827 Acpi->UID = (UINT32)Strtoi (UIDStr);
829 return (EFI_DEVICE_PATH_PROTOCOL *)Acpi;
833 Converts a text device path node to PCI root device path structure.
835 @param TextDeviceNode The input Text device path node.
837 @return A pointer to the newly-created PCI root device path structure.
841 EFI_DEVICE_PATH_PROTOCOL *
842 DevPathFromTextPciRoot (
843 IN CHAR16 *TextDeviceNode
846 return ConvertFromTextAcpi (TextDeviceNode, 0x0a03);
850 Converts a text device path node to PCIE root device path structure.
852 @param TextDeviceNode The input Text device path node.
854 @return A pointer to the newly-created PCIE root device path structure.
858 EFI_DEVICE_PATH_PROTOCOL *
859 DevPathFromTextPcieRoot (
860 IN CHAR16 *TextDeviceNode
863 return ConvertFromTextAcpi (TextDeviceNode, 0x0a08);
867 Converts a text device path node to Floppy device path structure.
869 @param TextDeviceNode The input Text device path node.
871 @return A pointer to the newly-created Floppy device path structure.
875 EFI_DEVICE_PATH_PROTOCOL *
876 DevPathFromTextFloppy (
877 IN CHAR16 *TextDeviceNode
880 return ConvertFromTextAcpi (TextDeviceNode, 0x0604);
884 Converts a text device path node to Keyboard device path structure.
886 @param TextDeviceNode The input Text device path node.
888 @return A pointer to the newly-created Keyboard device path structure.
892 EFI_DEVICE_PATH_PROTOCOL *
893 DevPathFromTextKeyboard (
894 IN CHAR16 *TextDeviceNode
897 return ConvertFromTextAcpi (TextDeviceNode, 0x0301);
901 Converts a text device path node to Serial device path structure.
903 @param TextDeviceNode The input Text device path node.
905 @return A pointer to the newly-created Serial device path structure.
909 EFI_DEVICE_PATH_PROTOCOL *
910 DevPathFromTextSerial (
911 IN CHAR16 *TextDeviceNode
914 return ConvertFromTextAcpi (TextDeviceNode, 0x0501);
918 Converts a text device path node to Parallel Port device path structure.
920 @param TextDeviceNode The input Text device path node.
922 @return A pointer to the newly-created Parallel Port device path structure.
926 EFI_DEVICE_PATH_PROTOCOL *
927 DevPathFromTextParallelPort (
928 IN CHAR16 *TextDeviceNode
931 return ConvertFromTextAcpi (TextDeviceNode, 0x0401);
935 Converts a text device path node to ACPI extension device path structure.
937 @param TextDeviceNode The input Text device path node.
939 @return A pointer to the newly-created ACPI extension device path structure.
943 EFI_DEVICE_PATH_PROTOCOL *
944 DevPathFromTextAcpiEx (
945 IN CHAR16 *TextDeviceNode
956 ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx;
958 HIDStr = GetNextParamStr (&TextDeviceNode);
959 CIDStr = GetNextParamStr (&TextDeviceNode);
960 UIDStr = GetNextParamStr (&TextDeviceNode);
961 HIDSTRStr = GetNextParamStr (&TextDeviceNode);
962 CIDSTRStr = GetNextParamStr (&TextDeviceNode);
963 UIDSTRStr = GetNextParamStr (&TextDeviceNode);
965 Length = (UINT16)(sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (HIDSTRStr) + 1);
966 Length = (UINT16)(Length + StrLen (UIDSTRStr) + 1);
967 Length = (UINT16)(Length + StrLen (CIDSTRStr) + 1);
968 AcpiEx = (ACPI_EXTENDED_HID_DEVICE_PATH *)CreateDeviceNode (
974 AcpiEx->HID = EisaIdFromText (HIDStr);
975 AcpiEx->CID = EisaIdFromText (CIDStr);
976 AcpiEx->UID = (UINT32)Strtoi (UIDStr);
978 AsciiStr = (CHAR8 *)((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
979 StrToAscii (HIDSTRStr, &AsciiStr);
980 StrToAscii (UIDSTRStr, &AsciiStr);
981 StrToAscii (CIDSTRStr, &AsciiStr);
983 return (EFI_DEVICE_PATH_PROTOCOL *)AcpiEx;
987 Converts a text device path node to ACPI extension device path structure.
989 @param TextDeviceNode The input Text device path node.
991 @return A pointer to the newly-created ACPI extension device path structure.
995 EFI_DEVICE_PATH_PROTOCOL *
996 DevPathFromTextAcpiExp (
997 IN CHAR16 *TextDeviceNode
1005 ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx;
1007 HIDStr = GetNextParamStr (&TextDeviceNode);
1008 CIDStr = GetNextParamStr (&TextDeviceNode);
1009 UIDSTRStr = GetNextParamStr (&TextDeviceNode);
1010 Length = (UINT16)(sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (UIDSTRStr) + 3);
1011 AcpiEx = (ACPI_EXTENDED_HID_DEVICE_PATH *)CreateDeviceNode (
1017 AcpiEx->HID = EisaIdFromText (HIDStr);
1019 // According to UEFI spec, the CID parameter is optional and has a default value of 0.
1020 // So when the CID parameter is not specified or specified as 0 in the text device node.
1021 // Set the CID to 0 in the ACPI extension device path structure.
1023 if ((*CIDStr == '\0') || (*CIDStr == '0')) {
1026 AcpiEx->CID = EisaIdFromText (CIDStr);
1031 AsciiStr = (CHAR8 *)((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
1033 // HID string is NULL
1037 // Convert UID string
1040 StrToAscii (UIDSTRStr, &AsciiStr);
1042 // CID string is NULL
1046 return (EFI_DEVICE_PATH_PROTOCOL *)AcpiEx;
1050 Converts a text device path node to ACPI _ADR device path structure.
1052 @param TextDeviceNode The input Text device path node.
1054 @return A pointer to the newly-created ACPI _ADR device path structure.
1058 EFI_DEVICE_PATH_PROTOCOL *
1059 DevPathFromTextAcpiAdr (
1060 IN CHAR16 *TextDeviceNode
1063 CHAR16 *DisplayDeviceStr;
1064 ACPI_ADR_DEVICE_PATH *AcpiAdr;
1068 AcpiAdr = (ACPI_ADR_DEVICE_PATH *)CreateDeviceNode (
1071 (UINT16)sizeof (ACPI_ADR_DEVICE_PATH)
1073 ASSERT (AcpiAdr != NULL);
1075 for (Index = 0; ; Index++) {
1076 DisplayDeviceStr = GetNextParamStr (&TextDeviceNode);
1077 if (IS_NULL (*DisplayDeviceStr)) {
1082 Length = DevicePathNodeLength (AcpiAdr);
1083 AcpiAdr = ReallocatePool (
1085 Length + sizeof (UINT32),
1088 ASSERT (AcpiAdr != NULL);
1089 SetDevicePathNodeLength (AcpiAdr, Length + sizeof (UINT32));
1092 (&AcpiAdr->ADR)[Index] = (UINT32)Strtoi (DisplayDeviceStr);
1095 return (EFI_DEVICE_PATH_PROTOCOL *)AcpiAdr;
1099 Converts a generic messaging text device path node to messaging device path structure.
1101 @param TextDeviceNode The input Text device path node.
1103 @return A pointer to messaging device path structure.
1107 EFI_DEVICE_PATH_PROTOCOL *
1108 DevPathFromTextMsg (
1109 IN CHAR16 *TextDeviceNode
1112 return DevPathFromTextGenericPath (MESSAGING_DEVICE_PATH, TextDeviceNode);
1116 Converts a text device path node to Parallel Port device path structure.
1118 @param TextDeviceNode The input Text device path node.
1120 @return A pointer to the newly-created Parallel Port device path structure.
1124 EFI_DEVICE_PATH_PROTOCOL *
1125 DevPathFromTextAta (
1126 IN CHAR16 *TextDeviceNode
1129 CHAR16 *PrimarySecondaryStr;
1130 CHAR16 *SlaveMasterStr;
1132 ATAPI_DEVICE_PATH *Atapi;
1134 Atapi = (ATAPI_DEVICE_PATH *)CreateDeviceNode (
1135 MESSAGING_DEVICE_PATH,
1137 (UINT16)sizeof (ATAPI_DEVICE_PATH)
1140 PrimarySecondaryStr = GetNextParamStr (&TextDeviceNode);
1141 SlaveMasterStr = GetNextParamStr (&TextDeviceNode);
1142 LunStr = GetNextParamStr (&TextDeviceNode);
1144 if (StrCmp (PrimarySecondaryStr, "Primary") == 0) {
1145 Atapi->PrimarySecondary = 0;
1146 } else if (StrCmp (PrimarySecondaryStr, "Secondary") == 0) {
1147 Atapi->PrimarySecondary = 1;
1149 Atapi->PrimarySecondary = (UINT8)Strtoi (PrimarySecondaryStr);
1152 if (StrCmp (SlaveMasterStr, "Master") == 0) {
1153 Atapi->SlaveMaster = 0;
1154 } else if (StrCmp (SlaveMasterStr, "Slave") == 0) {
1155 Atapi->SlaveMaster = 1;
1157 Atapi->SlaveMaster = (UINT8)Strtoi (SlaveMasterStr);
1160 Atapi->Lun = (UINT16)Strtoi (LunStr);
1162 return (EFI_DEVICE_PATH_PROTOCOL *)Atapi;
1166 Converts a text device path node to SCSI device path structure.
1168 @param TextDeviceNode The input Text device path node.
1170 @return A pointer to the newly-created SCSI device path structure.
1174 EFI_DEVICE_PATH_PROTOCOL *
1175 DevPathFromTextScsi (
1176 IN CHAR16 *TextDeviceNode
1181 SCSI_DEVICE_PATH *Scsi;
1183 PunStr = GetNextParamStr (&TextDeviceNode);
1184 LunStr = GetNextParamStr (&TextDeviceNode);
1185 Scsi = (SCSI_DEVICE_PATH *)CreateDeviceNode (
1186 MESSAGING_DEVICE_PATH,
1188 (UINT16)sizeof (SCSI_DEVICE_PATH)
1191 Scsi->Pun = (UINT16)Strtoi (PunStr);
1192 Scsi->Lun = (UINT16)Strtoi (LunStr);
1194 return (EFI_DEVICE_PATH_PROTOCOL *)Scsi;
1198 Converts a text device path node to Fibre device path structure.
1200 @param TextDeviceNode The input Text device path node.
1202 @return A pointer to the newly-created Fibre device path structure.
1206 EFI_DEVICE_PATH_PROTOCOL *
1207 DevPathFromTextFibre (
1208 IN CHAR16 *TextDeviceNode
1213 FIBRECHANNEL_DEVICE_PATH *Fibre;
1215 WWNStr = GetNextParamStr (&TextDeviceNode);
1216 LunStr = GetNextParamStr (&TextDeviceNode);
1217 Fibre = (FIBRECHANNEL_DEVICE_PATH *)CreateDeviceNode (
1218 MESSAGING_DEVICE_PATH,
1219 MSG_FIBRECHANNEL_DP,
1220 (UINT16)sizeof (FIBRECHANNEL_DEVICE_PATH)
1223 Fibre->Reserved = 0;
1224 Strtoi64 (WWNStr, &Fibre->WWN);
1225 Strtoi64 (LunStr, &Fibre->Lun);
1227 return (EFI_DEVICE_PATH_PROTOCOL *)Fibre;
1231 Converts a text device path node to FibreEx device path structure.
1233 @param TextDeviceNode The input Text device path node.
1235 @return A pointer to the newly-created FibreEx device path structure.
1239 EFI_DEVICE_PATH_PROTOCOL *
1240 DevPathFromTextFibreEx (
1241 IN CHAR16 *TextDeviceNode
1246 FIBRECHANNELEX_DEVICE_PATH *FibreEx;
1248 WWNStr = GetNextParamStr (&TextDeviceNode);
1249 LunStr = GetNextParamStr (&TextDeviceNode);
1250 FibreEx = (FIBRECHANNELEX_DEVICE_PATH *)CreateDeviceNode (
1251 MESSAGING_DEVICE_PATH,
1252 MSG_FIBRECHANNELEX_DP,
1253 (UINT16)sizeof (FIBRECHANNELEX_DEVICE_PATH)
1256 FibreEx->Reserved = 0;
1257 Strtoi64 (WWNStr, (UINT64 *)(&FibreEx->WWN));
1258 Strtoi64 (LunStr, (UINT64 *)(&FibreEx->Lun));
1260 *(UINT64 *)(&FibreEx->WWN) = SwapBytes64 (*(UINT64 *)(&FibreEx->WWN));
1261 *(UINT64 *)(&FibreEx->Lun) = SwapBytes64 (*(UINT64 *)(&FibreEx->Lun));
1263 return (EFI_DEVICE_PATH_PROTOCOL *)FibreEx;
1267 Converts a text device path node to 1394 device path structure.
1269 @param TextDeviceNode The input Text device path node.
1271 @return A pointer to the newly-created 1394 device path structure.
1275 EFI_DEVICE_PATH_PROTOCOL *
1276 DevPathFromText1394 (
1277 IN CHAR16 *TextDeviceNode
1281 F1394_DEVICE_PATH *F1394DevPath;
1283 GuidStr = GetNextParamStr (&TextDeviceNode);
1284 F1394DevPath = (F1394_DEVICE_PATH *)CreateDeviceNode (
1285 MESSAGING_DEVICE_PATH,
1287 (UINT16)sizeof (F1394_DEVICE_PATH)
1290 F1394DevPath->Reserved = 0;
1291 F1394DevPath->Guid = StrHexToUint64 (GuidStr);
1293 return (EFI_DEVICE_PATH_PROTOCOL *)F1394DevPath;
1297 Converts a text device path node to USB device path structure.
1299 @param TextDeviceNode The input Text device path node.
1301 @return A pointer to the newly-created USB device path structure.
1305 EFI_DEVICE_PATH_PROTOCOL *
1306 DevPathFromTextUsb (
1307 IN CHAR16 *TextDeviceNode
1311 CHAR16 *InterfaceStr;
1312 USB_DEVICE_PATH *Usb;
1314 PortStr = GetNextParamStr (&TextDeviceNode);
1315 InterfaceStr = GetNextParamStr (&TextDeviceNode);
1316 Usb = (USB_DEVICE_PATH *)CreateDeviceNode (
1317 MESSAGING_DEVICE_PATH,
1319 (UINT16)sizeof (USB_DEVICE_PATH)
1322 Usb->ParentPortNumber = (UINT8)Strtoi (PortStr);
1323 Usb->InterfaceNumber = (UINT8)Strtoi (InterfaceStr);
1325 return (EFI_DEVICE_PATH_PROTOCOL *)Usb;
1329 Converts a text device path node to I20 device path structure.
1331 @param TextDeviceNode The input Text device path node.
1333 @return A pointer to the newly-created I20 device path structure.
1337 EFI_DEVICE_PATH_PROTOCOL *
1338 DevPathFromTextI2O (
1339 IN CHAR16 *TextDeviceNode
1343 I2O_DEVICE_PATH *I2ODevPath;
1345 TIDStr = GetNextParamStr (&TextDeviceNode);
1346 I2ODevPath = (I2O_DEVICE_PATH *)CreateDeviceNode (
1347 MESSAGING_DEVICE_PATH,
1349 (UINT16)sizeof (I2O_DEVICE_PATH)
1352 I2ODevPath->Tid = (UINT32)Strtoi (TIDStr);
1354 return (EFI_DEVICE_PATH_PROTOCOL *)I2ODevPath;
1358 Converts a text device path node to Infini Band device path structure.
1360 @param TextDeviceNode The input Text device path node.
1362 @return A pointer to the newly-created Infini Band device path structure.
1366 EFI_DEVICE_PATH_PROTOCOL *
1367 DevPathFromTextInfiniband (
1368 IN CHAR16 *TextDeviceNode
1376 INFINIBAND_DEVICE_PATH *InfiniBand;
1378 FlagsStr = GetNextParamStr (&TextDeviceNode);
1379 GuidStr = GetNextParamStr (&TextDeviceNode);
1380 SidStr = GetNextParamStr (&TextDeviceNode);
1381 TidStr = GetNextParamStr (&TextDeviceNode);
1382 DidStr = GetNextParamStr (&TextDeviceNode);
1383 InfiniBand = (INFINIBAND_DEVICE_PATH *)CreateDeviceNode (
1384 MESSAGING_DEVICE_PATH,
1386 (UINT16)sizeof (INFINIBAND_DEVICE_PATH)
1389 InfiniBand->ResourceFlags = (UINT32)Strtoi (FlagsStr);
1390 StrToGuid (GuidStr, (EFI_GUID *)InfiniBand->PortGid);
1391 Strtoi64 (SidStr, &InfiniBand->ServiceId);
1392 Strtoi64 (TidStr, &InfiniBand->TargetPortId);
1393 Strtoi64 (DidStr, &InfiniBand->DeviceId);
1395 return (EFI_DEVICE_PATH_PROTOCOL *)InfiniBand;
1399 Converts a text device path node to Vendor-Defined Messaging device path structure.
1401 @param TextDeviceNode The input Text device path node.
1403 @return A pointer to the newly-created Vendor-Defined Messaging device path structure.
1407 EFI_DEVICE_PATH_PROTOCOL *
1408 DevPathFromTextVenMsg (
1409 IN CHAR16 *TextDeviceNode
1412 return ConvertFromTextVendor (
1414 MESSAGING_DEVICE_PATH,
1420 Converts a text device path node to Vendor defined PC-ANSI device path structure.
1422 @param TextDeviceNode The input Text device path node.
1424 @return A pointer to the newly-created Vendor defined PC-ANSI device path structure.
1428 EFI_DEVICE_PATH_PROTOCOL *
1429 DevPathFromTextVenPcAnsi (
1430 IN CHAR16 *TextDeviceNode
1433 VENDOR_DEVICE_PATH *Vendor;
1435 Vendor = (VENDOR_DEVICE_PATH *)CreateDeviceNode (
1436 MESSAGING_DEVICE_PATH,
1438 (UINT16)sizeof (VENDOR_DEVICE_PATH)
1440 CopyGuid (&Vendor->Guid, &gEfiPcAnsiGuid);
1442 return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
1446 Converts a text device path node to Vendor defined VT100 device path structure.
1448 @param TextDeviceNode The input Text device path node.
1450 @return A pointer to the newly-created Vendor defined VT100 device path structure.
1454 EFI_DEVICE_PATH_PROTOCOL *
1455 DevPathFromTextVenVt100 (
1456 IN CHAR16 *TextDeviceNode
1459 VENDOR_DEVICE_PATH *Vendor;
1461 Vendor = (VENDOR_DEVICE_PATH *)CreateDeviceNode (
1462 MESSAGING_DEVICE_PATH,
1464 (UINT16)sizeof (VENDOR_DEVICE_PATH)
1466 CopyGuid (&Vendor->Guid, &gEfiVT100Guid);
1468 return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
1472 Converts a text device path node to Vendor defined VT100 Plus device path structure.
1474 @param TextDeviceNode The input Text device path node.
1476 @return A pointer to the newly-created Vendor defined VT100 Plus device path structure.
1480 EFI_DEVICE_PATH_PROTOCOL *
1481 DevPathFromTextVenVt100Plus (
1482 IN CHAR16 *TextDeviceNode
1485 VENDOR_DEVICE_PATH *Vendor;
1487 Vendor = (VENDOR_DEVICE_PATH *)CreateDeviceNode (
1488 MESSAGING_DEVICE_PATH,
1490 (UINT16)sizeof (VENDOR_DEVICE_PATH)
1492 CopyGuid (&Vendor->Guid, &gEfiVT100PlusGuid);
1494 return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
1498 Converts a text device path node to Vendor defined UTF8 device path structure.
1500 @param TextDeviceNode The input Text device path node.
1502 @return A pointer to the newly-created Vendor defined UTF8 device path structure.
1506 EFI_DEVICE_PATH_PROTOCOL *
1507 DevPathFromTextVenUtf8 (
1508 IN CHAR16 *TextDeviceNode
1511 VENDOR_DEVICE_PATH *Vendor;
1513 Vendor = (VENDOR_DEVICE_PATH *)CreateDeviceNode (
1514 MESSAGING_DEVICE_PATH,
1516 (UINT16)sizeof (VENDOR_DEVICE_PATH)
1518 CopyGuid (&Vendor->Guid, &gEfiVTUTF8Guid);
1520 return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
1524 Converts a text device path node to UART Flow Control device path structure.
1526 @param TextDeviceNode The input Text device path node.
1528 @return A pointer to the newly-created UART Flow Control device path structure.
1532 EFI_DEVICE_PATH_PROTOCOL *
1533 DevPathFromTextUartFlowCtrl (
1534 IN CHAR16 *TextDeviceNode
1538 UART_FLOW_CONTROL_DEVICE_PATH *UartFlowControl;
1540 ValueStr = GetNextParamStr (&TextDeviceNode);
1541 UartFlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *)CreateDeviceNode (
1542 MESSAGING_DEVICE_PATH,
1544 (UINT16)sizeof (UART_FLOW_CONTROL_DEVICE_PATH)
1547 CopyGuid (&UartFlowControl->Guid, &gEfiUartDevicePathGuid);
1548 if (StrCmp (ValueStr, "XonXoff") == 0) {
1549 UartFlowControl->FlowControlMap = 2;
1550 } else if (StrCmp (ValueStr, "Hardware") == 0) {
1551 UartFlowControl->FlowControlMap = 1;
1553 UartFlowControl->FlowControlMap = 0;
1556 return (EFI_DEVICE_PATH_PROTOCOL *)UartFlowControl;
1560 Converts a text device path node to Serial Attached SCSI device path structure.
1562 @param TextDeviceNode The input Text device path node.
1564 @return A pointer to the newly-created Serial Attached SCSI device path structure.
1568 EFI_DEVICE_PATH_PROTOCOL *
1569 DevPathFromTextSAS (
1570 IN CHAR16 *TextDeviceNode
1577 CHAR16 *LocationStr;
1579 CHAR16 *DriveBayStr;
1580 CHAR16 *ReservedStr;
1583 SAS_DEVICE_PATH *Sas;
1585 AddressStr = GetNextParamStr (&TextDeviceNode);
1586 LunStr = GetNextParamStr (&TextDeviceNode);
1587 RTPStr = GetNextParamStr (&TextDeviceNode);
1588 SASSATAStr = GetNextParamStr (&TextDeviceNode);
1589 LocationStr = GetNextParamStr (&TextDeviceNode);
1590 ConnectStr = GetNextParamStr (&TextDeviceNode);
1591 DriveBayStr = GetNextParamStr (&TextDeviceNode);
1592 ReservedStr = GetNextParamStr (&TextDeviceNode);
1593 Sas = (SAS_DEVICE_PATH *)CreateDeviceNode (
1594 MESSAGING_DEVICE_PATH,
1596 (UINT16)sizeof (SAS_DEVICE_PATH)
1599 CopyGuid (&Sas->Guid, &gEfiSasDevicePathGuid);
1600 Strtoi64 (AddressStr, &Sas->SasAddress);
1601 Strtoi64 (LunStr, &Sas->Lun);
1602 Sas->RelativeTargetPort = (UINT16)Strtoi (RTPStr);
1604 if (StrCmp (SASSATAStr, "NoTopology") == 0) {
1606 } else if ((StrCmp (SASSATAStr, "SATA") == 0) || (StrCmp (SASSATAStr, "SAS") == 0)) {
1607 Uint16 = (UINT16)Strtoi (DriveBayStr);
1611 Info = (UINT16)(0x2 | ((Uint16 - 1) << 8));
1614 if (StrCmp (SASSATAStr, "SATA") == 0) {
1619 // Location is an integer between 0 and 1 or else
1620 // the keyword Internal (0) or External (1).
1622 if (StrCmp (LocationStr, "External") == 0) {
1624 } else if (StrCmp (LocationStr, "Internal") == 0) {
1627 Uint16 = ((UINT16)Strtoi (LocationStr) & BIT0);
1630 Info |= (Uint16 << 5);
1633 // Connect is an integer between 0 and 3 or else
1634 // the keyword Direct (0) or Expanded (1).
1636 if (StrCmp (ConnectStr, "Expanded") == 0) {
1638 } else if (StrCmp (ConnectStr, "Direct") == 0) {
1641 Uint16 = ((UINT16)Strtoi (ConnectStr) & (BIT0 | BIT1));
1644 Info |= (Uint16 << 6);
1646 Info = (UINT16)Strtoi (SASSATAStr);
1649 Sas->DeviceTopology = Info;
1650 Sas->Reserved = (UINT32)Strtoi (ReservedStr);
1652 return (EFI_DEVICE_PATH_PROTOCOL *)Sas;
1656 Converts a text device path node to Serial Attached SCSI Ex device path structure.
1658 @param TextDeviceNode The input Text device path node.
1660 @return A pointer to the newly-created Serial Attached SCSI Ex device path structure.
1664 EFI_DEVICE_PATH_PROTOCOL *
1665 DevPathFromTextSasEx (
1666 IN CHAR16 *TextDeviceNode
1673 CHAR16 *LocationStr;
1675 CHAR16 *DriveBayStr;
1680 SASEX_DEVICE_PATH *SasEx;
1682 AddressStr = GetNextParamStr (&TextDeviceNode);
1683 LunStr = GetNextParamStr (&TextDeviceNode);
1684 RTPStr = GetNextParamStr (&TextDeviceNode);
1685 SASSATAStr = GetNextParamStr (&TextDeviceNode);
1686 LocationStr = GetNextParamStr (&TextDeviceNode);
1687 ConnectStr = GetNextParamStr (&TextDeviceNode);
1688 DriveBayStr = GetNextParamStr (&TextDeviceNode);
1689 SasEx = (SASEX_DEVICE_PATH *)CreateDeviceNode (
1690 MESSAGING_DEVICE_PATH,
1692 (UINT16)sizeof (SASEX_DEVICE_PATH)
1695 Strtoi64 (AddressStr, &SasAddress);
1696 Strtoi64 (LunStr, &Lun);
1697 WriteUnaligned64 ((UINT64 *)&SasEx->SasAddress, SwapBytes64 (SasAddress));
1698 WriteUnaligned64 ((UINT64 *)&SasEx->Lun, SwapBytes64 (Lun));
1699 SasEx->RelativeTargetPort = (UINT16)Strtoi (RTPStr);
1701 if (StrCmp (SASSATAStr, "NoTopology") == 0) {
1703 } else if ((StrCmp (SASSATAStr, "SATA") == 0) || (StrCmp (SASSATAStr, "SAS") == 0)) {
1704 Uint16 = (UINT16)Strtoi (DriveBayStr);
1708 Info = (UINT16)(0x2 | ((Uint16 - 1) << 8));
1711 if (StrCmp (SASSATAStr, "SATA") == 0) {
1716 // Location is an integer between 0 and 1 or else
1717 // the keyword Internal (0) or External (1).
1719 if (StrCmp (LocationStr, "External") == 0) {
1721 } else if (StrCmp (LocationStr, "Internal") == 0) {
1724 Uint16 = ((UINT16)Strtoi (LocationStr) & BIT0);
1727 Info |= (Uint16 << 5);
1730 // Connect is an integer between 0 and 3 or else
1731 // the keyword Direct (0) or Expanded (1).
1733 if (StrCmp (ConnectStr, "Expanded") == 0) {
1735 } else if (StrCmp (ConnectStr, "Direct") == 0) {
1738 Uint16 = ((UINT16)Strtoi (ConnectStr) & (BIT0 | BIT1));
1741 Info |= (Uint16 << 6);
1743 Info = (UINT16)Strtoi (SASSATAStr);
1746 SasEx->DeviceTopology = Info;
1748 return (EFI_DEVICE_PATH_PROTOCOL *)SasEx;
1752 Converts a text device path node to NVM Express Namespace device path structure.
1754 @param TextDeviceNode The input Text device path node.
1756 @return A pointer to the newly-created NVM Express Namespace device path structure.
1760 EFI_DEVICE_PATH_PROTOCOL *
1761 DevPathFromTextNVMe (
1762 IN CHAR16 *TextDeviceNode
1765 CHAR16 *NamespaceIdStr;
1766 CHAR16 *NamespaceUuidStr;
1767 NVME_NAMESPACE_DEVICE_PATH *Nvme;
1771 NamespaceIdStr = GetNextParamStr (&TextDeviceNode);
1772 NamespaceUuidStr = GetNextParamStr (&TextDeviceNode);
1773 Nvme = (NVME_NAMESPACE_DEVICE_PATH *)CreateDeviceNode (
1774 MESSAGING_DEVICE_PATH,
1775 MSG_NVME_NAMESPACE_DP,
1776 (UINT16)sizeof (NVME_NAMESPACE_DEVICE_PATH)
1779 Nvme->NamespaceId = (UINT32)Strtoi (NamespaceIdStr);
1780 Uuid = (UINT8 *)&Nvme->NamespaceUuid;
1782 Index = sizeof (Nvme->NamespaceUuid) / sizeof (UINT8);
1783 while (Index-- != 0) {
1784 Uuid[Index] = (UINT8)StrHexToUintn (SplitStr (&NamespaceUuidStr, '-'));
1787 return (EFI_DEVICE_PATH_PROTOCOL *)Nvme;
1791 Converts a text device path node to UFS device path structure.
1793 @param TextDeviceNode The input Text device path node.
1795 @return A pointer to the newly-created UFS device path structure.
1799 EFI_DEVICE_PATH_PROTOCOL *
1800 DevPathFromTextUfs (
1801 IN CHAR16 *TextDeviceNode
1806 UFS_DEVICE_PATH *Ufs;
1808 PunStr = GetNextParamStr (&TextDeviceNode);
1809 LunStr = GetNextParamStr (&TextDeviceNode);
1810 Ufs = (UFS_DEVICE_PATH *)CreateDeviceNode (
1811 MESSAGING_DEVICE_PATH,
1813 (UINT16)sizeof (UFS_DEVICE_PATH)
1816 Ufs->Pun = (UINT8)Strtoi (PunStr);
1817 Ufs->Lun = (UINT8)Strtoi (LunStr);
1819 return (EFI_DEVICE_PATH_PROTOCOL *)Ufs;
1823 Converts a text device path node to SD (Secure Digital) device path structure.
1825 @param TextDeviceNode The input Text device path node.
1827 @return A pointer to the newly-created SD device path structure.
1831 EFI_DEVICE_PATH_PROTOCOL *
1833 IN CHAR16 *TextDeviceNode
1836 CHAR16 *SlotNumberStr;
1839 SlotNumberStr = GetNextParamStr (&TextDeviceNode);
1840 Sd = (SD_DEVICE_PATH *)CreateDeviceNode (
1841 MESSAGING_DEVICE_PATH,
1843 (UINT16)sizeof (SD_DEVICE_PATH)
1846 Sd->SlotNumber = (UINT8)Strtoi (SlotNumberStr);
1848 return (EFI_DEVICE_PATH_PROTOCOL *)Sd;
1852 Converts a text device path node to EMMC (Embedded MMC) device path structure.
1854 @param TextDeviceNode The input Text device path node.
1856 @return A pointer to the newly-created EMMC device path structure.
1860 EFI_DEVICE_PATH_PROTOCOL *
1861 DevPathFromTextEmmc (
1862 IN CHAR16 *TextDeviceNode
1865 CHAR16 *SlotNumberStr;
1866 EMMC_DEVICE_PATH *Emmc;
1868 SlotNumberStr = GetNextParamStr (&TextDeviceNode);
1869 Emmc = (EMMC_DEVICE_PATH *)CreateDeviceNode (
1870 MESSAGING_DEVICE_PATH,
1872 (UINT16)sizeof (EMMC_DEVICE_PATH)
1875 Emmc->SlotNumber = (UINT8)Strtoi (SlotNumberStr);
1877 return (EFI_DEVICE_PATH_PROTOCOL *)Emmc;
1881 Converts a text device path node to Debug Port device path structure.
1883 @param TextDeviceNode The input Text device path node.
1885 @return A pointer to the newly-created Debug Port device path structure.
1889 EFI_DEVICE_PATH_PROTOCOL *
1890 DevPathFromTextDebugPort (
1891 IN CHAR16 *TextDeviceNode
1894 VENDOR_DEVICE_PATH *Vend;
1896 Vend = (VENDOR_DEVICE_PATH *)CreateDeviceNode (
1897 MESSAGING_DEVICE_PATH,
1899 (UINT16)sizeof (VENDOR_DEVICE_PATH)
1902 CopyGuid (&Vend->Guid, &gEfiDebugPortProtocolGuid);
1904 return (EFI_DEVICE_PATH_PROTOCOL *)Vend;
1908 Converts a text device path node to MAC device path structure.
1910 @param TextDeviceNode The input Text device path node.
1912 @return A pointer to the newly-created MAC device path structure.
1916 EFI_DEVICE_PATH_PROTOCOL *
1917 DevPathFromTextMAC (
1918 IN CHAR16 *TextDeviceNode
1924 MAC_ADDR_DEVICE_PATH *MACDevPath;
1926 AddressStr = GetNextParamStr (&TextDeviceNode);
1927 IfTypeStr = GetNextParamStr (&TextDeviceNode);
1928 MACDevPath = (MAC_ADDR_DEVICE_PATH *)CreateDeviceNode (
1929 MESSAGING_DEVICE_PATH,
1931 (UINT16)sizeof (MAC_ADDR_DEVICE_PATH)
1934 MACDevPath->IfType = (UINT8)Strtoi (IfTypeStr);
1936 Length = sizeof (EFI_MAC_ADDRESS);
1937 if ((MACDevPath->IfType == 0x01) || (MACDevPath->IfType == 0x00)) {
1941 StrHexToBytes (AddressStr, Length * 2, MACDevPath->MacAddress.Addr, Length);
1943 return (EFI_DEVICE_PATH_PROTOCOL *)MACDevPath;
1947 Converts a text format to the network protocol ID.
1949 @param Text String of protocol field.
1951 @return Network protocol ID .
1956 NetworkProtocolFromText (
1960 if (StrCmp (Text, "UDP") == 0) {
1961 return RFC_1700_UDP_PROTOCOL;
1964 if (StrCmp (Text, "TCP") == 0) {
1965 return RFC_1700_TCP_PROTOCOL;
1968 return Strtoi (Text);
1972 Converts a text device path node to IPV4 device path structure.
1974 @param TextDeviceNode The input Text device path node.
1976 @return A pointer to the newly-created IPV4 device path structure.
1980 EFI_DEVICE_PATH_PROTOCOL *
1981 DevPathFromTextIPv4 (
1982 IN CHAR16 *TextDeviceNode
1985 CHAR16 *RemoteIPStr;
1986 CHAR16 *ProtocolStr;
1989 CHAR16 *GatewayIPStr;
1990 CHAR16 *SubnetMaskStr;
1991 IPv4_DEVICE_PATH *IPv4;
1993 RemoteIPStr = GetNextParamStr (&TextDeviceNode);
1994 ProtocolStr = GetNextParamStr (&TextDeviceNode);
1995 TypeStr = GetNextParamStr (&TextDeviceNode);
1996 LocalIPStr = GetNextParamStr (&TextDeviceNode);
1997 GatewayIPStr = GetNextParamStr (&TextDeviceNode);
1998 SubnetMaskStr = GetNextParamStr (&TextDeviceNode);
1999 IPv4 = (IPv4_DEVICE_PATH *)CreateDeviceNode (
2000 MESSAGING_DEVICE_PATH,
2002 (UINT16)sizeof (IPv4_DEVICE_PATH)
2005 StrToIpv4Address (RemoteIPStr, NULL, &IPv4->RemoteIpAddress, NULL);
2006 IPv4->Protocol = (UINT16)NetworkProtocolFromText (ProtocolStr);
2007 if (StrCmp (TypeStr, "Static") == 0) {
2008 IPv4->StaticIpAddress = TRUE;
2010 IPv4->StaticIpAddress = FALSE;
2013 StrToIpv4Address (LocalIPStr, NULL, &IPv4->LocalIpAddress, NULL);
2014 if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*SubnetMaskStr)) {
2015 StrToIpv4Address (GatewayIPStr, NULL, &IPv4->GatewayIpAddress, NULL);
2016 StrToIpv4Address (SubnetMaskStr, NULL, &IPv4->SubnetMask, NULL);
2018 ZeroMem (&IPv4->GatewayIpAddress, sizeof (IPv4->GatewayIpAddress));
2019 ZeroMem (&IPv4->SubnetMask, sizeof (IPv4->SubnetMask));
2022 IPv4->LocalPort = 0;
2023 IPv4->RemotePort = 0;
2025 return (EFI_DEVICE_PATH_PROTOCOL *)IPv4;
2029 Converts a text device path node to IPV6 device path structure.
2031 @param TextDeviceNode The input Text device path node.
2033 @return A pointer to the newly-created IPV6 device path structure.
2037 EFI_DEVICE_PATH_PROTOCOL *
2038 DevPathFromTextIPv6 (
2039 IN CHAR16 *TextDeviceNode
2042 CHAR16 *RemoteIPStr;
2043 CHAR16 *ProtocolStr;
2046 CHAR16 *GatewayIPStr;
2047 CHAR16 *PrefixLengthStr;
2048 IPv6_DEVICE_PATH *IPv6;
2050 RemoteIPStr = GetNextParamStr (&TextDeviceNode);
2051 ProtocolStr = GetNextParamStr (&TextDeviceNode);
2052 TypeStr = GetNextParamStr (&TextDeviceNode);
2053 LocalIPStr = GetNextParamStr (&TextDeviceNode);
2054 PrefixLengthStr = GetNextParamStr (&TextDeviceNode);
2055 GatewayIPStr = GetNextParamStr (&TextDeviceNode);
2056 IPv6 = (IPv6_DEVICE_PATH *)CreateDeviceNode (
2057 MESSAGING_DEVICE_PATH,
2059 (UINT16)sizeof (IPv6_DEVICE_PATH)
2062 StrToIpv6Address (RemoteIPStr, NULL, &IPv6->RemoteIpAddress, NULL);
2063 IPv6->Protocol = (UINT16)NetworkProtocolFromText (ProtocolStr);
2064 if (StrCmp (TypeStr, "Static") == 0) {
2065 IPv6->IpAddressOrigin = 0;
2066 } else if (StrCmp (TypeStr, "StatelessAutoConfigure") == 0) {
2067 IPv6->IpAddressOrigin = 1;
2069 IPv6->IpAddressOrigin = 2;
2072 StrToIpv6Address (LocalIPStr, NULL, &IPv6->LocalIpAddress, NULL);
2073 if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*PrefixLengthStr)) {
2074 StrToIpv6Address (GatewayIPStr, NULL, &IPv6->GatewayIpAddress, NULL);
2075 IPv6->PrefixLength = (UINT8)Strtoi (PrefixLengthStr);
2077 ZeroMem (&IPv6->GatewayIpAddress, sizeof (IPv6->GatewayIpAddress));
2078 IPv6->PrefixLength = 0;
2081 IPv6->LocalPort = 0;
2082 IPv6->RemotePort = 0;
2084 return (EFI_DEVICE_PATH_PROTOCOL *)IPv6;
2088 Converts a text device path node to UART device path structure.
2090 @param TextDeviceNode The input Text device path node.
2092 @return A pointer to the newly-created UART device path structure.
2096 EFI_DEVICE_PATH_PROTOCOL *
2097 DevPathFromTextUart (
2098 IN CHAR16 *TextDeviceNode
2102 CHAR16 *DataBitsStr;
2104 CHAR16 *StopBitsStr;
2105 UART_DEVICE_PATH *Uart;
2107 BaudStr = GetNextParamStr (&TextDeviceNode);
2108 DataBitsStr = GetNextParamStr (&TextDeviceNode);
2109 ParityStr = GetNextParamStr (&TextDeviceNode);
2110 StopBitsStr = GetNextParamStr (&TextDeviceNode);
2111 Uart = (UART_DEVICE_PATH *)CreateDeviceNode (
2112 MESSAGING_DEVICE_PATH,
2114 (UINT16)sizeof (UART_DEVICE_PATH)
2117 if (StrCmp (BaudStr, "DEFAULT") == 0) {
2118 Uart->BaudRate = 115200;
2120 Strtoi64 (BaudStr, &Uart->BaudRate);
2123 Uart->DataBits = (UINT8)((StrCmp (DataBitsStr, "DEFAULT") == 0) ? 8 : Strtoi (DataBitsStr));
2124 switch (*ParityStr) {
2150 Uart->Parity = (UINT8)Strtoi (ParityStr);
2154 if (StrCmp (StopBitsStr, "D") == 0) {
2155 Uart->StopBits = (UINT8)0;
2156 } else if (StrCmp (StopBitsStr, "1") == 0) {
2157 Uart->StopBits = (UINT8)1;
2158 } else if (StrCmp (StopBitsStr, "1.5") == 0) {
2159 Uart->StopBits = (UINT8)2;
2160 } else if (StrCmp (StopBitsStr, "2") == 0) {
2161 Uart->StopBits = (UINT8)3;
2163 Uart->StopBits = (UINT8)Strtoi (StopBitsStr);
2166 return (EFI_DEVICE_PATH_PROTOCOL *)Uart;
2170 Converts a text device path node to USB class device path structure.
2172 @param TextDeviceNode The input Text device path node.
2173 @param UsbClassText A pointer to USB_CLASS_TEXT structure to be integrated to USB Class Text.
2175 @return A pointer to the newly-created USB class device path structure.
2179 EFI_DEVICE_PATH_PROTOCOL *
2180 ConvertFromTextUsbClass (
2181 IN CHAR16 *TextDeviceNode,
2182 IN USB_CLASS_TEXT *UsbClassText
2188 CHAR16 *SubClassStr;
2189 CHAR16 *ProtocolStr;
2190 USB_CLASS_DEVICE_PATH *UsbClass;
2192 UsbClass = (USB_CLASS_DEVICE_PATH *)CreateDeviceNode (
2193 MESSAGING_DEVICE_PATH,
2195 (UINT16)sizeof (USB_CLASS_DEVICE_PATH)
2198 VIDStr = GetNextParamStr (&TextDeviceNode);
2199 PIDStr = GetNextParamStr (&TextDeviceNode);
2200 if (UsbClassText->ClassExist) {
2201 ClassStr = GetNextParamStr (&TextDeviceNode);
2202 if (*ClassStr == '\0') {
2203 UsbClass->DeviceClass = 0xFF;
2205 UsbClass->DeviceClass = (UINT8)Strtoi (ClassStr);
2208 UsbClass->DeviceClass = UsbClassText->Class;
2211 if (UsbClassText->SubClassExist) {
2212 SubClassStr = GetNextParamStr (&TextDeviceNode);
2213 if (*SubClassStr == '\0') {
2214 UsbClass->DeviceSubClass = 0xFF;
2216 UsbClass->DeviceSubClass = (UINT8)Strtoi (SubClassStr);
2219 UsbClass->DeviceSubClass = UsbClassText->SubClass;
2222 ProtocolStr = GetNextParamStr (&TextDeviceNode);
2224 if (*VIDStr == '\0') {
2225 UsbClass->VendorId = 0xFFFF;
2227 UsbClass->VendorId = (UINT16)Strtoi (VIDStr);
2230 if (*PIDStr == '\0') {
2231 UsbClass->ProductId = 0xFFFF;
2233 UsbClass->ProductId = (UINT16)Strtoi (PIDStr);
2236 if (*ProtocolStr == '\0') {
2237 UsbClass->DeviceProtocol = 0xFF;
2239 UsbClass->DeviceProtocol = (UINT8)Strtoi (ProtocolStr);
2242 return (EFI_DEVICE_PATH_PROTOCOL *)UsbClass;
2246 Converts a text device path node to USB class device path structure.
2248 @param TextDeviceNode The input Text device path node.
2250 @return A pointer to the newly-created USB class device path structure.
2254 EFI_DEVICE_PATH_PROTOCOL *
2255 DevPathFromTextUsbClass (
2256 IN CHAR16 *TextDeviceNode
2259 USB_CLASS_TEXT UsbClassText;
2261 UsbClassText.ClassExist = TRUE;
2262 UsbClassText.SubClassExist = TRUE;
2264 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2268 Converts a text device path node to USB audio device path structure.
2270 @param TextDeviceNode The input Text device path node.
2272 @return A pointer to the newly-created USB audio device path structure.
2276 EFI_DEVICE_PATH_PROTOCOL *
2277 DevPathFromTextUsbAudio (
2278 IN CHAR16 *TextDeviceNode
2281 USB_CLASS_TEXT UsbClassText;
2283 UsbClassText.ClassExist = FALSE;
2284 UsbClassText.Class = USB_CLASS_AUDIO;
2285 UsbClassText.SubClassExist = TRUE;
2287 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2291 Converts a text device path node to USB CDC Control device path structure.
2293 @param TextDeviceNode The input Text device path node.
2295 @return A pointer to the newly-created USB CDC Control device path structure.
2299 EFI_DEVICE_PATH_PROTOCOL *
2300 DevPathFromTextUsbCDCControl (
2301 IN CHAR16 *TextDeviceNode
2304 USB_CLASS_TEXT UsbClassText;
2306 UsbClassText.ClassExist = FALSE;
2307 UsbClassText.Class = USB_CLASS_CDCCONTROL;
2308 UsbClassText.SubClassExist = TRUE;
2310 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2314 Converts a text device path node to USB HID device path structure.
2316 @param TextDeviceNode The input Text device path node.
2318 @return A pointer to the newly-created USB HID device path structure.
2322 EFI_DEVICE_PATH_PROTOCOL *
2323 DevPathFromTextUsbHID (
2324 IN CHAR16 *TextDeviceNode
2327 USB_CLASS_TEXT UsbClassText;
2329 UsbClassText.ClassExist = FALSE;
2330 UsbClassText.Class = USB_CLASS_HID;
2331 UsbClassText.SubClassExist = TRUE;
2333 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2337 Converts a text device path node to USB Image device path structure.
2339 @param TextDeviceNode The input Text device path node.
2341 @return A pointer to the newly-created USB Image device path structure.
2345 EFI_DEVICE_PATH_PROTOCOL *
2346 DevPathFromTextUsbImage (
2347 IN CHAR16 *TextDeviceNode
2350 USB_CLASS_TEXT UsbClassText;
2352 UsbClassText.ClassExist = FALSE;
2353 UsbClassText.Class = USB_CLASS_IMAGE;
2354 UsbClassText.SubClassExist = TRUE;
2356 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2360 Converts a text device path node to USB Print device path structure.
2362 @param TextDeviceNode The input Text device path node.
2364 @return A pointer to the newly-created USB Print device path structure.
2368 EFI_DEVICE_PATH_PROTOCOL *
2369 DevPathFromTextUsbPrinter (
2370 IN CHAR16 *TextDeviceNode
2373 USB_CLASS_TEXT UsbClassText;
2375 UsbClassText.ClassExist = FALSE;
2376 UsbClassText.Class = USB_CLASS_PRINTER;
2377 UsbClassText.SubClassExist = TRUE;
2379 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2383 Converts a text device path node to USB mass storage device path structure.
2385 @param TextDeviceNode The input Text device path node.
2387 @return A pointer to the newly-created USB mass storage device path structure.
2391 EFI_DEVICE_PATH_PROTOCOL *
2392 DevPathFromTextUsbMassStorage (
2393 IN CHAR16 *TextDeviceNode
2396 USB_CLASS_TEXT UsbClassText;
2398 UsbClassText.ClassExist = FALSE;
2399 UsbClassText.Class = USB_CLASS_MASS_STORAGE;
2400 UsbClassText.SubClassExist = TRUE;
2402 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2406 Converts a text device path node to USB HUB device path structure.
2408 @param TextDeviceNode The input Text device path node.
2410 @return A pointer to the newly-created USB HUB device path structure.
2414 EFI_DEVICE_PATH_PROTOCOL *
2415 DevPathFromTextUsbHub (
2416 IN CHAR16 *TextDeviceNode
2419 USB_CLASS_TEXT UsbClassText;
2421 UsbClassText.ClassExist = FALSE;
2422 UsbClassText.Class = USB_CLASS_HUB;
2423 UsbClassText.SubClassExist = TRUE;
2425 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2429 Converts a text device path node to USB CDC data device path structure.
2431 @param TextDeviceNode The input Text device path node.
2433 @return A pointer to the newly-created USB CDC data device path structure.
2437 EFI_DEVICE_PATH_PROTOCOL *
2438 DevPathFromTextUsbCDCData (
2439 IN CHAR16 *TextDeviceNode
2442 USB_CLASS_TEXT UsbClassText;
2444 UsbClassText.ClassExist = FALSE;
2445 UsbClassText.Class = USB_CLASS_CDCDATA;
2446 UsbClassText.SubClassExist = TRUE;
2448 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2452 Converts a text device path node to USB smart card device path structure.
2454 @param TextDeviceNode The input Text device path node.
2456 @return A pointer to the newly-created USB smart card device path structure.
2460 EFI_DEVICE_PATH_PROTOCOL *
2461 DevPathFromTextUsbSmartCard (
2462 IN CHAR16 *TextDeviceNode
2465 USB_CLASS_TEXT UsbClassText;
2467 UsbClassText.ClassExist = FALSE;
2468 UsbClassText.Class = USB_CLASS_SMART_CARD;
2469 UsbClassText.SubClassExist = TRUE;
2471 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2475 Converts a text device path node to USB video device path structure.
2477 @param TextDeviceNode The input Text device path node.
2479 @return A pointer to the newly-created USB video device path structure.
2483 EFI_DEVICE_PATH_PROTOCOL *
2484 DevPathFromTextUsbVideo (
2485 IN CHAR16 *TextDeviceNode
2488 USB_CLASS_TEXT UsbClassText;
2490 UsbClassText.ClassExist = FALSE;
2491 UsbClassText.Class = USB_CLASS_VIDEO;
2492 UsbClassText.SubClassExist = TRUE;
2494 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2498 Converts a text device path node to USB diagnostic device path structure.
2500 @param TextDeviceNode The input Text device path node.
2502 @return A pointer to the newly-created USB diagnostic device path structure.
2506 EFI_DEVICE_PATH_PROTOCOL *
2507 DevPathFromTextUsbDiagnostic (
2508 IN CHAR16 *TextDeviceNode
2511 USB_CLASS_TEXT UsbClassText;
2513 UsbClassText.ClassExist = FALSE;
2514 UsbClassText.Class = USB_CLASS_DIAGNOSTIC;
2515 UsbClassText.SubClassExist = TRUE;
2517 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2521 Converts a text device path node to USB wireless device path structure.
2523 @param TextDeviceNode The input Text device path node.
2525 @return A pointer to the newly-created USB wireless device path structure.
2529 EFI_DEVICE_PATH_PROTOCOL *
2530 DevPathFromTextUsbWireless (
2531 IN CHAR16 *TextDeviceNode
2534 USB_CLASS_TEXT UsbClassText;
2536 UsbClassText.ClassExist = FALSE;
2537 UsbClassText.Class = USB_CLASS_WIRELESS;
2538 UsbClassText.SubClassExist = TRUE;
2540 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2544 Converts a text device path node to USB device firmware update device path structure.
2546 @param TextDeviceNode The input Text device path node.
2548 @return A pointer to the newly-created USB device firmware update device path structure.
2552 EFI_DEVICE_PATH_PROTOCOL *
2553 DevPathFromTextUsbDeviceFirmwareUpdate (
2554 IN CHAR16 *TextDeviceNode
2557 USB_CLASS_TEXT UsbClassText;
2559 UsbClassText.ClassExist = FALSE;
2560 UsbClassText.Class = USB_CLASS_RESERVE;
2561 UsbClassText.SubClassExist = FALSE;
2562 UsbClassText.SubClass = USB_SUBCLASS_FW_UPDATE;
2564 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2568 Converts a text device path node to USB IRDA bridge device path structure.
2570 @param TextDeviceNode The input Text device path node.
2572 @return A pointer to the newly-created USB IRDA bridge device path structure.
2576 EFI_DEVICE_PATH_PROTOCOL *
2577 DevPathFromTextUsbIrdaBridge (
2578 IN CHAR16 *TextDeviceNode
2581 USB_CLASS_TEXT UsbClassText;
2583 UsbClassText.ClassExist = FALSE;
2584 UsbClassText.Class = USB_CLASS_RESERVE;
2585 UsbClassText.SubClassExist = FALSE;
2586 UsbClassText.SubClass = USB_SUBCLASS_IRDA_BRIDGE;
2588 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2592 Converts a text device path node to USB text and measurement device path structure.
2594 @param TextDeviceNode The input Text device path node.
2596 @return A pointer to the newly-created USB text and measurement device path structure.
2600 EFI_DEVICE_PATH_PROTOCOL *
2601 DevPathFromTextUsbTestAndMeasurement (
2602 IN CHAR16 *TextDeviceNode
2605 USB_CLASS_TEXT UsbClassText;
2607 UsbClassText.ClassExist = FALSE;
2608 UsbClassText.Class = USB_CLASS_RESERVE;
2609 UsbClassText.SubClassExist = FALSE;
2610 UsbClassText.SubClass = USB_SUBCLASS_TEST;
2612 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2616 Converts a text device path node to USB WWID device path structure.
2618 @param TextDeviceNode The input Text device path node.
2620 @return A pointer to the newly-created USB WWID device path structure.
2624 EFI_DEVICE_PATH_PROTOCOL *
2625 DevPathFromTextUsbWwid (
2626 IN CHAR16 *TextDeviceNode
2631 CHAR16 *InterfaceNumStr;
2632 CHAR16 *SerialNumberStr;
2633 USB_WWID_DEVICE_PATH *UsbWwid;
2634 UINTN SerialNumberStrLen;
2636 VIDStr = GetNextParamStr (&TextDeviceNode);
2637 PIDStr = GetNextParamStr (&TextDeviceNode);
2638 InterfaceNumStr = GetNextParamStr (&TextDeviceNode);
2639 SerialNumberStr = GetNextParamStr (&TextDeviceNode);
2640 SerialNumberStrLen = StrLen (SerialNumberStr);
2641 if ((SerialNumberStrLen >= 2) &&
2642 (SerialNumberStr[0] == '\"') &&
2643 (SerialNumberStr[SerialNumberStrLen - 1] == '\"')
2646 SerialNumberStr[SerialNumberStrLen - 1] = '\0';
2648 SerialNumberStrLen -= 2;
2651 UsbWwid = (USB_WWID_DEVICE_PATH *)CreateDeviceNode (
2652 MESSAGING_DEVICE_PATH,
2654 (UINT16)(sizeof (USB_WWID_DEVICE_PATH) + SerialNumberStrLen * sizeof (CHAR16))
2656 UsbWwid->VendorId = (UINT16)Strtoi (VIDStr);
2657 UsbWwid->ProductId = (UINT16)Strtoi (PIDStr);
2658 UsbWwid->InterfaceNumber = (UINT16)Strtoi (InterfaceNumStr);
2661 // There is no memory allocated in UsbWwid for the '\0' in SerialNumberStr.
2662 // Therefore, the '\0' will not be copied.
2665 (UINT8 *)UsbWwid + sizeof (USB_WWID_DEVICE_PATH),
2667 SerialNumberStrLen * sizeof (CHAR16)
2670 return (EFI_DEVICE_PATH_PROTOCOL *)UsbWwid;
2674 Converts a text device path node to Logic Unit device path structure.
2676 @param TextDeviceNode The input Text device path node.
2678 @return A pointer to the newly-created Logic Unit device path structure.
2682 EFI_DEVICE_PATH_PROTOCOL *
2683 DevPathFromTextUnit (
2684 IN CHAR16 *TextDeviceNode
2688 DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
2690 LunStr = GetNextParamStr (&TextDeviceNode);
2691 LogicalUnit = (DEVICE_LOGICAL_UNIT_DEVICE_PATH *)CreateDeviceNode (
2692 MESSAGING_DEVICE_PATH,
2693 MSG_DEVICE_LOGICAL_UNIT_DP,
2694 (UINT16)sizeof (DEVICE_LOGICAL_UNIT_DEVICE_PATH)
2697 LogicalUnit->Lun = (UINT8)Strtoi (LunStr);
2699 return (EFI_DEVICE_PATH_PROTOCOL *)LogicalUnit;
2703 Converts a text device path node to iSCSI device path structure.
2705 @param TextDeviceNode The input Text device path node.
2707 @return A pointer to the newly-created iSCSI device path structure.
2711 EFI_DEVICE_PATH_PROTOCOL *
2712 DevPathFromTextiSCSI (
2713 IN CHAR16 *TextDeviceNode
2718 CHAR16 *PortalGroupStr;
2720 CHAR16 *HeaderDigestStr;
2721 CHAR16 *DataDigestStr;
2722 CHAR16 *AuthenticationStr;
2723 CHAR16 *ProtocolStr;
2725 ISCSI_DEVICE_PATH_WITH_NAME *ISCSIDevPath;
2728 NameStr = GetNextParamStr (&TextDeviceNode);
2729 PortalGroupStr = GetNextParamStr (&TextDeviceNode);
2730 LunStr = GetNextParamStr (&TextDeviceNode);
2731 HeaderDigestStr = GetNextParamStr (&TextDeviceNode);
2732 DataDigestStr = GetNextParamStr (&TextDeviceNode);
2733 AuthenticationStr = GetNextParamStr (&TextDeviceNode);
2734 ProtocolStr = GetNextParamStr (&TextDeviceNode);
2735 ISCSIDevPath = (ISCSI_DEVICE_PATH_WITH_NAME *)CreateDeviceNode (
2736 MESSAGING_DEVICE_PATH,
2738 (UINT16)(sizeof (ISCSI_DEVICE_PATH_WITH_NAME) + StrLen (NameStr))
2741 AsciiStr = ISCSIDevPath->TargetName;
2742 StrToAscii (NameStr, &AsciiStr);
2744 ISCSIDevPath->TargetPortalGroupTag = (UINT16)Strtoi (PortalGroupStr);
2745 Strtoi64 (LunStr, &Lun);
2746 WriteUnaligned64 ((UINT64 *)&ISCSIDevPath->Lun, SwapBytes64 (Lun));
2749 if (StrCmp (HeaderDigestStr, "CRC32C") == 0) {
2753 if (StrCmp (DataDigestStr, "CRC32C") == 0) {
2757 if (StrCmp (AuthenticationStr, "None") == 0) {
2761 if (StrCmp (AuthenticationStr, "CHAP_UNI") == 0) {
2765 ISCSIDevPath->LoginOption = (UINT16)Options;
2767 if (IS_NULL (*ProtocolStr) || (StrCmp (ProtocolStr, "TCP") == 0)) {
2768 ISCSIDevPath->NetworkProtocol = 0;
2771 // Undefined and reserved.
2773 ISCSIDevPath->NetworkProtocol = 1;
2776 return (EFI_DEVICE_PATH_PROTOCOL *)ISCSIDevPath;
2780 Converts a text device path node to VLAN device path structure.
2782 @param TextDeviceNode The input Text device path node.
2784 @return A pointer to the newly-created VLAN device path structure.
2788 EFI_DEVICE_PATH_PROTOCOL *
2789 DevPathFromTextVlan (
2790 IN CHAR16 *TextDeviceNode
2794 VLAN_DEVICE_PATH *Vlan;
2796 VlanStr = GetNextParamStr (&TextDeviceNode);
2797 Vlan = (VLAN_DEVICE_PATH *)CreateDeviceNode (
2798 MESSAGING_DEVICE_PATH,
2800 (UINT16)sizeof (VLAN_DEVICE_PATH)
2803 Vlan->VlanId = (UINT16)Strtoi (VlanStr);
2805 return (EFI_DEVICE_PATH_PROTOCOL *)Vlan;
2809 Converts a text device path node to Bluetooth device path structure.
2811 @param TextDeviceNode The input Text device path node.
2813 @return A pointer to the newly-created Bluetooth device path structure.
2817 EFI_DEVICE_PATH_PROTOCOL *
2818 DevPathFromTextBluetooth (
2819 IN CHAR16 *TextDeviceNode
2822 CHAR16 *BluetoothStr;
2823 BLUETOOTH_DEVICE_PATH *BluetoothDp;
2825 BluetoothStr = GetNextParamStr (&TextDeviceNode);
2826 BluetoothDp = (BLUETOOTH_DEVICE_PATH *)CreateDeviceNode (
2827 MESSAGING_DEVICE_PATH,
2829 (UINT16)sizeof (BLUETOOTH_DEVICE_PATH)
2833 sizeof (BLUETOOTH_ADDRESS) * 2,
2834 BluetoothDp->BD_ADDR.Address,
2835 sizeof (BLUETOOTH_ADDRESS)
2837 return (EFI_DEVICE_PATH_PROTOCOL *)BluetoothDp;
2841 Converts a text device path node to Wi-Fi device path structure.
2843 @param TextDeviceNode The input Text device path node.
2845 @return A pointer to the newly-created Wi-Fi device path structure.
2849 EFI_DEVICE_PATH_PROTOCOL *
2850 DevPathFromTextWiFi (
2851 IN CHAR16 *TextDeviceNode
2857 WIFI_DEVICE_PATH *WiFiDp;
2859 SSIdStr = GetNextParamStr (&TextDeviceNode);
2860 WiFiDp = (WIFI_DEVICE_PATH *)CreateDeviceNode (
2861 MESSAGING_DEVICE_PATH,
2863 (UINT16)sizeof (WIFI_DEVICE_PATH)
2866 if (NULL != SSIdStr) {
2867 DataLen = StrLen (SSIdStr);
2868 if (StrLen (SSIdStr) > 32) {
2873 UnicodeStrToAsciiStrS (SSIdStr, AsciiStr, sizeof (AsciiStr));
2874 CopyMem (WiFiDp->SSId, AsciiStr, DataLen);
2877 return (EFI_DEVICE_PATH_PROTOCOL *)WiFiDp;
2881 Converts a text device path node to Bluetooth LE device path structure.
2883 @param TextDeviceNode The input Text device path node.
2885 @return A pointer to the newly-created Bluetooth LE device path structure.
2889 EFI_DEVICE_PATH_PROTOCOL *
2890 DevPathFromTextBluetoothLE (
2891 IN CHAR16 *TextDeviceNode
2894 CHAR16 *BluetoothLeAddrStr;
2895 CHAR16 *BluetoothLeAddrTypeStr;
2896 BLUETOOTH_LE_DEVICE_PATH *BluetoothLeDp;
2898 BluetoothLeAddrStr = GetNextParamStr (&TextDeviceNode);
2899 BluetoothLeAddrTypeStr = GetNextParamStr (&TextDeviceNode);
2900 BluetoothLeDp = (BLUETOOTH_LE_DEVICE_PATH *)CreateDeviceNode (
2901 MESSAGING_DEVICE_PATH,
2902 MSG_BLUETOOTH_LE_DP,
2903 (UINT16)sizeof (BLUETOOTH_LE_DEVICE_PATH)
2906 BluetoothLeDp->Address.Type = (UINT8)Strtoi (BluetoothLeAddrTypeStr);
2909 sizeof (BluetoothLeDp->Address.Address) * 2,
2910 BluetoothLeDp->Address.Address,
2911 sizeof (BluetoothLeDp->Address.Address)
2913 return (EFI_DEVICE_PATH_PROTOCOL *)BluetoothLeDp;
2917 Converts a text device path node to DNS device path structure.
2919 @param TextDeviceNode The input Text device path node.
2921 @return A pointer to the newly-created DNS device path structure.
2925 EFI_DEVICE_PATH_PROTOCOL *
2926 DevPathFromTextDns (
2927 IN CHAR16 *TextDeviceNode
2930 CHAR16 *DeviceNodeStr;
2931 CHAR16 *DeviceNodeStrPtr;
2932 UINT32 DnsServerIpCount;
2933 UINT16 DnsDeviceNodeLength;
2934 DNS_DEVICE_PATH *DnsDeviceNode;
2935 UINT32 DnsServerIpIndex;
2936 CHAR16 *DnsServerIp;
2939 // Count the DNS server address number.
2941 DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);
2942 if (DeviceNodeStr == NULL) {
2946 DeviceNodeStrPtr = DeviceNodeStr;
2948 DnsServerIpCount = 0;
2949 while (DeviceNodeStrPtr != NULL && *DeviceNodeStrPtr != '\0') {
2950 GetNextParamStr (&DeviceNodeStrPtr);
2954 FreePool (DeviceNodeStr);
2955 DeviceNodeStr = NULL;
2958 // One or more instances of the DNS server address in EFI_IP_ADDRESS,
2959 // otherwise, NULL will be returned.
2961 if (DnsServerIpCount == 0) {
2966 // Create the DNS DeviceNode.
2968 DnsDeviceNodeLength = (UINT16)(sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (UINT8) + DnsServerIpCount * sizeof (EFI_IP_ADDRESS));
2969 DnsDeviceNode = (DNS_DEVICE_PATH *)CreateDeviceNode (
2970 MESSAGING_DEVICE_PATH,
2974 if (DnsDeviceNode == NULL) {
2979 // Confirm the DNS server address is IPv4 or IPv6 type.
2981 DeviceNodeStrPtr = TextDeviceNode;
2982 while (!IS_NULL (*DeviceNodeStrPtr)) {
2983 if (*DeviceNodeStrPtr == '.') {
2984 DnsDeviceNode->IsIPv6 = 0x00;
2988 if (*DeviceNodeStrPtr == ':') {
2989 DnsDeviceNode->IsIPv6 = 0x01;
2996 for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; DnsServerIpIndex++) {
2997 DnsServerIp = GetNextParamStr (&TextDeviceNode);
2998 if (DnsDeviceNode->IsIPv6 == 0x00) {
2999 StrToIpv4Address (DnsServerIp, NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v4), NULL);
3001 StrToIpv6Address (DnsServerIp, NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v6), NULL);
3005 return (EFI_DEVICE_PATH_PROTOCOL *)DnsDeviceNode;
3009 Converts a text device path node to URI device path structure.
3011 @param TextDeviceNode The input Text device path node.
3013 @return A pointer to the newly-created URI device path structure.
3017 EFI_DEVICE_PATH_PROTOCOL *
3018 DevPathFromTextUri (
3019 IN CHAR16 *TextDeviceNode
3024 URI_DEVICE_PATH *Uri;
3026 UriStr = GetNextParamStr (&TextDeviceNode);
3027 UriLength = StrnLenS (UriStr, MAX_UINT16 - sizeof (URI_DEVICE_PATH));
3028 Uri = (URI_DEVICE_PATH *)CreateDeviceNode (
3029 MESSAGING_DEVICE_PATH,
3031 (UINT16)(sizeof (URI_DEVICE_PATH) + UriLength)
3034 while (UriLength-- != 0) {
3035 Uri->Uri[UriLength] = (CHAR8)UriStr[UriLength];
3038 return (EFI_DEVICE_PATH_PROTOCOL *)Uri;
3042 Converts a media text device path node to media device path structure.
3044 @param TextDeviceNode The input Text device path node.
3046 @return A pointer to media device path structure.
3050 EFI_DEVICE_PATH_PROTOCOL *
3051 DevPathFromTextMediaPath (
3052 IN CHAR16 *TextDeviceNode
3055 return DevPathFromTextGenericPath (MEDIA_DEVICE_PATH, TextDeviceNode);
3059 Converts a text device path node to HD device path structure.
3061 @param TextDeviceNode The input Text device path node.
3063 @return A pointer to the newly-created HD device path structure.
3067 EFI_DEVICE_PATH_PROTOCOL *
3069 IN CHAR16 *TextDeviceNode
3072 CHAR16 *PartitionStr;
3074 CHAR16 *SignatureStr;
3078 HARDDRIVE_DEVICE_PATH *Hd;
3080 PartitionStr = GetNextParamStr (&TextDeviceNode);
3081 TypeStr = GetNextParamStr (&TextDeviceNode);
3082 SignatureStr = GetNextParamStr (&TextDeviceNode);
3083 StartStr = GetNextParamStr (&TextDeviceNode);
3084 SizeStr = GetNextParamStr (&TextDeviceNode);
3085 Hd = (HARDDRIVE_DEVICE_PATH *)CreateDeviceNode (
3088 (UINT16)sizeof (HARDDRIVE_DEVICE_PATH)
3091 Hd->PartitionNumber = (UINT32)Strtoi (PartitionStr);
3093 ZeroMem (Hd->Signature, 16);
3094 Hd->MBRType = (UINT8)0;
3096 if (StrCmp (TypeStr, "MBR") == 0) {
3097 Hd->SignatureType = SIGNATURE_TYPE_MBR;
3100 Signature32 = (UINT32)Strtoi (SignatureStr);
3101 CopyMem (Hd->Signature, &Signature32, sizeof (UINT32));
3102 } else if (StrCmp (TypeStr, "GPT") == 0) {
3103 Hd->SignatureType = SIGNATURE_TYPE_GUID;
3106 StrToGuid (SignatureStr, (EFI_GUID *)Hd->Signature);
3108 Hd->SignatureType = (UINT8)Strtoi (TypeStr);
3111 Strtoi64 (StartStr, &Hd->PartitionStart);
3112 Strtoi64 (SizeStr, &Hd->PartitionSize);
3114 return (EFI_DEVICE_PATH_PROTOCOL *)Hd;
3118 Converts a text device path node to CDROM device path structure.
3120 @param TextDeviceNode The input Text device path node.
3122 @return A pointer to the newly-created CDROM device path structure.
3126 EFI_DEVICE_PATH_PROTOCOL *
3127 DevPathFromTextCDROM (
3128 IN CHAR16 *TextDeviceNode
3134 CDROM_DEVICE_PATH *CDROMDevPath;
3136 EntryStr = GetNextParamStr (&TextDeviceNode);
3137 StartStr = GetNextParamStr (&TextDeviceNode);
3138 SizeStr = GetNextParamStr (&TextDeviceNode);
3139 CDROMDevPath = (CDROM_DEVICE_PATH *)CreateDeviceNode (
3142 (UINT16)sizeof (CDROM_DEVICE_PATH)
3145 CDROMDevPath->BootEntry = (UINT32)Strtoi (EntryStr);
3146 Strtoi64 (StartStr, &CDROMDevPath->PartitionStart);
3147 Strtoi64 (SizeStr, &CDROMDevPath->PartitionSize);
3149 return (EFI_DEVICE_PATH_PROTOCOL *)CDROMDevPath;
3153 Converts a text device path node to Vendor-defined media device path structure.
3155 @param TextDeviceNode The input Text device path node.
3157 @return A pointer to the newly-created Vendor-defined media device path structure.
3161 EFI_DEVICE_PATH_PROTOCOL *
3162 DevPathFromTextVenMedia (
3163 IN CHAR16 *TextDeviceNode
3166 return ConvertFromTextVendor (
3174 Converts a text device path node to File device path structure.
3176 @param TextDeviceNode The input Text device path node.
3178 @return A pointer to the newly-created File device path structure.
3182 EFI_DEVICE_PATH_PROTOCOL *
3183 DevPathFromTextFilePath (
3184 IN CHAR16 *TextDeviceNode
3187 FILEPATH_DEVICE_PATH *File;
3190 File = (FILEPATH_DEVICE_PATH *)CreateDeviceNode (
3193 (UINT16)(sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) * 2)
3196 StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode);
3198 size_t len = (sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) * 2);
3200 File = (FILEPATH_DEVICE_PATH *)CreateDeviceNode (
3206 utf8_to_ucs2(TextDeviceNode, &v, &len);
3209 return (EFI_DEVICE_PATH_PROTOCOL *)File;
3213 Converts a text device path node to Media protocol device path structure.
3215 @param TextDeviceNode The input Text device path node.
3217 @return A pointer to the newly-created Media protocol device path structure.
3221 EFI_DEVICE_PATH_PROTOCOL *
3222 DevPathFromTextMedia (
3223 IN CHAR16 *TextDeviceNode
3227 MEDIA_PROTOCOL_DEVICE_PATH *Media;
3229 GuidStr = GetNextParamStr (&TextDeviceNode);
3230 Media = (MEDIA_PROTOCOL_DEVICE_PATH *)CreateDeviceNode (
3233 (UINT16)sizeof (MEDIA_PROTOCOL_DEVICE_PATH)
3236 StrToGuid (GuidStr, &Media->Protocol);
3238 return (EFI_DEVICE_PATH_PROTOCOL *)Media;
3242 Converts a text device path node to firmware volume device path structure.
3244 @param TextDeviceNode The input Text device path node.
3246 @return A pointer to the newly-created firmware volume device path structure.
3250 EFI_DEVICE_PATH_PROTOCOL *
3252 IN CHAR16 *TextDeviceNode
3256 MEDIA_FW_VOL_DEVICE_PATH *Fv;
3258 GuidStr = GetNextParamStr (&TextDeviceNode);
3259 Fv = (MEDIA_FW_VOL_DEVICE_PATH *)CreateDeviceNode (
3261 MEDIA_PIWG_FW_VOL_DP,
3262 (UINT16)sizeof (MEDIA_FW_VOL_DEVICE_PATH)
3265 StrToGuid (GuidStr, &Fv->FvName);
3267 return (EFI_DEVICE_PATH_PROTOCOL *)Fv;
3271 Converts a text device path node to firmware file device path structure.
3273 @param TextDeviceNode The input Text device path node.
3275 @return A pointer to the newly-created firmware file device path structure.
3279 EFI_DEVICE_PATH_PROTOCOL *
3280 DevPathFromTextFvFile (
3281 IN CHAR16 *TextDeviceNode
3285 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFile;
3287 GuidStr = GetNextParamStr (&TextDeviceNode);
3288 FvFile = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)CreateDeviceNode (
3290 MEDIA_PIWG_FW_FILE_DP,
3291 (UINT16)sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH)
3294 StrToGuid (GuidStr, &FvFile->FvFileName);
3296 return (EFI_DEVICE_PATH_PROTOCOL *)FvFile;
3300 Converts a text device path node to text relative offset device path structure.
3302 @param TextDeviceNode The input Text device path node.
3304 @return A pointer to the newly-created Text device path structure.
3308 EFI_DEVICE_PATH_PROTOCOL *
3309 DevPathFromTextRelativeOffsetRange (
3310 IN CHAR16 *TextDeviceNode
3313 CHAR16 *StartingOffsetStr;
3314 CHAR16 *EndingOffsetStr;
3315 MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset;
3317 StartingOffsetStr = GetNextParamStr (&TextDeviceNode);
3318 EndingOffsetStr = GetNextParamStr (&TextDeviceNode);
3319 Offset = (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *)CreateDeviceNode (
3321 MEDIA_RELATIVE_OFFSET_RANGE_DP,
3322 (UINT16)sizeof (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH)
3325 Strtoi64 (StartingOffsetStr, &Offset->StartingOffset);
3326 Strtoi64 (EndingOffsetStr, &Offset->EndingOffset);
3328 return (EFI_DEVICE_PATH_PROTOCOL *)Offset;
3332 Converts a text device path node to text ram disk device path structure.
3334 @param TextDeviceNode The input Text device path node.
3336 @return A pointer to the newly-created Text device path structure.
3340 EFI_DEVICE_PATH_PROTOCOL *
3341 DevPathFromTextRamDisk (
3342 IN CHAR16 *TextDeviceNode
3345 CHAR16 *StartingAddrStr;
3346 CHAR16 *EndingAddrStr;
3347 CHAR16 *TypeGuidStr;
3348 CHAR16 *InstanceStr;
3349 MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
3350 UINT64 StartingAddr;
3353 StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3354 EndingAddrStr = GetNextParamStr (&TextDeviceNode);
3355 InstanceStr = GetNextParamStr (&TextDeviceNode);
3356 TypeGuidStr = GetNextParamStr (&TextDeviceNode);
3357 RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *)CreateDeviceNode (
3360 (UINT16)sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3363 Strtoi64 (StartingAddrStr, &StartingAddr);
3364 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
3365 Strtoi64 (EndingAddrStr, &EndingAddr);
3366 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
3367 RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
3368 StrToGuid (TypeGuidStr, &RamDisk->TypeGuid);
3370 return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
3374 Converts a text device path node to text virtual disk device path structure.
3376 @param TextDeviceNode The input Text device path node.
3378 @return A pointer to the newly-created Text device path structure.
3382 EFI_DEVICE_PATH_PROTOCOL *
3383 DevPathFromTextVirtualDisk (
3384 IN CHAR16 *TextDeviceNode
3387 CHAR16 *StartingAddrStr;
3388 CHAR16 *EndingAddrStr;
3389 CHAR16 *InstanceStr;
3390 MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
3391 UINT64 StartingAddr;
3394 StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3395 EndingAddrStr = GetNextParamStr (&TextDeviceNode);
3396 InstanceStr = GetNextParamStr (&TextDeviceNode);
3398 RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *)CreateDeviceNode (
3401 (UINT16)sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3404 Strtoi64 (StartingAddrStr, &StartingAddr);
3405 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
3406 Strtoi64 (EndingAddrStr, &EndingAddr);
3407 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
3408 RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
3409 CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid);
3411 return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
3415 Converts a text device path node to text virtual cd device path structure.
3417 @param TextDeviceNode The input Text device path node.
3419 @return A pointer to the newly-created Text device path structure.
3423 EFI_DEVICE_PATH_PROTOCOL *
3424 DevPathFromTextVirtualCd (
3425 IN CHAR16 *TextDeviceNode
3428 CHAR16 *StartingAddrStr;
3429 CHAR16 *EndingAddrStr;
3430 CHAR16 *InstanceStr;
3431 MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
3432 UINT64 StartingAddr;
3435 StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3436 EndingAddrStr = GetNextParamStr (&TextDeviceNode);
3437 InstanceStr = GetNextParamStr (&TextDeviceNode);
3439 RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *)CreateDeviceNode (
3442 (UINT16)sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3445 Strtoi64 (StartingAddrStr, &StartingAddr);
3446 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
3447 Strtoi64 (EndingAddrStr, &EndingAddr);
3448 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
3449 RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
3450 CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid);
3452 return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
3456 Converts a text device path node to text persistent virtual disk device path structure.
3458 @param TextDeviceNode The input Text device path node.
3460 @return A pointer to the newly-created Text device path structure.
3464 EFI_DEVICE_PATH_PROTOCOL *
3465 DevPathFromTextPersistentVirtualDisk (
3466 IN CHAR16 *TextDeviceNode
3469 CHAR16 *StartingAddrStr;
3470 CHAR16 *EndingAddrStr;
3471 CHAR16 *InstanceStr;
3472 MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
3473 UINT64 StartingAddr;
3476 StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3477 EndingAddrStr = GetNextParamStr (&TextDeviceNode);
3478 InstanceStr = GetNextParamStr (&TextDeviceNode);
3480 RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *)CreateDeviceNode (
3483 (UINT16)sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3486 Strtoi64 (StartingAddrStr, &StartingAddr);
3487 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
3488 Strtoi64 (EndingAddrStr, &EndingAddr);
3489 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
3490 RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
3491 CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid);
3493 return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
3497 Converts a text device path node to text persistent virtual cd device path structure.
3499 @param TextDeviceNode The input Text device path node.
3501 @return A pointer to the newly-created Text device path structure.
3505 EFI_DEVICE_PATH_PROTOCOL *
3506 DevPathFromTextPersistentVirtualCd (
3507 IN CHAR16 *TextDeviceNode
3510 CHAR16 *StartingAddrStr;
3511 CHAR16 *EndingAddrStr;
3512 CHAR16 *InstanceStr;
3513 MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
3514 UINT64 StartingAddr;
3517 StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3518 EndingAddrStr = GetNextParamStr (&TextDeviceNode);
3519 InstanceStr = GetNextParamStr (&TextDeviceNode);
3521 RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *)CreateDeviceNode (
3524 (UINT16)sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3527 Strtoi64 (StartingAddrStr, &StartingAddr);
3528 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
3529 Strtoi64 (EndingAddrStr, &EndingAddr);
3530 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
3531 RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
3532 CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid);
3534 return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
3538 Converts a BBS text device path node to BBS device path structure.
3540 @param TextDeviceNode The input Text device path node.
3542 @return A pointer to BBS device path structure.
3546 EFI_DEVICE_PATH_PROTOCOL *
3547 DevPathFromTextBbsPath (
3548 IN CHAR16 *TextDeviceNode
3551 return DevPathFromTextGenericPath (BBS_DEVICE_PATH, TextDeviceNode);
3555 Converts a text device path node to BIOS Boot Specification device path structure.
3557 @param TextDeviceNode The input Text device path node.
3559 @return A pointer to the newly-created BIOS Boot Specification device path structure.
3563 EFI_DEVICE_PATH_PROTOCOL *
3564 DevPathFromTextBBS (
3565 IN CHAR16 *TextDeviceNode
3572 BBS_BBS_DEVICE_PATH *Bbs;
3574 TypeStr = GetNextParamStr (&TextDeviceNode);
3575 IdStr = GetNextParamStr (&TextDeviceNode);
3576 FlagsStr = GetNextParamStr (&TextDeviceNode);
3577 Bbs = (BBS_BBS_DEVICE_PATH *)CreateDeviceNode (
3580 (UINT16)(sizeof (BBS_BBS_DEVICE_PATH) + StrLen (IdStr))
3583 if (StrCmp (TypeStr, "Floppy") == 0) {
3584 Bbs->DeviceType = BBS_TYPE_FLOPPY;
3585 } else if (StrCmp (TypeStr, "HD") == 0) {
3586 Bbs->DeviceType = BBS_TYPE_HARDDRIVE;
3587 } else if (StrCmp (TypeStr, "CDROM") == 0) {
3588 Bbs->DeviceType = BBS_TYPE_CDROM;
3589 } else if (StrCmp (TypeStr, "PCMCIA") == 0) {
3590 Bbs->DeviceType = BBS_TYPE_PCMCIA;
3591 } else if (StrCmp (TypeStr, "USB") == 0) {
3592 Bbs->DeviceType = BBS_TYPE_USB;
3593 } else if (StrCmp (TypeStr, "Network") == 0) {
3594 Bbs->DeviceType = BBS_TYPE_EMBEDDED_NETWORK;
3596 Bbs->DeviceType = (UINT16)Strtoi (TypeStr);
3599 AsciiStr = Bbs->String;
3600 StrToAscii (IdStr, &AsciiStr);
3602 Bbs->StatusFlag = (UINT16)Strtoi (FlagsStr);
3604 return (EFI_DEVICE_PATH_PROTOCOL *)Bbs;
3608 Converts a text device path node to SATA device path structure.
3610 @param TextDeviceNode The input Text device path node.
3612 @return A pointer to the newly-created SATA device path structure.
3616 EFI_DEVICE_PATH_PROTOCOL *
3617 DevPathFromTextSata (
3618 IN CHAR16 *TextDeviceNode
3621 SATA_DEVICE_PATH *Sata;
3626 Param1 = GetNextParamStr (&TextDeviceNode);
3627 Param2 = GetNextParamStr (&TextDeviceNode);
3628 Param3 = GetNextParamStr (&TextDeviceNode);
3630 Sata = (SATA_DEVICE_PATH *)CreateDeviceNode (
3631 MESSAGING_DEVICE_PATH,
3633 (UINT16)sizeof (SATA_DEVICE_PATH)
3635 Sata->HBAPortNumber = (UINT16)Strtoi (Param1);
3638 // According to UEFI spec, if PMPN is not provided, the default is 0xFFFF
3640 if (*Param2 == '\0' ) {
3641 Sata->PortMultiplierPortNumber = 0xFFFF;
3643 Sata->PortMultiplierPortNumber = (UINT16)Strtoi (Param2);
3646 Sata->Lun = (UINT16)Strtoi (Param3);
3648 return (EFI_DEVICE_PATH_PROTOCOL *)Sata;
3651 GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevPathFromTextTable[] = {
3652 { "Path", DevPathFromTextPath },
3654 { "HardwarePath", DevPathFromTextHardwarePath },
3655 { "Pci", DevPathFromTextPci },
3656 { "PcCard", DevPathFromTextPcCard },
3657 { "MemoryMapped", DevPathFromTextMemoryMapped },
3658 { "VenHw", DevPathFromTextVenHw },
3659 { "Ctrl", DevPathFromTextCtrl },
3660 { "BMC", DevPathFromTextBmc },
3662 { "AcpiPath", DevPathFromTextAcpiPath },
3663 { "Acpi", DevPathFromTextAcpi },
3664 { "PciRoot", DevPathFromTextPciRoot },
3665 { "PcieRoot", DevPathFromTextPcieRoot },
3666 { "Floppy", DevPathFromTextFloppy },
3667 { "Keyboard", DevPathFromTextKeyboard },
3668 { "Serial", DevPathFromTextSerial },
3669 { "ParallelPort", DevPathFromTextParallelPort },
3670 { "AcpiEx", DevPathFromTextAcpiEx },
3671 { "AcpiExp", DevPathFromTextAcpiExp },
3672 { "AcpiAdr", DevPathFromTextAcpiAdr },
3674 { "Msg", DevPathFromTextMsg },
3675 { "Ata", DevPathFromTextAta },
3676 { "Scsi", DevPathFromTextScsi },
3677 { "Fibre", DevPathFromTextFibre },
3678 { "FibreEx", DevPathFromTextFibreEx },
3679 { "I1394", DevPathFromText1394 },
3680 { "USB", DevPathFromTextUsb },
3681 { "I2O", DevPathFromTextI2O },
3682 { "Infiniband", DevPathFromTextInfiniband },
3683 { "VenMsg", DevPathFromTextVenMsg },
3684 { "VenPcAnsi", DevPathFromTextVenPcAnsi },
3685 { "VenVt100", DevPathFromTextVenVt100 },
3686 { "VenVt100Plus", DevPathFromTextVenVt100Plus },
3687 { "VenUtf8", DevPathFromTextVenUtf8 },
3688 { "UartFlowCtrl", DevPathFromTextUartFlowCtrl },
3689 { "SAS", DevPathFromTextSAS },
3690 { "SasEx", DevPathFromTextSasEx },
3691 { "NVMe", DevPathFromTextNVMe },
3692 { "UFS", DevPathFromTextUfs },
3693 { "SD", DevPathFromTextSd },
3694 { "eMMC", DevPathFromTextEmmc },
3695 { "DebugPort", DevPathFromTextDebugPort },
3696 { "MAC", DevPathFromTextMAC },
3697 { "IPv4", DevPathFromTextIPv4 },
3698 { "IPv6", DevPathFromTextIPv6 },
3699 { "Uart", DevPathFromTextUart },
3700 { "UsbClass", DevPathFromTextUsbClass },
3701 { "UsbAudio", DevPathFromTextUsbAudio },
3702 { "UsbCDCControl", DevPathFromTextUsbCDCControl },
3703 { "UsbHID", DevPathFromTextUsbHID },
3704 { "UsbImage", DevPathFromTextUsbImage },
3705 { "UsbPrinter", DevPathFromTextUsbPrinter },
3706 { "UsbMassStorage", DevPathFromTextUsbMassStorage },
3707 { "UsbHub", DevPathFromTextUsbHub },
3708 { "UsbCDCData", DevPathFromTextUsbCDCData },
3709 { "UsbSmartCard", DevPathFromTextUsbSmartCard },
3710 { "UsbVideo", DevPathFromTextUsbVideo },
3711 { "UsbDiagnostic", DevPathFromTextUsbDiagnostic },
3712 { "UsbWireless", DevPathFromTextUsbWireless },
3713 { "UsbDeviceFirmwareUpdate", DevPathFromTextUsbDeviceFirmwareUpdate },
3714 { "UsbIrdaBridge", DevPathFromTextUsbIrdaBridge },
3715 { "UsbTestAndMeasurement", DevPathFromTextUsbTestAndMeasurement },
3716 { "UsbWwid", DevPathFromTextUsbWwid },
3717 { "Unit", DevPathFromTextUnit },
3718 { "iSCSI", DevPathFromTextiSCSI },
3719 { "Vlan", DevPathFromTextVlan },
3720 { "Dns", DevPathFromTextDns },
3721 { "Uri", DevPathFromTextUri },
3722 { "Bluetooth", DevPathFromTextBluetooth },
3723 { "Wi-Fi", DevPathFromTextWiFi },
3724 { "BluetoothLE", DevPathFromTextBluetoothLE },
3725 { "MediaPath", DevPathFromTextMediaPath },
3726 { "HD", DevPathFromTextHD },
3727 { "CDROM", DevPathFromTextCDROM },
3728 { "VenMedia", DevPathFromTextVenMedia },
3729 { "Media", DevPathFromTextMedia },
3730 { "Fv", DevPathFromTextFv },
3731 { "FvFile", DevPathFromTextFvFile },
3732 { "File", DevPathFromTextFilePath },
3733 { "Offset", DevPathFromTextRelativeOffsetRange },
3734 { "RamDisk", DevPathFromTextRamDisk },
3735 { "VirtualDisk", DevPathFromTextVirtualDisk },
3736 { "VirtualCD", DevPathFromTextVirtualCd },
3737 { "PersistentVirtualDisk", DevPathFromTextPersistentVirtualDisk },
3738 { "PersistentVirtualCD", DevPathFromTextPersistentVirtualCd },
3740 { "BbsPath", DevPathFromTextBbsPath },
3741 { "BBS", DevPathFromTextBBS },
3742 { "Sata", DevPathFromTextSata },
3747 Convert text to the binary representation of a device node.
3749 @param TextDeviceNode TextDeviceNode points to the text representation of a device
3750 node. Conversion starts with the first character and continues
3751 until the first non-device node character.
3753 @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
3754 insufficient memory or text unsupported.
3758 EFI_DEVICE_PATH_PROTOCOL *
3760 UefiDevicePathLibConvertTextToDeviceNode (
3761 IN CONST CHAR16 *TextDeviceNode
3764 DEVICE_PATH_FROM_TEXT FromText;
3766 EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
3767 CHAR16 *DeviceNodeStr;
3770 if ((TextDeviceNode == NULL) || (IS_NULL (*TextDeviceNode))) {
3776 DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);
3777 ASSERT (DeviceNodeStr != NULL);
3779 for (Index = 0; mUefiDevicePathLibDevPathFromTextTable[Index].Function != NULL; Index++) {
3780 ParamStr = GetParamByNodeName (DeviceNodeStr, mUefiDevicePathLibDevPathFromTextTable[Index].DevicePathNodeText);
3781 if (ParamStr != NULL) {
3782 FromText = mUefiDevicePathLibDevPathFromTextTable[Index].Function;
3787 if (FromText == NULL) {
3791 FromText = DevPathFromTextFilePath;
3792 DeviceNode = FromText (DeviceNodeStr);
3794 DeviceNode = FromText (ParamStr);
3795 FreePool (ParamStr);
3798 FreePool (DeviceNodeStr);
3804 Convert text to the binary representation of a device path.
3807 @param TextDevicePath TextDevicePath points to the text representation of a device
3808 path. Conversion starts with the first character and continues
3809 until the first non-device node character.
3811 @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
3812 there was insufficient memory.
3816 EFI_DEVICE_PATH_PROTOCOL *
3818 UefiDevicePathLibConvertTextToDevicePath (
3819 IN CONST CHAR16 *TextDevicePath
3822 EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
3823 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
3824 CHAR16 *DevicePathStr;
3826 CHAR16 *DeviceNodeStr;
3827 BOOLEAN IsInstanceEnd;
3828 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
3830 if ((TextDevicePath == NULL) || (IS_NULL (*TextDevicePath))) {
3834 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)AllocatePool (END_DEVICE_PATH_LENGTH);
3835 ASSERT (DevicePath != NULL);
3836 SetDevicePathEndNode (DevicePath);
3838 DevicePathStr = UefiDevicePathLibStrDuplicate (TextDevicePath);
3840 Str = DevicePathStr;
3841 while ((DeviceNodeStr = GetNextDeviceNodeStr (&Str, &IsInstanceEnd)) != NULL) {
3842 DeviceNode = UefiDevicePathLibConvertTextToDeviceNode (DeviceNodeStr);
3844 NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
3845 FreePool (DevicePath);
3846 FreePool (DeviceNode);
3847 DevicePath = NewDevicePath;
3849 if (IsInstanceEnd) {
3850 DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *)AllocatePool (END_DEVICE_PATH_LENGTH);
3851 ASSERT (DeviceNode != NULL);
3852 SetDevicePathEndNode (DeviceNode);
3853 DeviceNode->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;
3855 NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
3856 FreePool (DevicePath);
3857 FreePool (DeviceNode);
3858 DevicePath = NewDevicePath;
3862 FreePool (DevicePathStr);
3867 efidp_parse_device_path(char *path, efidp out, size_t max)
3869 EFI_DEVICE_PATH_PROTOCOL *dp;
3872 dp = UefiDevicePathLibConvertTextToDevicePath (path);
3875 len = GetDevicePathSize(dp);
3880 memcpy(out, dp, len);