david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[efi] Provide efi_guid_ntoa() for printing EFI GUIDs

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2013-03-20 15:25:16 +00:00
parent d938e50136
commit 1920aa4376
4 changed files with 36 additions and 26 deletions

View File

@ -54,12 +54,7 @@
/** An EFI protocol used by iPXE */ /** An EFI protocol used by iPXE */
struct efi_protocol { struct efi_protocol {
/** GUID */ /** GUID */
union { EFI_GUID guid;
/** EFI protocol GUID */
EFI_GUID guid;
/** UUID structure understood by iPXE */
union uuid uuid;
} u;
/** Variable containing pointer to protocol structure */ /** Variable containing pointer to protocol structure */
void **protocol; void **protocol;
}; };
@ -77,7 +72,7 @@ struct efi_protocol {
*/ */
#define EFI_REQUIRE_PROTOCOL( _protocol, _ptr ) \ #define EFI_REQUIRE_PROTOCOL( _protocol, _ptr ) \
struct efi_protocol __ ## _protocol __efi_protocol = { \ struct efi_protocol __ ## _protocol __efi_protocol = { \
.u.guid = _protocol ## _GUID, \ .guid = _protocol ## _GUID, \
.protocol = ( ( void ** ) ( void * ) \ .protocol = ( ( void ** ) ( void * ) \
( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ? \ ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ? \
(_ptr) : (_ptr) ) ), \ (_ptr) : (_ptr) ) ), \
@ -86,12 +81,7 @@ struct efi_protocol {
/** An EFI configuration table used by iPXE */ /** An EFI configuration table used by iPXE */
struct efi_config_table { struct efi_config_table {
/** GUID */ /** GUID */
union { EFI_GUID guid;
/** EFI configuration table GUID */
EFI_GUID guid;
/** UUID structure understood by iPXE */
union uuid uuid;
} u;
/** Variable containing pointer to configuration table */ /** Variable containing pointer to configuration table */
void **table; void **table;
/** Table is required for operation */ /** Table is required for operation */
@ -113,7 +103,7 @@ struct efi_config_table {
*/ */
#define EFI_USE_TABLE( _table, _ptr, _required ) \ #define EFI_USE_TABLE( _table, _ptr, _required ) \
struct efi_config_table __ ## _table __efi_config_table = { \ struct efi_config_table __ ## _table __efi_config_table = { \
.u.guid = _table ## _GUID, \ .guid = _table ## _GUID, \
.table = ( ( void ** ) ( void * ) (_ptr) ), \ .table = ( ( void ** ) ( void * ) (_ptr) ), \
.required = (_required), \ .required = (_required), \
} }
@ -140,6 +130,7 @@ extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image;
extern EFI_SYSTEM_TABLE *efi_systab; extern EFI_SYSTEM_TABLE *efi_systab;
extern const char * efi_strerror ( EFI_STATUS efirc ); extern const char * efi_strerror ( EFI_STATUS efirc );
extern const char * efi_guid_ntoa ( EFI_GUID *guid );
extern void dbg_efi_protocols ( EFI_HANDLE handle ); extern void dbg_efi_protocols ( EFI_HANDLE handle );
extern void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path ); extern void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path );

View File

@ -27,6 +27,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <ipxe/uuid.h>
#include <ipxe/efi/efi.h> #include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_driver.h> #include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/Protocol/DevicePath.h> #include <ipxe/efi/Protocol/DevicePath.h>
@ -36,6 +38,24 @@ FILE_LICENCE ( GPL2_OR_LATER );
static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt; static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt;
EFI_REQUIRE_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt ); EFI_REQUIRE_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt );
/**
* Convert GUID to a printable string
*
* @v guid GUID
* @ret string Printable string
*/
const char * efi_guid_ntoa ( EFI_GUID *guid ) {
union {
union uuid uuid;
EFI_GUID guid;
} u;
/* Convert GUID to standard endianness */
memcpy ( &u.guid, guid, sizeof ( u.guid ) );
uuid_mangle ( &u.uuid );
return uuid_ntoa ( &u.uuid );
}
/** /**
* Print list of protocol handlers attached to a handle * Print list of protocol handlers attached to a handle
* *
@ -57,9 +77,8 @@ void dbg_efi_protocols ( EFI_HANDLE handle ) {
} }
/* Dump list of protocols */ /* Dump list of protocols */
for ( i = 0 ; i < count ; i++ ) { for ( i = 0 ; i < count ; i++ )
printf ( "%s\n", uuid_ntoa ( ( union uuid * ) protocols[i] ) ); printf ( "%s\n", efi_guid_ntoa ( protocols[i] ) );
}
/* Free list */ /* Free list */
bs->FreePool ( protocols ); bs->FreePool ( protocols );

View File

@ -414,8 +414,7 @@ static EFI_STATUS EFIAPI efi_file_get_info ( EFI_FILE_PROTOCOL *this,
} else { } else {
DBGC ( file, "EFIFILE %s cannot get information of type %s\n", DBGC ( file, "EFIFILE %s cannot get information of type %s\n",
efi_file_name ( file ), efi_file_name ( file ), efi_guid_ntoa ( type ) );
uuid_ntoa ( ( union uuid * ) type ) );
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
} }
@ -435,7 +434,7 @@ efi_file_set_info ( EFI_FILE_PROTOCOL *this, EFI_GUID *type,
struct efi_file *file = container_of ( this, struct efi_file, file ); struct efi_file *file = container_of ( this, struct efi_file, file );
DBGC ( file, "EFIFILE %s cannot set information of type %s\n", DBGC ( file, "EFIFILE %s cannot set information of type %s\n",
efi_file_name ( file ), uuid_ntoa ( ( union uuid * ) type ) ); efi_file_name ( file ), efi_guid_ntoa ( type ) );
return EFI_WRITE_PROTECTED; return EFI_WRITE_PROTECTED;
} }

View File

@ -121,13 +121,14 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
/* Look up used protocols */ /* Look up used protocols */
for_each_table_entry ( prot, EFI_PROTOCOLS ) { for_each_table_entry ( prot, EFI_PROTOCOLS ) {
if ( ( efirc = bs->LocateProtocol ( &prot->u.guid, NULL, if ( ( efirc = bs->LocateProtocol ( &prot->guid, NULL,
prot->protocol ) ) == 0 ) { prot->protocol ) ) == 0 ) {
DBGC ( systab, "EFI protocol %s is at %p\n", DBGC ( systab, "EFI protocol %s is at %p\n",
uuid_ntoa ( &prot->u.uuid ), *(prot->protocol)); efi_guid_ntoa ( &prot->guid ),
*(prot->protocol) );
} else { } else {
DBGC ( systab, "EFI does not provide protocol %s\n", DBGC ( systab, "EFI does not provide protocol %s\n",
uuid_ntoa ( &prot->u.uuid ) ); efi_guid_ntoa ( &prot->guid ) );
/* All protocols are required */ /* All protocols are required */
return efirc; return efirc;
} }
@ -135,12 +136,12 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
/* Look up used configuration tables */ /* Look up used configuration tables */
for_each_table_entry ( tab, EFI_CONFIG_TABLES ) { for_each_table_entry ( tab, EFI_CONFIG_TABLES ) {
if ( ( *(tab->table) = efi_find_table ( &tab->u.guid ) ) ) { if ( ( *(tab->table) = efi_find_table ( &tab->guid ) ) ) {
DBGC ( systab, "EFI configuration table %s is at %p\n", DBGC ( systab, "EFI configuration table %s is at %p\n",
uuid_ntoa ( &tab->u.uuid ), *(tab->table) ); efi_guid_ntoa ( &tab->guid ), *(tab->table) );
} else { } else {
DBGC ( systab, "EFI does not provide configuration " DBGC ( systab, "EFI does not provide configuration "
"table %s\n", uuid_ntoa ( &tab->u.uuid ) ); "table %s\n", efi_guid_ntoa ( &tab->guid ) );
if ( tab->required ) if ( tab->required )
return EFI_NOT_AVAILABLE_YET; return EFI_NOT_AVAILABLE_YET;
} }