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

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

@@ -27,6 +27,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
27 27
  */
28 28
 
29 29
 #include <stdio.h>
30
+#include <string.h>
31
+#include <ipxe/uuid.h>
30 32
 #include <ipxe/efi/efi.h>
31 33
 #include <ipxe/efi/efi_driver.h>
32 34
 #include <ipxe/efi/Protocol/DevicePath.h>
@@ -36,6 +38,24 @@ FILE_LICENCE ( GPL2_OR_LATER );
36 38
 static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt;
37 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 60
  * Print list of protocol handlers attached to a handle
41 61
  *
@@ -57,9 +77,8 @@ void dbg_efi_protocols ( EFI_HANDLE handle ) {
57 77
 	}
58 78
 
59 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 83
 	/* Free list */
65 84
 	bs->FreePool ( protocols );

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

@@ -414,8 +414,7 @@ static EFI_STATUS EFIAPI efi_file_get_info ( EFI_FILE_PROTOCOL *this,
414 414
 	} else {
415 415
 
416 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 418
 		return EFI_UNSUPPORTED;
420 419
 	}
421 420
 }
@@ -435,7 +434,7 @@ efi_file_set_info ( EFI_FILE_PROTOCOL *this, EFI_GUID *type,
435 434
 	struct efi_file *file = container_of ( this, struct efi_file, file );
436 435
 
437 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 438
 	return EFI_WRITE_PROTECTED;
440 439
 }
441 440
 

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

@@ -121,13 +121,14 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
121 121
 
122 122
 	/* Look up used protocols */
123 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 125
 						    prot->protocol ) ) == 0 ) {
126 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 129
 		} else {
129 130
 			DBGC ( systab, "EFI does not provide protocol %s\n",
130
-			       uuid_ntoa ( &prot->u.uuid ) );
131
+			       efi_guid_ntoa ( &prot->guid ) );
131 132
 			/* All protocols are required */
132 133
 			return efirc;
133 134
 		}
@@ -135,12 +136,12 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
135 136
 
136 137
 	/* Look up used configuration tables */
137 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 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 142
 		} else {
142 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 145
 			if ( tab->required )
145 146
 				return EFI_NOT_AVAILABLE_YET;
146 147
 		}

Loading…
Cancel
Save