]>
Commit | Line | Data |
---|---|---|
7dbc50bd YZ |
1 | /** @file\r |
2 | Definition for Device Path Tool.\r | |
3 | \r | |
46cced28 | 4 | Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>\r |
7dbc50bd YZ |
5 | This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "UefiDevicePathLib.h"\r | |
16 | \r | |
17 | //\r | |
18 | // Utility Name\r | |
19 | //\r | |
20 | #define UTILITY_NAME "DevicePath"\r | |
21 | \r | |
22 | //\r | |
23 | // Utility version information\r | |
24 | //\r | |
25 | #define UTILITY_MAJOR_VERSION 0\r | |
26 | #define UTILITY_MINOR_VERSION 1\r | |
27 | \r | |
28 | EFI_GUID gEfiDebugPortDevicePathGuid = DEVICE_PATH_MESSAGING_DEBUGPORT;\r | |
29 | EFI_GUID gEfiPcAnsiGuid = EFI_PC_ANSI_GUID;\r | |
30 | EFI_GUID gEfiVT100Guid = EFI_VT_100_GUID;\r | |
31 | EFI_GUID gEfiVT100PlusGuid = EFI_VT_100_PLUS_GUID;\r | |
32 | EFI_GUID gEfiVTUTF8Guid = EFI_VT_UTF8_GUID;\r | |
33 | EFI_GUID gEfiUartDevicePathGuid = EFI_UART_DEVICE_PATH_GUID;\r | |
34 | EFI_GUID gEfiSasDevicePathGuid = EFI_SAS_DEVICE_PATH_GUID;\r | |
35 | EFI_GUID gEfiVirtualDiskGuid = EFI_VIRTUAL_DISK_GUID;\r | |
36 | EFI_GUID gEfiVirtualCdGuid = EFI_VIRTUAL_CD_GUID;\r | |
37 | EFI_GUID gEfiPersistentVirtualDiskGuid = EFI_PERSISTENT_VIRTUAL_DISK_GUID;\r | |
38 | EFI_GUID gEfiPersistentVirtualCdGuid = EFI_PERSISTENT_VIRTUAL_CD_GUID;\r | |
39 | \r | |
40 | STATIC\r | |
41 | VOID\r | |
42 | Version (\r | |
43 | VOID\r | |
44 | )\r | |
45 | /*++\r | |
46 | \r | |
47 | Routine Description:\r | |
48 | \r | |
49 | Displays the standard utility information to SDTOUT\r | |
50 | \r | |
51 | Arguments:\r | |
52 | \r | |
53 | None\r | |
54 | \r | |
55 | Returns:\r | |
56 | \r | |
57 | None\r | |
58 | \r | |
59 | --*/\r | |
60 | {\r | |
61 | fprintf (stdout, "%s Version %d.%d %s \n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);\r | |
62 | }\r | |
63 | \r | |
64 | STATIC\r | |
65 | VOID\r | |
66 | Usage (\r | |
67 | VOID\r | |
68 | )\r | |
69 | /*++\r | |
70 | \r | |
71 | Routine Description:\r | |
72 | \r | |
73 | Displays the utility usage syntax to STDOUT\r | |
74 | \r | |
75 | Arguments:\r | |
76 | \r | |
77 | None\r | |
78 | \r | |
79 | Returns:\r | |
80 | \r | |
81 | None\r | |
82 | \r | |
83 | --*/\r | |
84 | {\r | |
85 | //\r | |
86 | // Summary usage\r | |
87 | //\r | |
88 | fprintf (stdout, "\nUsage: %s [options]\n\n", UTILITY_NAME);\r | |
89 | \r | |
90 | //\r | |
91 | // Copyright declaration\r | |
92 | //\r | |
93 | fprintf (stdout, "Copyright (c) 2017, Intel Corporation. All rights reserved.\n\n");\r | |
94 | //\r | |
95 | // Details Option\r | |
96 | //\r | |
97 | fprintf (stdout, "Options:\n");\r | |
98 | fprintf (stdout, " DevicePathString Device Path string is specified, no space character.\n"\r | |
99 | " Example: \"PciRoot(0)/Pci(0,0)\"\n");\r | |
100 | \r | |
101 | fprintf (stdout, " --version Show program's version number and exit.\n");\r | |
102 | fprintf (stdout, " -h, --help Show this help message and exit.\n");\r | |
103 | }\r | |
104 | \r | |
105 | \r | |
9a6b445b LE |
106 | STATIC\r |
107 | VOID\r | |
108 | PrintMem (\r | |
109 | CONST VOID *Buffer,\r | |
110 | UINTN Count\r | |
111 | )\r | |
7dbc50bd | 112 | {\r |
9a6b445b LE |
113 | CONST UINT8 *Bytes;\r |
114 | UINTN Idx;\r | |
115 | \r | |
116 | Bytes = Buffer;\r | |
117 | for (Idx = 0; Idx < Count; Idx++) {\r | |
118 | printf("0x%02x ", Bytes[Idx]);\r | |
7dbc50bd YZ |
119 | }\r |
120 | }\r | |
121 | \r | |
122 | VOID\r | |
123 | Ascii2UnicodeString (\r | |
124 | CHAR8 *String,\r | |
125 | CHAR16 *UniString\r | |
126 | )\r | |
127 | /*++\r | |
128 | \r | |
129 | Routine Description:\r | |
130 | \r | |
131 | Write ascii string as unicode string format to FILE\r | |
132 | \r | |
133 | Arguments:\r | |
134 | \r | |
135 | String - Pointer to string that is written to FILE.\r | |
136 | UniString - Pointer to unicode string\r | |
137 | \r | |
138 | Returns:\r | |
139 | \r | |
140 | NULL\r | |
141 | \r | |
142 | --*/\r | |
143 | {\r | |
144 | while (*String != '\0') {\r | |
145 | *(UniString++) = (CHAR16) *(String++);\r | |
146 | }\r | |
147 | //\r | |
148 | // End the UniString with a NULL.\r | |
149 | //\r | |
150 | *UniString = '\0';\r | |
151 | }\r | |
152 | \r | |
153 | int main(int argc, CHAR8 *argv[])\r | |
154 | {\r | |
155 | CHAR8 * Str;\r | |
156 | CHAR16* Str16;\r | |
157 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
158 | \r | |
159 | if (argc == 1) {\r | |
160 | Error (NULL, 0, 1001, "Missing options", "No input options specified.");\r | |
161 | Usage ();\r | |
162 | return STATUS_ERROR;\r | |
163 | }\r | |
164 | if ((stricmp (argv[1], "-h") == 0) || (stricmp (argv[1], "--help") == 0)) {\r | |
165 | Version ();\r | |
166 | Usage ();\r | |
167 | return STATUS_SUCCESS;\r | |
168 | }\r | |
169 | \r | |
170 | if (stricmp (argv[1], "--version") == 0) {\r | |
171 | Version ();\r | |
172 | return STATUS_SUCCESS;\r | |
173 | }\r | |
174 | Str = argv[1];\r | |
175 | if (Str == NULL) {\r | |
176 | fprintf(stderr, "Invalid option value, Device Path can't be NULL");\r | |
177 | return STATUS_ERROR;\r | |
178 | }\r | |
179 | Str16 = (CHAR16 *)malloc(1024);\r | |
180 | if (Str16 == NULL) {\r | |
181 | fprintf(stderr, "Resource, memory cannot be allcoated");\r | |
182 | return STATUS_ERROR;\r | |
183 | }\r | |
184 | Ascii2UnicodeString(Str, Str16);\r | |
185 | DevicePath = UefiDevicePathLibConvertTextToDevicePath(Str16);\r | |
e73fbac5 HW |
186 | if (DevicePath == NULL) {\r |
187 | fprintf(stderr, "Convert fail, Cannot convert text to a device path");\r | |
188 | free(Str16);\r | |
189 | return STATUS_ERROR;\r | |
190 | }\r | |
7dbc50bd YZ |
191 | while (!((DevicePath->Type == END_DEVICE_PATH_TYPE) && (DevicePath->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE)) )\r |
192 | {\r | |
9a6b445b | 193 | PrintMem (DevicePath, DevicePath->Length[0] | DevicePath->Length[1] << 8);\r |
7dbc50bd YZ |
194 | DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)DevicePath + (DevicePath->Length[0] | DevicePath->Length[1] << 8));\r |
195 | }\r | |
9a6b445b | 196 | PrintMem (DevicePath, DevicePath->Length[0] | DevicePath->Length[1] << 8);\r |
7dbc50bd | 197 | putchar('\n');\r |
46cced28 | 198 | free(Str16);\r |
7dbc50bd YZ |
199 | return STATUS_SUCCESS;\r |
200 | }\r |