]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/DevicePath/DevicePath.c
BaseTools: Add DevicePath support for PCD values
[mirror_edk2.git] / BaseTools / Source / C / DevicePath / DevicePath.c
CommitLineData
7dbc50bd
YZ
1/** @file\r
2 Definition for Device Path Tool.\r
3\r
4Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT 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
28EFI_GUID gEfiDebugPortDevicePathGuid = DEVICE_PATH_MESSAGING_DEBUGPORT;\r
29EFI_GUID gEfiPcAnsiGuid = EFI_PC_ANSI_GUID;\r
30EFI_GUID gEfiVT100Guid = EFI_VT_100_GUID;\r
31EFI_GUID gEfiVT100PlusGuid = EFI_VT_100_PLUS_GUID;\r
32EFI_GUID gEfiVTUTF8Guid = EFI_VT_UTF8_GUID;\r
33EFI_GUID gEfiUartDevicePathGuid = EFI_UART_DEVICE_PATH_GUID;\r
34EFI_GUID gEfiSasDevicePathGuid = EFI_SAS_DEVICE_PATH_GUID;\r
35EFI_GUID gEfiVirtualDiskGuid = EFI_VIRTUAL_DISK_GUID;\r
36EFI_GUID gEfiVirtualCdGuid = EFI_VIRTUAL_CD_GUID;\r
37EFI_GUID gEfiPersistentVirtualDiskGuid = EFI_PERSISTENT_VIRTUAL_DISK_GUID;\r
38EFI_GUID gEfiPersistentVirtualCdGuid = EFI_PERSISTENT_VIRTUAL_CD_GUID;\r
39\r
40STATIC\r
41VOID\r
42Version (\r
43 VOID\r
44)\r
45/*++\r
46\r
47Routine Description:\r
48\r
49 Displays the standard utility information to SDTOUT\r
50\r
51Arguments:\r
52\r
53 None\r
54\r
55Returns:\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
64STATIC\r
65VOID\r
66Usage (\r
67 VOID\r
68 )\r
69/*++\r
70\r
71Routine Description:\r
72\r
73 Displays the utility usage syntax to STDOUT\r
74\r
75Arguments:\r
76\r
77 None\r
78\r
79Returns:\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
106void print_mem(void const *vp, size_t n)\r
107{\r
108 unsigned char const *p = vp;\r
109 for (size_t i=0; i<n; i++) {\r
110 printf("0x%02x ", p[i]);\r
111 }\r
112}\r
113\r
114VOID\r
115Ascii2UnicodeString (\r
116 CHAR8 *String,\r
117 CHAR16 *UniString\r
118 )\r
119/*++\r
120\r
121Routine Description:\r
122\r
123 Write ascii string as unicode string format to FILE\r
124\r
125Arguments:\r
126\r
127 String - Pointer to string that is written to FILE.\r
128 UniString - Pointer to unicode string\r
129\r
130Returns:\r
131\r
132 NULL\r
133\r
134--*/\r
135{\r
136 while (*String != '\0') {\r
137 *(UniString++) = (CHAR16) *(String++);\r
138 }\r
139 //\r
140 // End the UniString with a NULL.\r
141 //\r
142 *UniString = '\0';\r
143}\r
144\r
145int main(int argc, CHAR8 *argv[])\r
146{\r
147 CHAR8 * Str;\r
148 CHAR16* Str16;\r
149 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
150\r
151 if (argc == 1) {\r
152 Error (NULL, 0, 1001, "Missing options", "No input options specified.");\r
153 Usage ();\r
154 return STATUS_ERROR;\r
155 }\r
156 if ((stricmp (argv[1], "-h") == 0) || (stricmp (argv[1], "--help") == 0)) {\r
157 Version ();\r
158 Usage ();\r
159 return STATUS_SUCCESS;\r
160 }\r
161\r
162 if (stricmp (argv[1], "--version") == 0) {\r
163 Version ();\r
164 return STATUS_SUCCESS;\r
165 }\r
166 Str = argv[1];\r
167 if (Str == NULL) {\r
168 fprintf(stderr, "Invalid option value, Device Path can't be NULL");\r
169 return STATUS_ERROR;\r
170 }\r
171 Str16 = (CHAR16 *)malloc(1024);\r
172 if (Str16 == NULL) {\r
173 fprintf(stderr, "Resource, memory cannot be allcoated");\r
174 return STATUS_ERROR;\r
175 }\r
176 Ascii2UnicodeString(Str, Str16);\r
177 DevicePath = UefiDevicePathLibConvertTextToDevicePath(Str16);\r
178 while (!((DevicePath->Type == END_DEVICE_PATH_TYPE) && (DevicePath->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE)) )\r
179 {\r
180 print_mem(DevicePath, (DevicePath->Length[0] | DevicePath->Length[1] << 8));\r
181 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)DevicePath + (DevicePath->Length[0] | DevicePath->Length[1] << 8));\r
182 }\r
183 print_mem(DevicePath, (DevicePath->Length[0] | DevicePath->Length[1] << 8));\r
184 putchar('\n');\r
185 return STATUS_SUCCESS;\r
186}\r