2 Definition for Device Path Tool.
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiDevicePathLib.h"
20 #define UTILITY_NAME "DevicePath"
23 // Utility version information
25 #define UTILITY_MAJOR_VERSION 0
26 #define UTILITY_MINOR_VERSION 1
28 EFI_GUID gEfiDebugPortDevicePathGuid
= DEVICE_PATH_MESSAGING_DEBUGPORT
;
29 EFI_GUID gEfiPcAnsiGuid
= EFI_PC_ANSI_GUID
;
30 EFI_GUID gEfiVT100Guid
= EFI_VT_100_GUID
;
31 EFI_GUID gEfiVT100PlusGuid
= EFI_VT_100_PLUS_GUID
;
32 EFI_GUID gEfiVTUTF8Guid
= EFI_VT_UTF8_GUID
;
33 EFI_GUID gEfiUartDevicePathGuid
= EFI_UART_DEVICE_PATH_GUID
;
34 EFI_GUID gEfiSasDevicePathGuid
= EFI_SAS_DEVICE_PATH_GUID
;
35 EFI_GUID gEfiVirtualDiskGuid
= EFI_VIRTUAL_DISK_GUID
;
36 EFI_GUID gEfiVirtualCdGuid
= EFI_VIRTUAL_CD_GUID
;
37 EFI_GUID gEfiPersistentVirtualDiskGuid
= EFI_PERSISTENT_VIRTUAL_DISK_GUID
;
38 EFI_GUID gEfiPersistentVirtualCdGuid
= EFI_PERSISTENT_VIRTUAL_CD_GUID
;
49 Displays the standard utility information to SDTOUT
61 fprintf (stdout
, "%s Version %d.%d %s \n", UTILITY_NAME
, UTILITY_MAJOR_VERSION
, UTILITY_MINOR_VERSION
, __BUILD_VERSION
);
73 Displays the utility usage syntax to STDOUT
88 fprintf (stdout
, "\nUsage: %s [options]\n\n", UTILITY_NAME
);
91 // Copyright declaration
93 fprintf (stdout
, "Copyright (c) 2017, Intel Corporation. All rights reserved.\n\n");
97 fprintf (stdout
, "Options:\n");
98 fprintf (stdout
, " DevicePathString Device Path string is specified, no space character.\n"
99 " Example: \"PciRoot(0)/Pci(0,0)\"\n");
101 fprintf (stdout
, " --version Show program's version number and exit.\n");
102 fprintf (stdout
, " -h, --help Show this help message and exit.\n");
106 void print_mem(void const *vp
, size_t n
)
108 unsigned char const *p
= vp
;
109 for (size_t i
=0; i
<n
; i
++) {
110 printf("0x%02x ", p
[i
]);
115 Ascii2UnicodeString (
123 Write ascii string as unicode string format to FILE
127 String - Pointer to string that is written to FILE.
128 UniString - Pointer to unicode string
136 while (*String
!= '\0') {
137 *(UniString
++) = (CHAR16
) *(String
++);
140 // End the UniString with a NULL.
145 int main(int argc
, CHAR8
*argv
[])
149 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
152 Error (NULL
, 0, 1001, "Missing options", "No input options specified.");
156 if ((stricmp (argv
[1], "-h") == 0) || (stricmp (argv
[1], "--help") == 0)) {
159 return STATUS_SUCCESS
;
162 if (stricmp (argv
[1], "--version") == 0) {
164 return STATUS_SUCCESS
;
168 fprintf(stderr
, "Invalid option value, Device Path can't be NULL");
171 Str16
= (CHAR16
*)malloc(1024);
173 fprintf(stderr
, "Resource, memory cannot be allcoated");
176 Ascii2UnicodeString(Str
, Str16
);
177 DevicePath
= UefiDevicePathLibConvertTextToDevicePath(Str16
);
178 while (!((DevicePath
->Type
== END_DEVICE_PATH_TYPE
) && (DevicePath
->SubType
== END_ENTIRE_DEVICE_PATH_SUBTYPE
)) )
180 print_mem(DevicePath
, (DevicePath
->Length
[0] | DevicePath
->Length
[1] << 8));
181 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*)((UINT8
*)DevicePath
+ (DevicePath
->Length
[0] | DevicePath
->Length
[1] << 8));
183 print_mem(DevicePath
, (DevicePath
->Length
[0] | DevicePath
->Length
[1] << 8));
185 return STATUS_SUCCESS
;