xref: /freebsd/lib/libefivar/efivar-dp-parse.c (revision 9a62aa9329063f7e0c1d90262863b94fef436d7a)
1 /*-
2  * Copyright (c) 2017 Netflix, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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
23  * SUCH DAMAGE.
24  */
25 
26 /*
27  * Routines to format EFI_DEVICE_PATHs from the UEFI standard. Much of
28  * this file is taken from EDK2 and rototilled.
29  */
30 
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33 
34 #include <ctype.h>
35 #include <efivar.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <wchar.h>
39 
40 #include "efichar.h"
41 
42 #include "efi-osdep.h"
43 #include "efivar-dp.h"
44 
45 #include "uefi-dplib.h"
46 
47 /* XXX STUBS -- this stuff doesn't work yet */
48 #define StrToIpv4Address(str, unk, ipv4ptr, unk2)
49 #define StrToIpv6Address(str, unk, ipv6ptr, unk2)
50 
51 /*
52  * OK. Now this is evil. Can't typedef it again. Sure beats changing them all.
53  * Since we're doing it all as narrow characters since wchar_t can't be used on
54  * FreeBSD and CHAR16 strings generally aren't a good fit. Since this parsing
55  * doesn't need Unicode for anything, this works out well.
56  */
57 #define CHAR16 char
58 
59 /*
60  * Taken from MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
61  */
62 
63 /** @file
64   DevicePathFromText protocol as defined in the UEFI 2.0 specification.
65 
66 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
67 This program and the accompanying materials
68 are licensed and made available under the terms and conditions of the BSD License
69 which accompanies this distribution.  The full text of the license may be found at
70 http://opensource.org/licenses/bsd-license.php
71 
72 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
73 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
74 
75 **/
76 
77 // #include "UefiDevicePathLib.h"
78 
79 /**
80 
81   Duplicates a string.
82 
83   @param  Src  Source string.
84 
85   @return The duplicated string.
86 
87 **/
88 static
89 CHAR16 *
90 UefiDevicePathLibStrDuplicate (
91   IN CONST CHAR16  *Src
92   )
93 {
94   return AllocateCopyPool (StrSize (Src), Src);
95 }
96 
97 /**
98 
99   Get parameter in a pair of parentheses follow the given node name.
100   For example, given the "Pci(0,1)" and NodeName "Pci", it returns "0,1".
101 
102   @param  Str      Device Path Text.
103   @param  NodeName Name of the node.
104 
105   @return Parameter text for the node.
106 
107 **/
108 static
109 CHAR16 *
110 GetParamByNodeName (
111   IN CHAR16 *Str,
112   IN const CHAR16 *NodeName
113   )
114 {
115   CHAR16  *ParamStr;
116   CHAR16  *StrPointer;
117   UINTN   NodeNameLength;
118   UINTN   ParameterLength;
119 
120   //
121   // Check whether the node name matchs
122   //
123   NodeNameLength = StrLen (NodeName);
124   if (StrnCmp (Str, NodeName, NodeNameLength) != 0) {
125     return NULL;
126   }
127 
128   ParamStr = Str + NodeNameLength;
129   if (!IS_LEFT_PARENTH (*ParamStr)) {
130     return NULL;
131   }
132 
133   //
134   // Skip the found '(' and find first occurrence of ')'
135   //
136   ParamStr++;
137   ParameterLength = 0;
138   StrPointer = ParamStr;
139   while (!IS_NULL (*StrPointer)) {
140     if (IS_RIGHT_PARENTH (*StrPointer)) {
141       break;
142     }
143     StrPointer++;
144     ParameterLength++;
145   }
146   if (IS_NULL (*StrPointer)) {
147     //
148     // ')' not found
149     //
150     return NULL;
151   }
152 
153   ParamStr = AllocateCopyPool ((ParameterLength + 1) * sizeof (CHAR16), ParamStr);
154   if (ParamStr == NULL) {
155     return NULL;
156   }
157   //
158   // Terminate the parameter string
159   //
160   ParamStr[ParameterLength] = '\0';
161 
162   return ParamStr;
163 }
164 
165 /**
166   Gets current sub-string from a string list, before return
167   the list header is moved to next sub-string. The sub-string is separated
168   by the specified character. For example, the separator is ',', the string
169   list is "2,0,3", it returns "2", the remain list move to "0,3"
170 
171   @param  List        A string list separated by the specified separator
172   @param  Separator   The separator character
173 
174   @return A pointer to the current sub-string
175 
176 **/
177 static
178 CHAR16 *
179 SplitStr (
180   IN OUT CHAR16 **List,
181   IN     CHAR16 Separator
182   )
183 {
184   CHAR16  *Str;
185   CHAR16  *ReturnStr;
186 
187   Str = *List;
188   ReturnStr = Str;
189 
190   if (IS_NULL (*Str)) {
191     return ReturnStr;
192   }
193 
194   //
195   // Find first occurrence of the separator
196   //
197   while (!IS_NULL (*Str)) {
198     if (*Str == Separator) {
199       break;
200     }
201     Str++;
202   }
203 
204   if (*Str == Separator) {
205     //
206     // Find a sub-string, terminate it
207     //
208     *Str = '\0';
209     Str++;
210   }
211 
212   //
213   // Move to next sub-string
214   //
215   *List = Str;
216 
217   return ReturnStr;
218 }
219 
220 /**
221   Gets the next parameter string from the list.
222 
223   @param List            A string list separated by the specified separator
224 
225   @return A pointer to the current sub-string
226 
227 **/
228 static
229 CHAR16 *
230 GetNextParamStr (
231   IN OUT CHAR16 **List
232   )
233 {
234   //
235   // The separator is comma
236   //
237   return SplitStr (List, ',');
238 }
239 
240 /**
241   Get one device node from entire device path text.
242 
243   @param DevicePath      On input, the current Device Path node; on output, the next device path node
244   @param IsInstanceEnd   This node is the end of a device path instance
245 
246   @return A device node text or NULL if no more device node available
247 
248 **/
249 static
250 CHAR16 *
251 GetNextDeviceNodeStr (
252   IN OUT CHAR16   **DevicePath,
253   OUT    BOOLEAN  *IsInstanceEnd
254   )
255 {
256   CHAR16  *Str;
257   CHAR16  *ReturnStr;
258   UINTN   ParenthesesStack;
259 
260   Str = *DevicePath;
261   if (IS_NULL (*Str)) {
262     return NULL;
263   }
264 
265   //
266   // Skip the leading '/', '(', ')' and ','
267   //
268   while (!IS_NULL (*Str)) {
269     if (!IS_SLASH (*Str) &&
270         !IS_COMMA (*Str) &&
271         !IS_LEFT_PARENTH (*Str) &&
272         !IS_RIGHT_PARENTH (*Str)) {
273       break;
274     }
275     Str++;
276   }
277 
278   ReturnStr = Str;
279 
280   //
281   // Scan for the separator of this device node, '/' or ','
282   //
283   ParenthesesStack = 0;
284   while (!IS_NULL (*Str)) {
285     if ((IS_COMMA (*Str) || IS_SLASH (*Str)) && (ParenthesesStack == 0)) {
286       break;
287     }
288 
289     if (IS_LEFT_PARENTH (*Str)) {
290       ParenthesesStack++;
291     } else if (IS_RIGHT_PARENTH (*Str)) {
292       ParenthesesStack--;
293     }
294 
295     Str++;
296   }
297 
298   if (ParenthesesStack != 0) {
299     //
300     // The '(' doesn't pair with ')', invalid device path text
301     //
302     return NULL;
303   }
304 
305   if (IS_COMMA (*Str)) {
306     *IsInstanceEnd = TRUE;
307     *Str = '\0';
308     Str++;
309   } else {
310     *IsInstanceEnd = FALSE;
311     if (!IS_NULL (*Str)) {
312       *Str = '\0';
313       Str++;
314     }
315   }
316 
317   *DevicePath = Str;
318 
319   return ReturnStr;
320 }
321 
322 
323 #ifndef __FreeBSD__
324 /**
325   Return whether the integer string is a hex string.
326 
327   @param Str             The integer string
328 
329   @retval TRUE   Hex string
330   @retval FALSE  Decimal string
331 
332 **/
333 static
334 BOOLEAN
335 IsHexStr (
336   IN CHAR16   *Str
337   )
338 {
339   //
340   // skip preceeding white space
341   //
342   while ((*Str != 0) && *Str == ' ') {
343     Str ++;
344   }
345   //
346   // skip preceeding zeros
347   //
348   while ((*Str != 0) && *Str == '0') {
349     Str ++;
350   }
351 
352   return (BOOLEAN) (*Str == 'x' || *Str == 'X');
353 }
354 
355 /**
356 
357   Convert integer string to uint.
358 
359   @param Str             The integer string. If leading with "0x" or "0X", it's hexadecimal.
360 
361   @return A UINTN value represented by Str
362 
363 **/
364 static
365 UINTN
366 Strtoi (
367   IN CHAR16  *Str
368   )
369 {
370   if (IsHexStr (Str)) {
371     return StrHexToUintn (Str);
372   } else {
373     return StrDecimalToUintn (Str);
374   }
375 }
376 
377 /**
378 
379   Convert integer string to 64 bit data.
380 
381   @param Str             The integer string. If leading with "0x" or "0X", it's hexadecimal.
382   @param Data            A pointer to the UINT64 value represented by Str
383 
384 **/
385 static
386 VOID
387 Strtoi64 (
388   IN  CHAR16  *Str,
389   OUT UINT64  *Data
390   )
391 {
392   if (IsHexStr (Str)) {
393     *Data = StrHexToUint64 (Str);
394   } else {
395     *Data = StrDecimalToUint64 (Str);
396   }
397 }
398 #endif
399 
400 /**
401   Converts a Unicode string to ASCII string.
402 
403   @param Str             The equivalent Unicode string
404   @param AsciiStr        On input, it points to destination ASCII string buffer; on output, it points
405                          to the next ASCII string next to it
406 
407 **/
408 static
409 VOID
410 StrToAscii (
411   IN     CHAR16 *Str,
412   IN OUT CHAR8  **AsciiStr
413   )
414 {
415   CHAR8 *Dest;
416 
417   Dest = *AsciiStr;
418   while (!IS_NULL (*Str)) {
419     *(Dest++) = (CHAR8) *(Str++);
420   }
421   *Dest = 0;
422 
423   //
424   // Return the string next to it
425   //
426   *AsciiStr = Dest + 1;
427 }
428 
429 /**
430   Converts a generic text device path node to device path structure.
431 
432   @param Type            The type of the device path node.
433   @param TextDeviceNode  The input text device path node.
434 
435   @return A pointer to device path structure.
436 **/
437 static
438 EFI_DEVICE_PATH_PROTOCOL *
439 DevPathFromTextGenericPath (
440   IN UINT8  Type,
441   IN CHAR16 *TextDeviceNode
442   )
443 {
444   EFI_DEVICE_PATH_PROTOCOL *Node;
445   CHAR16                   *SubtypeStr;
446   CHAR16                   *DataStr;
447   UINTN                    DataLength;
448 
449   SubtypeStr = GetNextParamStr (&TextDeviceNode);
450   DataStr    = GetNextParamStr (&TextDeviceNode);
451 
452   if (DataStr == NULL) {
453     DataLength = 0;
454   } else {
455     DataLength = StrLen (DataStr) / 2;
456   }
457   Node = CreateDeviceNode (
458            Type,
459            (UINT8) Strtoi (SubtypeStr),
460            (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + DataLength)
461            );
462 
463   StrHexToBytes (DataStr, DataLength * 2, (UINT8 *) (Node + 1), DataLength);
464   return Node;
465 }
466 
467 /**
468   Converts a generic text device path node to device path structure.
469 
470   @param TextDeviceNode  The input Text device path node.
471 
472   @return A pointer to device path structure.
473 
474 **/
475 static
476 EFI_DEVICE_PATH_PROTOCOL *
477 DevPathFromTextPath (
478   IN CHAR16 *TextDeviceNode
479   )
480 {
481   CHAR16                   *TypeStr;
482 
483   TypeStr    = GetNextParamStr (&TextDeviceNode);
484 
485   return DevPathFromTextGenericPath ((UINT8) Strtoi (TypeStr), TextDeviceNode);
486 }
487 
488 /**
489   Converts a generic hardware text device path node to Hardware device path structure.
490 
491   @param TextDeviceNode  The input Text device path node.
492 
493   @return A pointer to Hardware device path structure.
494 
495 **/
496 static
497 EFI_DEVICE_PATH_PROTOCOL *
498 DevPathFromTextHardwarePath (
499   IN CHAR16 *TextDeviceNode
500   )
501 {
502   return DevPathFromTextGenericPath (HARDWARE_DEVICE_PATH, TextDeviceNode);
503 }
504 
505 /**
506   Converts a text device path node to Hardware PCI device path structure.
507 
508   @param TextDeviceNode  The input Text device path node.
509 
510   @return A pointer to Hardware PCI device path structure.
511 
512 **/
513 static
514 EFI_DEVICE_PATH_PROTOCOL *
515 DevPathFromTextPci (
516   IN CHAR16 *TextDeviceNode
517   )
518 {
519   CHAR16          *FunctionStr;
520   CHAR16          *DeviceStr;
521   PCI_DEVICE_PATH *Pci;
522 
523   DeviceStr   = GetNextParamStr (&TextDeviceNode);
524   FunctionStr = GetNextParamStr (&TextDeviceNode);
525   Pci         = (PCI_DEVICE_PATH *) CreateDeviceNode (
526                                       HARDWARE_DEVICE_PATH,
527                                       HW_PCI_DP,
528                                       (UINT16) sizeof (PCI_DEVICE_PATH)
529                                       );
530 
531   Pci->Function = (UINT8) Strtoi (FunctionStr);
532   Pci->Device   = (UINT8) Strtoi (DeviceStr);
533 
534   return (EFI_DEVICE_PATH_PROTOCOL *) Pci;
535 }
536 
537 /**
538   Converts a text device path node to Hardware PC card device path structure.
539 
540   @param TextDeviceNode  The input Text device path node.
541 
542   @return A pointer to Hardware PC card device path structure.
543 
544 **/
545 static
546 EFI_DEVICE_PATH_PROTOCOL *
547 DevPathFromTextPcCard (
548   IN CHAR16 *TextDeviceNode
549   )
550 {
551   CHAR16              *FunctionNumberStr;
552   PCCARD_DEVICE_PATH  *Pccard;
553 
554   FunctionNumberStr = GetNextParamStr (&TextDeviceNode);
555   Pccard            = (PCCARD_DEVICE_PATH *) CreateDeviceNode (
556                                                HARDWARE_DEVICE_PATH,
557                                                HW_PCCARD_DP,
558                                                (UINT16) sizeof (PCCARD_DEVICE_PATH)
559                                                );
560 
561   Pccard->FunctionNumber  = (UINT8) Strtoi (FunctionNumberStr);
562 
563   return (EFI_DEVICE_PATH_PROTOCOL *) Pccard;
564 }
565 
566 /**
567   Converts a text device path node to Hardware memory map device path structure.
568 
569   @param TextDeviceNode  The input Text device path node.
570 
571   @return A pointer to Hardware memory map device path structure.
572 
573 **/
574 static
575 EFI_DEVICE_PATH_PROTOCOL *
576 DevPathFromTextMemoryMapped (
577   IN CHAR16 *TextDeviceNode
578   )
579 {
580   CHAR16              *MemoryTypeStr;
581   CHAR16              *StartingAddressStr;
582   CHAR16              *EndingAddressStr;
583   MEMMAP_DEVICE_PATH  *MemMap;
584 
585   MemoryTypeStr      = GetNextParamStr (&TextDeviceNode);
586   StartingAddressStr = GetNextParamStr (&TextDeviceNode);
587   EndingAddressStr   = GetNextParamStr (&TextDeviceNode);
588   MemMap             = (MEMMAP_DEVICE_PATH *) CreateDeviceNode (
589                                                HARDWARE_DEVICE_PATH,
590                                                HW_MEMMAP_DP,
591                                                (UINT16) sizeof (MEMMAP_DEVICE_PATH)
592                                                );
593 
594   MemMap->MemoryType = (UINT32) Strtoi (MemoryTypeStr);
595   Strtoi64 (StartingAddressStr, &MemMap->StartingAddress);
596   Strtoi64 (EndingAddressStr, &MemMap->EndingAddress);
597 
598   return (EFI_DEVICE_PATH_PROTOCOL *) MemMap;
599 }
600 
601 /**
602   Converts a text device path node to Vendor device path structure based on the input Type
603   and SubType.
604 
605   @param TextDeviceNode  The input Text device path node.
606   @param Type            The type of device path node.
607   @param SubType         The subtype of device path node.
608 
609   @return A pointer to the newly-created Vendor device path structure.
610 
611 **/
612 static
613 EFI_DEVICE_PATH_PROTOCOL *
614 ConvertFromTextVendor (
615   IN CHAR16 *TextDeviceNode,
616   IN UINT8  Type,
617   IN UINT8  SubType
618   )
619 {
620   CHAR16              *GuidStr;
621   CHAR16              *DataStr;
622   UINTN               Length;
623   VENDOR_DEVICE_PATH  *Vendor;
624 
625   GuidStr = GetNextParamStr (&TextDeviceNode);
626 
627   DataStr = GetNextParamStr (&TextDeviceNode);
628   Length  = StrLen (DataStr);
629   //
630   // Two hex characters make up 1 buffer byte
631   //
632   Length  = (Length + 1) / 2;
633 
634   Vendor  = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
635                                      Type,
636                                      SubType,
637                                      (UINT16) (sizeof (VENDOR_DEVICE_PATH) + Length)
638                                      );
639 
640   StrToGuid (GuidStr, &Vendor->Guid);
641   StrHexToBytes (DataStr, Length * 2, (UINT8 *) (Vendor + 1), Length);
642 
643   return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
644 }
645 
646 /**
647   Converts a text device path node to Vendor Hardware device path structure.
648 
649   @param TextDeviceNode  The input Text device path node.
650 
651   @return A pointer to the newly-created Vendor Hardware device path structure.
652 
653 **/
654 static
655 EFI_DEVICE_PATH_PROTOCOL *
656 DevPathFromTextVenHw (
657   IN CHAR16 *TextDeviceNode
658   )
659 {
660   return ConvertFromTextVendor (
661            TextDeviceNode,
662            HARDWARE_DEVICE_PATH,
663            HW_VENDOR_DP
664            );
665 }
666 
667 /**
668   Converts a text device path node to Hardware Controller device path structure.
669 
670   @param TextDeviceNode  The input Text device path node.
671 
672   @return A pointer to the newly-created Hardware Controller device path structure.
673 
674 **/
675 static
676 EFI_DEVICE_PATH_PROTOCOL *
677 DevPathFromTextCtrl (
678   IN CHAR16 *TextDeviceNode
679   )
680 {
681   CHAR16                  *ControllerStr;
682   CONTROLLER_DEVICE_PATH  *Controller;
683 
684   ControllerStr = GetNextParamStr (&TextDeviceNode);
685   Controller    = (CONTROLLER_DEVICE_PATH *) CreateDeviceNode (
686                                                HARDWARE_DEVICE_PATH,
687                                                HW_CONTROLLER_DP,
688                                                (UINT16) sizeof (CONTROLLER_DEVICE_PATH)
689                                                );
690   Controller->ControllerNumber = (UINT32) Strtoi (ControllerStr);
691 
692   return (EFI_DEVICE_PATH_PROTOCOL *) Controller;
693 }
694 
695 /**
696   Converts a text device path node to BMC device path structure.
697 
698   @param TextDeviceNode  The input Text device path node.
699 
700   @return A pointer to the newly-created BMC device path structure.
701 
702 **/
703 static
704 EFI_DEVICE_PATH_PROTOCOL *
705 DevPathFromTextBmc (
706   IN CHAR16 *TextDeviceNode
707   )
708 {
709   CHAR16                *InterfaceTypeStr;
710   CHAR16                *BaseAddressStr;
711   BMC_DEVICE_PATH       *BmcDp;
712 
713   InterfaceTypeStr = GetNextParamStr (&TextDeviceNode);
714   BaseAddressStr   = GetNextParamStr (&TextDeviceNode);
715   BmcDp            = (BMC_DEVICE_PATH *) CreateDeviceNode (
716                                            HARDWARE_DEVICE_PATH,
717                                            HW_BMC_DP,
718                                            (UINT16) sizeof (BMC_DEVICE_PATH)
719                                            );
720 
721   BmcDp->InterfaceType = (UINT8) Strtoi (InterfaceTypeStr);
722   WriteUnaligned64 (
723     (UINT64 *) (&BmcDp->BaseAddress),
724     StrHexToUint64 (BaseAddressStr)
725     );
726 
727   return (EFI_DEVICE_PATH_PROTOCOL *) BmcDp;
728 }
729 
730 /**
731   Converts a generic ACPI text device path node to ACPI device path structure.
732 
733   @param TextDeviceNode  The input Text device path node.
734 
735   @return A pointer to ACPI device path structure.
736 
737 **/
738 static
739 EFI_DEVICE_PATH_PROTOCOL *
740 DevPathFromTextAcpiPath (
741   IN CHAR16 *TextDeviceNode
742   )
743 {
744   return DevPathFromTextGenericPath (ACPI_DEVICE_PATH, TextDeviceNode);
745 }
746 
747 /**
748   Converts a string to EisaId.
749 
750   @param Text   The input string.
751 
752   @return UINT32 EISA ID.
753 **/
754 static
755 UINT32
756 EisaIdFromText (
757   IN CHAR16 *Text
758   )
759 {
760   return (((Text[0] - 'A' + 1) & 0x1f) << 10)
761        + (((Text[1] - 'A' + 1) & 0x1f) <<  5)
762        + (((Text[2] - 'A' + 1) & 0x1f) <<  0)
763        + (UINT32) (StrHexToUintn (&Text[3]) << 16)
764        ;
765 }
766 
767 /**
768   Converts a text device path node to ACPI HID device path structure.
769 
770   @param TextDeviceNode  The input Text device path node.
771 
772   @return A pointer to the newly-created ACPI HID device path structure.
773 
774 **/
775 static
776 EFI_DEVICE_PATH_PROTOCOL *
777 DevPathFromTextAcpi (
778   IN CHAR16 *TextDeviceNode
779   )
780 {
781   CHAR16                *HIDStr;
782   CHAR16                *UIDStr;
783   ACPI_HID_DEVICE_PATH  *Acpi;
784 
785   HIDStr = GetNextParamStr (&TextDeviceNode);
786   UIDStr = GetNextParamStr (&TextDeviceNode);
787   Acpi   = (ACPI_HID_DEVICE_PATH *) CreateDeviceNode (
788                                       ACPI_DEVICE_PATH,
789                                       ACPI_DP,
790                                       (UINT16) sizeof (ACPI_HID_DEVICE_PATH)
791                                       );
792 
793   Acpi->HID = EisaIdFromText (HIDStr);
794   Acpi->UID = (UINT32) Strtoi (UIDStr);
795 
796   return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;
797 }
798 
799 /**
800   Converts a text device path node to ACPI HID device path structure.
801 
802   @param TextDeviceNode  The input Text device path node.
803   @param PnPId           The input plug and play identification.
804 
805   @return A pointer to the newly-created ACPI HID device path structure.
806 
807 **/
808 static
809 EFI_DEVICE_PATH_PROTOCOL *
810 ConvertFromTextAcpi (
811   IN CHAR16 *TextDeviceNode,
812   IN UINT32  PnPId
813   )
814 {
815   CHAR16                *UIDStr;
816   ACPI_HID_DEVICE_PATH  *Acpi;
817 
818   UIDStr = GetNextParamStr (&TextDeviceNode);
819   Acpi   = (ACPI_HID_DEVICE_PATH *) CreateDeviceNode (
820                                       ACPI_DEVICE_PATH,
821                                       ACPI_DP,
822                                       (UINT16) sizeof (ACPI_HID_DEVICE_PATH)
823                                       );
824 
825   Acpi->HID = EFI_PNP_ID (PnPId);
826   Acpi->UID = (UINT32) Strtoi (UIDStr);
827 
828   return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;
829 }
830 
831 /**
832   Converts a text device path node to PCI root device path structure.
833 
834   @param TextDeviceNode  The input Text device path node.
835 
836   @return A pointer to the newly-created PCI root device path structure.
837 
838 **/
839 static
840 EFI_DEVICE_PATH_PROTOCOL *
841 DevPathFromTextPciRoot (
842   IN CHAR16 *TextDeviceNode
843   )
844 {
845   return ConvertFromTextAcpi (TextDeviceNode, 0x0a03);
846 }
847 
848 /**
849   Converts a text device path node to PCIE root device path structure.
850 
851   @param TextDeviceNode  The input Text device path node.
852 
853   @return A pointer to the newly-created PCIE root device path structure.
854 
855 **/
856 static
857 EFI_DEVICE_PATH_PROTOCOL *
858 DevPathFromTextPcieRoot (
859   IN CHAR16 *TextDeviceNode
860   )
861 {
862   return ConvertFromTextAcpi (TextDeviceNode, 0x0a08);
863 }
864 
865 /**
866   Converts a text device path node to Floppy device path structure.
867 
868   @param TextDeviceNode  The input Text device path node.
869 
870   @return A pointer to the newly-created Floppy device path structure.
871 
872 **/
873 static
874 EFI_DEVICE_PATH_PROTOCOL *
875 DevPathFromTextFloppy (
876   IN CHAR16 *TextDeviceNode
877   )
878 {
879   return ConvertFromTextAcpi (TextDeviceNode, 0x0604);
880 }
881 
882 /**
883   Converts a text device path node to Keyboard device path structure.
884 
885   @param TextDeviceNode  The input Text device path node.
886 
887   @return A pointer to the newly-created  Keyboard device path structure.
888 
889 **/
890 static
891 EFI_DEVICE_PATH_PROTOCOL *
892 DevPathFromTextKeyboard (
893   IN CHAR16 *TextDeviceNode
894   )
895 {
896   return ConvertFromTextAcpi (TextDeviceNode, 0x0301);
897 }
898 
899 /**
900   Converts a text device path node to Serial device path structure.
901 
902   @param TextDeviceNode  The input Text device path node.
903 
904   @return A pointer to the newly-created Serial device path structure.
905 
906 **/
907 static
908 EFI_DEVICE_PATH_PROTOCOL *
909 DevPathFromTextSerial (
910   IN CHAR16 *TextDeviceNode
911   )
912 {
913   return ConvertFromTextAcpi (TextDeviceNode, 0x0501);
914 }
915 
916 /**
917   Converts a text device path node to Parallel Port device path structure.
918 
919   @param TextDeviceNode  The input Text device path node.
920 
921   @return A pointer to the newly-created Parallel Port device path structure.
922 
923 **/
924 static
925 EFI_DEVICE_PATH_PROTOCOL *
926 DevPathFromTextParallelPort (
927   IN CHAR16 *TextDeviceNode
928   )
929 {
930   return ConvertFromTextAcpi (TextDeviceNode, 0x0401);
931 }
932 
933 /**
934   Converts a text device path node to ACPI extension device path structure.
935 
936   @param TextDeviceNode  The input Text device path node.
937 
938   @return A pointer to the newly-created ACPI extension device path structure.
939 
940 **/
941 static
942 EFI_DEVICE_PATH_PROTOCOL *
943 DevPathFromTextAcpiEx (
944   IN CHAR16 *TextDeviceNode
945   )
946 {
947   CHAR16                         *HIDStr;
948   CHAR16                         *CIDStr;
949   CHAR16                         *UIDStr;
950   CHAR16                         *HIDSTRStr;
951   CHAR16                         *CIDSTRStr;
952   CHAR16                         *UIDSTRStr;
953   CHAR8                          *AsciiStr;
954   UINT16                         Length;
955   ACPI_EXTENDED_HID_DEVICE_PATH  *AcpiEx;
956 
957   HIDStr    = GetNextParamStr (&TextDeviceNode);
958   CIDStr    = GetNextParamStr (&TextDeviceNode);
959   UIDStr    = GetNextParamStr (&TextDeviceNode);
960   HIDSTRStr = GetNextParamStr (&TextDeviceNode);
961   CIDSTRStr = GetNextParamStr (&TextDeviceNode);
962   UIDSTRStr = GetNextParamStr (&TextDeviceNode);
963 
964   Length    = (UINT16) (sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (HIDSTRStr) + 1);
965   Length    = (UINT16) (Length + StrLen (UIDSTRStr) + 1);
966   Length    = (UINT16) (Length + StrLen (CIDSTRStr) + 1);
967   AcpiEx = (ACPI_EXTENDED_HID_DEVICE_PATH *) CreateDeviceNode (
968                                                ACPI_DEVICE_PATH,
969                                                ACPI_EXTENDED_DP,
970                                                Length
971                                                );
972 
973   AcpiEx->HID = EisaIdFromText (HIDStr);
974   AcpiEx->CID = EisaIdFromText (CIDStr);
975   AcpiEx->UID = (UINT32) Strtoi (UIDStr);
976 
977   AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
978   StrToAscii (HIDSTRStr, &AsciiStr);
979   StrToAscii (UIDSTRStr, &AsciiStr);
980   StrToAscii (CIDSTRStr, &AsciiStr);
981 
982   return (EFI_DEVICE_PATH_PROTOCOL *) AcpiEx;
983 }
984 
985 /**
986   Converts a text device path node to ACPI extension device path structure.
987 
988   @param TextDeviceNode  The input Text device path node.
989 
990   @return A pointer to the newly-created ACPI extension device path structure.
991 
992 **/
993 static
994 EFI_DEVICE_PATH_PROTOCOL *
995 DevPathFromTextAcpiExp (
996   IN CHAR16 *TextDeviceNode
997   )
998 {
999   CHAR16                         *HIDStr;
1000   CHAR16                         *CIDStr;
1001   CHAR16                         *UIDSTRStr;
1002   CHAR8                          *AsciiStr;
1003   UINT16                         Length;
1004   ACPI_EXTENDED_HID_DEVICE_PATH  *AcpiEx;
1005 
1006   HIDStr    = GetNextParamStr (&TextDeviceNode);
1007   CIDStr    = GetNextParamStr (&TextDeviceNode);
1008   UIDSTRStr = GetNextParamStr (&TextDeviceNode);
1009   Length    = (UINT16) (sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (UIDSTRStr) + 3);
1010   AcpiEx    = (ACPI_EXTENDED_HID_DEVICE_PATH *) CreateDeviceNode (
1011                                                   ACPI_DEVICE_PATH,
1012                                                   ACPI_EXTENDED_DP,
1013                                                   Length
1014                                                   );
1015 
1016   AcpiEx->HID = EisaIdFromText (HIDStr);
1017   AcpiEx->CID = EisaIdFromText (CIDStr);
1018   AcpiEx->UID = 0;
1019 
1020   AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
1021   //
1022   // HID string is NULL
1023   //
1024   *AsciiStr = '\0';
1025   //
1026   // Convert UID string
1027   //
1028   AsciiStr++;
1029   StrToAscii (UIDSTRStr, &AsciiStr);
1030   //
1031   // CID string is NULL
1032   //
1033   *AsciiStr = '\0';
1034 
1035   return (EFI_DEVICE_PATH_PROTOCOL *) AcpiEx;
1036 }
1037 
1038 /**
1039   Converts a text device path node to ACPI _ADR device path structure.
1040 
1041   @param TextDeviceNode  The input Text device path node.
1042 
1043   @return A pointer to the newly-created ACPI _ADR device path structure.
1044 
1045 **/
1046 static
1047 EFI_DEVICE_PATH_PROTOCOL *
1048 DevPathFromTextAcpiAdr (
1049   IN CHAR16 *TextDeviceNode
1050   )
1051 {
1052   CHAR16                *DisplayDeviceStr;
1053   ACPI_ADR_DEVICE_PATH  *AcpiAdr;
1054   UINTN                 Index;
1055   UINTN                 Length;
1056 
1057   AcpiAdr = (ACPI_ADR_DEVICE_PATH *) CreateDeviceNode (
1058                                        ACPI_DEVICE_PATH,
1059                                        ACPI_ADR_DP,
1060                                        (UINT16) sizeof (ACPI_ADR_DEVICE_PATH)
1061                                        );
1062   ASSERT (AcpiAdr != NULL);
1063 
1064   for (Index = 0; ; Index++) {
1065     DisplayDeviceStr = GetNextParamStr (&TextDeviceNode);
1066     if (IS_NULL (*DisplayDeviceStr)) {
1067       break;
1068     }
1069     if (Index > 0) {
1070       Length  = DevicePathNodeLength (AcpiAdr);
1071       AcpiAdr = ReallocatePool (
1072                   Length,
1073                   Length + sizeof (UINT32),
1074                   AcpiAdr
1075                   );
1076       ASSERT (AcpiAdr != NULL);
1077       SetDevicePathNodeLength (AcpiAdr, Length + sizeof (UINT32));
1078     }
1079 
1080     (&AcpiAdr->ADR)[Index] = (UINT32) Strtoi (DisplayDeviceStr);
1081   }
1082 
1083   return (EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr;
1084 }
1085 
1086 /**
1087   Converts a generic messaging text device path node to messaging device path structure.
1088 
1089   @param TextDeviceNode  The input Text device path node.
1090 
1091   @return A pointer to messaging device path structure.
1092 
1093 **/
1094 static
1095 EFI_DEVICE_PATH_PROTOCOL *
1096 DevPathFromTextMsg (
1097   IN CHAR16 *TextDeviceNode
1098   )
1099 {
1100   return DevPathFromTextGenericPath (MESSAGING_DEVICE_PATH, TextDeviceNode);
1101 }
1102 
1103 /**
1104   Converts a text device path node to Parallel Port device path structure.
1105 
1106   @param TextDeviceNode  The input Text device path node.
1107 
1108   @return A pointer to the newly-created Parallel Port device path structure.
1109 
1110 **/
1111 static
1112 EFI_DEVICE_PATH_PROTOCOL *
1113 DevPathFromTextAta (
1114 IN CHAR16 *TextDeviceNode
1115 )
1116 {
1117   CHAR16            *PrimarySecondaryStr;
1118   CHAR16            *SlaveMasterStr;
1119   CHAR16            *LunStr;
1120   ATAPI_DEVICE_PATH *Atapi;
1121 
1122   Atapi = (ATAPI_DEVICE_PATH *) CreateDeviceNode (
1123     MESSAGING_DEVICE_PATH,
1124     MSG_ATAPI_DP,
1125     (UINT16) sizeof (ATAPI_DEVICE_PATH)
1126     );
1127 
1128   PrimarySecondaryStr = GetNextParamStr (&TextDeviceNode);
1129   SlaveMasterStr      = GetNextParamStr (&TextDeviceNode);
1130   LunStr              = GetNextParamStr (&TextDeviceNode);
1131 
1132   if (StrCmp (PrimarySecondaryStr, "Primary") == 0) {
1133     Atapi->PrimarySecondary = 0;
1134   } else if (StrCmp (PrimarySecondaryStr, "Secondary") == 0) {
1135     Atapi->PrimarySecondary = 1;
1136   } else {
1137     Atapi->PrimarySecondary = (UINT8) Strtoi (PrimarySecondaryStr);
1138   }
1139   if (StrCmp (SlaveMasterStr, "Master") == 0) {
1140     Atapi->SlaveMaster      = 0;
1141   } else if (StrCmp (SlaveMasterStr, "Slave") == 0) {
1142     Atapi->SlaveMaster      = 1;
1143   } else {
1144     Atapi->SlaveMaster      = (UINT8) Strtoi (SlaveMasterStr);
1145   }
1146 
1147   Atapi->Lun                = (UINT16) Strtoi (LunStr);
1148 
1149   return (EFI_DEVICE_PATH_PROTOCOL *) Atapi;
1150 }
1151 
1152 /**
1153   Converts a text device path node to SCSI device path structure.
1154 
1155   @param TextDeviceNode  The input Text device path node.
1156 
1157   @return A pointer to the newly-created SCSI device path structure.
1158 
1159 **/
1160 static
1161 EFI_DEVICE_PATH_PROTOCOL *
1162 DevPathFromTextScsi (
1163   IN CHAR16 *TextDeviceNode
1164   )
1165 {
1166   CHAR16            *PunStr;
1167   CHAR16            *LunStr;
1168   SCSI_DEVICE_PATH  *Scsi;
1169 
1170   PunStr = GetNextParamStr (&TextDeviceNode);
1171   LunStr = GetNextParamStr (&TextDeviceNode);
1172   Scsi   = (SCSI_DEVICE_PATH *) CreateDeviceNode (
1173                                    MESSAGING_DEVICE_PATH,
1174                                    MSG_SCSI_DP,
1175                                    (UINT16) sizeof (SCSI_DEVICE_PATH)
1176                                    );
1177 
1178   Scsi->Pun = (UINT16) Strtoi (PunStr);
1179   Scsi->Lun = (UINT16) Strtoi (LunStr);
1180 
1181   return (EFI_DEVICE_PATH_PROTOCOL *) Scsi;
1182 }
1183 
1184 /**
1185   Converts a text device path node to Fibre device path structure.
1186 
1187   @param TextDeviceNode  The input Text device path node.
1188 
1189   @return A pointer to the newly-created Fibre device path structure.
1190 
1191 **/
1192 static
1193 EFI_DEVICE_PATH_PROTOCOL *
1194 DevPathFromTextFibre (
1195   IN CHAR16 *TextDeviceNode
1196   )
1197 {
1198   CHAR16                    *WWNStr;
1199   CHAR16                    *LunStr;
1200   FIBRECHANNEL_DEVICE_PATH  *Fibre;
1201 
1202   WWNStr = GetNextParamStr (&TextDeviceNode);
1203   LunStr = GetNextParamStr (&TextDeviceNode);
1204   Fibre  = (FIBRECHANNEL_DEVICE_PATH *) CreateDeviceNode (
1205                                           MESSAGING_DEVICE_PATH,
1206                                           MSG_FIBRECHANNEL_DP,
1207                                           (UINT16) sizeof (FIBRECHANNEL_DEVICE_PATH)
1208                                           );
1209 
1210   Fibre->Reserved = 0;
1211   Strtoi64 (WWNStr, &Fibre->WWN);
1212   Strtoi64 (LunStr, &Fibre->Lun);
1213 
1214   return (EFI_DEVICE_PATH_PROTOCOL *) Fibre;
1215 }
1216 
1217 /**
1218   Converts a text device path node to FibreEx device path structure.
1219 
1220   @param TextDeviceNode  The input Text device path node.
1221 
1222   @return A pointer to the newly-created FibreEx device path structure.
1223 
1224 **/
1225 static
1226 EFI_DEVICE_PATH_PROTOCOL *
1227 DevPathFromTextFibreEx (
1228   IN CHAR16 *TextDeviceNode
1229   )
1230 {
1231   CHAR16                      *WWNStr;
1232   CHAR16                      *LunStr;
1233   FIBRECHANNELEX_DEVICE_PATH  *FibreEx;
1234 
1235   WWNStr  = GetNextParamStr (&TextDeviceNode);
1236   LunStr  = GetNextParamStr (&TextDeviceNode);
1237   FibreEx = (FIBRECHANNELEX_DEVICE_PATH *) CreateDeviceNode (
1238                                              MESSAGING_DEVICE_PATH,
1239                                              MSG_FIBRECHANNELEX_DP,
1240                                              (UINT16) sizeof (FIBRECHANNELEX_DEVICE_PATH)
1241                                              );
1242 
1243   FibreEx->Reserved = 0;
1244   Strtoi64 (WWNStr, (UINT64 *) (&FibreEx->WWN));
1245   Strtoi64 (LunStr, (UINT64 *) (&FibreEx->Lun));
1246 
1247   *(UINT64 *) (&FibreEx->WWN) = SwapBytes64 (*(UINT64 *) (&FibreEx->WWN));
1248   *(UINT64 *) (&FibreEx->Lun) = SwapBytes64 (*(UINT64 *) (&FibreEx->Lun));
1249 
1250   return (EFI_DEVICE_PATH_PROTOCOL *) FibreEx;
1251 }
1252 
1253 /**
1254   Converts a text device path node to 1394 device path structure.
1255 
1256   @param TextDeviceNode  The input Text device path node.
1257 
1258   @return A pointer to the newly-created 1394 device path structure.
1259 
1260 **/
1261 static
1262 EFI_DEVICE_PATH_PROTOCOL *
1263 DevPathFromText1394 (
1264   IN CHAR16 *TextDeviceNode
1265   )
1266 {
1267   CHAR16            *GuidStr;
1268   F1394_DEVICE_PATH *F1394DevPath;
1269 
1270   GuidStr = GetNextParamStr (&TextDeviceNode);
1271   F1394DevPath  = (F1394_DEVICE_PATH *) CreateDeviceNode (
1272                                           MESSAGING_DEVICE_PATH,
1273                                           MSG_1394_DP,
1274                                           (UINT16) sizeof (F1394_DEVICE_PATH)
1275                                           );
1276 
1277   F1394DevPath->Reserved = 0;
1278   F1394DevPath->Guid     = StrHexToUint64 (GuidStr);
1279 
1280   return (EFI_DEVICE_PATH_PROTOCOL *) F1394DevPath;
1281 }
1282 
1283 /**
1284   Converts a text device path node to USB device path structure.
1285 
1286   @param TextDeviceNode  The input Text device path node.
1287 
1288   @return A pointer to the newly-created USB device path structure.
1289 
1290 **/
1291 static
1292 EFI_DEVICE_PATH_PROTOCOL *
1293 DevPathFromTextUsb (
1294   IN CHAR16 *TextDeviceNode
1295   )
1296 {
1297   CHAR16          *PortStr;
1298   CHAR16          *InterfaceStr;
1299   USB_DEVICE_PATH *Usb;
1300 
1301   PortStr               = GetNextParamStr (&TextDeviceNode);
1302   InterfaceStr          = GetNextParamStr (&TextDeviceNode);
1303   Usb                   = (USB_DEVICE_PATH *) CreateDeviceNode (
1304                                                 MESSAGING_DEVICE_PATH,
1305                                                 MSG_USB_DP,
1306                                                 (UINT16) sizeof (USB_DEVICE_PATH)
1307                                                 );
1308 
1309   Usb->ParentPortNumber = (UINT8) Strtoi (PortStr);
1310   Usb->InterfaceNumber  = (UINT8) Strtoi (InterfaceStr);
1311 
1312   return (EFI_DEVICE_PATH_PROTOCOL *) Usb;
1313 }
1314 
1315 /**
1316   Converts a text device path node to I20 device path structure.
1317 
1318   @param TextDeviceNode  The input Text device path node.
1319 
1320   @return A pointer to the newly-created I20 device path structure.
1321 
1322 **/
1323 static
1324 EFI_DEVICE_PATH_PROTOCOL *
1325 DevPathFromTextI2O (
1326   IN CHAR16 *TextDeviceNode
1327   )
1328 {
1329   CHAR16          *TIDStr;
1330   I2O_DEVICE_PATH *I2ODevPath;
1331 
1332   TIDStr     = GetNextParamStr (&TextDeviceNode);
1333   I2ODevPath = (I2O_DEVICE_PATH *) CreateDeviceNode (
1334                                     MESSAGING_DEVICE_PATH,
1335                                     MSG_I2O_DP,
1336                                     (UINT16) sizeof (I2O_DEVICE_PATH)
1337                                     );
1338 
1339   I2ODevPath->Tid  = (UINT32) Strtoi (TIDStr);
1340 
1341   return (EFI_DEVICE_PATH_PROTOCOL *) I2ODevPath;
1342 }
1343 
1344 /**
1345   Converts a text device path node to Infini Band device path structure.
1346 
1347   @param TextDeviceNode  The input Text device path node.
1348 
1349   @return A pointer to the newly-created Infini Band device path structure.
1350 
1351 **/
1352 static
1353 EFI_DEVICE_PATH_PROTOCOL *
1354 DevPathFromTextInfiniband (
1355   IN CHAR16 *TextDeviceNode
1356   )
1357 {
1358   CHAR16                  *FlagsStr;
1359   CHAR16                  *GuidStr;
1360   CHAR16                  *SidStr;
1361   CHAR16                  *TidStr;
1362   CHAR16                  *DidStr;
1363   INFINIBAND_DEVICE_PATH  *InfiniBand;
1364 
1365   FlagsStr   = GetNextParamStr (&TextDeviceNode);
1366   GuidStr    = GetNextParamStr (&TextDeviceNode);
1367   SidStr     = GetNextParamStr (&TextDeviceNode);
1368   TidStr     = GetNextParamStr (&TextDeviceNode);
1369   DidStr     = GetNextParamStr (&TextDeviceNode);
1370   InfiniBand = (INFINIBAND_DEVICE_PATH *) CreateDeviceNode (
1371                                             MESSAGING_DEVICE_PATH,
1372                                             MSG_INFINIBAND_DP,
1373                                             (UINT16) sizeof (INFINIBAND_DEVICE_PATH)
1374                                             );
1375 
1376   InfiniBand->ResourceFlags = (UINT32) Strtoi (FlagsStr);
1377   StrToGuid (GuidStr, (EFI_GUID *) InfiniBand->PortGid);
1378   Strtoi64 (SidStr, &InfiniBand->ServiceId);
1379   Strtoi64 (TidStr, &InfiniBand->TargetPortId);
1380   Strtoi64 (DidStr, &InfiniBand->DeviceId);
1381 
1382   return (EFI_DEVICE_PATH_PROTOCOL *) InfiniBand;
1383 }
1384 
1385 /**
1386   Converts a text device path node to Vendor-Defined Messaging device path structure.
1387 
1388   @param TextDeviceNode  The input Text device path node.
1389 
1390   @return A pointer to the newly-created Vendor-Defined Messaging device path structure.
1391 
1392 **/
1393 static
1394 EFI_DEVICE_PATH_PROTOCOL *
1395 DevPathFromTextVenMsg (
1396   IN CHAR16 *TextDeviceNode
1397   )
1398 {
1399   return ConvertFromTextVendor (
1400             TextDeviceNode,
1401             MESSAGING_DEVICE_PATH,
1402             MSG_VENDOR_DP
1403             );
1404 }
1405 
1406 /**
1407   Converts a text device path node to Vendor defined PC-ANSI device path structure.
1408 
1409   @param TextDeviceNode  The input Text device path node.
1410 
1411   @return A pointer to the newly-created Vendor defined PC-ANSI device path structure.
1412 
1413 **/
1414 static
1415 EFI_DEVICE_PATH_PROTOCOL *
1416 DevPathFromTextVenPcAnsi (
1417   IN CHAR16 *TextDeviceNode
1418   )
1419 {
1420   VENDOR_DEVICE_PATH  *Vendor;
1421 
1422   Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1423                                     MESSAGING_DEVICE_PATH,
1424                                     MSG_VENDOR_DP,
1425                                     (UINT16) sizeof (VENDOR_DEVICE_PATH));
1426   CopyGuid (&Vendor->Guid, &gEfiPcAnsiGuid);
1427 
1428   return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1429 }
1430 
1431 /**
1432   Converts a text device path node to Vendor defined VT100 device path structure.
1433 
1434   @param TextDeviceNode  The input Text device path node.
1435 
1436   @return A pointer to the newly-created Vendor defined VT100 device path structure.
1437 
1438 **/
1439 static
1440 EFI_DEVICE_PATH_PROTOCOL *
1441 DevPathFromTextVenVt100 (
1442   IN CHAR16 *TextDeviceNode
1443   )
1444 {
1445   VENDOR_DEVICE_PATH  *Vendor;
1446 
1447   Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1448                                     MESSAGING_DEVICE_PATH,
1449                                     MSG_VENDOR_DP,
1450                                     (UINT16) sizeof (VENDOR_DEVICE_PATH));
1451   CopyGuid (&Vendor->Guid, &gEfiVT100Guid);
1452 
1453   return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1454 }
1455 
1456 /**
1457   Converts a text device path node to Vendor defined VT100 Plus device path structure.
1458 
1459   @param TextDeviceNode  The input Text device path node.
1460 
1461   @return A pointer to the newly-created Vendor defined VT100 Plus device path structure.
1462 
1463 **/
1464 static
1465 EFI_DEVICE_PATH_PROTOCOL *
1466 DevPathFromTextVenVt100Plus (
1467   IN CHAR16 *TextDeviceNode
1468   )
1469 {
1470   VENDOR_DEVICE_PATH  *Vendor;
1471 
1472   Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1473                                     MESSAGING_DEVICE_PATH,
1474                                     MSG_VENDOR_DP,
1475                                     (UINT16) sizeof (VENDOR_DEVICE_PATH));
1476   CopyGuid (&Vendor->Guid, &gEfiVT100PlusGuid);
1477 
1478   return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1479 }
1480 
1481 /**
1482   Converts a text device path node to Vendor defined UTF8 device path structure.
1483 
1484   @param TextDeviceNode  The input Text device path node.
1485 
1486   @return A pointer to the newly-created Vendor defined UTF8 device path structure.
1487 
1488 **/
1489 static
1490 EFI_DEVICE_PATH_PROTOCOL *
1491 DevPathFromTextVenUtf8 (
1492   IN CHAR16 *TextDeviceNode
1493   )
1494 {
1495   VENDOR_DEVICE_PATH  *Vendor;
1496 
1497   Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1498                                     MESSAGING_DEVICE_PATH,
1499                                     MSG_VENDOR_DP,
1500                                     (UINT16) sizeof (VENDOR_DEVICE_PATH));
1501   CopyGuid (&Vendor->Guid, &gEfiVTUTF8Guid);
1502 
1503   return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1504 }
1505 
1506 /**
1507   Converts a text device path node to UART Flow Control device path structure.
1508 
1509   @param TextDeviceNode  The input Text device path node.
1510 
1511   @return A pointer to the newly-created UART Flow Control device path structure.
1512 
1513 **/
1514 static
1515 EFI_DEVICE_PATH_PROTOCOL *
1516 DevPathFromTextUartFlowCtrl (
1517   IN CHAR16 *TextDeviceNode
1518   )
1519 {
1520   CHAR16                        *ValueStr;
1521   UART_FLOW_CONTROL_DEVICE_PATH *UartFlowControl;
1522 
1523   ValueStr        = GetNextParamStr (&TextDeviceNode);
1524   UartFlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *) CreateDeviceNode (
1525                                                         MESSAGING_DEVICE_PATH,
1526                                                         MSG_VENDOR_DP,
1527                                                         (UINT16) sizeof (UART_FLOW_CONTROL_DEVICE_PATH)
1528                                                         );
1529 
1530   CopyGuid (&UartFlowControl->Guid, &gEfiUartDevicePathGuid);
1531   if (StrCmp (ValueStr, "XonXoff") == 0) {
1532     UartFlowControl->FlowControlMap = 2;
1533   } else if (StrCmp (ValueStr, "Hardware") == 0) {
1534     UartFlowControl->FlowControlMap = 1;
1535   } else {
1536     UartFlowControl->FlowControlMap = 0;
1537   }
1538 
1539   return (EFI_DEVICE_PATH_PROTOCOL *) UartFlowControl;
1540 }
1541 
1542 /**
1543   Converts a text device path node to Serial Attached SCSI device path structure.
1544 
1545   @param TextDeviceNode  The input Text device path node.
1546 
1547   @return A pointer to the newly-created Serial Attached SCSI device path structure.
1548 
1549 **/
1550 static
1551 EFI_DEVICE_PATH_PROTOCOL *
1552 DevPathFromTextSAS (
1553   IN CHAR16 *TextDeviceNode
1554   )
1555 {
1556   CHAR16          *AddressStr;
1557   CHAR16          *LunStr;
1558   CHAR16          *RTPStr;
1559   CHAR16          *SASSATAStr;
1560   CHAR16          *LocationStr;
1561   CHAR16          *ConnectStr;
1562   CHAR16          *DriveBayStr;
1563   CHAR16          *ReservedStr;
1564   UINT16          Info;
1565   UINT16          Uint16;
1566   SAS_DEVICE_PATH *Sas;
1567 
1568   AddressStr  = GetNextParamStr (&TextDeviceNode);
1569   LunStr      = GetNextParamStr (&TextDeviceNode);
1570   RTPStr      = GetNextParamStr (&TextDeviceNode);
1571   SASSATAStr  = GetNextParamStr (&TextDeviceNode);
1572   LocationStr = GetNextParamStr (&TextDeviceNode);
1573   ConnectStr  = GetNextParamStr (&TextDeviceNode);
1574   DriveBayStr = GetNextParamStr (&TextDeviceNode);
1575   ReservedStr = GetNextParamStr (&TextDeviceNode);
1576   Sas         = (SAS_DEVICE_PATH *) CreateDeviceNode (
1577                                        MESSAGING_DEVICE_PATH,
1578                                        MSG_VENDOR_DP,
1579                                        (UINT16) sizeof (SAS_DEVICE_PATH)
1580                                        );
1581 
1582   CopyGuid (&Sas->Guid, &gEfiSasDevicePathGuid);
1583   Strtoi64 (AddressStr, &Sas->SasAddress);
1584   Strtoi64 (LunStr, &Sas->Lun);
1585   Sas->RelativeTargetPort = (UINT16) Strtoi (RTPStr);
1586 
1587   if (StrCmp (SASSATAStr, "NoTopology") == 0) {
1588     Info = 0x0;
1589 
1590   } else if ((StrCmp (SASSATAStr, "SATA") == 0) || (StrCmp (SASSATAStr, "SAS") == 0)) {
1591 
1592     Uint16 = (UINT16) Strtoi (DriveBayStr);
1593     if (Uint16 == 0) {
1594       Info = 0x1;
1595     } else {
1596       Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));
1597     }
1598 
1599     if (StrCmp (SASSATAStr, "SATA") == 0) {
1600       Info |= BIT4;
1601     }
1602 
1603     //
1604     // Location is an integer between 0 and 1 or else
1605     // the keyword Internal (0) or External (1).
1606     //
1607     if (StrCmp (LocationStr, "External") == 0) {
1608       Uint16 = 1;
1609     } else if (StrCmp (LocationStr, "Internal") == 0) {
1610       Uint16 = 0;
1611     } else {
1612       Uint16 = ((UINT16) Strtoi (LocationStr) & BIT0);
1613     }
1614     Info |= (Uint16 << 5);
1615 
1616     //
1617     // Connect is an integer between 0 and 3 or else
1618     // the keyword Direct (0) or Expanded (1).
1619     //
1620     if (StrCmp (ConnectStr, "Expanded") == 0) {
1621       Uint16 = 1;
1622     } else if (StrCmp (ConnectStr, "Direct") == 0) {
1623       Uint16 = 0;
1624     } else {
1625       Uint16 = ((UINT16) Strtoi (ConnectStr) & (BIT0 | BIT1));
1626     }
1627     Info |= (Uint16 << 6);
1628 
1629   } else {
1630     Info = (UINT16) Strtoi (SASSATAStr);
1631   }
1632 
1633   Sas->DeviceTopology = Info;
1634   Sas->Reserved       = (UINT32) Strtoi (ReservedStr);
1635 
1636   return (EFI_DEVICE_PATH_PROTOCOL *) Sas;
1637 }
1638 
1639 /**
1640   Converts a text device path node to Serial Attached SCSI Ex device path structure.
1641 
1642   @param TextDeviceNode  The input Text device path node.
1643 
1644   @return A pointer to the newly-created Serial Attached SCSI Ex device path structure.
1645 
1646 **/
1647 static
1648 EFI_DEVICE_PATH_PROTOCOL *
1649 DevPathFromTextSasEx (
1650   IN CHAR16 *TextDeviceNode
1651   )
1652 {
1653   CHAR16            *AddressStr;
1654   CHAR16            *LunStr;
1655   CHAR16            *RTPStr;
1656   CHAR16            *SASSATAStr;
1657   CHAR16            *LocationStr;
1658   CHAR16            *ConnectStr;
1659   CHAR16            *DriveBayStr;
1660   UINT16            Info;
1661   UINT16            Uint16;
1662   UINT64            SasAddress;
1663   UINT64            Lun;
1664   SASEX_DEVICE_PATH *SasEx;
1665 
1666   AddressStr  = GetNextParamStr (&TextDeviceNode);
1667   LunStr      = GetNextParamStr (&TextDeviceNode);
1668   RTPStr      = GetNextParamStr (&TextDeviceNode);
1669   SASSATAStr  = GetNextParamStr (&TextDeviceNode);
1670   LocationStr = GetNextParamStr (&TextDeviceNode);
1671   ConnectStr  = GetNextParamStr (&TextDeviceNode);
1672   DriveBayStr = GetNextParamStr (&TextDeviceNode);
1673   SasEx       = (SASEX_DEVICE_PATH *) CreateDeviceNode (
1674                                         MESSAGING_DEVICE_PATH,
1675                                         MSG_SASEX_DP,
1676                                         (UINT16) sizeof (SASEX_DEVICE_PATH)
1677                                         );
1678 
1679   Strtoi64 (AddressStr, &SasAddress);
1680   Strtoi64 (LunStr,     &Lun);
1681   WriteUnaligned64 ((UINT64 *) &SasEx->SasAddress, SwapBytes64 (SasAddress));
1682   WriteUnaligned64 ((UINT64 *) &SasEx->Lun,        SwapBytes64 (Lun));
1683   SasEx->RelativeTargetPort      = (UINT16) Strtoi (RTPStr);
1684 
1685   if (StrCmp (SASSATAStr, "NoTopology") == 0) {
1686     Info = 0x0;
1687 
1688   } else if ((StrCmp (SASSATAStr, "SATA") == 0) || (StrCmp (SASSATAStr, "SAS") == 0)) {
1689 
1690     Uint16 = (UINT16) Strtoi (DriveBayStr);
1691     if (Uint16 == 0) {
1692       Info = 0x1;
1693     } else {
1694       Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));
1695     }
1696 
1697     if (StrCmp (SASSATAStr, "SATA") == 0) {
1698       Info |= BIT4;
1699     }
1700 
1701     //
1702     // Location is an integer between 0 and 1 or else
1703     // the keyword Internal (0) or External (1).
1704     //
1705     if (StrCmp (LocationStr, "External") == 0) {
1706       Uint16 = 1;
1707     } else if (StrCmp (LocationStr, "Internal") == 0) {
1708       Uint16 = 0;
1709     } else {
1710       Uint16 = ((UINT16) Strtoi (LocationStr) & BIT0);
1711     }
1712     Info |= (Uint16 << 5);
1713 
1714     //
1715     // Connect is an integer between 0 and 3 or else
1716     // the keyword Direct (0) or Expanded (1).
1717     //
1718     if (StrCmp (ConnectStr, "Expanded") == 0) {
1719       Uint16 = 1;
1720     } else if (StrCmp (ConnectStr, "Direct") == 0) {
1721       Uint16 = 0;
1722     } else {
1723       Uint16 = ((UINT16) Strtoi (ConnectStr) & (BIT0 | BIT1));
1724     }
1725     Info |= (Uint16 << 6);
1726 
1727   } else {
1728     Info = (UINT16) Strtoi (SASSATAStr);
1729   }
1730 
1731   SasEx->DeviceTopology = Info;
1732 
1733   return (EFI_DEVICE_PATH_PROTOCOL *) SasEx;
1734 }
1735 
1736 /**
1737   Converts a text device path node to NVM Express Namespace device path structure.
1738 
1739   @param TextDeviceNode  The input Text device path node.
1740 
1741   @return A pointer to the newly-created NVM Express Namespace device path structure.
1742 
1743 **/
1744 static
1745 EFI_DEVICE_PATH_PROTOCOL *
1746 DevPathFromTextNVMe (
1747   IN CHAR16 *TextDeviceNode
1748   )
1749 {
1750   CHAR16                     *NamespaceIdStr;
1751   CHAR16                     *NamespaceUuidStr;
1752   NVME_NAMESPACE_DEVICE_PATH *Nvme;
1753   UINT8                      *Uuid;
1754   UINTN                      Index;
1755 
1756   NamespaceIdStr   = GetNextParamStr (&TextDeviceNode);
1757   NamespaceUuidStr = GetNextParamStr (&TextDeviceNode);
1758   Nvme = (NVME_NAMESPACE_DEVICE_PATH *) CreateDeviceNode (
1759     MESSAGING_DEVICE_PATH,
1760     MSG_NVME_NAMESPACE_DP,
1761     (UINT16) sizeof (NVME_NAMESPACE_DEVICE_PATH)
1762     );
1763 
1764   Nvme->NamespaceId = (UINT32) Strtoi (NamespaceIdStr);
1765   Uuid = (UINT8 *) &Nvme->NamespaceUuid;
1766 
1767   Index = sizeof (Nvme->NamespaceUuid) / sizeof (UINT8);
1768   while (Index-- != 0) {
1769     Uuid[Index] = (UINT8) StrHexToUintn (SplitStr (&NamespaceUuidStr, '-'));
1770   }
1771 
1772   return (EFI_DEVICE_PATH_PROTOCOL *) Nvme;
1773 }
1774 
1775 /**
1776   Converts a text device path node to UFS device path structure.
1777 
1778   @param TextDeviceNode  The input Text device path node.
1779 
1780   @return A pointer to the newly-created UFS device path structure.
1781 
1782 **/
1783 static
1784 EFI_DEVICE_PATH_PROTOCOL *
1785 DevPathFromTextUfs (
1786   IN CHAR16 *TextDeviceNode
1787   )
1788 {
1789   CHAR16            *PunStr;
1790   CHAR16            *LunStr;
1791   UFS_DEVICE_PATH   *Ufs;
1792 
1793   PunStr = GetNextParamStr (&TextDeviceNode);
1794   LunStr = GetNextParamStr (&TextDeviceNode);
1795   Ufs    = (UFS_DEVICE_PATH *) CreateDeviceNode (
1796                                  MESSAGING_DEVICE_PATH,
1797                                  MSG_UFS_DP,
1798                                  (UINT16) sizeof (UFS_DEVICE_PATH)
1799                                  );
1800 
1801   Ufs->Pun = (UINT8) Strtoi (PunStr);
1802   Ufs->Lun = (UINT8) Strtoi (LunStr);
1803 
1804   return (EFI_DEVICE_PATH_PROTOCOL *) Ufs;
1805 }
1806 
1807 /**
1808   Converts a text device path node to SD (Secure Digital) device path structure.
1809 
1810   @param TextDeviceNode  The input Text device path node.
1811 
1812   @return A pointer to the newly-created SD device path structure.
1813 
1814 **/
1815 static
1816 EFI_DEVICE_PATH_PROTOCOL *
1817 DevPathFromTextSd (
1818   IN CHAR16 *TextDeviceNode
1819   )
1820 {
1821   CHAR16            *SlotNumberStr;
1822   SD_DEVICE_PATH    *Sd;
1823 
1824   SlotNumberStr = GetNextParamStr (&TextDeviceNode);
1825   Sd            = (SD_DEVICE_PATH *) CreateDeviceNode (
1826                                        MESSAGING_DEVICE_PATH,
1827                                        MSG_SD_DP,
1828                                        (UINT16) sizeof (SD_DEVICE_PATH)
1829                                        );
1830 
1831   Sd->SlotNumber = (UINT8) Strtoi (SlotNumberStr);
1832 
1833   return (EFI_DEVICE_PATH_PROTOCOL *) Sd;
1834 }
1835 
1836 /**
1837   Converts a text device path node to EMMC (Embedded MMC) device path structure.
1838 
1839   @param TextDeviceNode  The input Text device path node.
1840 
1841   @return A pointer to the newly-created EMMC device path structure.
1842 
1843 **/
1844 static
1845 EFI_DEVICE_PATH_PROTOCOL *
1846 DevPathFromTextEmmc (
1847   IN CHAR16 *TextDeviceNode
1848   )
1849 {
1850   CHAR16            *SlotNumberStr;
1851   EMMC_DEVICE_PATH  *Emmc;
1852 
1853   SlotNumberStr = GetNextParamStr (&TextDeviceNode);
1854   Emmc          = (EMMC_DEVICE_PATH *) CreateDeviceNode (
1855                                        MESSAGING_DEVICE_PATH,
1856                                        MSG_EMMC_DP,
1857                                        (UINT16) sizeof (EMMC_DEVICE_PATH)
1858                                        );
1859 
1860   Emmc->SlotNumber = (UINT8) Strtoi (SlotNumberStr);
1861 
1862   return (EFI_DEVICE_PATH_PROTOCOL *) Emmc;
1863 }
1864 
1865 /**
1866   Converts a text device path node to Debug Port device path structure.
1867 
1868   @param TextDeviceNode  The input Text device path node.
1869 
1870   @return A pointer to the newly-created Debug Port device path structure.
1871 
1872 **/
1873 static
1874 EFI_DEVICE_PATH_PROTOCOL *
1875 DevPathFromTextDebugPort (
1876   IN CHAR16 *TextDeviceNode
1877   )
1878 {
1879   VENDOR_DEVICE_PATH  *Vend;
1880 
1881   Vend = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1882                                                     MESSAGING_DEVICE_PATH,
1883                                                     MSG_VENDOR_DP,
1884                                                     (UINT16) sizeof (VENDOR_DEVICE_PATH)
1885                                                     );
1886 
1887   CopyGuid (&Vend->Guid, &gEfiDebugPortProtocolGuid);
1888 
1889   return (EFI_DEVICE_PATH_PROTOCOL *) Vend;
1890 }
1891 
1892 /**
1893   Converts a text device path node to MAC device path structure.
1894 
1895   @param TextDeviceNode  The input Text device path node.
1896 
1897   @return A pointer to the newly-created MAC device path structure.
1898 
1899 **/
1900 static
1901 EFI_DEVICE_PATH_PROTOCOL *
1902 DevPathFromTextMAC (
1903   IN CHAR16 *TextDeviceNode
1904   )
1905 {
1906   CHAR16                *AddressStr;
1907   CHAR16                *IfTypeStr;
1908   UINTN                 Length;
1909   MAC_ADDR_DEVICE_PATH  *MACDevPath;
1910 
1911   AddressStr    = GetNextParamStr (&TextDeviceNode);
1912   IfTypeStr     = GetNextParamStr (&TextDeviceNode);
1913   MACDevPath    = (MAC_ADDR_DEVICE_PATH *) CreateDeviceNode (
1914                                               MESSAGING_DEVICE_PATH,
1915                                               MSG_MAC_ADDR_DP,
1916                                               (UINT16) sizeof (MAC_ADDR_DEVICE_PATH)
1917                                               );
1918 
1919   MACDevPath->IfType   = (UINT8) Strtoi (IfTypeStr);
1920 
1921   Length = sizeof (EFI_MAC_ADDRESS);
1922   if (MACDevPath->IfType == 0x01 || MACDevPath->IfType == 0x00) {
1923     Length = 6;
1924   }
1925 
1926   StrHexToBytes (AddressStr, Length * 2, MACDevPath->MacAddress.Addr, Length);
1927 
1928   return (EFI_DEVICE_PATH_PROTOCOL *) MACDevPath;
1929 }
1930 
1931 
1932 /**
1933   Converts a text format to the network protocol ID.
1934 
1935   @param Text  String of protocol field.
1936 
1937   @return Network protocol ID .
1938 
1939 **/
1940 static
1941 UINTN
1942 NetworkProtocolFromText (
1943   IN CHAR16 *Text
1944   )
1945 {
1946   if (StrCmp (Text, "UDP") == 0) {
1947     return RFC_1700_UDP_PROTOCOL;
1948   }
1949 
1950   if (StrCmp (Text, "TCP") == 0) {
1951     return RFC_1700_TCP_PROTOCOL;
1952   }
1953 
1954   return Strtoi (Text);
1955 }
1956 
1957 
1958 /**
1959   Converts a text device path node to IPV4 device path structure.
1960 
1961   @param TextDeviceNode  The input Text device path node.
1962 
1963   @return A pointer to the newly-created IPV4 device path structure.
1964 
1965 **/
1966 static
1967 EFI_DEVICE_PATH_PROTOCOL *
1968 DevPathFromTextIPv4 (
1969   IN CHAR16 *TextDeviceNode
1970   )
1971 {
1972   CHAR16            *RemoteIPStr;
1973   CHAR16            *ProtocolStr;
1974   CHAR16            *TypeStr;
1975   CHAR16            *LocalIPStr;
1976   CHAR16            *GatewayIPStr;
1977   CHAR16            *SubnetMaskStr;
1978   IPv4_DEVICE_PATH  *IPv4;
1979 
1980   RemoteIPStr           = GetNextParamStr (&TextDeviceNode);
1981   ProtocolStr           = GetNextParamStr (&TextDeviceNode);
1982   TypeStr               = GetNextParamStr (&TextDeviceNode);
1983   LocalIPStr            = GetNextParamStr (&TextDeviceNode);
1984   GatewayIPStr          = GetNextParamStr (&TextDeviceNode);
1985   SubnetMaskStr         = GetNextParamStr (&TextDeviceNode);
1986   IPv4                  = (IPv4_DEVICE_PATH *) CreateDeviceNode (
1987                                                  MESSAGING_DEVICE_PATH,
1988                                                  MSG_IPv4_DP,
1989                                                  (UINT16) sizeof (IPv4_DEVICE_PATH)
1990                                                  );
1991 
1992   StrToIpv4Address (RemoteIPStr, NULL, &IPv4->RemoteIpAddress, NULL);
1993   IPv4->Protocol = (UINT16) NetworkProtocolFromText (ProtocolStr);
1994   if (StrCmp (TypeStr, "Static") == 0) {
1995     IPv4->StaticIpAddress = TRUE;
1996   } else {
1997     IPv4->StaticIpAddress = FALSE;
1998   }
1999 
2000   StrToIpv4Address (LocalIPStr, NULL, &IPv4->LocalIpAddress, NULL);
2001   if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*SubnetMaskStr)) {
2002     StrToIpv4Address (GatewayIPStr,  NULL, &IPv4->GatewayIpAddress, NULL);
2003     StrToIpv4Address (SubnetMaskStr, NULL, &IPv4->SubnetMask,       NULL);
2004   } else {
2005     ZeroMem (&IPv4->GatewayIpAddress, sizeof (IPv4->GatewayIpAddress));
2006     ZeroMem (&IPv4->SubnetMask,    sizeof (IPv4->SubnetMask));
2007   }
2008 
2009   IPv4->LocalPort       = 0;
2010   IPv4->RemotePort      = 0;
2011 
2012   return (EFI_DEVICE_PATH_PROTOCOL *) IPv4;
2013 }
2014 
2015 /**
2016   Converts a text device path node to IPV6 device path structure.
2017 
2018   @param TextDeviceNode  The input Text device path node.
2019 
2020   @return A pointer to the newly-created IPV6 device path structure.
2021 
2022 **/
2023 static
2024 EFI_DEVICE_PATH_PROTOCOL *
2025 DevPathFromTextIPv6 (
2026   IN CHAR16 *TextDeviceNode
2027   )
2028 {
2029   CHAR16            *RemoteIPStr;
2030   CHAR16            *ProtocolStr;
2031   CHAR16            *TypeStr;
2032   CHAR16            *LocalIPStr;
2033   CHAR16            *GatewayIPStr;
2034   CHAR16            *PrefixLengthStr;
2035   IPv6_DEVICE_PATH  *IPv6;
2036 
2037   RemoteIPStr           = GetNextParamStr (&TextDeviceNode);
2038   ProtocolStr           = GetNextParamStr (&TextDeviceNode);
2039   TypeStr               = GetNextParamStr (&TextDeviceNode);
2040   LocalIPStr            = GetNextParamStr (&TextDeviceNode);
2041   PrefixLengthStr       = GetNextParamStr (&TextDeviceNode);
2042   GatewayIPStr          = GetNextParamStr (&TextDeviceNode);
2043   IPv6                  = (IPv6_DEVICE_PATH *) CreateDeviceNode (
2044                                                  MESSAGING_DEVICE_PATH,
2045                                                  MSG_IPv6_DP,
2046                                                  (UINT16) sizeof (IPv6_DEVICE_PATH)
2047                                                  );
2048 
2049   StrToIpv6Address (RemoteIPStr, NULL, &IPv6->RemoteIpAddress, NULL);
2050   IPv6->Protocol        = (UINT16) NetworkProtocolFromText (ProtocolStr);
2051   if (StrCmp (TypeStr, "Static") == 0) {
2052     IPv6->IpAddressOrigin = 0;
2053   } else if (StrCmp (TypeStr, "StatelessAutoConfigure") == 0) {
2054     IPv6->IpAddressOrigin = 1;
2055   } else {
2056     IPv6->IpAddressOrigin = 2;
2057   }
2058 
2059   StrToIpv6Address (LocalIPStr, NULL, &IPv6->LocalIpAddress, NULL);
2060   if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*PrefixLengthStr)) {
2061     StrToIpv6Address (GatewayIPStr, NULL, &IPv6->GatewayIpAddress, NULL);
2062     IPv6->PrefixLength = (UINT8) Strtoi (PrefixLengthStr);
2063   } else {
2064     ZeroMem (&IPv6->GatewayIpAddress, sizeof (IPv6->GatewayIpAddress));
2065     IPv6->PrefixLength = 0;
2066   }
2067 
2068   IPv6->LocalPort       = 0;
2069   IPv6->RemotePort      = 0;
2070 
2071   return (EFI_DEVICE_PATH_PROTOCOL *) IPv6;
2072 }
2073 
2074 /**
2075   Converts a text device path node to UART device path structure.
2076 
2077   @param TextDeviceNode  The input Text device path node.
2078 
2079   @return A pointer to the newly-created UART device path structure.
2080 
2081 **/
2082 static
2083 EFI_DEVICE_PATH_PROTOCOL *
2084 DevPathFromTextUart (
2085   IN CHAR16 *TextDeviceNode
2086   )
2087 {
2088   CHAR16            *BaudStr;
2089   CHAR16            *DataBitsStr;
2090   CHAR16            *ParityStr;
2091   CHAR16            *StopBitsStr;
2092   UART_DEVICE_PATH  *Uart;
2093 
2094   BaudStr         = GetNextParamStr (&TextDeviceNode);
2095   DataBitsStr     = GetNextParamStr (&TextDeviceNode);
2096   ParityStr       = GetNextParamStr (&TextDeviceNode);
2097   StopBitsStr     = GetNextParamStr (&TextDeviceNode);
2098   Uart            = (UART_DEVICE_PATH *) CreateDeviceNode (
2099                                            MESSAGING_DEVICE_PATH,
2100                                            MSG_UART_DP,
2101                                            (UINT16) sizeof (UART_DEVICE_PATH)
2102                                            );
2103 
2104   if (StrCmp (BaudStr, "DEFAULT") == 0) {
2105     Uart->BaudRate = 115200;
2106   } else {
2107     Strtoi64 (BaudStr, &Uart->BaudRate);
2108   }
2109   Uart->DataBits  = (UINT8) ((StrCmp (DataBitsStr, "DEFAULT") == 0) ? 8 : Strtoi (DataBitsStr));
2110   switch (*ParityStr) {
2111   case 'D':
2112     Uart->Parity = 0;
2113     break;
2114 
2115   case 'N':
2116     Uart->Parity = 1;
2117     break;
2118 
2119   case 'E':
2120     Uart->Parity = 2;
2121     break;
2122 
2123   case 'O':
2124     Uart->Parity = 3;
2125     break;
2126 
2127   case 'M':
2128     Uart->Parity = 4;
2129     break;
2130 
2131   case 'S':
2132     Uart->Parity = 5;
2133     break;
2134 
2135   default:
2136     Uart->Parity = (UINT8) Strtoi (ParityStr);
2137     break;
2138   }
2139 
2140   if (StrCmp (StopBitsStr, "D") == 0) {
2141     Uart->StopBits = (UINT8) 0;
2142   } else if (StrCmp (StopBitsStr, "1") == 0) {
2143     Uart->StopBits = (UINT8) 1;
2144   } else if (StrCmp (StopBitsStr, "1.5") == 0) {
2145     Uart->StopBits = (UINT8) 2;
2146   } else if (StrCmp (StopBitsStr, "2") == 0) {
2147     Uart->StopBits = (UINT8) 3;
2148   } else {
2149     Uart->StopBits = (UINT8) Strtoi (StopBitsStr);
2150   }
2151 
2152   return (EFI_DEVICE_PATH_PROTOCOL *) Uart;
2153 }
2154 
2155 /**
2156   Converts a text device path node to USB class device path structure.
2157 
2158   @param TextDeviceNode  The input Text device path node.
2159   @param UsbClassText    A pointer to USB_CLASS_TEXT structure to be integrated to USB Class Text.
2160 
2161   @return A pointer to the newly-created USB class device path structure.
2162 
2163 **/
2164 static
2165 EFI_DEVICE_PATH_PROTOCOL *
2166 ConvertFromTextUsbClass (
2167   IN CHAR16         *TextDeviceNode,
2168   IN USB_CLASS_TEXT *UsbClassText
2169   )
2170 {
2171   CHAR16                *VIDStr;
2172   CHAR16                *PIDStr;
2173   CHAR16                *ClassStr;
2174   CHAR16                *SubClassStr;
2175   CHAR16                *ProtocolStr;
2176   USB_CLASS_DEVICE_PATH *UsbClass;
2177 
2178   UsbClass    = (USB_CLASS_DEVICE_PATH *) CreateDeviceNode (
2179                                             MESSAGING_DEVICE_PATH,
2180                                             MSG_USB_CLASS_DP,
2181                                             (UINT16) sizeof (USB_CLASS_DEVICE_PATH)
2182                                             );
2183 
2184   VIDStr      = GetNextParamStr (&TextDeviceNode);
2185   PIDStr      = GetNextParamStr (&TextDeviceNode);
2186   if (UsbClassText->ClassExist) {
2187     ClassStr = GetNextParamStr (&TextDeviceNode);
2188     UsbClass->DeviceClass = (UINT8) Strtoi (ClassStr);
2189   } else {
2190     UsbClass->DeviceClass = UsbClassText->Class;
2191   }
2192   if (UsbClassText->SubClassExist) {
2193     SubClassStr = GetNextParamStr (&TextDeviceNode);
2194     UsbClass->DeviceSubClass = (UINT8) Strtoi (SubClassStr);
2195   } else {
2196     UsbClass->DeviceSubClass = UsbClassText->SubClass;
2197   }
2198 
2199   ProtocolStr = GetNextParamStr (&TextDeviceNode);
2200 
2201   UsbClass->VendorId        = (UINT16) Strtoi (VIDStr);
2202   UsbClass->ProductId       = (UINT16) Strtoi (PIDStr);
2203   UsbClass->DeviceProtocol  = (UINT8) Strtoi (ProtocolStr);
2204 
2205   return (EFI_DEVICE_PATH_PROTOCOL *) UsbClass;
2206 }
2207 
2208 
2209 /**
2210   Converts a text device path node to USB class device path structure.
2211 
2212   @param TextDeviceNode  The input Text device path node.
2213 
2214   @return A pointer to the newly-created USB class device path structure.
2215 
2216 **/
2217 static
2218 EFI_DEVICE_PATH_PROTOCOL *
2219 DevPathFromTextUsbClass (
2220   IN CHAR16 *TextDeviceNode
2221   )
2222 {
2223   USB_CLASS_TEXT  UsbClassText;
2224 
2225   UsbClassText.ClassExist    = TRUE;
2226   UsbClassText.SubClassExist = TRUE;
2227 
2228   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2229 }
2230 
2231 /**
2232   Converts a text device path node to USB audio device path structure.
2233 
2234   @param TextDeviceNode  The input Text device path node.
2235 
2236   @return A pointer to the newly-created USB audio device path structure.
2237 
2238 **/
2239 static
2240 EFI_DEVICE_PATH_PROTOCOL *
2241 DevPathFromTextUsbAudio (
2242   IN CHAR16 *TextDeviceNode
2243   )
2244 {
2245   USB_CLASS_TEXT  UsbClassText;
2246 
2247   UsbClassText.ClassExist    = FALSE;
2248   UsbClassText.Class         = USB_CLASS_AUDIO;
2249   UsbClassText.SubClassExist = TRUE;
2250 
2251   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2252 }
2253 
2254 /**
2255   Converts a text device path node to USB CDC Control device path structure.
2256 
2257   @param TextDeviceNode  The input Text device path node.
2258 
2259   @return A pointer to the newly-created USB CDC Control device path structure.
2260 
2261 **/
2262 static
2263 EFI_DEVICE_PATH_PROTOCOL *
2264 DevPathFromTextUsbCDCControl (
2265   IN CHAR16 *TextDeviceNode
2266   )
2267 {
2268   USB_CLASS_TEXT  UsbClassText;
2269 
2270   UsbClassText.ClassExist    = FALSE;
2271   UsbClassText.Class         = USB_CLASS_CDCCONTROL;
2272   UsbClassText.SubClassExist = TRUE;
2273 
2274   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2275 }
2276 
2277 /**
2278   Converts a text device path node to USB HID device path structure.
2279 
2280   @param TextDeviceNode  The input Text device path node.
2281 
2282   @return A pointer to the newly-created USB HID device path structure.
2283 
2284 **/
2285 static
2286 EFI_DEVICE_PATH_PROTOCOL *
2287 DevPathFromTextUsbHID (
2288   IN CHAR16 *TextDeviceNode
2289   )
2290 {
2291   USB_CLASS_TEXT  UsbClassText;
2292 
2293   UsbClassText.ClassExist    = FALSE;
2294   UsbClassText.Class         = USB_CLASS_HID;
2295   UsbClassText.SubClassExist = TRUE;
2296 
2297   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2298 }
2299 
2300 /**
2301   Converts a text device path node to USB Image device path structure.
2302 
2303   @param TextDeviceNode  The input Text device path node.
2304 
2305   @return A pointer to the newly-created USB Image device path structure.
2306 
2307 **/
2308 static
2309 EFI_DEVICE_PATH_PROTOCOL *
2310 DevPathFromTextUsbImage (
2311   IN CHAR16 *TextDeviceNode
2312   )
2313 {
2314   USB_CLASS_TEXT  UsbClassText;
2315 
2316   UsbClassText.ClassExist    = FALSE;
2317   UsbClassText.Class         = USB_CLASS_IMAGE;
2318   UsbClassText.SubClassExist = TRUE;
2319 
2320   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2321 }
2322 
2323 /**
2324   Converts a text device path node to USB Print device path structure.
2325 
2326   @param TextDeviceNode  The input Text device path node.
2327 
2328   @return A pointer to the newly-created USB Print device path structure.
2329 
2330 **/
2331 static
2332 EFI_DEVICE_PATH_PROTOCOL *
2333 DevPathFromTextUsbPrinter (
2334   IN CHAR16 *TextDeviceNode
2335   )
2336 {
2337   USB_CLASS_TEXT  UsbClassText;
2338 
2339   UsbClassText.ClassExist    = FALSE;
2340   UsbClassText.Class         = USB_CLASS_PRINTER;
2341   UsbClassText.SubClassExist = TRUE;
2342 
2343   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2344 }
2345 
2346 /**
2347   Converts a text device path node to USB mass storage device path structure.
2348 
2349   @param TextDeviceNode  The input Text device path node.
2350 
2351   @return A pointer to the newly-created USB mass storage device path structure.
2352 
2353 **/
2354 static
2355 EFI_DEVICE_PATH_PROTOCOL *
2356 DevPathFromTextUsbMassStorage (
2357   IN CHAR16 *TextDeviceNode
2358   )
2359 {
2360   USB_CLASS_TEXT  UsbClassText;
2361 
2362   UsbClassText.ClassExist    = FALSE;
2363   UsbClassText.Class         = USB_CLASS_MASS_STORAGE;
2364   UsbClassText.SubClassExist = TRUE;
2365 
2366   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2367 }
2368 
2369 /**
2370   Converts a text device path node to USB HUB device path structure.
2371 
2372   @param TextDeviceNode  The input Text device path node.
2373 
2374   @return A pointer to the newly-created USB HUB device path structure.
2375 
2376 **/
2377 static
2378 EFI_DEVICE_PATH_PROTOCOL *
2379 DevPathFromTextUsbHub (
2380   IN CHAR16 *TextDeviceNode
2381   )
2382 {
2383   USB_CLASS_TEXT  UsbClassText;
2384 
2385   UsbClassText.ClassExist    = FALSE;
2386   UsbClassText.Class         = USB_CLASS_HUB;
2387   UsbClassText.SubClassExist = TRUE;
2388 
2389   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2390 }
2391 
2392 /**
2393   Converts a text device path node to USB CDC data device path structure.
2394 
2395   @param TextDeviceNode  The input Text device path node.
2396 
2397   @return A pointer to the newly-created USB CDC data device path structure.
2398 
2399 **/
2400 static
2401 EFI_DEVICE_PATH_PROTOCOL *
2402 DevPathFromTextUsbCDCData (
2403   IN CHAR16 *TextDeviceNode
2404   )
2405 {
2406   USB_CLASS_TEXT  UsbClassText;
2407 
2408   UsbClassText.ClassExist    = FALSE;
2409   UsbClassText.Class         = USB_CLASS_CDCDATA;
2410   UsbClassText.SubClassExist = TRUE;
2411 
2412   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2413 }
2414 
2415 /**
2416   Converts a text device path node to USB smart card device path structure.
2417 
2418   @param TextDeviceNode  The input Text device path node.
2419 
2420   @return A pointer to the newly-created USB smart card device path structure.
2421 
2422 **/
2423 static
2424 EFI_DEVICE_PATH_PROTOCOL *
2425 DevPathFromTextUsbSmartCard (
2426   IN CHAR16 *TextDeviceNode
2427   )
2428 {
2429   USB_CLASS_TEXT  UsbClassText;
2430 
2431   UsbClassText.ClassExist    = FALSE;
2432   UsbClassText.Class         = USB_CLASS_SMART_CARD;
2433   UsbClassText.SubClassExist = TRUE;
2434 
2435   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2436 }
2437 
2438 /**
2439   Converts a text device path node to USB video device path structure.
2440 
2441   @param TextDeviceNode  The input Text device path node.
2442 
2443   @return A pointer to the newly-created USB video device path structure.
2444 
2445 **/
2446 static
2447 EFI_DEVICE_PATH_PROTOCOL *
2448 DevPathFromTextUsbVideo (
2449   IN CHAR16 *TextDeviceNode
2450   )
2451 {
2452   USB_CLASS_TEXT  UsbClassText;
2453 
2454   UsbClassText.ClassExist    = FALSE;
2455   UsbClassText.Class         = USB_CLASS_VIDEO;
2456   UsbClassText.SubClassExist = TRUE;
2457 
2458   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2459 }
2460 
2461 /**
2462   Converts a text device path node to USB diagnostic device path structure.
2463 
2464   @param TextDeviceNode  The input Text device path node.
2465 
2466   @return A pointer to the newly-created USB diagnostic device path structure.
2467 
2468 **/
2469 static
2470 EFI_DEVICE_PATH_PROTOCOL *
2471 DevPathFromTextUsbDiagnostic (
2472   IN CHAR16 *TextDeviceNode
2473   )
2474 {
2475   USB_CLASS_TEXT  UsbClassText;
2476 
2477   UsbClassText.ClassExist    = FALSE;
2478   UsbClassText.Class         = USB_CLASS_DIAGNOSTIC;
2479   UsbClassText.SubClassExist = TRUE;
2480 
2481   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2482 }
2483 
2484 /**
2485   Converts a text device path node to USB wireless device path structure.
2486 
2487   @param TextDeviceNode  The input Text device path node.
2488 
2489   @return A pointer to the newly-created USB wireless device path structure.
2490 
2491 **/
2492 static
2493 EFI_DEVICE_PATH_PROTOCOL *
2494 DevPathFromTextUsbWireless (
2495   IN CHAR16 *TextDeviceNode
2496   )
2497 {
2498   USB_CLASS_TEXT  UsbClassText;
2499 
2500   UsbClassText.ClassExist    = FALSE;
2501   UsbClassText.Class         = USB_CLASS_WIRELESS;
2502   UsbClassText.SubClassExist = TRUE;
2503 
2504   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2505 }
2506 
2507 /**
2508   Converts a text device path node to USB device firmware update device path structure.
2509 
2510   @param TextDeviceNode  The input Text device path node.
2511 
2512   @return A pointer to the newly-created USB device firmware update device path structure.
2513 
2514 **/
2515 static
2516 EFI_DEVICE_PATH_PROTOCOL *
2517 DevPathFromTextUsbDeviceFirmwareUpdate (
2518   IN CHAR16 *TextDeviceNode
2519   )
2520 {
2521   USB_CLASS_TEXT  UsbClassText;
2522 
2523   UsbClassText.ClassExist    = FALSE;
2524   UsbClassText.Class         = USB_CLASS_RESERVE;
2525   UsbClassText.SubClassExist = FALSE;
2526   UsbClassText.SubClass      = USB_SUBCLASS_FW_UPDATE;
2527 
2528   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2529 }
2530 
2531 /**
2532   Converts a text device path node to USB IRDA bridge device path structure.
2533 
2534   @param TextDeviceNode  The input Text device path node.
2535 
2536   @return A pointer to the newly-created USB IRDA bridge device path structure.
2537 
2538 **/
2539 static
2540 EFI_DEVICE_PATH_PROTOCOL *
2541 DevPathFromTextUsbIrdaBridge (
2542   IN CHAR16 *TextDeviceNode
2543   )
2544 {
2545   USB_CLASS_TEXT  UsbClassText;
2546 
2547   UsbClassText.ClassExist    = FALSE;
2548   UsbClassText.Class         = USB_CLASS_RESERVE;
2549   UsbClassText.SubClassExist = FALSE;
2550   UsbClassText.SubClass      = USB_SUBCLASS_IRDA_BRIDGE;
2551 
2552   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2553 }
2554 
2555 /**
2556   Converts a text device path node to USB text and measurement device path structure.
2557 
2558   @param TextDeviceNode  The input Text device path node.
2559 
2560   @return A pointer to the newly-created USB text and measurement device path structure.
2561 
2562 **/
2563 static
2564 EFI_DEVICE_PATH_PROTOCOL *
2565 DevPathFromTextUsbTestAndMeasurement (
2566   IN CHAR16 *TextDeviceNode
2567   )
2568 {
2569   USB_CLASS_TEXT  UsbClassText;
2570 
2571   UsbClassText.ClassExist    = FALSE;
2572   UsbClassText.Class         = USB_CLASS_RESERVE;
2573   UsbClassText.SubClassExist = FALSE;
2574   UsbClassText.SubClass      = USB_SUBCLASS_TEST;
2575 
2576   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2577 }
2578 
2579 /**
2580   Converts a text device path node to USB WWID device path structure.
2581 
2582   @param TextDeviceNode  The input Text device path node.
2583 
2584   @return A pointer to the newly-created USB WWID device path structure.
2585 
2586 **/
2587 static
2588 EFI_DEVICE_PATH_PROTOCOL *
2589 DevPathFromTextUsbWwid (
2590   IN CHAR16 *TextDeviceNode
2591   )
2592 {
2593   CHAR16                *VIDStr;
2594   CHAR16                *PIDStr;
2595   CHAR16                *InterfaceNumStr;
2596   CHAR16                *SerialNumberStr;
2597   USB_WWID_DEVICE_PATH  *UsbWwid;
2598   UINTN                 SerialNumberStrLen;
2599 
2600   VIDStr                   = GetNextParamStr (&TextDeviceNode);
2601   PIDStr                   = GetNextParamStr (&TextDeviceNode);
2602   InterfaceNumStr          = GetNextParamStr (&TextDeviceNode);
2603   SerialNumberStr          = GetNextParamStr (&TextDeviceNode);
2604   SerialNumberStrLen       = StrLen (SerialNumberStr);
2605   if (SerialNumberStrLen >= 2 &&
2606       SerialNumberStr[0] == '\"' &&
2607       SerialNumberStr[SerialNumberStrLen - 1] == '\"'
2608     ) {
2609     SerialNumberStr[SerialNumberStrLen - 1] = '\0';
2610     SerialNumberStr++;
2611     SerialNumberStrLen -= 2;
2612   }
2613   UsbWwid                  = (USB_WWID_DEVICE_PATH *) CreateDeviceNode (
2614                                                          MESSAGING_DEVICE_PATH,
2615                                                          MSG_USB_WWID_DP,
2616                                                          (UINT16) (sizeof (USB_WWID_DEVICE_PATH) + SerialNumberStrLen * sizeof (CHAR16))
2617                                                          );
2618   UsbWwid->VendorId        = (UINT16) Strtoi (VIDStr);
2619   UsbWwid->ProductId       = (UINT16) Strtoi (PIDStr);
2620   UsbWwid->InterfaceNumber = (UINT16) Strtoi (InterfaceNumStr);
2621 
2622   //
2623   // There is no memory allocated in UsbWwid for the '\0' in SerialNumberStr.
2624   // Therefore, the '\0' will not be copied.
2625   //
2626   CopyMem (
2627     (UINT8 *) UsbWwid + sizeof (USB_WWID_DEVICE_PATH),
2628     SerialNumberStr,
2629     SerialNumberStrLen * sizeof (CHAR16)
2630     );
2631 
2632   return (EFI_DEVICE_PATH_PROTOCOL *) UsbWwid;
2633 }
2634 
2635 /**
2636   Converts a text device path node to Logic Unit device path structure.
2637 
2638   @param TextDeviceNode  The input Text device path node.
2639 
2640   @return A pointer to the newly-created Logic Unit device path structure.
2641 
2642 **/
2643 static
2644 EFI_DEVICE_PATH_PROTOCOL *
2645 DevPathFromTextUnit (
2646   IN CHAR16 *TextDeviceNode
2647   )
2648 {
2649   CHAR16                          *LunStr;
2650   DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
2651 
2652   LunStr      = GetNextParamStr (&TextDeviceNode);
2653   LogicalUnit = (DEVICE_LOGICAL_UNIT_DEVICE_PATH *) CreateDeviceNode (
2654                                                       MESSAGING_DEVICE_PATH,
2655                                                       MSG_DEVICE_LOGICAL_UNIT_DP,
2656                                                       (UINT16) sizeof (DEVICE_LOGICAL_UNIT_DEVICE_PATH)
2657                                                       );
2658 
2659   LogicalUnit->Lun  = (UINT8) Strtoi (LunStr);
2660 
2661   return (EFI_DEVICE_PATH_PROTOCOL *) LogicalUnit;
2662 }
2663 
2664 /**
2665   Converts a text device path node to iSCSI device path structure.
2666 
2667   @param TextDeviceNode  The input Text device path node.
2668 
2669   @return A pointer to the newly-created iSCSI device path structure.
2670 
2671 **/
2672 static
2673 EFI_DEVICE_PATH_PROTOCOL *
2674 DevPathFromTextiSCSI (
2675   IN CHAR16 *TextDeviceNode
2676   )
2677 {
2678   UINT16                      Options;
2679   CHAR16                      *NameStr;
2680   CHAR16                      *PortalGroupStr;
2681   CHAR16                      *LunStr;
2682   CHAR16                      *HeaderDigestStr;
2683   CHAR16                      *DataDigestStr;
2684   CHAR16                      *AuthenticationStr;
2685   CHAR16                      *ProtocolStr;
2686   CHAR8                       *AsciiStr;
2687   ISCSI_DEVICE_PATH_WITH_NAME *ISCSIDevPath;
2688   UINT64                      Lun;
2689 
2690   NameStr           = GetNextParamStr (&TextDeviceNode);
2691   PortalGroupStr    = GetNextParamStr (&TextDeviceNode);
2692   LunStr            = GetNextParamStr (&TextDeviceNode);
2693   HeaderDigestStr   = GetNextParamStr (&TextDeviceNode);
2694   DataDigestStr     = GetNextParamStr (&TextDeviceNode);
2695   AuthenticationStr = GetNextParamStr (&TextDeviceNode);
2696   ProtocolStr       = GetNextParamStr (&TextDeviceNode);
2697   ISCSIDevPath      = (ISCSI_DEVICE_PATH_WITH_NAME *) CreateDeviceNode (
2698                                                         MESSAGING_DEVICE_PATH,
2699                                                         MSG_ISCSI_DP,
2700                                                         (UINT16) (sizeof (ISCSI_DEVICE_PATH_WITH_NAME) + StrLen (NameStr))
2701                                                         );
2702 
2703   AsciiStr = ISCSIDevPath->TargetName;
2704   StrToAscii (NameStr, &AsciiStr);
2705 
2706   ISCSIDevPath->TargetPortalGroupTag = (UINT16) Strtoi (PortalGroupStr);
2707   Strtoi64 (LunStr, &Lun);
2708   WriteUnaligned64 ((UINT64 *) &ISCSIDevPath->Lun, SwapBytes64 (Lun));
2709 
2710   Options = 0x0000;
2711   if (StrCmp (HeaderDigestStr, "CRC32C") == 0) {
2712     Options |= 0x0002;
2713   }
2714 
2715   if (StrCmp (DataDigestStr, "CRC32C") == 0) {
2716     Options |= 0x0008;
2717   }
2718 
2719   if (StrCmp (AuthenticationStr, "None") == 0) {
2720     Options |= 0x0800;
2721   }
2722 
2723   if (StrCmp (AuthenticationStr, "CHAP_UNI") == 0) {
2724     Options |= 0x1000;
2725   }
2726 
2727   ISCSIDevPath->LoginOption      = (UINT16) Options;
2728 
2729   if (IS_NULL (*ProtocolStr) || (StrCmp (ProtocolStr, "TCP") == 0)) {
2730     ISCSIDevPath->NetworkProtocol = 0;
2731   } else {
2732     //
2733     // Undefined and reserved.
2734     //
2735     ISCSIDevPath->NetworkProtocol = 1;
2736   }
2737 
2738   return (EFI_DEVICE_PATH_PROTOCOL *) ISCSIDevPath;
2739 }
2740 
2741 /**
2742   Converts a text device path node to VLAN device path structure.
2743 
2744   @param TextDeviceNode  The input Text device path node.
2745 
2746   @return A pointer to the newly-created VLAN device path structure.
2747 
2748 **/
2749 static
2750 EFI_DEVICE_PATH_PROTOCOL *
2751 DevPathFromTextVlan (
2752   IN CHAR16 *TextDeviceNode
2753   )
2754 {
2755   CHAR16            *VlanStr;
2756   VLAN_DEVICE_PATH  *Vlan;
2757 
2758   VlanStr = GetNextParamStr (&TextDeviceNode);
2759   Vlan    = (VLAN_DEVICE_PATH *) CreateDeviceNode (
2760                                    MESSAGING_DEVICE_PATH,
2761                                    MSG_VLAN_DP,
2762                                    (UINT16) sizeof (VLAN_DEVICE_PATH)
2763                                    );
2764 
2765   Vlan->VlanId = (UINT16) Strtoi (VlanStr);
2766 
2767   return (EFI_DEVICE_PATH_PROTOCOL *) Vlan;
2768 }
2769 
2770 /**
2771   Converts a text device path node to Bluetooth device path structure.
2772 
2773   @param TextDeviceNode  The input Text device path node.
2774 
2775   @return A pointer to the newly-created Bluetooth device path structure.
2776 
2777 **/
2778 static
2779 EFI_DEVICE_PATH_PROTOCOL *
2780 DevPathFromTextBluetooth (
2781   IN CHAR16 *TextDeviceNode
2782   )
2783 {
2784   CHAR16                  *BluetoothStr;
2785   BLUETOOTH_DEVICE_PATH   *BluetoothDp;
2786 
2787   BluetoothStr = GetNextParamStr (&TextDeviceNode);
2788   BluetoothDp  = (BLUETOOTH_DEVICE_PATH *) CreateDeviceNode (
2789                                              MESSAGING_DEVICE_PATH,
2790                                              MSG_BLUETOOTH_DP,
2791                                              (UINT16) sizeof (BLUETOOTH_DEVICE_PATH)
2792                                              );
2793   StrHexToBytes (
2794     BluetoothStr,
2795     sizeof (BLUETOOTH_ADDRESS) * 2,
2796     BluetoothDp->BD_ADDR.Address,
2797     sizeof (BLUETOOTH_ADDRESS)
2798     );
2799   return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothDp;
2800 }
2801 
2802 /**
2803   Converts a text device path node to Wi-Fi device path structure.
2804 
2805   @param TextDeviceNode  The input Text device path node.
2806 
2807   @return A pointer to the newly-created Wi-Fi device path structure.
2808 
2809 **/
2810 static
2811 EFI_DEVICE_PATH_PROTOCOL *
2812 DevPathFromTextWiFi (
2813   IN CHAR16 *TextDeviceNode
2814   )
2815 {
2816   CHAR16                *SSIdStr;
2817   CHAR8                 AsciiStr[33];
2818   UINTN                 DataLen;
2819   WIFI_DEVICE_PATH      *WiFiDp;
2820 
2821   SSIdStr = GetNextParamStr (&TextDeviceNode);
2822   WiFiDp  = (WIFI_DEVICE_PATH *) CreateDeviceNode (
2823                                    MESSAGING_DEVICE_PATH,
2824                                    MSG_WIFI_DP,
2825                                    (UINT16) sizeof (WIFI_DEVICE_PATH)
2826                                    );
2827 
2828   if (NULL != SSIdStr) {
2829     DataLen = StrLen (SSIdStr);
2830     if (StrLen (SSIdStr) > 32) {
2831       SSIdStr[32] = '\0';
2832       DataLen     = 32;
2833     }
2834 
2835     UnicodeStrToAsciiStrS (SSIdStr, AsciiStr, sizeof (AsciiStr));
2836     CopyMem (WiFiDp->SSId, AsciiStr, DataLen);
2837   }
2838 
2839   return (EFI_DEVICE_PATH_PROTOCOL *) WiFiDp;
2840 }
2841 
2842 /**
2843   Converts a text device path node to Bluetooth LE device path structure.
2844 
2845   @param TextDeviceNode  The input Text device path node.
2846 
2847   @return A pointer to the newly-created Bluetooth LE device path structure.
2848 
2849 **/
2850 static
2851 EFI_DEVICE_PATH_PROTOCOL *
2852 DevPathFromTextBluetoothLE (
2853   IN CHAR16 *TextDeviceNode
2854   )
2855 {
2856   CHAR16                     *BluetoothLeAddrStr;
2857   CHAR16                     *BluetoothLeAddrTypeStr;
2858   BLUETOOTH_LE_DEVICE_PATH   *BluetoothLeDp;
2859 
2860   BluetoothLeAddrStr     = GetNextParamStr (&TextDeviceNode);
2861   BluetoothLeAddrTypeStr = GetNextParamStr (&TextDeviceNode);
2862   BluetoothLeDp = (BLUETOOTH_LE_DEVICE_PATH *) CreateDeviceNode (
2863                                                  MESSAGING_DEVICE_PATH,
2864                                                  MSG_BLUETOOTH_LE_DP,
2865                                                  (UINT16) sizeof (BLUETOOTH_LE_DEVICE_PATH)
2866                                                  );
2867 
2868   BluetoothLeDp->Address.Type = (UINT8) Strtoi (BluetoothLeAddrTypeStr);
2869   StrHexToBytes (
2870     BluetoothLeAddrStr, sizeof (BluetoothLeDp->Address.Address) * 2,
2871     BluetoothLeDp->Address.Address, sizeof (BluetoothLeDp->Address.Address)
2872     );
2873   return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothLeDp;
2874 }
2875 
2876 /**
2877   Converts a text device path node to DNS device path structure.
2878 
2879   @param TextDeviceNode  The input Text device path node.
2880 
2881   @return A pointer to the newly-created DNS device path structure.
2882 
2883 **/
2884 static
2885 EFI_DEVICE_PATH_PROTOCOL *
2886 DevPathFromTextDns (
2887   IN CHAR16 *TextDeviceNode
2888   )
2889 {
2890   CHAR16            *DeviceNodeStr;
2891   CHAR16            *DeviceNodeStrPtr;
2892   UINT32            DnsServerIpCount;
2893   UINT16            DnsDeviceNodeLength;
2894   DNS_DEVICE_PATH   *DnsDeviceNode;
2895   UINT32            DnsServerIpIndex;
2896   CHAR16            *DnsServerIp;
2897 
2898 
2899   //
2900   // Count the DNS server address number.
2901   //
2902   DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);
2903   if (DeviceNodeStr == NULL) {
2904     return NULL;
2905   }
2906 
2907   DeviceNodeStrPtr = DeviceNodeStr;
2908 
2909   DnsServerIpCount = 0;
2910   while (DeviceNodeStrPtr != NULL && *DeviceNodeStrPtr != '\0') {
2911     GetNextParamStr (&DeviceNodeStrPtr);
2912     DnsServerIpCount ++;
2913   }
2914 
2915   FreePool (DeviceNodeStr);
2916   DeviceNodeStr = NULL;
2917 
2918   //
2919   // One or more instances of the DNS server address in EFI_IP_ADDRESS,
2920   // otherwise, NULL will be returned.
2921   //
2922   if (DnsServerIpCount == 0) {
2923     return NULL;
2924   }
2925 
2926   //
2927   // Create the DNS DeviceNode.
2928   //
2929   DnsDeviceNodeLength = (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (UINT8) + DnsServerIpCount * sizeof (EFI_IP_ADDRESS));
2930   DnsDeviceNode       = (DNS_DEVICE_PATH *) CreateDeviceNode (
2931                                               MESSAGING_DEVICE_PATH,
2932                                               MSG_DNS_DP,
2933                                               DnsDeviceNodeLength
2934                                               );
2935   if (DnsDeviceNode == NULL) {
2936     return NULL;
2937   }
2938 
2939   //
2940   // Confirm the DNS server address is IPv4 or IPv6 type.
2941   //
2942   DeviceNodeStrPtr = TextDeviceNode;
2943   while (!IS_NULL (*DeviceNodeStrPtr)) {
2944     if (*DeviceNodeStrPtr == '.') {
2945       DnsDeviceNode->IsIPv6 = 0x00;
2946       break;
2947     }
2948 
2949     if (*DeviceNodeStrPtr == ':') {
2950       DnsDeviceNode->IsIPv6 = 0x01;
2951       break;
2952     }
2953 
2954     DeviceNodeStrPtr++;
2955   }
2956 
2957   for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; DnsServerIpIndex++) {
2958     DnsServerIp = GetNextParamStr (&TextDeviceNode);
2959     if (DnsDeviceNode->IsIPv6 == 0x00) {
2960       StrToIpv4Address (DnsServerIp,  NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v4), NULL);
2961     } else {
2962       StrToIpv6Address (DnsServerIp, NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v6), NULL);
2963     }
2964   }
2965 
2966   return (EFI_DEVICE_PATH_PROTOCOL *) DnsDeviceNode;
2967 }
2968 
2969 /**
2970   Converts a text device path node to URI device path structure.
2971 
2972   @param TextDeviceNode  The input Text device path node.
2973 
2974   @return A pointer to the newly-created URI device path structure.
2975 
2976 **/
2977 static
2978 EFI_DEVICE_PATH_PROTOCOL *
2979 DevPathFromTextUri (
2980   IN CHAR16 *TextDeviceNode
2981   )
2982 {
2983   CHAR16           *UriStr;
2984   UINTN            UriLength;
2985   URI_DEVICE_PATH  *Uri;
2986 
2987   UriStr = GetNextParamStr (&TextDeviceNode);
2988   UriLength = StrnLenS (UriStr, MAX_UINT16 - sizeof (URI_DEVICE_PATH));
2989   Uri    = (URI_DEVICE_PATH *) CreateDeviceNode (
2990                                  MESSAGING_DEVICE_PATH,
2991                                  MSG_URI_DP,
2992                                  (UINT16) (sizeof (URI_DEVICE_PATH) + UriLength)
2993                                  );
2994 
2995   while (UriLength-- != 0) {
2996     Uri->Uri[UriLength] = (CHAR8) UriStr[UriLength];
2997   }
2998 
2999   return (EFI_DEVICE_PATH_PROTOCOL *) Uri;
3000 }
3001 
3002 /**
3003   Converts a media text device path node to media device path structure.
3004 
3005   @param TextDeviceNode  The input Text device path node.
3006 
3007   @return A pointer to media device path structure.
3008 
3009 **/
3010 static
3011 EFI_DEVICE_PATH_PROTOCOL *
3012 DevPathFromTextMediaPath (
3013   IN CHAR16 *TextDeviceNode
3014   )
3015 {
3016   return DevPathFromTextGenericPath (MEDIA_DEVICE_PATH, TextDeviceNode);
3017 }
3018 
3019 /**
3020   Converts a text device path node to HD device path structure.
3021 
3022   @param TextDeviceNode  The input Text device path node.
3023 
3024   @return A pointer to the newly-created HD device path structure.
3025 
3026 **/
3027 static
3028 EFI_DEVICE_PATH_PROTOCOL *
3029 DevPathFromTextHD (
3030   IN CHAR16 *TextDeviceNode
3031   )
3032 {
3033   CHAR16                *PartitionStr;
3034   CHAR16                *TypeStr;
3035   CHAR16                *SignatureStr;
3036   CHAR16                *StartStr;
3037   CHAR16                *SizeStr;
3038   UINT32                Signature32;
3039   HARDDRIVE_DEVICE_PATH *Hd;
3040 
3041   PartitionStr        = GetNextParamStr (&TextDeviceNode);
3042   TypeStr             = GetNextParamStr (&TextDeviceNode);
3043   SignatureStr        = GetNextParamStr (&TextDeviceNode);
3044   StartStr            = GetNextParamStr (&TextDeviceNode);
3045   SizeStr             = GetNextParamStr (&TextDeviceNode);
3046   Hd                  = (HARDDRIVE_DEVICE_PATH *) CreateDeviceNode (
3047                                                     MEDIA_DEVICE_PATH,
3048                                                     MEDIA_HARDDRIVE_DP,
3049                                                     (UINT16) sizeof (HARDDRIVE_DEVICE_PATH)
3050                                                     );
3051 
3052   Hd->PartitionNumber = (UINT32) Strtoi (PartitionStr);
3053 
3054   ZeroMem (Hd->Signature, 16);
3055   Hd->MBRType = (UINT8) 0;
3056 
3057   if (StrCmp (TypeStr, "MBR") == 0) {
3058     Hd->SignatureType = SIGNATURE_TYPE_MBR;
3059     Hd->MBRType       = 0x01;
3060 
3061     Signature32       = (UINT32) Strtoi (SignatureStr);
3062     CopyMem (Hd->Signature, &Signature32, sizeof (UINT32));
3063   } else if (StrCmp (TypeStr, "GPT") == 0) {
3064     Hd->SignatureType = SIGNATURE_TYPE_GUID;
3065     Hd->MBRType       = 0x02;
3066 
3067     StrToGuid (SignatureStr, (EFI_GUID *) Hd->Signature);
3068   } else {
3069     Hd->SignatureType = (UINT8) Strtoi (TypeStr);
3070   }
3071 
3072   Strtoi64 (StartStr, &Hd->PartitionStart);
3073   Strtoi64 (SizeStr, &Hd->PartitionSize);
3074 
3075   return (EFI_DEVICE_PATH_PROTOCOL *) Hd;
3076 }
3077 
3078 /**
3079   Converts a text device path node to CDROM device path structure.
3080 
3081   @param TextDeviceNode  The input Text device path node.
3082 
3083   @return A pointer to the newly-created CDROM device path structure.
3084 
3085 **/
3086 static
3087 EFI_DEVICE_PATH_PROTOCOL *
3088 DevPathFromTextCDROM (
3089   IN CHAR16 *TextDeviceNode
3090   )
3091 {
3092   CHAR16            *EntryStr;
3093   CHAR16            *StartStr;
3094   CHAR16            *SizeStr;
3095   CDROM_DEVICE_PATH *CDROMDevPath;
3096 
3097   EntryStr              = GetNextParamStr (&TextDeviceNode);
3098   StartStr              = GetNextParamStr (&TextDeviceNode);
3099   SizeStr               = GetNextParamStr (&TextDeviceNode);
3100   CDROMDevPath          = (CDROM_DEVICE_PATH *) CreateDeviceNode (
3101                                                   MEDIA_DEVICE_PATH,
3102                                                   MEDIA_CDROM_DP,
3103                                                   (UINT16) sizeof (CDROM_DEVICE_PATH)
3104                                                   );
3105 
3106   CDROMDevPath->BootEntry = (UINT32) Strtoi (EntryStr);
3107   Strtoi64 (StartStr, &CDROMDevPath->PartitionStart);
3108   Strtoi64 (SizeStr, &CDROMDevPath->PartitionSize);
3109 
3110   return (EFI_DEVICE_PATH_PROTOCOL *) CDROMDevPath;
3111 }
3112 
3113 /**
3114   Converts a text device path node to Vendor-defined media device path structure.
3115 
3116   @param TextDeviceNode  The input Text device path node.
3117 
3118   @return A pointer to the newly-created Vendor-defined media device path structure.
3119 
3120 **/
3121 static
3122 EFI_DEVICE_PATH_PROTOCOL *
3123 DevPathFromTextVenMedia (
3124   IN CHAR16 *TextDeviceNode
3125   )
3126 {
3127   return ConvertFromTextVendor (
3128            TextDeviceNode,
3129            MEDIA_DEVICE_PATH,
3130            MEDIA_VENDOR_DP
3131            );
3132 }
3133 
3134 /**
3135   Converts a text device path node to File device path structure.
3136 
3137   @param TextDeviceNode  The input Text device path node.
3138 
3139   @return A pointer to the newly-created File device path structure.
3140 
3141 **/
3142 static
3143 EFI_DEVICE_PATH_PROTOCOL *
3144 DevPathFromTextFilePath (
3145   IN CHAR16 *TextDeviceNode
3146   )
3147 {
3148   FILEPATH_DEVICE_PATH  *File;
3149 
3150 #ifndef __FreeBSD__
3151   File = (FILEPATH_DEVICE_PATH *) CreateDeviceNode (
3152                                     MEDIA_DEVICE_PATH,
3153                                     MEDIA_FILEPATH_DP,
3154                                     (UINT16) (sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) * 2)
3155                                     );
3156 
3157   StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode);
3158 #else
3159   size_t len = (sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) * 2);
3160   efi_char * v;
3161   File = (FILEPATH_DEVICE_PATH *) CreateDeviceNode (
3162                                     MEDIA_DEVICE_PATH,
3163                                     MEDIA_FILEPATH_DP,
3164 				    (UINT16)len
3165                                     );
3166   v = File->PathName;
3167   utf8_to_ucs2(TextDeviceNode, &v, &len);
3168 #endif
3169 
3170   return (EFI_DEVICE_PATH_PROTOCOL *) File;
3171 }
3172 
3173 /**
3174   Converts a text device path node to Media protocol device path structure.
3175 
3176   @param TextDeviceNode  The input Text device path node.
3177 
3178   @return A pointer to the newly-created Media protocol device path structure.
3179 
3180 **/
3181 static
3182 EFI_DEVICE_PATH_PROTOCOL *
3183 DevPathFromTextMedia (
3184   IN CHAR16 *TextDeviceNode
3185   )
3186 {
3187   CHAR16                      *GuidStr;
3188   MEDIA_PROTOCOL_DEVICE_PATH  *Media;
3189 
3190   GuidStr = GetNextParamStr (&TextDeviceNode);
3191   Media   = (MEDIA_PROTOCOL_DEVICE_PATH *) CreateDeviceNode (
3192                                              MEDIA_DEVICE_PATH,
3193                                              MEDIA_PROTOCOL_DP,
3194                                              (UINT16) sizeof (MEDIA_PROTOCOL_DEVICE_PATH)
3195                                              );
3196 
3197   StrToGuid (GuidStr, &Media->Protocol);
3198 
3199   return (EFI_DEVICE_PATH_PROTOCOL *) Media;
3200 }
3201 
3202 /**
3203   Converts a text device path node to firmware volume device path structure.
3204 
3205   @param TextDeviceNode  The input Text device path node.
3206 
3207   @return A pointer to the newly-created firmware volume device path structure.
3208 
3209 **/
3210 static
3211 EFI_DEVICE_PATH_PROTOCOL *
3212 DevPathFromTextFv (
3213   IN CHAR16 *TextDeviceNode
3214   )
3215 {
3216   CHAR16                    *GuidStr;
3217   MEDIA_FW_VOL_DEVICE_PATH  *Fv;
3218 
3219   GuidStr = GetNextParamStr (&TextDeviceNode);
3220   Fv      = (MEDIA_FW_VOL_DEVICE_PATH *) CreateDeviceNode (
3221                                            MEDIA_DEVICE_PATH,
3222                                            MEDIA_PIWG_FW_VOL_DP,
3223                                            (UINT16) sizeof (MEDIA_FW_VOL_DEVICE_PATH)
3224                                            );
3225 
3226   StrToGuid (GuidStr, &Fv->FvName);
3227 
3228   return (EFI_DEVICE_PATH_PROTOCOL *) Fv;
3229 }
3230 
3231 /**
3232   Converts a text device path node to firmware file device path structure.
3233 
3234   @param TextDeviceNode  The input Text device path node.
3235 
3236   @return A pointer to the newly-created firmware file device path structure.
3237 
3238 **/
3239 static
3240 EFI_DEVICE_PATH_PROTOCOL *
3241 DevPathFromTextFvFile (
3242   IN CHAR16 *TextDeviceNode
3243   )
3244 {
3245   CHAR16                             *GuidStr;
3246   MEDIA_FW_VOL_FILEPATH_DEVICE_PATH  *FvFile;
3247 
3248   GuidStr = GetNextParamStr (&TextDeviceNode);
3249   FvFile  = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) CreateDeviceNode (
3250                                                     MEDIA_DEVICE_PATH,
3251                                                     MEDIA_PIWG_FW_FILE_DP,
3252                                                     (UINT16) sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH)
3253                                                     );
3254 
3255   StrToGuid (GuidStr, &FvFile->FvFileName);
3256 
3257   return (EFI_DEVICE_PATH_PROTOCOL *) FvFile;
3258 }
3259 
3260 /**
3261   Converts a text device path node to text relative offset device path structure.
3262 
3263   @param TextDeviceNode  The input Text device path node.
3264 
3265   @return A pointer to the newly-created Text device path structure.
3266 
3267 **/
3268 static
3269 EFI_DEVICE_PATH_PROTOCOL *
3270 DevPathFromTextRelativeOffsetRange (
3271   IN CHAR16 *TextDeviceNode
3272   )
3273 {
3274   CHAR16                                  *StartingOffsetStr;
3275   CHAR16                                  *EndingOffsetStr;
3276   MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset;
3277 
3278   StartingOffsetStr = GetNextParamStr (&TextDeviceNode);
3279   EndingOffsetStr   = GetNextParamStr (&TextDeviceNode);
3280   Offset            = (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *) CreateDeviceNode (
3281                                                                     MEDIA_DEVICE_PATH,
3282                                                                     MEDIA_RELATIVE_OFFSET_RANGE_DP,
3283                                                                     (UINT16) sizeof (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH)
3284                                                                     );
3285 
3286   Strtoi64 (StartingOffsetStr, &Offset->StartingOffset);
3287   Strtoi64 (EndingOffsetStr, &Offset->EndingOffset);
3288 
3289   return (EFI_DEVICE_PATH_PROTOCOL *) Offset;
3290 }
3291 
3292 /**
3293   Converts a text device path node to text ram disk device path structure.
3294 
3295   @param TextDeviceNode  The input Text device path node.
3296 
3297   @return A pointer to the newly-created Text device path structure.
3298 
3299 **/
3300 static
3301 EFI_DEVICE_PATH_PROTOCOL *
3302 DevPathFromTextRamDisk (
3303   IN CHAR16 *TextDeviceNode
3304   )
3305 {
3306   CHAR16                                  *StartingAddrStr;
3307   CHAR16                                  *EndingAddrStr;
3308   CHAR16                                  *TypeGuidStr;
3309   CHAR16                                  *InstanceStr;
3310   MEDIA_RAM_DISK_DEVICE_PATH              *RamDisk;
3311   UINT64                                  StartingAddr;
3312   UINT64                                  EndingAddr;
3313 
3314   StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3315   EndingAddrStr   = GetNextParamStr (&TextDeviceNode);
3316   InstanceStr     = GetNextParamStr (&TextDeviceNode);
3317   TypeGuidStr     = GetNextParamStr (&TextDeviceNode);
3318   RamDisk         = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
3319                                                      MEDIA_DEVICE_PATH,
3320                                                      MEDIA_RAM_DISK_DP,
3321                                                      (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3322                                                      );
3323 
3324   Strtoi64 (StartingAddrStr, &StartingAddr);
3325   WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
3326   Strtoi64 (EndingAddrStr, &EndingAddr);
3327   WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
3328   RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
3329   StrToGuid (TypeGuidStr, &RamDisk->TypeGuid);
3330 
3331   return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
3332 }
3333 
3334 /**
3335   Converts a text device path node to text virtual disk device path structure.
3336 
3337   @param TextDeviceNode  The input Text device path node.
3338 
3339   @return A pointer to the newly-created Text device path structure.
3340 
3341 **/
3342 static
3343 EFI_DEVICE_PATH_PROTOCOL *
3344 DevPathFromTextVirtualDisk (
3345   IN CHAR16 *TextDeviceNode
3346   )
3347 {
3348   CHAR16                                  *StartingAddrStr;
3349   CHAR16                                  *EndingAddrStr;
3350   CHAR16                                  *InstanceStr;
3351   MEDIA_RAM_DISK_DEVICE_PATH              *RamDisk;
3352   UINT64                                  StartingAddr;
3353   UINT64                                  EndingAddr;
3354 
3355   StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3356   EndingAddrStr   = GetNextParamStr (&TextDeviceNode);
3357   InstanceStr     = GetNextParamStr (&TextDeviceNode);
3358 
3359   RamDisk         = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
3360                                                      MEDIA_DEVICE_PATH,
3361                                                      MEDIA_RAM_DISK_DP,
3362                                                      (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3363                                                      );
3364 
3365   Strtoi64 (StartingAddrStr, &StartingAddr);
3366   WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
3367   Strtoi64 (EndingAddrStr, &EndingAddr);
3368   WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
3369   RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
3370   CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid);
3371 
3372   return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
3373 }
3374 
3375 /**
3376   Converts a text device path node to text virtual cd device path structure.
3377 
3378   @param TextDeviceNode  The input Text device path node.
3379 
3380   @return A pointer to the newly-created Text device path structure.
3381 
3382 **/
3383 static
3384 EFI_DEVICE_PATH_PROTOCOL *
3385 DevPathFromTextVirtualCd (
3386   IN CHAR16 *TextDeviceNode
3387   )
3388 {
3389   CHAR16                                  *StartingAddrStr;
3390   CHAR16                                  *EndingAddrStr;
3391   CHAR16                                  *InstanceStr;
3392   MEDIA_RAM_DISK_DEVICE_PATH              *RamDisk;
3393   UINT64                                  StartingAddr;
3394   UINT64                                  EndingAddr;
3395 
3396   StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3397   EndingAddrStr   = GetNextParamStr (&TextDeviceNode);
3398   InstanceStr     = GetNextParamStr (&TextDeviceNode);
3399 
3400   RamDisk         = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
3401                                                      MEDIA_DEVICE_PATH,
3402                                                      MEDIA_RAM_DISK_DP,
3403                                                      (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3404                                                      );
3405 
3406   Strtoi64 (StartingAddrStr, &StartingAddr);
3407   WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
3408   Strtoi64 (EndingAddrStr, &EndingAddr);
3409   WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
3410   RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
3411   CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid);
3412 
3413   return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
3414 }
3415 
3416 /**
3417   Converts a text device path node to text persistent virtual disk device path structure.
3418 
3419   @param TextDeviceNode  The input Text device path node.
3420 
3421   @return A pointer to the newly-created Text device path structure.
3422 
3423 **/
3424 static
3425 EFI_DEVICE_PATH_PROTOCOL *
3426 DevPathFromTextPersistentVirtualDisk (
3427   IN CHAR16 *TextDeviceNode
3428   )
3429 {
3430   CHAR16                                  *StartingAddrStr;
3431   CHAR16                                  *EndingAddrStr;
3432   CHAR16                                  *InstanceStr;
3433   MEDIA_RAM_DISK_DEVICE_PATH              *RamDisk;
3434   UINT64                                  StartingAddr;
3435   UINT64                                  EndingAddr;
3436 
3437   StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3438   EndingAddrStr   = GetNextParamStr (&TextDeviceNode);
3439   InstanceStr     = GetNextParamStr (&TextDeviceNode);
3440 
3441   RamDisk         = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
3442                                                      MEDIA_DEVICE_PATH,
3443                                                      MEDIA_RAM_DISK_DP,
3444                                                      (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3445                                                      );
3446 
3447   Strtoi64 (StartingAddrStr, &StartingAddr);
3448   WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
3449   Strtoi64 (EndingAddrStr, &EndingAddr);
3450   WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
3451   RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
3452   CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid);
3453 
3454   return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
3455 }
3456 
3457 /**
3458   Converts a text device path node to text persistent virtual cd device path structure.
3459 
3460   @param TextDeviceNode  The input Text device path node.
3461 
3462   @return A pointer to the newly-created Text device path structure.
3463 
3464 **/
3465 static
3466 EFI_DEVICE_PATH_PROTOCOL *
3467 DevPathFromTextPersistentVirtualCd (
3468   IN CHAR16 *TextDeviceNode
3469   )
3470 {
3471   CHAR16                                  *StartingAddrStr;
3472   CHAR16                                  *EndingAddrStr;
3473   CHAR16                                  *InstanceStr;
3474   MEDIA_RAM_DISK_DEVICE_PATH              *RamDisk;
3475   UINT64                                  StartingAddr;
3476   UINT64                                  EndingAddr;
3477 
3478   StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3479   EndingAddrStr   = GetNextParamStr (&TextDeviceNode);
3480   InstanceStr     = GetNextParamStr (&TextDeviceNode);
3481 
3482   RamDisk         = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
3483                                                      MEDIA_DEVICE_PATH,
3484                                                      MEDIA_RAM_DISK_DP,
3485                                                      (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3486                                                      );
3487 
3488   Strtoi64 (StartingAddrStr, &StartingAddr);
3489   WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
3490   Strtoi64 (EndingAddrStr, &EndingAddr);
3491   WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
3492   RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
3493   CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid);
3494 
3495   return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
3496 }
3497 
3498 /**
3499   Converts a BBS text device path node to BBS device path structure.
3500 
3501   @param TextDeviceNode  The input Text device path node.
3502 
3503   @return A pointer to BBS device path structure.
3504 
3505 **/
3506 static
3507 EFI_DEVICE_PATH_PROTOCOL *
3508 DevPathFromTextBbsPath (
3509   IN CHAR16 *TextDeviceNode
3510   )
3511 {
3512   return DevPathFromTextGenericPath (BBS_DEVICE_PATH, TextDeviceNode);
3513 }
3514 
3515 /**
3516   Converts a text device path node to BIOS Boot Specification device path structure.
3517 
3518   @param TextDeviceNode  The input Text device path node.
3519 
3520   @return A pointer to the newly-created BIOS Boot Specification device path structure.
3521 
3522 **/
3523 static
3524 EFI_DEVICE_PATH_PROTOCOL *
3525 DevPathFromTextBBS (
3526   IN CHAR16 *TextDeviceNode
3527   )
3528 {
3529   CHAR16              *TypeStr;
3530   CHAR16              *IdStr;
3531   CHAR16              *FlagsStr;
3532   CHAR8               *AsciiStr;
3533   BBS_BBS_DEVICE_PATH *Bbs;
3534 
3535   TypeStr   = GetNextParamStr (&TextDeviceNode);
3536   IdStr     = GetNextParamStr (&TextDeviceNode);
3537   FlagsStr  = GetNextParamStr (&TextDeviceNode);
3538   Bbs       = (BBS_BBS_DEVICE_PATH *) CreateDeviceNode (
3539                                         BBS_DEVICE_PATH,
3540                                         BBS_BBS_DP,
3541                                         (UINT16) (sizeof (BBS_BBS_DEVICE_PATH) + StrLen (IdStr))
3542                                         );
3543 
3544   if (StrCmp (TypeStr, "Floppy") == 0) {
3545     Bbs->DeviceType = BBS_TYPE_FLOPPY;
3546   } else if (StrCmp (TypeStr, "HD") == 0) {
3547     Bbs->DeviceType = BBS_TYPE_HARDDRIVE;
3548   } else if (StrCmp (TypeStr, "CDROM") == 0) {
3549     Bbs->DeviceType = BBS_TYPE_CDROM;
3550   } else if (StrCmp (TypeStr, "PCMCIA") == 0) {
3551     Bbs->DeviceType = BBS_TYPE_PCMCIA;
3552   } else if (StrCmp (TypeStr, "USB") == 0) {
3553     Bbs->DeviceType = BBS_TYPE_USB;
3554   } else if (StrCmp (TypeStr, "Network") == 0) {
3555     Bbs->DeviceType = BBS_TYPE_EMBEDDED_NETWORK;
3556   } else {
3557     Bbs->DeviceType = (UINT16) Strtoi (TypeStr);
3558   }
3559 
3560   AsciiStr = Bbs->String;
3561   StrToAscii (IdStr, &AsciiStr);
3562 
3563   Bbs->StatusFlag = (UINT16) Strtoi (FlagsStr);
3564 
3565   return (EFI_DEVICE_PATH_PROTOCOL *) Bbs;
3566 }
3567 
3568 /**
3569   Converts a text device path node to SATA device path structure.
3570 
3571   @param TextDeviceNode  The input Text device path node.
3572 
3573   @return A pointer to the newly-created SATA device path structure.
3574 
3575 **/
3576 static
3577 EFI_DEVICE_PATH_PROTOCOL *
3578 DevPathFromTextSata (
3579   IN CHAR16 *TextDeviceNode
3580   )
3581 {
3582   SATA_DEVICE_PATH *Sata;
3583   CHAR16           *Param1;
3584   CHAR16           *Param2;
3585   CHAR16           *Param3;
3586 
3587   Param1 = GetNextParamStr (&TextDeviceNode);
3588   Param2 = GetNextParamStr (&TextDeviceNode);
3589   Param3 = GetNextParamStr (&TextDeviceNode);
3590 
3591   Sata = (SATA_DEVICE_PATH *) CreateDeviceNode (
3592                                 MESSAGING_DEVICE_PATH,
3593                                 MSG_SATA_DP,
3594                                 (UINT16) sizeof (SATA_DEVICE_PATH)
3595                                 );
3596   Sata->HBAPortNumber            = (UINT16) Strtoi (Param1);
3597   Sata->PortMultiplierPortNumber = (UINT16) Strtoi (Param2);
3598   Sata->Lun                      = (UINT16) Strtoi (Param3);
3599 
3600   return (EFI_DEVICE_PATH_PROTOCOL *) Sata;
3601 }
3602 
3603 GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevPathFromTextTable[] = {
3604   {"Path",                    DevPathFromTextPath                    },
3605 
3606   {"HardwarePath",            DevPathFromTextHardwarePath            },
3607   {"Pci",                     DevPathFromTextPci                     },
3608   {"PcCard",                  DevPathFromTextPcCard                  },
3609   {"MemoryMapped",            DevPathFromTextMemoryMapped            },
3610   {"VenHw",                   DevPathFromTextVenHw                   },
3611   {"Ctrl",                    DevPathFromTextCtrl                    },
3612   {"BMC",                     DevPathFromTextBmc                     },
3613 
3614   {"AcpiPath",                DevPathFromTextAcpiPath                },
3615   {"Acpi",                    DevPathFromTextAcpi                    },
3616   {"PciRoot",                 DevPathFromTextPciRoot                 },
3617   {"PcieRoot",                DevPathFromTextPcieRoot                },
3618   {"Floppy",                  DevPathFromTextFloppy                  },
3619   {"Keyboard",                DevPathFromTextKeyboard                },
3620   {"Serial",                  DevPathFromTextSerial                  },
3621   {"ParallelPort",            DevPathFromTextParallelPort            },
3622   {"AcpiEx",                  DevPathFromTextAcpiEx                  },
3623   {"AcpiExp",                 DevPathFromTextAcpiExp                 },
3624   {"AcpiAdr",                 DevPathFromTextAcpiAdr                 },
3625 
3626   {"Msg",                     DevPathFromTextMsg                     },
3627   {"Ata",                     DevPathFromTextAta                     },
3628   {"Scsi",                    DevPathFromTextScsi                    },
3629   {"Fibre",                   DevPathFromTextFibre                   },
3630   {"FibreEx",                 DevPathFromTextFibreEx                 },
3631   {"I1394",                   DevPathFromText1394                    },
3632   {"USB",                     DevPathFromTextUsb                     },
3633   {"I2O",                     DevPathFromTextI2O                     },
3634   {"Infiniband",              DevPathFromTextInfiniband              },
3635   {"VenMsg",                  DevPathFromTextVenMsg                  },
3636   {"VenPcAnsi",               DevPathFromTextVenPcAnsi               },
3637   {"VenVt100",                DevPathFromTextVenVt100                },
3638   {"VenVt100Plus",            DevPathFromTextVenVt100Plus            },
3639   {"VenUtf8",                 DevPathFromTextVenUtf8                 },
3640   {"UartFlowCtrl",            DevPathFromTextUartFlowCtrl            },
3641   {"SAS",                     DevPathFromTextSAS                     },
3642   {"SasEx",                   DevPathFromTextSasEx                   },
3643   {"NVMe",                    DevPathFromTextNVMe                    },
3644   {"UFS",                     DevPathFromTextUfs                     },
3645   {"SD",                      DevPathFromTextSd                      },
3646   {"eMMC",                    DevPathFromTextEmmc                    },
3647   {"DebugPort",               DevPathFromTextDebugPort               },
3648   {"MAC",                     DevPathFromTextMAC                     },
3649   {"IPv4",                    DevPathFromTextIPv4                    },
3650   {"IPv6",                    DevPathFromTextIPv6                    },
3651   {"Uart",                    DevPathFromTextUart                    },
3652   {"UsbClass",                DevPathFromTextUsbClass                },
3653   {"UsbAudio",                DevPathFromTextUsbAudio                },
3654   {"UsbCDCControl",           DevPathFromTextUsbCDCControl           },
3655   {"UsbHID",                  DevPathFromTextUsbHID                  },
3656   {"UsbImage",                DevPathFromTextUsbImage                },
3657   {"UsbPrinter",              DevPathFromTextUsbPrinter              },
3658   {"UsbMassStorage",          DevPathFromTextUsbMassStorage          },
3659   {"UsbHub",                  DevPathFromTextUsbHub                  },
3660   {"UsbCDCData",              DevPathFromTextUsbCDCData              },
3661   {"UsbSmartCard",            DevPathFromTextUsbSmartCard            },
3662   {"UsbVideo",                DevPathFromTextUsbVideo                },
3663   {"UsbDiagnostic",           DevPathFromTextUsbDiagnostic           },
3664   {"UsbWireless",             DevPathFromTextUsbWireless             },
3665   {"UsbDeviceFirmwareUpdate", DevPathFromTextUsbDeviceFirmwareUpdate },
3666   {"UsbIrdaBridge",           DevPathFromTextUsbIrdaBridge           },
3667   {"UsbTestAndMeasurement",   DevPathFromTextUsbTestAndMeasurement   },
3668   {"UsbWwid",                 DevPathFromTextUsbWwid                 },
3669   {"Unit",                    DevPathFromTextUnit                    },
3670   {"iSCSI",                   DevPathFromTextiSCSI                   },
3671   {"Vlan",                    DevPathFromTextVlan                    },
3672   {"Dns",                     DevPathFromTextDns                     },
3673   {"Uri",                     DevPathFromTextUri                     },
3674   {"Bluetooth",               DevPathFromTextBluetooth               },
3675   {"Wi-Fi",                   DevPathFromTextWiFi                    },
3676   {"BluetoothLE",             DevPathFromTextBluetoothLE             },
3677   {"MediaPath",               DevPathFromTextMediaPath               },
3678   {"HD",                      DevPathFromTextHD                      },
3679   {"CDROM",                   DevPathFromTextCDROM                   },
3680   {"VenMedia",                DevPathFromTextVenMedia                },
3681   {"Media",                   DevPathFromTextMedia                   },
3682   {"Fv",                      DevPathFromTextFv                      },
3683   {"FvFile",                  DevPathFromTextFvFile                  },
3684   {"File",                    DevPathFromTextFilePath                },
3685   {"Offset",                  DevPathFromTextRelativeOffsetRange     },
3686   {"RamDisk",                 DevPathFromTextRamDisk                 },
3687   {"VirtualDisk",             DevPathFromTextVirtualDisk             },
3688   {"VirtualCD",               DevPathFromTextVirtualCd               },
3689   {"PersistentVirtualDisk",   DevPathFromTextPersistentVirtualDisk   },
3690   {"PersistentVirtualCD",     DevPathFromTextPersistentVirtualCd     },
3691 
3692   {"BbsPath",                 DevPathFromTextBbsPath                 },
3693   {"BBS",                     DevPathFromTextBBS                     },
3694   {"Sata",                    DevPathFromTextSata                    },
3695   {NULL, NULL}
3696 };
3697 
3698 /**
3699   Convert text to the binary representation of a device node.
3700 
3701   @param TextDeviceNode  TextDeviceNode points to the text representation of a device
3702                          node. Conversion starts with the first character and continues
3703                          until the first non-device node character.
3704 
3705   @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
3706           insufficient memory or text unsupported.
3707 
3708 **/
3709 static
3710 EFI_DEVICE_PATH_PROTOCOL *
3711 EFIAPI
3712 UefiDevicePathLibConvertTextToDeviceNode (
3713   IN CONST CHAR16 *TextDeviceNode
3714   )
3715 {
3716   DEVICE_PATH_FROM_TEXT    FromText;
3717   CHAR16                   *ParamStr;
3718   EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
3719   CHAR16                   *DeviceNodeStr;
3720   UINTN                    Index;
3721 
3722   if ((TextDeviceNode == NULL) || (IS_NULL (*TextDeviceNode))) {
3723     return NULL;
3724   }
3725 
3726   ParamStr      = NULL;
3727   FromText      = NULL;
3728   DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);
3729   ASSERT (DeviceNodeStr != NULL);
3730 
3731   for (Index = 0; mUefiDevicePathLibDevPathFromTextTable[Index].Function != NULL; Index++) {
3732     ParamStr = GetParamByNodeName (DeviceNodeStr, mUefiDevicePathLibDevPathFromTextTable[Index].DevicePathNodeText);
3733     if (ParamStr != NULL) {
3734       FromText = mUefiDevicePathLibDevPathFromTextTable[Index].Function;
3735       break;
3736     }
3737   }
3738 
3739   if (FromText == NULL) {
3740     //
3741     // A file path
3742     //
3743     FromText = DevPathFromTextFilePath;
3744     DeviceNode = FromText (DeviceNodeStr);
3745   } else {
3746     DeviceNode = FromText (ParamStr);
3747     FreePool (ParamStr);
3748   }
3749 
3750   FreePool (DeviceNodeStr);
3751 
3752   return DeviceNode;
3753 }
3754 
3755 /**
3756   Convert text to the binary representation of a device path.
3757 
3758 
3759   @param TextDevicePath  TextDevicePath points to the text representation of a device
3760                          path. Conversion starts with the first character and continues
3761                          until the first non-device node character.
3762 
3763   @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
3764           there was insufficient memory.
3765 
3766 **/
3767 static
3768 EFI_DEVICE_PATH_PROTOCOL *
3769 EFIAPI
3770 UefiDevicePathLibConvertTextToDevicePath (
3771   IN CONST CHAR16 *TextDevicePath
3772   )
3773 {
3774   EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
3775   EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
3776   CHAR16                   *DevicePathStr;
3777   CHAR16                   *Str;
3778   CHAR16                   *DeviceNodeStr;
3779   BOOLEAN                  IsInstanceEnd;
3780   EFI_DEVICE_PATH_PROTOCOL *DevicePath;
3781 
3782   if ((TextDevicePath == NULL) || (IS_NULL (*TextDevicePath))) {
3783     return NULL;
3784   }
3785 
3786   DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
3787   ASSERT (DevicePath != NULL);
3788   SetDevicePathEndNode (DevicePath);
3789 
3790   DevicePathStr = UefiDevicePathLibStrDuplicate (TextDevicePath);
3791 
3792   Str           = DevicePathStr;
3793   while ((DeviceNodeStr = GetNextDeviceNodeStr (&Str, &IsInstanceEnd)) != NULL) {
3794     DeviceNode = UefiDevicePathLibConvertTextToDeviceNode (DeviceNodeStr);
3795 
3796     NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
3797     FreePool (DevicePath);
3798     FreePool (DeviceNode);
3799     DevicePath = NewDevicePath;
3800 
3801     if (IsInstanceEnd) {
3802       DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
3803       ASSERT (DeviceNode != NULL);
3804       SetDevicePathEndNode (DeviceNode);
3805       DeviceNode->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;
3806 
3807       NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
3808       FreePool (DevicePath);
3809       FreePool (DeviceNode);
3810       DevicePath = NewDevicePath;
3811     }
3812   }
3813 
3814   FreePool (DevicePathStr);
3815   return DevicePath;
3816 }
3817 
3818 ssize_t
3819 efidp_parse_device_path(char *path, efidp out, size_t max)
3820 {
3821 	EFI_DEVICE_PATH_PROTOCOL *dp;
3822 	UINTN len;
3823 
3824 	dp = UefiDevicePathLibConvertTextToDevicePath (path);
3825 	if (dp == NULL)
3826 		return -1;
3827 	len = GetDevicePathSize(dp);
3828 	if (len > max) {
3829 		free(dp);
3830 		return -1;
3831 	}
3832 	memcpy(out, dp, len);
3833 	free(dp);
3834 
3835 	return len;
3836 }
3837