From 44338bfd223c0594420385c21eb25c77d45b405f Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 25 Jun 2014 14:44:13 +0100 Subject: [PATCH] [efi] Allow device paths to be easily included in debug messages Signed-off-by: Michael Brown --- src/include/ipxe/efi/efi.h | 18 +-------- src/interface/efi/efi_debug.c | 72 +++++++++++++++++++++++++---------- 2 files changed, 53 insertions(+), 37 deletions(-) diff --git a/src/include/ipxe/efi/efi.h b/src/include/ipxe/efi/efi.h index 05576f9d..38342f73 100644 --- a/src/include/ipxe/efi/efi.h +++ b/src/include/ipxe/efi/efi.h @@ -149,9 +149,10 @@ extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path; extern EFI_SYSTEM_TABLE *efi_systab; extern const char * efi_guid_ntoa ( EFI_GUID *guid ); +extern const char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ); +extern const char * efi_handle_devpath_text ( EFI_HANDLE handle ); extern void dbg_efi_protocols ( EFI_HANDLE handle ); -extern void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path ); #define DBG_EFI_PROTOCOLS_IF( level, handle ) do { \ if ( DBG_ ## level ) { \ @@ -159,30 +160,15 @@ extern void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path ); } \ } while ( 0 ) -#define DBG_EFI_DEVPATH_IF( level, path ) do { \ - if ( DBG_ ## level ) { \ - dbg_efi_devpath ( path ); \ - } \ - } while ( 0 ) - #define DBGC_EFI_PROTOCOLS_IF( level, id, ... ) do { \ DBG_AC_IF ( level, id ); \ DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ ); \ DBG_DC_IF ( level ); \ } while ( 0 ) -#define DBGC_EFI_DEVPATH_IF( level, id, ... ) do { \ - DBG_AC_IF ( level, id ); \ - DBG_EFI_DEVPATH_IF ( level, __VA_ARGS__ ); \ - DBG_DC_IF ( level ); \ - } while ( 0 ) - #define DBGC_EFI_PROTOCOLS( ... ) \ DBGC_EFI_PROTOCOLS_IF( LOG, ##__VA_ARGS__ ) -#define DBGC_EFI_DEVPATH( ... ) \ - DBGC_EFI_DEVPATH_IF( LOG, ##__VA_ARGS__ ) - extern EFI_STATUS efi_init ( EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab ); diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index 6d834bc8..f1427f51 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -35,6 +35,10 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include #include +/** Device path protocol GUID */ +static EFI_GUID efi_device_path_protocol_guid + = EFI_DEVICE_PATH_PROTOCOL_GUID; + /** Device path to text protocol */ static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt; EFI_REQUEST_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt ); @@ -88,36 +92,62 @@ void dbg_efi_protocols ( EFI_HANDLE handle ) { } /** - * Print device path + * Get textual representation of device path * * @v path Device path + * @ret text Textual representation of device path, or NULL */ -void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path ) { +const char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_DEVICE_PATH_PROTOCOL *end; - CHAR16 *text; - size_t len; + static char text[256]; + CHAR16 *wtext; /* Convert path to a textual representation */ if ( ! efidpt ) - goto err_no_efidpt; - text = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE ); - if ( ! text ) - goto err_convert; + return NULL; + wtext = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE ); + if ( ! wtext ) + return NULL; - /* Print path */ - printf ( "%ls", text ); + /* Store path in buffer */ + snprintf ( text, sizeof ( text ), "%ls", wtext ); /* Free path */ - bs->FreePool ( text ); + bs->FreePool ( wtext ); - return; - - err_convert: - err_no_efidpt: - printf ( ":\n" ); - end = efi_devpath_end ( path ); - len = ( ( ( void * ) end ) - ( ( void * ) path ) + - sizeof ( *end ) ); - dbg_hex_dump_da ( 0, path, len ); + return text; +} + +/** + * Get textual representation of device path for a handle + * + * @v handle EFI handle + * @ret text Textual representation of device path, or NULL + */ +const char * efi_handle_devpath_text ( EFI_HANDLE handle ) { + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + union { + EFI_DEVICE_PATH_PROTOCOL *path; + void *interface; + } path; + const char *text; + EFI_STATUS efirc; + + /* Obtain device path, if any */ + if ( ( efirc = bs->OpenProtocol ( handle, + &efi_device_path_protocol_guid, + &path.interface, efi_image_handle, + handle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ + return NULL; + } + + /* Format device path */ + text = efi_devpath_text ( path.path ); + + /* Close device path */ + bs->CloseProtocol ( handle, &efi_device_path_protocol_guid, + efi_image_handle, handle ); + + return text; }