ソースを参照

[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年前
コミット
44338bfd22
2個のファイルの変更52行の追加36行の削除
  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 ファイルの表示

@@ -149,9 +149,10 @@ extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path;
149 149
 extern EFI_SYSTEM_TABLE *efi_systab;
150 150
 
151 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 155
 extern void dbg_efi_protocols ( EFI_HANDLE handle );
154
-extern void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path );
155 156
 
156 157
 #define DBG_EFI_PROTOCOLS_IF( level, handle ) do {		\
157 158
 		if ( DBG_ ## level ) {				\
@@ -159,30 +160,15 @@ extern void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path );
159 160
 		}						\
160 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 163
 #define DBGC_EFI_PROTOCOLS_IF( level, id, ... ) do {		\
169 164
 		DBG_AC_IF ( level, id );			\
170 165
 		DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ );	\
171 166
 		DBG_DC_IF ( level );				\
172 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 169
 #define DBGC_EFI_PROTOCOLS( ... )				\
181 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 172
 extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
187 173
 			     EFI_SYSTEM_TABLE *systab );
188 174
 

+ 50
- 20
src/interface/efi/efi_debug.c ファイルの表示

@@ -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
 }

読み込み中…
キャンセル
保存