浏览代码

[efi] Add EFI-specific debugging macros

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 年前
父节点
当前提交
6b9b44319f
共有 3 个文件被更改,包括 216 次插入0 次删除
  1. 87
    0
      src/include/ipxe/efi/Protocol/DevicePathToText.h
  2. 34
    0
      src/include/ipxe/efi/efi.h
  3. 95
    0
      src/interface/efi/efi_debug.c

+ 87
- 0
src/include/ipxe/efi/Protocol/DevicePathToText.h 查看文件

@@ -0,0 +1,87 @@
1
+/** @file
2
+  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL as defined in UEFI 2.0.
3
+  This protocol provides service to convert device nodes and paths to text.
4
+
5
+  Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
6
+  This program and the accompanying materials
7
+  are licensed and made available under the terms and conditions of the BSD License
8
+  which accompanies this distribution.  The full text of the license may be found at
9
+  http://opensource.org/licenses/bsd-license.php
10
+
11
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
+
14
+**/
15
+
16
+#ifndef __DEVICE_PATH_TO_TEXT_PROTOCOL_H__
17
+#define __DEVICE_PATH_TO_TEXT_PROTOCOL_H__
18
+
19
+FILE_LICENCE ( BSD3 );
20
+
21
+///
22
+/// Device Path To Text protocol
23
+///
24
+#define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID \
25
+  { \
26
+    0x8b843e20, 0x8132, 0x4852, {0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c } \
27
+  }
28
+
29
+/**
30
+  Convert a device node to its text representation.
31
+
32
+  @param  DeviceNode     Points to the device node to be converted.
33
+  @param  DisplayOnly    If DisplayOnly is TRUE, then the shorter text representation
34
+                         of the display node is used, where applicable. If DisplayOnly
35
+                         is FALSE, then the longer text representation of the display node
36
+                         is used.
37
+  @param  AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
38
+                         representation for a device node can be used, where applicable.
39
+
40
+  @retval a_pointer      a pointer to the allocated text representation of the device node data
41
+  @retval NULL           if DeviceNode is NULL or there was insufficient memory.
42
+
43
+**/
44
+typedef
45
+CHAR16*
46
+(EFIAPI *EFI_DEVICE_PATH_TO_TEXT_NODE)(
47
+  IN CONST EFI_DEVICE_PATH_PROTOCOL   *DeviceNode,
48
+  IN BOOLEAN                          DisplayOnly,
49
+  IN BOOLEAN                          AllowShortcuts
50
+  );
51
+
52
+/**
53
+  Convert a device path to its text representation.
54
+
55
+  @param  DevicePath     Points to the device path to be converted.
56
+  @param  DisplayOnly    If DisplayOnly is TRUE, then the shorter text representation
57
+                         of the display node is used, where applicable. If DisplayOnly
58
+                         is FALSE, then the longer text representation of the display node
59
+                         is used.
60
+  @param  AllowShortcuts The AllowShortcuts is FALSE, then the shortcut forms of
61
+                         text representation for a device node cannot be used.
62
+
63
+  @retval a_pointer      a pointer to the allocated text representation of the device node.
64
+  @retval NULL           if DevicePath is NULL or there was insufficient memory.
65
+
66
+**/
67
+typedef
68
+CHAR16*
69
+(EFIAPI *EFI_DEVICE_PATH_TO_TEXT_PATH)(
70
+  IN CONST EFI_DEVICE_PATH_PROTOCOL   *DevicePath,
71
+  IN BOOLEAN                          DisplayOnly,
72
+  IN BOOLEAN                          AllowShortcuts
73
+  );
74
+
75
+///
76
+/// This protocol converts device paths and device nodes to text.
77
+///
78
+typedef struct {
79
+  EFI_DEVICE_PATH_TO_TEXT_NODE        ConvertDeviceNodeToText;
80
+  EFI_DEVICE_PATH_TO_TEXT_PATH        ConvertDevicePathToText;
81
+} EFI_DEVICE_PATH_TO_TEXT_PROTOCOL;
82
+
83
+extern EFI_GUID gEfiDevicePathToTextProtocolGuid;
84
+
85
+#endif
86
+
87
+

+ 34
- 0
src/include/ipxe/efi/efi.h 查看文件

@@ -140,6 +140,40 @@ extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image;
140 140
 extern EFI_SYSTEM_TABLE *efi_systab;
141 141
 
142 142
 extern const char * efi_strerror ( EFI_STATUS efirc );
143
+
144
+extern void dbg_efi_protocols ( EFI_HANDLE handle );
145
+extern void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path );
146
+
147
+#define DBG_EFI_PROTOCOLS_IF( level, handle ) do {		\
148
+		if ( DBG_ ## level ) {				\
149
+			dbg_efi_protocols ( handle );		\
150
+		}						\
151
+	} while ( 0 )
152
+
153
+#define DBG_EFI_DEVPATH_IF( level, path ) do {			\
154
+		if ( DBG_ ## level ) {				\
155
+			dbg_efi_devpath ( path );		\
156
+		}						\
157
+	} while ( 0 )
158
+
159
+#define DBGC_EFI_PROTOCOLS_IF( level, id, ... ) do {		\
160
+		DBG_AC_IF ( level, id );			\
161
+		DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ );	\
162
+		DBG_DC_IF ( level );				\
163
+	} while ( 0 )
164
+
165
+#define DBGC_EFI_DEVPATH_IF( level, id, ... ) do {		\
166
+		DBG_AC_IF ( level, id );			\
167
+		DBG_EFI_DEVPATH_IF ( level, __VA_ARGS__ );	\
168
+		DBG_DC_IF ( level );				\
169
+	} while ( 0 )
170
+
171
+#define DBGC_EFI_PROTOCOLS( ... )				\
172
+	DBGC_EFI_PROTOCOLS_IF( LOG, ##__VA_ARGS__ )
173
+
174
+#define DBGC_EFI_DEVPATH( ... )					\
175
+	DBGC_EFI_DEVPATH_IF( LOG, ##__VA_ARGS__ )
176
+
143 177
 extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
144 178
 			     EFI_SYSTEM_TABLE *systab );
145 179
 

+ 95
- 0
src/interface/efi/efi_debug.c 查看文件

@@ -0,0 +1,95 @@
1
+/*
2
+ * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
+ * 02110-1301, USA.
18
+ */
19
+
20
+FILE_LICENCE ( GPL2_OR_LATER );
21
+
22
+/**
23
+ * @file
24
+ *
25
+ * EFI debugging utilities
26
+ *
27
+ */
28
+
29
+#include <stdio.h>
30
+#include <ipxe/efi/efi.h>
31
+#include <ipxe/efi/efi_driver.h>
32
+#include <ipxe/efi/Protocol/DevicePath.h>
33
+#include <ipxe/efi/Protocol/DevicePathToText.h>
34
+
35
+/** Device path to text protocol */
36
+static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt;
37
+EFI_REQUIRE_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt );
38
+
39
+/**
40
+ * Print list of protocol handlers attached to a handle
41
+ *
42
+ * @v handle		EFI handle
43
+ */
44
+void dbg_efi_protocols ( EFI_HANDLE handle ) {
45
+	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
46
+        EFI_GUID **protocols;
47
+	UINTN count;
48
+	unsigned int i;
49
+	EFI_STATUS efirc;
50
+
51
+	/* Retrieve list of protocols */
52
+	if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
53
+						&count ) ) != 0 ) {
54
+		printf ( "EFI could not retrieve protocols for %p: %s\n",
55
+			 handle, efi_strerror ( efirc ) );
56
+		return;
57
+	}
58
+
59
+	/* Dump list of protocols */
60
+	for ( i = 0 ; i < count ; i++ ) {
61
+		printf ( "%s\n", uuid_ntoa ( ( union uuid * ) protocols[i] ) );
62
+	}
63
+
64
+	/* Free list */
65
+	bs->FreePool ( protocols );
66
+}
67
+
68
+/**
69
+ * Print device path
70
+ *
71
+ * @v path		Device path
72
+ */
73
+void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path ) {
74
+	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
75
+	EFI_DEVICE_PATH_PROTOCOL *end;
76
+	CHAR16 *text;
77
+	size_t len;
78
+
79
+	/* Convert path to a textual representation */
80
+	text = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE );
81
+	if ( ! text ) {
82
+		printf ( "<cannot convert>:\n" );
83
+		end = efi_devpath_end ( path );
84
+		len = ( ( ( void * ) end ) - ( ( void * ) path ) +
85
+			sizeof ( *end ) );
86
+		dbg_hex_dump_da ( 0, path, len );
87
+		return;
88
+	}
89
+
90
+	/* Print path */
91
+	printf ( "%ls", text );
92
+
93
+	/* Free path */
94
+	bs->FreePool ( text );
95
+}

正在加载...
取消
保存