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