BaseTools/DevicePath: fix GCC build error in print_mem(), and clean it up
[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
9a6b445b
LE
106STATIC\r
107VOID\r
108PrintMem (\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
122VOID\r
123Ascii2UnicodeString (\r
124 CHAR8 *String,\r
125 CHAR16 *UniString\r
126 )\r
127/*++\r
128\r
129Routine Description:\r
130\r
131 Write ascii string as unicode string format to FILE\r
132\r
133Arguments:\r
134\r
135 String - Pointer to string that is written to FILE.\r
136 UniString - Pointer to unicode string\r
137\r
138Returns:\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
153int 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
186 while (!((DevicePath->Type == END_DEVICE_PATH_TYPE) && (DevicePath->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE)) )\r
187 {\r
9a6b445b 188 PrintMem (DevicePath, DevicePath->Length[0] | DevicePath->Length[1] << 8);\r
7dbc50bd
YZ
189 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)DevicePath + (DevicePath->Length[0] | DevicePath->Length[1] << 8));\r
190 }\r
9a6b445b 191 PrintMem (DevicePath, DevicePath->Length[0] | DevicePath->Length[1] << 8);\r
7dbc50bd
YZ
192 putchar('\n');\r
193 return STATUS_SUCCESS;\r
194}\r