|
@@ -35,6 +35,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
35
|
35
|
#include <ipxe/efi/Protocol/DevicePath.h>
|
36
|
36
|
#include <ipxe/efi/Protocol/DevicePathToText.h>
|
37
|
37
|
|
|
38
|
+/** Device path protocol GUID */
|
|
39
|
+static EFI_GUID efi_device_path_protocol_guid
|
|
40
|
+ = EFI_DEVICE_PATH_PROTOCOL_GUID;
|
|
41
|
+
|
38
|
42
|
/** Device path to text protocol */
|
39
|
43
|
static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt;
|
40
|
44
|
EFI_REQUEST_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt );
|
|
@@ -88,36 +92,62 @@ void dbg_efi_protocols ( EFI_HANDLE handle ) {
|
88
|
92
|
}
|
89
|
93
|
|
90
|
94
|
/**
|
91
|
|
- * Print device path
|
|
95
|
+ * Get textual representation of device path
|
92
|
96
|
*
|
93
|
97
|
* @v path Device path
|
|
98
|
+ * @ret text Textual representation of device path, or NULL
|
94
|
99
|
*/
|
95
|
|
-void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path ) {
|
|
100
|
+const char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) {
|
96
|
101
|
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
97
|
|
- EFI_DEVICE_PATH_PROTOCOL *end;
|
98
|
|
- CHAR16 *text;
|
99
|
|
- size_t len;
|
|
102
|
+ static char text[256];
|
|
103
|
+ CHAR16 *wtext;
|
100
|
104
|
|
101
|
105
|
/* Convert path to a textual representation */
|
102
|
106
|
if ( ! efidpt )
|
103
|
|
- goto err_no_efidpt;
|
104
|
|
- text = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE );
|
105
|
|
- if ( ! text )
|
106
|
|
- goto err_convert;
|
|
107
|
+ return NULL;
|
|
108
|
+ wtext = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE );
|
|
109
|
+ if ( ! wtext )
|
|
110
|
+ return NULL;
|
107
|
111
|
|
108
|
|
- /* Print path */
|
109
|
|
- printf ( "%ls", text );
|
|
112
|
+ /* Store path in buffer */
|
|
113
|
+ snprintf ( text, sizeof ( text ), "%ls", wtext );
|
110
|
114
|
|
111
|
115
|
/* Free path */
|
112
|
|
- bs->FreePool ( text );
|
|
116
|
+ bs->FreePool ( wtext );
|
|
117
|
+
|
|
118
|
+ return text;
|
|
119
|
+}
|
|
120
|
+
|
|
121
|
+/**
|
|
122
|
+ * Get textual representation of device path for a handle
|
|
123
|
+ *
|
|
124
|
+ * @v handle EFI handle
|
|
125
|
+ * @ret text Textual representation of device path, or NULL
|
|
126
|
+ */
|
|
127
|
+const char * efi_handle_devpath_text ( EFI_HANDLE handle ) {
|
|
128
|
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
|
129
|
+ union {
|
|
130
|
+ EFI_DEVICE_PATH_PROTOCOL *path;
|
|
131
|
+ void *interface;
|
|
132
|
+ } path;
|
|
133
|
+ const char *text;
|
|
134
|
+ EFI_STATUS efirc;
|
|
135
|
+
|
|
136
|
+ /* Obtain device path, if any */
|
|
137
|
+ if ( ( efirc = bs->OpenProtocol ( handle,
|
|
138
|
+ &efi_device_path_protocol_guid,
|
|
139
|
+ &path.interface, efi_image_handle,
|
|
140
|
+ handle,
|
|
141
|
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
|
|
142
|
+ return NULL;
|
|
143
|
+ }
|
|
144
|
+
|
|
145
|
+ /* Format device path */
|
|
146
|
+ text = efi_devpath_text ( path.path );
|
113
|
147
|
|
114
|
|
- return;
|
|
148
|
+ /* Close device path */
|
|
149
|
+ bs->CloseProtocol ( handle, &efi_device_path_protocol_guid,
|
|
150
|
+ efi_image_handle, handle );
|
115
|
151
|
|
116
|
|
- err_convert:
|
117
|
|
- err_no_efidpt:
|
118
|
|
- printf ( "<cannot convert>:\n" );
|
119
|
|
- end = efi_devpath_end ( path );
|
120
|
|
- len = ( ( ( void * ) end ) - ( ( void * ) path ) +
|
121
|
|
- sizeof ( *end ) );
|
122
|
|
- dbg_hex_dump_da ( 0, path, len );
|
|
152
|
+ return text;
|
123
|
153
|
}
|