Browse Source

[efi] Provide efi_guid_ntoa() for printing EFI GUIDs

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
1920aa4376

+ 5
- 14
src/include/ipxe/efi/efi.h View File

54
 /** An EFI protocol used by iPXE */
54
 /** An EFI protocol used by iPXE */
55
 struct efi_protocol {
55
 struct efi_protocol {
56
 	/** GUID */
56
 	/** GUID */
57
-	union {
58
-		/** EFI protocol GUID */
59
-		EFI_GUID guid;
60
-		/** UUID structure understood by iPXE */
61
-		union uuid uuid;
62
-	} u;
57
+	EFI_GUID guid;
63
 	/** Variable containing pointer to protocol structure */
58
 	/** Variable containing pointer to protocol structure */
64
 	void **protocol;
59
 	void **protocol;
65
 };
60
 };
77
  */
72
  */
78
 #define EFI_REQUIRE_PROTOCOL( _protocol, _ptr )				     \
73
 #define EFI_REQUIRE_PROTOCOL( _protocol, _ptr )				     \
79
 	struct efi_protocol __ ## _protocol __efi_protocol = {		     \
74
 	struct efi_protocol __ ## _protocol __efi_protocol = {		     \
80
-		.u.guid = _protocol ## _GUID,				     \
75
+		.guid = _protocol ## _GUID,				     \
81
 		.protocol = ( ( void ** ) ( void * )			     \
76
 		.protocol = ( ( void ** ) ( void * )			     \
82
 			      ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ?  \
77
 			      ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ?  \
83
 				(_ptr) : (_ptr) ) ),			     \
78
 				(_ptr) : (_ptr) ) ),			     \
86
 /** An EFI configuration table used by iPXE */
81
 /** An EFI configuration table used by iPXE */
87
 struct efi_config_table {
82
 struct efi_config_table {
88
 	/** GUID */
83
 	/** GUID */
89
-	union {
90
-		/** EFI configuration table GUID */
91
-		EFI_GUID guid;
92
-		/** UUID structure understood by iPXE */
93
-		union uuid uuid;
94
-	} u;
84
+	EFI_GUID guid;
95
 	/** Variable containing pointer to configuration table */
85
 	/** Variable containing pointer to configuration table */
96
 	void **table;
86
 	void **table;
97
 	/** Table is required for operation */
87
 	/** Table is required for operation */
113
  */
103
  */
114
 #define EFI_USE_TABLE( _table, _ptr, _required )			     \
104
 #define EFI_USE_TABLE( _table, _ptr, _required )			     \
115
 	struct efi_config_table __ ## _table __efi_config_table = {	     \
105
 	struct efi_config_table __ ## _table __efi_config_table = {	     \
116
-		.u.guid = _table ## _GUID,				     \
106
+		.guid = _table ## _GUID,				     \
117
 		.table = ( ( void ** ) ( void * ) (_ptr) ),		     \
107
 		.table = ( ( void ** ) ( void * ) (_ptr) ),		     \
118
 		.required = (_required),				     \
108
 		.required = (_required),				     \
119
 	}
109
 	}
140
 extern EFI_SYSTEM_TABLE *efi_systab;
130
 extern EFI_SYSTEM_TABLE *efi_systab;
141
 
131
 
142
 extern const char * efi_strerror ( EFI_STATUS efirc );
132
 extern const char * efi_strerror ( EFI_STATUS efirc );
133
+extern const char * efi_guid_ntoa ( EFI_GUID *guid );
143
 
134
 
144
 extern void dbg_efi_protocols ( EFI_HANDLE handle );
135
 extern void dbg_efi_protocols ( EFI_HANDLE handle );
145
 extern void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path );
136
 extern void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path );

+ 22
- 3
src/interface/efi/efi_debug.c View File

27
  */
27
  */
28
 
28
 
29
 #include <stdio.h>
29
 #include <stdio.h>
30
+#include <string.h>
31
+#include <ipxe/uuid.h>
30
 #include <ipxe/efi/efi.h>
32
 #include <ipxe/efi/efi.h>
31
 #include <ipxe/efi/efi_driver.h>
33
 #include <ipxe/efi/efi_driver.h>
32
 #include <ipxe/efi/Protocol/DevicePath.h>
34
 #include <ipxe/efi/Protocol/DevicePath.h>
36
 static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt;
38
 static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt;
37
 EFI_REQUIRE_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt );
39
 EFI_REQUIRE_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt );
38
 
40
 
41
+/**
42
+ * Convert GUID to a printable string
43
+ *
44
+ * @v guid		GUID
45
+ * @ret string		Printable string
46
+ */
47
+const char * efi_guid_ntoa ( EFI_GUID *guid ) {
48
+	union {
49
+		union uuid uuid;
50
+		EFI_GUID guid;
51
+	} u;
52
+
53
+	/* Convert GUID to standard endianness */
54
+	memcpy ( &u.guid, guid, sizeof ( u.guid ) );
55
+	uuid_mangle ( &u.uuid );
56
+	return uuid_ntoa ( &u.uuid );
57
+}
58
+
39
 /**
59
 /**
40
  * Print list of protocol handlers attached to a handle
60
  * Print list of protocol handlers attached to a handle
41
  *
61
  *
57
 	}
77
 	}
58
 
78
 
59
 	/* Dump list of protocols */
79
 	/* Dump list of protocols */
60
-	for ( i = 0 ; i < count ; i++ ) {
61
-		printf ( "%s\n", uuid_ntoa ( ( union uuid * ) protocols[i] ) );
62
-	}
80
+	for ( i = 0 ; i < count ; i++ )
81
+		printf ( "%s\n", efi_guid_ntoa ( protocols[i] ) );
63
 
82
 
64
 	/* Free list */
83
 	/* Free list */
65
 	bs->FreePool ( protocols );
84
 	bs->FreePool ( protocols );

+ 2
- 3
src/interface/efi/efi_file.c View File

414
 	} else {
414
 	} else {
415
 
415
 
416
 		DBGC ( file, "EFIFILE %s cannot get information of type %s\n",
416
 		DBGC ( file, "EFIFILE %s cannot get information of type %s\n",
417
-		       efi_file_name ( file ),
418
-		       uuid_ntoa ( ( union uuid * ) type ) );
417
+		       efi_file_name ( file ), efi_guid_ntoa ( type ) );
419
 		return EFI_UNSUPPORTED;
418
 		return EFI_UNSUPPORTED;
420
 	}
419
 	}
421
 }
420
 }
435
 	struct efi_file *file = container_of ( this, struct efi_file, file );
434
 	struct efi_file *file = container_of ( this, struct efi_file, file );
436
 
435
 
437
 	DBGC ( file, "EFIFILE %s cannot set information of type %s\n",
436
 	DBGC ( file, "EFIFILE %s cannot set information of type %s\n",
438
-	       efi_file_name ( file ), uuid_ntoa ( ( union uuid * ) type ) );
437
+	       efi_file_name ( file ), efi_guid_ntoa ( type ) );
439
 	return EFI_WRITE_PROTECTED;
438
 	return EFI_WRITE_PROTECTED;
440
 }
439
 }
441
 
440
 

+ 7
- 6
src/interface/efi/efi_init.c View File

121
 
121
 
122
 	/* Look up used protocols */
122
 	/* Look up used protocols */
123
 	for_each_table_entry ( prot, EFI_PROTOCOLS ) {
123
 	for_each_table_entry ( prot, EFI_PROTOCOLS ) {
124
-		if ( ( efirc = bs->LocateProtocol ( &prot->u.guid, NULL,
124
+		if ( ( efirc = bs->LocateProtocol ( &prot->guid, NULL,
125
 						    prot->protocol ) ) == 0 ) {
125
 						    prot->protocol ) ) == 0 ) {
126
 			DBGC ( systab, "EFI protocol %s is at %p\n",
126
 			DBGC ( systab, "EFI protocol %s is at %p\n",
127
-			       uuid_ntoa ( &prot->u.uuid ), *(prot->protocol));
127
+			       efi_guid_ntoa ( &prot->guid ),
128
+			       *(prot->protocol) );
128
 		} else {
129
 		} else {
129
 			DBGC ( systab, "EFI does not provide protocol %s\n",
130
 			DBGC ( systab, "EFI does not provide protocol %s\n",
130
-			       uuid_ntoa ( &prot->u.uuid ) );
131
+			       efi_guid_ntoa ( &prot->guid ) );
131
 			/* All protocols are required */
132
 			/* All protocols are required */
132
 			return efirc;
133
 			return efirc;
133
 		}
134
 		}
135
 
136
 
136
 	/* Look up used configuration tables */
137
 	/* Look up used configuration tables */
137
 	for_each_table_entry ( tab, EFI_CONFIG_TABLES ) {
138
 	for_each_table_entry ( tab, EFI_CONFIG_TABLES ) {
138
-		if ( ( *(tab->table) = efi_find_table ( &tab->u.guid ) ) ) {
139
+		if ( ( *(tab->table) = efi_find_table ( &tab->guid ) ) ) {
139
 			DBGC ( systab, "EFI configuration table %s is at %p\n",
140
 			DBGC ( systab, "EFI configuration table %s is at %p\n",
140
-			       uuid_ntoa ( &tab->u.uuid ), *(tab->table) );
141
+			       efi_guid_ntoa ( &tab->guid ), *(tab->table) );
141
 		} else {
142
 		} else {
142
 			DBGC ( systab, "EFI does not provide configuration "
143
 			DBGC ( systab, "EFI does not provide configuration "
143
-			       "table %s\n", uuid_ntoa ( &tab->u.uuid ) );
144
+			       "table %s\n", efi_guid_ntoa ( &tab->guid ) );
144
 			if ( tab->required )
145
 			if ( tab->required )
145
 				return EFI_NOT_AVAILABLE_YET;
146
 				return EFI_NOT_AVAILABLE_YET;
146
 		}
147
 		}

Loading…
Cancel
Save