Selaa lähdekoodia

[efi] Allow device paths to be easily included in debug messages

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 vuotta sitten
vanhempi
commit
44338bfd22
2 muutettua tiedostoa jossa 52 lisäystä ja 36 poistoa
  1. 2
    16
      src/include/ipxe/efi/efi.h
  2. 50
    20
      src/interface/efi/efi_debug.c

+ 2
- 16
src/include/ipxe/efi/efi.h Näytä tiedosto

149
 extern EFI_SYSTEM_TABLE *efi_systab;
149
 extern EFI_SYSTEM_TABLE *efi_systab;
150
 
150
 
151
 extern const char * efi_guid_ntoa ( EFI_GUID *guid );
151
 extern const char * efi_guid_ntoa ( EFI_GUID *guid );
152
+extern const char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path );
153
+extern const char * efi_handle_devpath_text ( EFI_HANDLE handle );
152
 
154
 
153
 extern void dbg_efi_protocols ( EFI_HANDLE handle );
155
 extern void dbg_efi_protocols ( EFI_HANDLE handle );
154
-extern void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path );
155
 
156
 
156
 #define DBG_EFI_PROTOCOLS_IF( level, handle ) do {		\
157
 #define DBG_EFI_PROTOCOLS_IF( level, handle ) do {		\
157
 		if ( DBG_ ## level ) {				\
158
 		if ( DBG_ ## level ) {				\
159
 		}						\
160
 		}						\
160
 	} while ( 0 )
161
 	} while ( 0 )
161
 
162
 
162
-#define DBG_EFI_DEVPATH_IF( level, path ) do {			\
163
-		if ( DBG_ ## level ) {				\
164
-			dbg_efi_devpath ( path );		\
165
-		}						\
166
-	} while ( 0 )
167
-
168
 #define DBGC_EFI_PROTOCOLS_IF( level, id, ... ) do {		\
163
 #define DBGC_EFI_PROTOCOLS_IF( level, id, ... ) do {		\
169
 		DBG_AC_IF ( level, id );			\
164
 		DBG_AC_IF ( level, id );			\
170
 		DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ );	\
165
 		DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ );	\
171
 		DBG_DC_IF ( level );				\
166
 		DBG_DC_IF ( level );				\
172
 	} while ( 0 )
167
 	} while ( 0 )
173
 
168
 
174
-#define DBGC_EFI_DEVPATH_IF( level, id, ... ) do {		\
175
-		DBG_AC_IF ( level, id );			\
176
-		DBG_EFI_DEVPATH_IF ( level, __VA_ARGS__ );	\
177
-		DBG_DC_IF ( level );				\
178
-	} while ( 0 )
179
-
180
 #define DBGC_EFI_PROTOCOLS( ... )				\
169
 #define DBGC_EFI_PROTOCOLS( ... )				\
181
 	DBGC_EFI_PROTOCOLS_IF( LOG, ##__VA_ARGS__ )
170
 	DBGC_EFI_PROTOCOLS_IF( LOG, ##__VA_ARGS__ )
182
 
171
 
183
-#define DBGC_EFI_DEVPATH( ... )					\
184
-	DBGC_EFI_DEVPATH_IF( LOG, ##__VA_ARGS__ )
185
-
186
 extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
172
 extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
187
 			     EFI_SYSTEM_TABLE *systab );
173
 			     EFI_SYSTEM_TABLE *systab );
188
 
174
 

+ 50
- 20
src/interface/efi/efi_debug.c Näytä tiedosto

35
 #include <ipxe/efi/Protocol/DevicePath.h>
35
 #include <ipxe/efi/Protocol/DevicePath.h>
36
 #include <ipxe/efi/Protocol/DevicePathToText.h>
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
 /** Device path to text protocol */
42
 /** Device path to text protocol */
39
 static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt;
43
 static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt;
40
 EFI_REQUEST_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt );
44
 EFI_REQUEST_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt );
88
 }
92
 }
89
 
93
 
90
 /**
94
 /**
91
- * Print device path
95
+ * Get textual representation of device path
92
  *
96
  *
93
  * @v path		Device path
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
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
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
 	/* Convert path to a textual representation */
105
 	/* Convert path to a textual representation */
102
 	if ( ! efidpt )
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
 	/* Free path */
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
 }

Loading…
Peruuta
Tallenna